CMakeLists.txt 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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.21")
  6. project (rotor LANGUAGES CXX VERSION ${ROTOR_VERSION})
  7. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
  8. include(CMakePrintHelpers)
  9. option(BUILD_BOOST_ASIO "Enable building with boost::asio support [default: OFF]" OFF)
  10. option(BUILD_WX "Enable building with wxWidgets support [default: OFF]" OFF)
  11. option(BUILD_EV "Enable building with libev support [default: OFF]" OFF)
  12. option(BUILD_THREAD "Enable building with thread support [default: ON]" ON)
  13. option(BUILD_EXAMPLES "Enable building examples [default: OFF]" OFF)
  14. option(BUILD_DOC "Enable building documentation [default: OFF]" OFF)
  15. option(BUILD_THREAD_UNSAFE "Enable building thead-unsafe library [default: OFF]" OFF)
  16. option(ROTOR_DEBUG_DELIVERY "Enable runtime messages debuging [default: OFF]" OFF)
  17. find_package(Boost COMPONENTS
  18. date_time
  19. system
  20. regex
  21. REQUIRED)
  22. set(ROTOR_TARGETS_TO_INSTALL)
  23. set(ROTOR_HEADERS_TO_INSTALL)
  24. add_library(rotor
  25. src/rotor/actor_base.cpp
  26. src/rotor/address_mapping.cpp
  27. src/rotor/error_code.cpp
  28. src/rotor/extended_error.cpp
  29. src/rotor/handler.cpp
  30. src/rotor/registry.cpp
  31. src/rotor/spawner.cpp
  32. src/rotor/subscription.cpp
  33. src/rotor/subscription_point.cpp
  34. src/rotor/supervisor.cpp
  35. src/rotor/system_context.cpp
  36. src/rotor/detail/child_info.cpp
  37. src/rotor/plugin/address_maker.cpp
  38. src/rotor/plugin/child_manager.cpp
  39. src/rotor/plugin/delivery.cpp
  40. src/rotor/plugin/foreigners_support.cpp
  41. src/rotor/plugin/init_shutdown.cpp
  42. src/rotor/plugin/lifetime.cpp
  43. src/rotor/plugin/link_client.cpp
  44. src/rotor/plugin/link_server.cpp
  45. src/rotor/plugin/locality.cpp
  46. src/rotor/plugin/plugin_base.cpp
  47. src/rotor/plugin/registry.cpp
  48. src/rotor/plugin/resources.cpp
  49. src/rotor/plugin/starter.cpp
  50. )
  51. target_include_directories(rotor
  52. PUBLIC
  53. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  54. $<INSTALL_INTERFACE:include>
  55. )
  56. target_link_libraries(rotor PUBLIC Boost::date_time Boost::system Boost::regex)
  57. if (BUILD_THREAD_UNSAFE)
  58. target_compile_definitions(rotor PUBLIC "ROTOR_REFCOUNT_THREADUNSAFE")
  59. endif()
  60. if (ROTOR_DEBUG_DELIVERY)
  61. list(APPEND ROTOR_PRIVATE_FLAGS ROTOR_DEBUG_DELIVERY)
  62. endif()
  63. if (WIN32)
  64. list(APPEND ROTOR_PRIVATE_FLAGS _CRT_SECURE_NO_WARNINGS)
  65. endif()
  66. target_compile_definitions(rotor PRIVATE ${ROTOR_PRIVATE_FLAGS})
  67. target_compile_features(rotor PUBLIC cxx_std_17)
  68. set_target_properties(rotor PROPERTIES
  69. CXX_STANDARD 17
  70. CXX_STANDARD_REQUIRED YES
  71. CXX_EXTENSIONS NO
  72. )
  73. add_library(rotor::core ALIAS rotor)
  74. list(APPEND ROTOR_TARGETS_TO_INSTALL rotor)
  75. list(APPEND ROTOR_HEADERS_TO_INSTALL
  76. include/rotor.hpp
  77. include/rotor/actor_base.h
  78. include/rotor/actor_config.h
  79. include/rotor/address.hpp
  80. include/rotor/address_mapping.h
  81. include/rotor/arc.hpp
  82. include/rotor/detail/child_info.h
  83. include/rotor/error_code.h
  84. include/rotor/extended_error.h
  85. include/rotor/forward.hpp
  86. include/rotor/handler.h
  87. include/rotor/message.h
  88. include/rotor/messages.hpp
  89. include/rotor/plugin/address_maker.h
  90. include/rotor/plugin/child_manager.h
  91. include/rotor/plugin/delivery.h
  92. include/rotor/plugin/foreigners_support.h
  93. include/rotor/plugin/init_shutdown.h
  94. include/rotor/plugin/lifetime.h
  95. include/rotor/plugin/link_client.h
  96. include/rotor/plugin/link_server.h
  97. include/rotor/plugin/locality.h
  98. include/rotor/plugin/plugin_base.h
  99. include/rotor/plugin/registry.h
  100. include/rotor/plugin/resources.h
  101. include/rotor/plugin/starter.h
  102. include/rotor/plugins.h
  103. include/rotor/policy.h
  104. include/rotor/registry.h
  105. include/rotor/request.hpp
  106. include/rotor/spawner.h
  107. include/rotor/state.h
  108. include/rotor/subscription.h
  109. include/rotor/subscription_point.h
  110. include/rotor/supervisor.h
  111. include/rotor/supervisor_config.h
  112. include/rotor/system_context.h
  113. include/rotor/timer_handler.hpp
  114. )
  115. if (BUILD_BOOST_ASIO)
  116. find_package(Threads)
  117. add_library(rotor_asio
  118. src/rotor/asio/supervisor_asio.cpp
  119. )
  120. if (WIN32)
  121. list(APPEND ROTOR_ASIO_PRIVATE_FLAGS
  122. _SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING
  123. _WIN32_WINNT=0x600
  124. )
  125. endif()
  126. target_compile_definitions(rotor_asio PRIVATE ${ROTOR_ASIO_PRIVATE_FLAGS})
  127. target_link_libraries(rotor_asio PUBLIC rotor Threads::Threads)
  128. add_library(rotor::asio ALIAS rotor_asio)
  129. list(APPEND ROTOR_TARGETS_TO_INSTALL rotor_asio)
  130. list(APPEND ROTOR_HEADERS_TO_INSTALL
  131. include/rotor/asio.hpp
  132. include/rotor/asio/forwarder.hpp
  133. include/rotor/asio/supervisor_asio.h
  134. include/rotor/asio/supervisor_config_asio.h
  135. include/rotor/asio/system_context_asio.h
  136. )
  137. endif()
  138. if (BUILD_WX)
  139. find_package(wxWidgets COMPONENTS base REQUIRED)
  140. include(${wxWidgets_USE_FILE})
  141. add_library(rotor_wx
  142. src/rotor/wx/supervisor_wx.cpp
  143. src/rotor/wx/system_context_wx.cpp
  144. )
  145. target_link_libraries(rotor_wx PUBLIC rotor ${wxWidgets_LIBRARIES})
  146. add_library(rotor::wx ALIAS rotor_wx)
  147. list(APPEND ROTOR_TARGETS_TO_INSTALL rotor_wx)
  148. list(APPEND ROTOR_HEADERS_TO_INSTALL
  149. include/rotor/wx.hpp
  150. include/rotor/wx/supervisor_config_wx.h
  151. include/rotor/wx/supervisor_wx.h
  152. include/rotor/wx/system_context_wx.h
  153. )
  154. endif()
  155. if (BUILD_EV)
  156. find_package(Libev REQUIRED)
  157. add_library(rotor_ev
  158. src/rotor/ev/supervisor_ev.cpp
  159. src/rotor/ev/system_context_ev.cpp
  160. )
  161. target_include_directories(rotor_ev PUBLIC ${LIBEV_INCLUDE_DIRS})
  162. target_link_libraries(rotor_ev PUBLIC rotor ${LIBEV_LIBRARY})
  163. add_library(rotor::ev ALIAS rotor_ev)
  164. list(APPEND ROTOR_TARGETS_TO_INSTALL rotor_ev)
  165. list(APPEND ROTOR_HEADERS_TO_INSTALL
  166. include/rotor/ev.hpp
  167. include/rotor/ev/supervisor_config_ev.h
  168. include/rotor/ev/supervisor_ev.h
  169. include/rotor/ev/system_context_ev.h
  170. )
  171. endif()
  172. if (BUILD_THREAD)
  173. find_package(Threads REQUIRED)
  174. add_library(rotor_thread
  175. src/rotor/thread/supervisor_thread.cpp
  176. src/rotor/thread/system_context_thread.cpp
  177. )
  178. target_link_libraries(rotor_thread PUBLIC rotor Threads::Threads)
  179. add_library(rotor::thread ALIAS rotor_thread)
  180. list(APPEND ROTOR_TARGETS_TO_INSTALL rotor_thread)
  181. list(APPEND ROTOR_HEADERS_TO_INSTALL
  182. include/rotor/thread.hpp
  183. include/rotor/thread/supervisor_thread.h
  184. include/rotor/thread/system_context_thread.h
  185. )
  186. endif()
  187. if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
  188. include(CTest)
  189. if (BUILD_TESTING)
  190. add_subdirectory("tests")
  191. endif()
  192. endif()
  193. if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_EXAMPLES)
  194. add_subdirectory("examples")
  195. endif()
  196. if(BUILD_DOC)
  197. find_package(Doxygen)
  198. if (DOXYGEN_FOUND)
  199. if (CMAKE_BUILD_TYPE MATCHES "^[Rr]elease")
  200. set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
  201. set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
  202. configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
  203. add_custom_target( doc_doxygen ALL
  204. COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
  205. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  206. COMMENT "Generating API documentation with Doxygen"
  207. VERBATIM)
  208. endif()
  209. file(GLOB DOC_IMAGES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/docs/*.png)
  210. file(COPY ${DOC_IMAGES} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/doxygen)
  211. else()
  212. message("Doxygen need to be installed to generate the doxygen documentation")
  213. endif()
  214. endif()
  215. set(ROTOR_CMAKE_FILES_DEST "lib/cmake/rotor")
  216. install(
  217. TARGETS ${ROTOR_TARGETS_TO_INSTALL}
  218. EXPORT ROTOR_ALL_TARGETS
  219. LIBRARY DESTINATION lib
  220. ARCHIVE DESTINATION lib
  221. RUNTIME DESTINATION bin
  222. )
  223. foreach( HEADER_FILE ${ROTOR_HEADERS_TO_INSTALL} )
  224. get_filename_component( DIR ${HEADER_FILE} PATH )
  225. install( FILES ${HEADER_FILE} DESTINATION ${DIR} )
  226. endforeach()
  227. install(
  228. EXPORT ROTOR_ALL_TARGETS
  229. FILE rotor-targets.cmake
  230. NAMESPACE rotor::
  231. DESTINATION ${ROTOR_CMAKE_FILES_DEST}
  232. )
  233. set(ROTOR_CONFIG_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/rotor-config-version.cmake")
  234. set(ROTOR_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/rotor-config.cmake")
  235. include(CMakePackageConfigHelpers)
  236. write_basic_package_version_file(
  237. ${ROTOR_CONFIG_VERSION_FILE}
  238. VERSION ${ROTOR_VERSION}
  239. COMPATIBILITY ExactVersion
  240. )
  241. configure_package_config_file(
  242. "${CMAKE_CURRENT_LIST_DIR}/cmake/rotor-config.cmake.in"
  243. ${ROTOR_CONFIG_FILE}
  244. INSTALL_DESTINATION ${ROTOR_CMAKE_FILES_DEST}
  245. PATH_VARS ROTOR_VERSION
  246. )
  247. install(
  248. FILES ${ROTOR_CONFIG_FILE} ${ROTOR_CONFIG_VERSION_FILE}
  249. DESTINATION ${ROTOR_CMAKE_FILES_DEST}
  250. )