CMakeLists.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. cmake_minimum_required(VERSION 3.15)
  2. cmake_policy(SET CMP0074 NEW)
  3. set(ROTOR_VERSION "0.34")
  4. project (rotor LANGUAGES CXX VERSION ${ROTOR_VERSION})
  5. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
  6. if (NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET AND
  7. NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN)
  8. set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  9. set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
  10. endif ()
  11. include(CMakePrintHelpers)
  12. include(GNUInstallDirs)
  13. include(GenerateExportHeader)
  14. include(CMakePackageConfigHelpers)
  15. option(ROTOR_BUILD_ASIO "Enable building with boost::asio support [default: OFF]" OFF)
  16. option(ROTOR_BUILD_WX "Enable building with wxWidgets support [default: OFF]" OFF)
  17. option(ROTOR_BUILD_EV "Enable building with libev support [default: OFF]" OFF)
  18. option(ROTOR_BUILD_FLTK "Enable building with fltk support [default: OFF]" OFF)
  19. option(ROTOR_BUILD_THREAD "Enable building with thread support [default: ON]" ON)
  20. option(ROTOR_BUILD_EXAMPLES "Enable building examples [default: OFF]" OFF)
  21. option(ROTOR_BUILD_DOC "Enable building documentation [default: OFF]" OFF)
  22. option(ROTOR_BUILD_TESTS "Enable building tests library [default: OFF]" OFF)
  23. option(ROTOR_BUILD_THREAD_UNSAFE "Enable building thread-unsafe library [default: OFF]" OFF)
  24. option(ROTOR_DEBUG_DELIVERY "Enable runtime messages debugging [default: OFF]" OFF)
  25. # output binaries to bin/lin
  26. foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
  27. string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
  28. set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/lib )
  29. set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/lib )
  30. set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/bin )
  31. endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )
  32. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
  33. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
  34. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  35. find_package(Boost COMPONENTS
  36. date_time
  37. system
  38. regex
  39. REQUIRED)
  40. if (BUILD_SHARED_LIBS)
  41. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin)
  42. endif ()
  43. add_library(rotor)
  44. file(GLOB CORE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/rotor/*.cpp")
  45. file(GLOB DETAIL_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/rotor/detail/*.cpp")
  46. file(GLOB PLUGIN_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/rotor/plugin/*.cpp")
  47. file(GLOB MISC_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/rotor/misc/*.cpp")
  48. target_sources(rotor PRIVATE
  49. ${CORE_SOURCES}
  50. ${DETAIL_SOURCES}
  51. ${PLUGIN_SOURCES}
  52. ${MISC_SOURCES}
  53. )
  54. generate_export_header(rotor
  55. EXPORT_MACRO_NAME ROTOR_API
  56. EXPORT_FILE_NAME include/rotor/export.h
  57. )
  58. target_include_directories(rotor
  59. PUBLIC
  60. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  61. $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
  62. $<INSTALL_INTERFACE:include>
  63. )
  64. target_link_libraries(rotor PUBLIC Boost::date_time Boost::system Boost::regex)
  65. if (ROTOR_BUILD_THREAD_UNSAFE)
  66. target_compile_definitions(rotor PUBLIC "ROTOR_REFCOUNT_THREADUNSAFE")
  67. endif()
  68. if (ROTOR_DEBUG_DELIVERY)
  69. list(APPEND ROTOR_PRIVATE_FLAGS ROTOR_DEBUG_DELIVERY)
  70. endif()
  71. if (WIN32)
  72. list(APPEND ROTOR_PRIVATE_FLAGS _CRT_SECURE_NO_WARNINGS)
  73. endif()
  74. target_compile_definitions(rotor
  75. PUBLIC "$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:ROTOR_STATIC_DEFINE>"
  76. PRIVATE ${ROTOR_PRIVATE_FLAGS}
  77. )
  78. target_compile_features(rotor PUBLIC cxx_std_17)
  79. set_target_properties(rotor PROPERTIES
  80. CXX_STANDARD 17
  81. CXX_STANDARD_REQUIRED YES
  82. CXX_EXTENSIONS NO
  83. )
  84. add_library(rotor::core ALIAS rotor)
  85. list(APPEND ROTOR_TARGETS_TO_INSTALL rotor)
  86. install(
  87. TARGETS rotor
  88. EXPORT ROTOR_ALL_TARGETS
  89. LIBRARY DESTINATION lib
  90. ARCHIVE DESTINATION lib
  91. RUNTIME DESTINATION bin
  92. )
  93. set(ROTOR_HEADERS_TO_INSTALL
  94. include/rotor.hpp
  95. include/rotor/actor_base.h
  96. include/rotor/actor_config.h
  97. include/rotor/address.hpp
  98. include/rotor/address_mapping.h
  99. include/rotor/arc.hpp
  100. include/rotor/detail/child_info.h
  101. include/rotor/error_code.h
  102. include/rotor/extended_error.h
  103. include/rotor/forward.hpp
  104. include/rotor/handler.h
  105. include/rotor/message.h
  106. include/rotor/message_stringifier.h
  107. include/rotor/messages.hpp
  108. include/rotor/misc/default_stringifier.h
  109. include/rotor/plugin/address_maker.h
  110. include/rotor/plugin/child_manager.h
  111. include/rotor/plugin/delivery.h
  112. include/rotor/plugin/foreigners_support.h
  113. include/rotor/plugin/init_shutdown.h
  114. include/rotor/plugin/lifetime.h
  115. include/rotor/plugin/link_client.h
  116. include/rotor/plugin/link_server.h
  117. include/rotor/plugin/locality.h
  118. include/rotor/plugin/plugin_base.h
  119. include/rotor/plugin/registry.h
  120. include/rotor/plugin/resources.h
  121. include/rotor/plugin/starter.h
  122. include/rotor/plugins.h
  123. include/rotor/policy.h
  124. include/rotor/registry.h
  125. include/rotor/request.hpp
  126. include/rotor/spawner.h
  127. include/rotor/state.h
  128. include/rotor/subscription.h
  129. include/rotor/subscription_point.h
  130. include/rotor/supervisor.h
  131. include/rotor/supervisor_config.h
  132. include/rotor/system_context.h
  133. include/rotor/timer_handler.hpp
  134. )
  135. install(FILES
  136. ${CMAKE_CURRENT_BINARY_DIR}/include/rotor/export.h
  137. DESTINATION include/rotor)
  138. if (ROTOR_BUILD_ASIO)
  139. find_package(Threads)
  140. add_library(rotor_asio)
  141. file(GLOB ASIO_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/rotor/asio/*.cpp")
  142. file(GLOB ASIO_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/rotor/asio/*.h*")
  143. generate_export_header(rotor_asio
  144. EXPORT_MACRO_NAME ROTOR_ASIO_API
  145. EXPORT_FILE_NAME include/rotor/asio/export.h
  146. )
  147. list(APPEND ROTOR_HEADERS_TO_INSTALL
  148. include/rotor/asio.hpp
  149. include/rotor/asio/forwarder.hpp
  150. include/rotor/asio/supervisor_asio.h
  151. include/rotor/asio/supervisor_config_asio.h
  152. include/rotor/asio/system_context_asio.h
  153. )
  154. target_sources(rotor_asio PRIVATE src/rotor/asio/supervisor_asio.cpp)
  155. if (WIN32)
  156. list(APPEND ROTOR_ASIO_PRIVATE_FLAGS
  157. _SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING
  158. _WIN32_WINNT=0x600
  159. )
  160. endif()
  161. target_compile_definitions(rotor_asio PRIVATE ${ROTOR_ASIO_PRIVATE_FLAGS})
  162. target_link_libraries(rotor_asio
  163. PUBLIC
  164. rotor
  165. Threads::Threads
  166. $<$<PLATFORM_ID:Windows>:ws2_32>
  167. )
  168. add_library(rotor::asio ALIAS rotor_asio)
  169. install(
  170. TARGETS rotor_asio
  171. EXPORT ROTOR_ALL_TARGETS
  172. LIBRARY DESTINATION lib
  173. ARCHIVE DESTINATION lib
  174. RUNTIME DESTINATION bin
  175. )
  176. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/rotor/asio/export.h
  177. DESTINATION include/rotor/asio)
  178. endif()
  179. if (ROTOR_BUILD_WX)
  180. find_package(wxWidgets COMPONENTS base REQUIRED)
  181. if (${wxWidgets_USE_FILE})
  182. include(${wxWidgets_USE_FILE})
  183. endif()
  184. add_library(rotor_wx)
  185. file(GLOB WX_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/rotor/wx/*.cpp")
  186. file(GLOB WX_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/rotor/wx/*.h*")
  187. generate_export_header(rotor_wx
  188. EXPORT_MACRO_NAME ROTOR_WX_API
  189. EXPORT_FILE_NAME include/rotor/wx/export.h
  190. )
  191. list(APPEND ROTOR_HEADERS_TO_INSTALL
  192. include/rotor/wx.hpp
  193. include/rotor/wx/supervisor_config_wx.h
  194. include/rotor/wx/supervisor_wx.h
  195. include/rotor/wx/system_context_wx.h
  196. )
  197. target_sources(rotor_wx PRIVATE ${WX_SOURCES})
  198. target_link_libraries(rotor_wx PUBLIC rotor ${wxWidgets_LIBRARIES})
  199. add_library(rotor::wx ALIAS rotor_wx)
  200. install(
  201. TARGETS rotor_wx
  202. EXPORT ROTOR_ALL_TARGETS
  203. LIBRARY DESTINATION lib
  204. ARCHIVE DESTINATION lib
  205. RUNTIME DESTINATION bin
  206. )
  207. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/rotor/wx/export.h
  208. DESTINATION include/rotor/wx)
  209. endif()
  210. if (ROTOR_BUILD_EV)
  211. find_package(Libev REQUIRED)
  212. add_library(rotor_ev)
  213. file(GLOB EV_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/rotor/ev/*.cpp")
  214. generate_export_header(rotor_ev
  215. EXPORT_MACRO_NAME ROTOR_EV_API
  216. EXPORT_FILE_NAME include/rotor/ev/export.h
  217. )
  218. list(APPEND ROTOR_HEADERS_TO_INSTALL
  219. include/rotor/ev.hpp
  220. include/rotor/ev/supervisor_config_ev.h
  221. include/rotor/ev/supervisor_ev.h
  222. include/rotor/ev/system_context_ev.h
  223. )
  224. target_sources(rotor_ev PRIVATE ${EV_SOURCES})
  225. target_include_directories(rotor_ev PUBLIC ${LIBEV_INCLUDE_DIRS})
  226. target_link_libraries(rotor_ev PUBLIC rotor libev::libev)
  227. add_library(rotor::ev ALIAS rotor_ev)
  228. install(
  229. TARGETS rotor_ev
  230. EXPORT ROTOR_ALL_TARGETS
  231. LIBRARY DESTINATION lib
  232. ARCHIVE DESTINATION lib
  233. RUNTIME DESTINATION bin
  234. )
  235. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/rotor/ev/export.h
  236. DESTINATION include/rotor/ev)
  237. endif()
  238. if (ROTOR_BUILD_FLTK)
  239. find_package(fltk REQUIRED)
  240. add_library(rotor_fltk)
  241. file(GLOB FLTK_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/rotor/fltk/*.cpp")
  242. generate_export_header(rotor_fltk
  243. EXPORT_MACRO_NAME ROTOR_FLTK_API
  244. EXPORT_FILE_NAME include/rotor/fltk/export.h
  245. )
  246. list(APPEND ROTOR_HEADERS_TO_INSTALL
  247. include/rotor/fltk.hpp
  248. include/rotor/fltk/supervisor_config_fltk.h
  249. include/rotor/fltk/supervisor_fltk.h
  250. include/rotor/fltk/system_context_fltk.h
  251. )
  252. target_sources(rotor_fltk PRIVATE ${FLTK_SOURCES})
  253. target_link_libraries(rotor_fltk PUBLIC rotor fltk::fltk)
  254. add_library(rotor::fltk ALIAS rotor_fltk)
  255. install(
  256. TARGETS rotor_fltk
  257. EXPORT ROTOR_ALL_TARGETS
  258. LIBRARY DESTINATION lib
  259. ARCHIVE DESTINATION lib
  260. RUNTIME DESTINATION bin
  261. )
  262. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/rotor/fltk/export.h
  263. DESTINATION include/rotor/fltk)
  264. endif()
  265. if (ROTOR_BUILD_THREAD)
  266. find_package(Threads REQUIRED)
  267. add_library(rotor_thread)
  268. file(GLOB THREAD_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/rotor/thread/*.cpp")
  269. generate_export_header(rotor_thread
  270. EXPORT_MACRO_NAME ROTOR_THREAD_API
  271. EXPORT_FILE_NAME include/rotor/thread/export.h
  272. )
  273. list(APPEND ROTOR_HEADERS_TO_INSTALL
  274. include/rotor/thread.hpp
  275. include/rotor/thread/supervisor_thread.h
  276. include/rotor/thread/system_context_thread.h
  277. include/rotor/timer_handler.hpp
  278. )
  279. target_sources(rotor_thread PRIVATE ${THREAD_SOURCES})
  280. target_link_libraries(rotor_thread PUBLIC rotor Threads::Threads)
  281. add_library(rotor::thread ALIAS rotor_thread)
  282. install(
  283. TARGETS rotor_thread
  284. EXPORT ROTOR_ALL_TARGETS
  285. LIBRARY DESTINATION lib
  286. ARCHIVE DESTINATION lib
  287. RUNTIME DESTINATION bin
  288. )
  289. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/rotor/thread/export.h
  290. DESTINATION include/rotor/thread)
  291. endif()
  292. if (ROTOR_BUILD_TESTS)
  293. enable_testing()
  294. add_subdirectory("tests")
  295. endif()
  296. if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND ROTOR_BUILD_EXAMPLES)
  297. add_subdirectory("examples")
  298. endif()
  299. if(ROTOR_BUILD_DOC)
  300. find_package(Doxygen)
  301. if (DOXYGEN_FOUND)
  302. if (CMAKE_BUILD_TYPE MATCHES "^[Rr]elease")
  303. set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
  304. set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
  305. configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
  306. add_custom_target( doc_doxygen ALL
  307. COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
  308. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  309. COMMENT "Generating API documentation with Doxygen"
  310. VERBATIM)
  311. endif()
  312. file(GLOB DOC_IMAGES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/docs/*.png)
  313. file(COPY ${DOC_IMAGES} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/doxygen)
  314. else()
  315. message("Doxygen need to be installed to generate the doxygen documentation")
  316. endif()
  317. endif()
  318. set(ROTOR_CMAKE_FILES_DEST "lib/cmake/rotor")
  319. if (BUILD_SHARED_LIBS)
  320. set(type shared)
  321. message(STATUS "going to build shared library/libraries")
  322. else ()
  323. set(type static)
  324. endif ()
  325. install(
  326. EXPORT ROTOR_ALL_TARGETS
  327. FILE rotor-${type}-targets.cmake
  328. NAMESPACE rotor::
  329. DESTINATION ${ROTOR_CMAKE_FILES_DEST}
  330. )
  331. set(ROTOR_CONFIG_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/rotor-config-version.cmake")
  332. set(ROTOR_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/rotor-config.cmake")
  333. write_basic_package_version_file(
  334. ${ROTOR_CONFIG_VERSION_FILE}
  335. VERSION ${ROTOR_VERSION}
  336. COMPATIBILITY ExactVersion
  337. )
  338. configure_package_config_file(
  339. "${CMAKE_CURRENT_LIST_DIR}/cmake/rotor-config.cmake.in"
  340. ${ROTOR_CONFIG_FILE}
  341. INSTALL_DESTINATION ${ROTOR_CMAKE_FILES_DEST}
  342. PATH_VARS ROTOR_VERSION
  343. )
  344. install(
  345. FILES ${ROTOR_CONFIG_FILE} ${ROTOR_CONFIG_VERSION_FILE}
  346. DESTINATION ${ROTOR_CMAKE_FILES_DEST}
  347. )
  348. foreach( HEADER_FILE ${ROTOR_HEADERS_TO_INSTALL} )
  349. get_filename_component( DIR ${HEADER_FILE} PATH )
  350. install( FILES ${HEADER_FILE} DESTINATION ${DIR} )
  351. endforeach()