CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. cmake_minimum_required(VERSION 3.15)
  2. cmake_policy(SET CMP0074 NEW)
  3. set(ROTOR_VERSION "0.27")
  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. )
  122. install(FILES
  123. ${CMAKE_CURRENT_BINARY_DIR}/include/rotor/export.h
  124. DESTINATION include/rotor)
  125. if (BUILD_BOOST_ASIO)
  126. find_package(Threads)
  127. add_library(rotor_asio)
  128. file(GLOB ASIO_SOURCES "${CMAKE_SOURCE_DIR}/src/rotor/asio/*.cpp")
  129. file(GLOB ASIO_HEADERS "${CMAKE_SOURCE_DIR}/include/rotor/asio/*.h*")
  130. generate_export_header(rotor_asio
  131. EXPORT_MACRO_NAME ROTOR_ASIO_API
  132. EXPORT_FILE_NAME include/rotor/asio/export.h
  133. )
  134. list(APPEND ROTOR_HEADERS_TO_INSTALL
  135. include/rotor/asio.hpp
  136. include/rotor/asio/forwarder.hpp
  137. include/rotor/asio/supervisor_asio.h
  138. include/rotor/asio/supervisor_config_asio.h
  139. include/rotor/asio/system_context_asio.h
  140. )
  141. target_sources(rotor_asio PRIVATE src/rotor/asio/supervisor_asio.cpp)
  142. if (WIN32)
  143. list(APPEND ROTOR_ASIO_PRIVATE_FLAGS
  144. _SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING
  145. _WIN32_WINNT=0x600
  146. )
  147. endif()
  148. target_compile_definitions(rotor_asio PRIVATE ${ROTOR_ASIO_PRIVATE_FLAGS})
  149. target_link_libraries(rotor_asio PUBLIC rotor Threads::Threads)
  150. add_library(rotor::asio ALIAS rotor_asio)
  151. install(
  152. TARGETS rotor_asio
  153. EXPORT ROTOR_ALL_TARGETS
  154. LIBRARY DESTINATION lib
  155. ARCHIVE DESTINATION lib
  156. RUNTIME DESTINATION bin
  157. )
  158. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/rotor/asio/export.h
  159. DESTINATION include/rotor/asio)
  160. endif()
  161. if (BUILD_WX)
  162. find_package(wxWidgets COMPONENTS base REQUIRED)
  163. include(${wxWidgets_USE_FILE})
  164. add_library(rotor_wx)
  165. file(GLOB WX_SOURCES "${CMAKE_SOURCE_DIR}/src/rotor/wx/*.cpp")
  166. file(GLOB WX_HEADERS "${CMAKE_SOURCE_DIR}/include/rotor/wx/*.h*")
  167. generate_export_header(rotor_wx
  168. EXPORT_MACRO_NAME ROTOR_WX_API
  169. EXPORT_FILE_NAME include/rotor/wx/export.h
  170. )
  171. list(APPEND ROTOR_HEADERS_TO_INSTALL
  172. include/rotor/wx.hpp
  173. include/rotor/wx/supervisor_config_wx.h
  174. include/rotor/wx/supervisor_wx.h
  175. include/rotor/wx/system_context_wx.h
  176. )
  177. target_sources(rotor_wx PRIVATE ${WX_SOURCES})
  178. target_link_libraries(rotor_wx PUBLIC rotor ${wxWidgets_LIBRARIES})
  179. add_library(rotor::wx ALIAS rotor_wx)
  180. install(
  181. TARGETS rotor_wx
  182. EXPORT ROTOR_ALL_TARGETS
  183. LIBRARY DESTINATION lib
  184. ARCHIVE DESTINATION lib
  185. RUNTIME DESTINATION bin
  186. )
  187. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/rotor/wx/export.h
  188. DESTINATION include/rotor/wx)
  189. endif()
  190. if (BUILD_EV)
  191. find_package(Libev REQUIRED)
  192. add_library(rotor_ev)
  193. file(GLOB EV_SOURCES "${CMAKE_SOURCE_DIR}/src/rotor/ev/*.cpp")
  194. generate_export_header(rotor_ev
  195. EXPORT_MACRO_NAME ROTOR_EV_API
  196. EXPORT_FILE_NAME include/rotor/ev/export.h
  197. )
  198. list(APPEND ROTOR_HEADERS_TO_INSTALL
  199. include/rotor/ev.hpp
  200. include/rotor/ev/supervisor_config_ev.h
  201. include/rotor/ev/supervisor_ev.h
  202. include/rotor/ev/system_context_ev.h
  203. )
  204. target_sources(rotor_ev PRIVATE ${EV_SOURCES})
  205. target_include_directories(rotor_ev PUBLIC ${LIBEV_INCLUDE_DIRS})
  206. target_link_libraries(rotor_ev PUBLIC rotor libev::libev)
  207. add_library(rotor::ev ALIAS rotor_ev)
  208. install(
  209. TARGETS rotor_ev
  210. EXPORT ROTOR_ALL_TARGETS
  211. LIBRARY DESTINATION lib
  212. ARCHIVE DESTINATION lib
  213. RUNTIME DESTINATION bin
  214. )
  215. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/rotor/ev/export.h
  216. DESTINATION include/rotor/ev)
  217. endif()
  218. if (BUILD_THREAD)
  219. find_package(Threads REQUIRED)
  220. add_library(rotor_thread)
  221. file(GLOB THREAD_SOURCES "${CMAKE_SOURCE_DIR}/src/rotor/thread/*.cpp")
  222. generate_export_header(rotor_thread
  223. EXPORT_MACRO_NAME ROTOR_THREAD_API
  224. EXPORT_FILE_NAME include/rotor/thread/export.h
  225. )
  226. list(APPEND ROTOR_HEADERS_TO_INSTALL
  227. include/rotor/thread.hpp
  228. include/rotor/thread/supervisor_thread.h
  229. include/rotor/thread/system_context_thread.h
  230. include/rotor/timer_handler.hpp
  231. )
  232. target_sources(rotor_thread PRIVATE ${THREAD_SOURCES})
  233. target_link_libraries(rotor_thread PUBLIC rotor Threads::Threads)
  234. add_library(rotor::thread ALIAS rotor_thread)
  235. install(
  236. TARGETS rotor_thread
  237. EXPORT ROTOR_ALL_TARGETS
  238. LIBRARY DESTINATION lib
  239. ARCHIVE DESTINATION lib
  240. RUNTIME DESTINATION bin
  241. )
  242. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/rotor/thread/export.h
  243. DESTINATION include/rotor/thread)
  244. endif()
  245. if (NOT BUILD_TESTING STREQUAL OFF)
  246. enable_testing()
  247. add_subdirectory("tests")
  248. endif()
  249. if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_EXAMPLES)
  250. add_subdirectory("examples")
  251. endif()
  252. if(BUILD_DOC)
  253. find_package(Doxygen)
  254. if (DOXYGEN_FOUND)
  255. if (CMAKE_BUILD_TYPE MATCHES "^[Rr]elease")
  256. set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
  257. set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
  258. configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
  259. add_custom_target( doc_doxygen ALL
  260. COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
  261. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  262. COMMENT "Generating API documentation with Doxygen"
  263. VERBATIM)
  264. endif()
  265. file(GLOB DOC_IMAGES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/docs/*.png)
  266. file(COPY ${DOC_IMAGES} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/doxygen)
  267. else()
  268. message("Doxygen need to be installed to generate the doxygen documentation")
  269. endif()
  270. endif()
  271. set(ROTOR_CMAKE_FILES_DEST "lib/cmake/rotor")
  272. if (BUILD_SHARED_LIBS)
  273. set(type shared)
  274. message(STATUS "going to build shared library/libraries")
  275. else ()
  276. set(type static)
  277. endif ()
  278. install(
  279. EXPORT ROTOR_ALL_TARGETS
  280. FILE rotor-${type}-targets.cmake
  281. NAMESPACE rotor::
  282. DESTINATION ${ROTOR_CMAKE_FILES_DEST}
  283. )
  284. set(ROTOR_CONFIG_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/rotor-config-version.cmake")
  285. set(ROTOR_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/rotor-config.cmake")
  286. write_basic_package_version_file(
  287. ${ROTOR_CONFIG_VERSION_FILE}
  288. VERSION ${ROTOR_VERSION}
  289. COMPATIBILITY ExactVersion
  290. )
  291. configure_package_config_file(
  292. "${CMAKE_CURRENT_LIST_DIR}/cmake/rotor-config.cmake.in"
  293. ${ROTOR_CONFIG_FILE}
  294. INSTALL_DESTINATION ${ROTOR_CMAKE_FILES_DEST}
  295. PATH_VARS ROTOR_VERSION
  296. )
  297. install(
  298. FILES ${ROTOR_CONFIG_FILE} ${ROTOR_CONFIG_VERSION_FILE}
  299. DESTINATION ${ROTOR_CMAKE_FILES_DEST}
  300. )
  301. foreach( HEADER_FILE ${ROTOR_HEADERS_TO_INSTALL} )
  302. get_filename_component( DIR ${HEADER_FILE} PATH )
  303. install( FILES ${HEADER_FILE} DESTINATION ${DIR} )
  304. endforeach()