CMakeLists.txt 8.5 KB

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