CMakeLists.txt 11 KB

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