CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. cmake_minimum_required(VERSION 3.8)
  2. if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.12)
  3. cmake_policy(SET CMP0074 NEW)
  4. endif()
  5. set(ROTOR_VERSION "0.24")
  6. project (rotor LANGUAGES CXX VERSION ${ROTOR_VERSION})
  7. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
  8. if (NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET AND
  9. NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN)
  10. set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  11. set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
  12. endif ()
  13. include(CMakePrintHelpers)
  14. option(BUILD_BOOST_ASIO "Enable building with boost::asio support [default: OFF]" OFF)
  15. option(BUILD_WX "Enable building with wxWidgets support [default: OFF]" OFF)
  16. option(BUILD_EV "Enable building with libev support [default: OFF]" OFF)
  17. option(BUILD_THREAD "Enable building with thread support [default: ON]" ON)
  18. option(BUILD_EXAMPLES "Enable building examples [default: OFF]" OFF)
  19. option(BUILD_DOC "Enable building documentation [default: OFF]" OFF)
  20. option(BUILD_THREAD_UNSAFE "Enable building thead-unsafe library [default: OFF]" OFF)
  21. option(ROTOR_DEBUG_DELIVERY "Enable runtime messages debuging [default: OFF]" OFF)
  22. find_package(Boost COMPONENTS
  23. date_time
  24. system
  25. regex
  26. REQUIRED)
  27. include(GenerateExportHeader)
  28. if (DEFINED rotor_SHARED_LIBS)
  29. set(BUILD_SHARED_LIBS "${rotor_SHARED_LIBS}")
  30. endif ()
  31. set(ROTOR_TARGETS_TO_INSTALL)
  32. set(ROTOR_HEADERS_TO_INSTALL)
  33. add_library(rotor
  34. src/rotor/actor_base.cpp
  35. src/rotor/address_mapping.cpp
  36. src/rotor/error_code.cpp
  37. src/rotor/extended_error.cpp
  38. src/rotor/handler.cpp
  39. src/rotor/message.cpp
  40. src/rotor/registry.cpp
  41. src/rotor/spawner.cpp
  42. src/rotor/subscription.cpp
  43. src/rotor/subscription_point.cpp
  44. src/rotor/supervisor.cpp
  45. src/rotor/system_context.cpp
  46. src/rotor/detail/child_info.cpp
  47. src/rotor/plugin/address_maker.cpp
  48. src/rotor/plugin/child_manager.cpp
  49. src/rotor/plugin/delivery.cpp
  50. src/rotor/plugin/foreigners_support.cpp
  51. src/rotor/plugin/init_shutdown.cpp
  52. src/rotor/plugin/lifetime.cpp
  53. src/rotor/plugin/link_client.cpp
  54. src/rotor/plugin/link_server.cpp
  55. src/rotor/plugin/locality.cpp
  56. src/rotor/plugin/plugin_base.cpp
  57. src/rotor/plugin/registry.cpp
  58. src/rotor/plugin/resources.cpp
  59. src/rotor/plugin/starter.cpp
  60. )
  61. generate_export_header(rotor
  62. EXPORT_MACRO_NAME ROTOR_API
  63. EXPORT_FILE_NAME include/rotor/export.h
  64. )
  65. target_include_directories(rotor
  66. PUBLIC
  67. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  68. $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
  69. $<INSTALL_INTERFACE:include>
  70. )
  71. target_link_libraries(rotor PUBLIC Boost::date_time Boost::system Boost::regex)
  72. if (BUILD_THREAD_UNSAFE)
  73. target_compile_definitions(rotor PUBLIC "ROTOR_REFCOUNT_THREADUNSAFE")
  74. endif()
  75. if (ROTOR_DEBUG_DELIVERY)
  76. list(APPEND ROTOR_PRIVATE_FLAGS ROTOR_DEBUG_DELIVERY)
  77. endif()
  78. if (WIN32)
  79. list(APPEND ROTOR_PRIVATE_FLAGS _CRT_SECURE_NO_WARNINGS)
  80. endif()
  81. target_compile_definitions(rotor
  82. PUBLIC "$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:ROTOR_STATIC_DEFINE>"
  83. PRIVATE ${ROTOR_PRIVATE_FLAGS}
  84. )
  85. target_compile_features(rotor PUBLIC cxx_std_17)
  86. set_target_properties(rotor PROPERTIES
  87. CXX_STANDARD 17
  88. CXX_STANDARD_REQUIRED YES
  89. CXX_EXTENSIONS NO
  90. )
  91. add_library(rotor::core ALIAS rotor)
  92. list(APPEND ROTOR_TARGETS_TO_INSTALL rotor)
  93. list(APPEND 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/messages.hpp
  107. include/rotor/plugin/address_maker.h
  108. include/rotor/plugin/child_manager.h
  109. include/rotor/plugin/delivery.h
  110. include/rotor/plugin/foreigners_support.h
  111. include/rotor/plugin/init_shutdown.h
  112. include/rotor/plugin/lifetime.h
  113. include/rotor/plugin/link_client.h
  114. include/rotor/plugin/link_server.h
  115. include/rotor/plugin/locality.h
  116. include/rotor/plugin/plugin_base.h
  117. include/rotor/plugin/registry.h
  118. include/rotor/plugin/resources.h
  119. include/rotor/plugin/starter.h
  120. include/rotor/plugins.h
  121. include/rotor/policy.h
  122. include/rotor/registry.h
  123. include/rotor/request.hpp
  124. include/rotor/spawner.h
  125. include/rotor/state.h
  126. include/rotor/subscription.h
  127. include/rotor/subscription_point.h
  128. include/rotor/supervisor.h
  129. include/rotor/supervisor_config.h
  130. include/rotor/system_context.h
  131. include/rotor/timer_handler.hpp
  132. )
  133. if (BUILD_BOOST_ASIO)
  134. find_package(Threads)
  135. add_library(rotor_asio
  136. src/rotor/asio/supervisor_asio.cpp
  137. )
  138. generate_export_header(rotor_asio
  139. EXPORT_MACRO_NAME ROTOR_ASIO_API
  140. EXPORT_FILE_NAME include/rotor/asio/export.h
  141. )
  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. list(APPEND ROTOR_TARGETS_TO_INSTALL rotor_asio)
  152. list(APPEND ROTOR_HEADERS_TO_INSTALL
  153. include/rotor/asio.hpp
  154. include/rotor/asio/forwarder.hpp
  155. include/rotor/asio/supervisor_asio.h
  156. include/rotor/asio/supervisor_config_asio.h
  157. include/rotor/asio/system_context_asio.h
  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. src/rotor/wx/supervisor_wx.cpp
  167. src/rotor/wx/system_context_wx.cpp
  168. )
  169. generate_export_header(rotor_wx
  170. EXPORT_MACRO_NAME ROTOR_WX_API
  171. EXPORT_FILE_NAME include/rotor/wx/export.h
  172. )
  173. target_link_libraries(rotor_wx PUBLIC rotor ${wxWidgets_LIBRARIES})
  174. add_library(rotor::wx ALIAS rotor_wx)
  175. list(APPEND ROTOR_TARGETS_TO_INSTALL rotor_wx)
  176. list(APPEND ROTOR_HEADERS_TO_INSTALL
  177. include/rotor/wx.hpp
  178. include/rotor/wx/supervisor_config_wx.h
  179. include/rotor/wx/supervisor_wx.h
  180. include/rotor/wx/system_context_wx.h
  181. )
  182. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/rotor/wx/export.h
  183. DESTINATION include/rotor/wx)
  184. endif()
  185. if (BUILD_EV)
  186. find_package(Libev REQUIRED)
  187. add_library(rotor_ev
  188. src/rotor/ev/supervisor_ev.cpp
  189. src/rotor/ev/system_context_ev.cpp
  190. )
  191. generate_export_header(rotor_ev
  192. EXPORT_MACRO_NAME ROTOR_EV_API
  193. EXPORT_FILE_NAME include/rotor/ev/export.h
  194. )
  195. target_include_directories(rotor_ev PUBLIC ${LIBEV_INCLUDE_DIRS})
  196. target_link_libraries(rotor_ev PUBLIC rotor ${LIBEV_LIBRARY})
  197. add_library(rotor::ev ALIAS rotor_ev)
  198. list(APPEND ROTOR_TARGETS_TO_INSTALL rotor_ev)
  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. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/rotor/ev/export.h
  206. DESTINATION include/rotor/ev)
  207. endif()
  208. if (BUILD_THREAD)
  209. find_package(Threads REQUIRED)
  210. add_library(rotor_thread
  211. src/rotor/thread/supervisor_thread.cpp
  212. src/rotor/thread/system_context_thread.cpp
  213. )
  214. generate_export_header(rotor_thread
  215. EXPORT_MACRO_NAME ROTOR_THREAD_API
  216. EXPORT_FILE_NAME include/rotor/thread/export.h
  217. )
  218. target_link_libraries(rotor_thread PUBLIC rotor Threads::Threads)
  219. add_library(rotor::thread ALIAS rotor_thread)
  220. list(APPEND ROTOR_TARGETS_TO_INSTALL rotor_thread)
  221. list(APPEND ROTOR_HEADERS_TO_INSTALL
  222. include/rotor/thread.hpp
  223. include/rotor/thread/supervisor_thread.h
  224. include/rotor/thread/system_context_thread.h
  225. )
  226. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/rotor/thread/export.h
  227. DESTINATION include/rotor/thread)
  228. endif()
  229. if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
  230. include(CTest)
  231. if (BUILD_TESTING)
  232. add_subdirectory("tests")
  233. endif()
  234. endif()
  235. if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_EXAMPLES)
  236. add_subdirectory("examples")
  237. endif()
  238. if(BUILD_DOC)
  239. find_package(Doxygen)
  240. if (DOXYGEN_FOUND)
  241. if (CMAKE_BUILD_TYPE MATCHES "^[Rr]elease")
  242. set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
  243. set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
  244. configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
  245. add_custom_target( doc_doxygen ALL
  246. COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
  247. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  248. COMMENT "Generating API documentation with Doxygen"
  249. VERBATIM)
  250. endif()
  251. file(GLOB DOC_IMAGES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/docs/*.png)
  252. file(COPY ${DOC_IMAGES} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/doxygen)
  253. else()
  254. message("Doxygen need to be installed to generate the doxygen documentation")
  255. endif()
  256. endif()
  257. set(ROTOR_CMAKE_FILES_DEST "lib/cmake/rotor")
  258. install(
  259. TARGETS ${ROTOR_TARGETS_TO_INSTALL}
  260. EXPORT ROTOR_ALL_TARGETS
  261. LIBRARY DESTINATION lib
  262. ARCHIVE DESTINATION lib
  263. RUNTIME DESTINATION bin
  264. )
  265. foreach( HEADER_FILE ${ROTOR_HEADERS_TO_INSTALL} )
  266. get_filename_component( DIR ${HEADER_FILE} PATH )
  267. install( FILES ${HEADER_FILE} DESTINATION ${DIR} )
  268. endforeach()
  269. install(FILES
  270. ${CMAKE_CURRENT_BINARY_DIR}/include/rotor/export.h
  271. DESTINATION include/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. include(CMakePackageConfigHelpers)
  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. )