CMakeLists.txt 13 KB

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