From f26c5f5b3cb0b58f747533ef3f9571e68fac99c6 Mon Sep 17 00:00:00 2001 From: Yauheni Akhotnikau Date: Fri, 12 Jan 2024 16:49:53 +0300 Subject: [PATCH] A first attempt to fix #207. --- dev/CMakeLists.txt | 28 +++++++++++++++++-- .../single_handler_so5_timer/CMakeLists.txt | 6 +++- .../async_chained_handlers/CMakeLists.txt | 6 +++- .../CMakeLists.txt | 6 +++- dev/sample/notificators/CMakeLists.txt | 6 +++- .../async_chained_handlers_2/CMakeLists.txt | 6 +++- .../websocket/notificators/CMakeLists.txt | 6 +++- .../websocket/ws_connection/CMakeLists.txt | 6 +++- 8 files changed, 61 insertions(+), 9 deletions(-) diff --git a/dev/CMakeLists.txt b/dev/CMakeLists.txt index 194dabee..7decbe67 100644 --- a/dev/CMakeLists.txt +++ b/dev/CMakeLists.txt @@ -106,12 +106,18 @@ set_property(CACHE RESTINIO_DEP_EXPECTED_LITE PROPERTY STRINGS "system;find;loca set(RESTINIO_DEP_CATCH2 "local" CACHE STRING "How to get Catch2 dependency)") set_property(CACHE RESTINIO_DEP_CATCH2 PROPERTY STRINGS "find;local") +# By default we assume to use an embedded version of SObjectizer. +set(RESTINIO_DEP_SOBJECTIZER "local" CACHE STRING "How to get SObjectizer dependency)") +set_property(CACHE RESTINIO_DEP_SOBJECTIZER PROPERTY STRINGS "system;find;local") + + message(STATUS "RESTINIO_DEP_STANDALONE_ASIO: ${RESTINIO_DEP_STANDALONE_ASIO}") message(STATUS "RESTINIO_DEP_BOOST_ASIO: ${RESTINIO_DEP_BOOST_ASIO}") message(STATUS "RESTINIO_DEP_LLHTTP: ${RESTINIO_DEP_LLHTTP}") message(STATUS "RESTINIO_DEP_FMT: ${RESTINIO_DEP_FMT}") message(STATUS "RESTINIO_DEP_EXPECTED_LITE: ${RESTINIO_DEP_EXPECTED_LITE}") message(STATUS "RESTINIO_DEP_CATCH2: ${RESTINIO_DEP_CATCH2}") +message(STATUS "RESTINIO_DEP_SOBJECTIZER: ${RESTINIO_DEP_SOBJECTIZER}") set(RESTINIO_ASIO_SOURCE "standalone" CACHE STRING "What source of ASIO to use (standalone, boost)") set(RESTINIO_ASIO_SOURCE_VALUES "standalone;boost") @@ -194,8 +200,24 @@ endif () if (RESTINIO_WITH_SOBJECTIZER) message("========================================") - SET(SOBJECTIZER_BUILD_STATIC ON) - add_subdirectory(so_5) + if (RESTINIO_DEP_SOBJECTIZER STREQUAL "local") + message(STATUS "Add subdirectory so_5") + SET(SOBJECTIZER_BUILD_STATIC ON) + add_subdirectory(so_5) + + set(RESTINIO_SOBJECTIZER_LIB_LINK_NAME "sobjectizer::StaticLib") + elseif (RESTINIO_DEP_SOBJECTIZER STREQUAL "find") + find_package(sobjectizer CONFIG REQUIRED) + + set(RESTINIO_SOBJECTIZER_LIB_LINK_NAME "sobjectizer::StaticLib") + elseif (RESTINIO_DEP_SOBJECTIZER STREQUAL "system") + if (NOT RESTINIO_SOBJECTIZER_LIB_LINK_NAME) + message(FATAL_ERROR "The RESTINIO_SOBJECTIZER_LIB_LINK_NAME has to be " + "specified explicitly when RESTINIO_DEP_SOBJECTIZER is 'system'") + endif() + endif() + + message(STATUS "RESTINIO_SOBJECTIZER_LIB_LINK_NAME: ${RESTINIO_SOBJECTIZER_LIB_LINK_NAME}") message("========================================") endif () @@ -340,3 +362,5 @@ if (RESTINIO_BENCHMARK) include_directories("${CMAKE_SOURCE_DIR}/clara") add_subdirectory(benches) endif () + +# vim:ts=4:sts=4:sw=4:expandtab: diff --git a/dev/benches/single_handler_so5_timer/CMakeLists.txt b/dev/benches/single_handler_so5_timer/CMakeLists.txt index 05a88881..c72971e0 100644 --- a/dev/benches/single_handler_so5_timer/CMakeLists.txt +++ b/dev/benches/single_handler_so5_timer/CMakeLists.txt @@ -1,7 +1,11 @@ set(BENCH _bench.restinio.single_handler_so5_timer) include(${CMAKE_SOURCE_DIR}/cmake/bench.cmake) -target_link_libraries(${BENCH} PRIVATE sobjectizer::StaticLib) +if (RESTINIO_DEP_SOBJECTIZER STREQUAL "system") + target_compile_definitions(${BENCH} PRIVATE SO_5_STATIC_LIB) +endif() + +target_link_libraries(${BENCH} PRIVATE ${RESTINIO_SOBJECTIZER_LIB_LINK_NAME}) target_link_libraries(${BENCH} PRIVATE restinio_helpers::cmd_line_args) diff --git a/dev/sample/async_chained_handlers/CMakeLists.txt b/dev/sample/async_chained_handlers/CMakeLists.txt index 489a42cf..5cc7fe9b 100644 --- a/dev/sample/async_chained_handlers/CMakeLists.txt +++ b/dev/sample/async_chained_handlers/CMakeLists.txt @@ -1,4 +1,8 @@ set(SAMPLE sample.async_chained_handlers) include(${CMAKE_SOURCE_DIR}/cmake/sample.cmake) -target_link_libraries(${SAMPLE} PRIVATE sobjectizer::StaticLib) +if (RESTINIO_DEP_SOBJECTIZER STREQUAL "system") + target_compile_definitions(${SAMPLE} PRIVATE SO_5_STATIC_LIB) +endif() + +target_link_libraries(${SAMPLE} PRIVATE ${RESTINIO_SOBJECTIZER_LIB_LINK_NAME}) diff --git a/dev/sample/async_handling_with_sobjectizer/CMakeLists.txt b/dev/sample/async_handling_with_sobjectizer/CMakeLists.txt index 245f9f6a..8e22e902 100644 --- a/dev/sample/async_handling_with_sobjectizer/CMakeLists.txt +++ b/dev/sample/async_handling_with_sobjectizer/CMakeLists.txt @@ -1,4 +1,8 @@ set(SAMPLE sample.async_handling_with_sobjectizer) include(${CMAKE_SOURCE_DIR}/cmake/sample.cmake) -TARGET_LINK_LIBRARIES(${SAMPLE} PRIVATE sobjectizer::StaticLib) +if (RESTINIO_DEP_SOBJECTIZER STREQUAL "system") + target_compile_definitions(${SAMPLE} PRIVATE SO_5_STATIC_LIB) +endif() + +target_link_libraries(${SAMPLE} PRIVATE ${RESTINIO_SOBJECTIZER_LIB_LINK_NAME}) diff --git a/dev/sample/notificators/CMakeLists.txt b/dev/sample/notificators/CMakeLists.txt index 23fd871c..3d980f7f 100644 --- a/dev/sample/notificators/CMakeLists.txt +++ b/dev/sample/notificators/CMakeLists.txt @@ -1,4 +1,8 @@ set(SAMPLE sample.notificators) include(${CMAKE_SOURCE_DIR}/cmake/sample.cmake) -TARGET_LINK_LIBRARIES(${SAMPLE} PRIVATE sobjectizer::StaticLib) +if (RESTINIO_DEP_SOBJECTIZER STREQUAL "system") + target_compile_definitions(${SAMPLE} PRIVATE SO_5_STATIC_LIB) +endif() + +target_link_libraries(${SAMPLE} PRIVATE ${RESTINIO_SOBJECTIZER_LIB_LINK_NAME}) diff --git a/dev/test/handle_requests/async_chained_handlers_2/CMakeLists.txt b/dev/test/handle_requests/async_chained_handlers_2/CMakeLists.txt index cdb1ea7f..a79edbf6 100644 --- a/dev/test/handle_requests/async_chained_handlers_2/CMakeLists.txt +++ b/dev/test/handle_requests/async_chained_handlers_2/CMakeLists.txt @@ -1,4 +1,8 @@ set(UNITTEST _unit.test.handle_requests.async_chained_handlers_2) include(${CMAKE_SOURCE_DIR}/cmake/unittest.cmake) -target_link_libraries(${UNITTEST} PRIVATE sobjectizer::StaticLib) +if (RESTINIO_DEP_SOBJECTIZER STREQUAL "system") + target_compile_definitions(${UNITTEST} PRIVATE SO_5_STATIC_LIB) +endif() + +target_link_libraries(${UNITTEST} PRIVATE ${RESTINIO_SOBJECTIZER_LIB_LINK_NAME}) diff --git a/dev/test/websocket/notificators/CMakeLists.txt b/dev/test/websocket/notificators/CMakeLists.txt index 19c54c99..6ccaf8d7 100644 --- a/dev/test/websocket/notificators/CMakeLists.txt +++ b/dev/test/websocket/notificators/CMakeLists.txt @@ -1,4 +1,8 @@ set(UNITTEST _unit.test.notificators) include(${CMAKE_SOURCE_DIR}/cmake/unittest.cmake) -TARGET_LINK_LIBRARIES(${UNITTEST} PRIVATE sobjectizer::StaticLib) +if (RESTINIO_DEP_SOBJECTIZER STREQUAL "system") + target_compile_definitions(${UNITTEST} PRIVATE SO_5_STATIC_LIB) +endif() + +target_link_libraries(${UNITTEST} PRIVATE ${RESTINIO_SOBJECTIZER_LIB_LINK_NAME}) diff --git a/dev/test/websocket/ws_connection/CMakeLists.txt b/dev/test/websocket/ws_connection/CMakeLists.txt index 835b0377..b3295711 100644 --- a/dev/test/websocket/ws_connection/CMakeLists.txt +++ b/dev/test/websocket/ws_connection/CMakeLists.txt @@ -1,4 +1,8 @@ set(UNITTEST _unit.test.ws_connection) include(${CMAKE_SOURCE_DIR}/cmake/unittest.cmake) -TARGET_LINK_LIBRARIES(${UNITTEST} PRIVATE sobjectizer::StaticLib) +if (RESTINIO_DEP_SOBJECTIZER STREQUAL "system") + target_compile_definitions(${UNITTEST} PRIVATE SO_5_STATIC_LIB) +endif() + +target_link_libraries(${UNITTEST} PRIVATE ${RESTINIO_SOBJECTIZER_LIB_LINK_NAME})