diff --git a/.github/actions/cmake-test/action.yml b/.github/actions/cmake-test/action.yml index f036b9134..1732d2762 100644 --- a/.github/actions/cmake-test/action.yml +++ b/.github/actions/cmake-test/action.yml @@ -12,7 +12,6 @@ inputs: description: 'Boost toolset' required: false - runs: using: composite steps: @@ -36,6 +35,15 @@ runs: # along in the same manner to those test projects via the command line. BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }} OPENSSL_ROOT_DIR: ${{ steps.install-openssl.outputs.OPENSSL_ROOT_DIR }} + CMAKE_INSTALL_PREFIX: ../LAUNCHDARKLY_INSTALL + - name: Build the SDK + shell: bash + run: | + cmake --build build + - name: Install the SDK + shell: bash + run: | + cmake --install build - name: Run CMake Integration Tests shell: bash run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fd6ee858..5a899977c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.19) include(CMakeDependentOption) project( - LaunchDarklyCPPSDKs + launchdarkly VERSION 0.1 DESCRIPTION "LaunchDarkly C++ SDK Monorepo (Server/Client)" LANGUAGES CXX C @@ -21,8 +21,6 @@ if (POLICY CMP0144) cmake_policy(SET CMP0144 NEW) endif () -include(GNUInstallDirs) - option(BUILD_TESTING "Top-level switch for testing. Turn off to disable unit and contract tests." ON) option(LD_BUILD_SHARED_LIBS "Build the SDKs as shared libraries" OFF) @@ -99,6 +97,14 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_POSITION_INDEPENDENT_CODE ON) +include(GNUInstallDirs) +set(LD_TARGETS_EXPORT_NAME ${PROJECT_NAME}Targets) +set(LD_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +set(LD_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}") +set(LD_CMAKE_PROJECT_CONFIG_FILE "${LD_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake") +set(LD_CMAKE_VERSION_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake") + + if (LD_BUILD_UNIT_TESTS) message(STATUS "LaunchDarkly: building unit tests") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG") @@ -155,12 +161,14 @@ endif () set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) + find_package(Boost 1.81 REQUIRED COMPONENTS json url coroutine) message(STATUS "LaunchDarkly: using Boost v${Boost_VERSION}") -include(${CMAKE_FILES}/certify.cmake) +set(FOXY_BUILD_TESTING OFF) add_subdirectory(vendor/foxy) + # Common, internal, and server-sent-events are built as "object" libraries. add_subdirectory(libs/common) add_subdirectory(libs/internal) @@ -185,3 +193,25 @@ if (LD_BUILD_EXAMPLES) message(STATUS "LaunchDarkly: building examples") add_subdirectory(examples) endif () + + +# Support installation of a cmake package. +include(CMakePackageConfigHelpers) + +write_basic_package_version_file( + ${LD_CMAKE_VERSION_CONFIG_FILE} + COMPATIBILITY SameMajorVersion +) + +install(FILES + ${LD_CMAKE_PROJECT_CONFIG_FILE} + ${LD_CMAKE_VERSION_CONFIG_FILE} + DESTINATION ${LD_CONFIG_INSTALL_DIR} +) + + +install( + EXPORT ${LD_TARGETS_EXPORT_NAME} + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${LD_CONFIG_INSTALL_DIR} +) diff --git a/README.md b/README.md index 16fcc6022..2903b02bb 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ GoogleTest is used for testing. For information on integrating an SDK package please refer to the SDK specific README. -## CMake Usage +## CMake Options Various CMake options are available to customize the client/server SDK builds. @@ -66,30 +66,59 @@ Various CMake options are available to customize the client/server SDK builds. | `LD_DYNAMIC_LINK_OPENSSL` | Whether OpenSSL is dynamically linked or not. | Off (static link) | N/A | | `LD_BUILD_REDIS_SUPPORT` | Whether the server-side Redis Source is built or not. | Off | N/A | -**Note:** _if building the SDKs as shared libraries, then unit tests won't be able to link correctly since the SDK's C++ -symbols aren't exposed. To run unit tests, build a static library._ - > [!WARNING] > When building shared libraries C++ symbols are not exported, only the C API will be exported. This is because C++ does -> not have a stable ABI. +> not have a stable ABI. For this reason, the SDK's unit tests are not built in shared library mode. + +## Building the SDK from Source -Basic usage example: +To configure the SDK's CMake project: ```bash -mkdir -p build && cd build -cmake -G"Unix Makefiles" .. +# Use 'make' as the build system. +cmake -B build -S . -G"Unix Makefiles" ``` -Slightly more advanced example - build shared libraries, and don't build any of the testing components: +To pass in config options defined in the table above, add them using `-D`: ```bash -mkdir -p build && cd build -cmake -G"Unix Makefiles" -DLD_BUILD_SHARED_LIBS=On -DBUILD_TESTING=Off .. +# Use 'make' as the build system, build shared libs, and disable testing. +cmake -B build -S . -G"Unix Makefiles" \ + -DLD_BUILD_SHARED_LIBS=On \ + -DBUILD_TESTING=Off .. ``` The example uses `make`, but you might instead use [Ninja](https://ninja-build.org/), MSVC, [etc.](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html) +## Incorporating the SDK via `add_subdirectory` + +The SDK can be incorporated into an existing application using CMake via `add_subdirectory.`. + +```cmake +# Set SDK build options, for example: +set(LD_BUILD_SHARED_LIBS On) + +add_subdirectory(path-to-cpp-sdks-repo) +target_link_libraries(your-app PRIVATE launchdarkly::client) +# ... or launchdarkly::server +```` + +## Incorporating the SDK via `find_package` + +> [!WARNING] +> Preliminary support for `find_package` is available. The package configuration is subject to change, do not expect it +> to be stable as long as this notice is present. + +If you've installed the SDK on the build system via `cmake --install`, you can consume it from +the target application like so: + +```cmake +find_package(launchdarkly REQUIRED) +target_link_libraries(your-app PRIVATE launchdarkly::launchdarkly-cpp-client) +# ... or launchdarkly::launchdarkly-cpp-server +``` + ## LaunchDarkly overview [LaunchDarkly](https://www.launchdarkly.com) is a feature management platform that serves trillions of feature flags diff --git a/cmake-tests/CMakeLists.txt b/cmake-tests/CMakeLists.txt index 9c0541576..bf9dbb518 100644 --- a/cmake-tests/CMakeLists.txt +++ b/cmake-tests/CMakeLists.txt @@ -1,2 +1,3 @@ include(declareProjectTest.cmake) +add_subdirectory(test_find_package) add_subdirectory(test_add_subdirectory) diff --git a/cmake-tests/README.md b/cmake-tests/README.md index a899bdc18..fd1b44768 100644 --- a/cmake-tests/README.md +++ b/cmake-tests/README.md @@ -62,3 +62,10 @@ Additionally, certain variables must be forwarded to each test project CMake con Checks that a project can include the SDK as a sub-project, via `add_subdirectory`. This would be a likely use-case when the repo is a submodule of another project. + +### cmake_projects/test_find_package + +Checks that a project can include the SDK via `find_package(ldserverapi)`. +This would be a likely use-case if the SDK was installed on the system by the user. + +**NOTE:** Requires SDK to be installed. diff --git a/cmake-tests/declareProjectTest.cmake b/cmake-tests/declareProjectTest.cmake index 0adbcf547..b68ba9aa8 100644 --- a/cmake-tests/declareProjectTest.cmake +++ b/cmake-tests/declareProjectTest.cmake @@ -75,9 +75,10 @@ macro(declare_find_package_test name) NAME ${test_prefix}_configure COMMAND ${CMAKE_COMMAND} - # Since project/CMakeLists.txt uses find_package(), it needs to know where to find - # ldserverapiConfig.cmake. That can be found where the SDK is installed, which is CMAKE_INSTALL_PREFIX. - -DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX} + # The project under test is going to use find_package() to find the launchdarkly SDK. The package config + # is going to in turn find_package() for boost. So, we need to pass in the location of the SDK's package + # config file, as well as boost's. + "-DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX};${BOOST_ROOT}" ${CMAKE_CURRENT_SOURCE_DIR}/project ) diff --git a/cmake-tests/test_find_package/CMakeLists.txt b/cmake-tests/test_find_package/CMakeLists.txt new file mode 100644 index 000000000..2f4be4b56 --- /dev/null +++ b/cmake-tests/test_find_package/CMakeLists.txt @@ -0,0 +1,3 @@ +# This test assumes that the SDK has been installed at CMAKE_INSTALL_PREFIX. +declare_find_package_test(test_find_package) +add_build_step(test_find_package) diff --git a/cmake-tests/test_find_package/project/CMakeLists.txt b/cmake-tests/test_find_package/project/CMakeLists.txt new file mode 100644 index 000000000..a90dfaa65 --- /dev/null +++ b/cmake-tests/test_find_package/project/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.19) + +project(UseFindPackageTest) + +find_package(launchdarkly REQUIRED) + +add_executable(use_find_package_server main_server.cpp) +target_link_libraries(use_find_package_server launchdarkly::launchdarkly-cpp-server) + + +add_executable(use_find_package_client main_client.cpp) +target_link_libraries(use_find_package_client launchdarkly::launchdarkly-cpp-client) diff --git a/cmake-tests/test_find_package/project/main_client.cpp b/cmake-tests/test_find_package/project/main_client.cpp new file mode 100644 index 000000000..6c548ab8f --- /dev/null +++ b/cmake-tests/test_find_package/project/main_client.cpp @@ -0,0 +1,25 @@ +#include +#include + +#include +#include + +using namespace launchdarkly; +using namespace launchdarkly::client_side; + +int main() { + auto config = ConfigBuilder("sdk-key").Build(); + if (!config) { + std::cout << "error: config is invalid: " << config.error() << '\n'; + return 1; + } + + auto context = + ContextBuilder().Kind("user", "example-user-key").Name("Sandy").Build(); + + auto client = Client(std::move(*config), std::move(context)); + + client.StartAsync(); + + std::cout << client.Initialized() << '\n'; +} diff --git a/cmake-tests/test_find_package/project/main_server.cpp b/cmake-tests/test_find_package/project/main_server.cpp new file mode 100644 index 000000000..aa55e3575 --- /dev/null +++ b/cmake-tests/test_find_package/project/main_server.cpp @@ -0,0 +1,23 @@ +#include +#include + +#include +#include + +using namespace launchdarkly; +using namespace launchdarkly::server_side; + +int main() { + auto config = ConfigBuilder("sdk-key").Build(); + if (!config) { + std::cout << "error: config is invalid: " << config.error() << '\n'; + return 1; + } + + auto client = Client(std::move(*config)); + + client.StartAsync(); + + std::cout << client.Initialized() << '\n'; + +} diff --git a/cmake/certify.cmake b/cmake/certify.cmake deleted file mode 100644 index f28da6fba..000000000 --- a/cmake/certify.cmake +++ /dev/null @@ -1,23 +0,0 @@ -cmake_minimum_required(VERSION 3.11) - -include(FetchContent) - -if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24") - # Affects robustness of timestamp checking on FetchContent dependencies. - cmake_policy(SET CMP0135 NEW) -endif () - -FetchContent_Declare(boost_certify - GIT_REPOSITORY https://github.com/djarek/certify.git - GIT_TAG 97f5eebfd99a5d6e99d07e4820240994e4e59787 -) - -set(BUILD_TESTING OFF) - -FetchContent_GetProperties(boost_certify) -if (NOT boost_certify_POPULATED) - FetchContent_Populate(boost_certify) - add_subdirectory(${boost_certify_SOURCE_DIR} ${boost_certify_BINARY_DIR} EXCLUDE_FROM_ALL) -endif () - -set(BUILD_TESTING "${ORIGINAL_BUILD_TESTING}") diff --git a/cmake/googletest.cmake b/cmake/googletest.cmake index 5be70af2c..153c18aae 100644 --- a/cmake/googletest.cmake +++ b/cmake/googletest.cmake @@ -13,4 +13,8 @@ FetchContent_Declare(googletest ) # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +# Disable installation of googletest +set(INSTALL_GTEST OFF CACHE BOOL "Disable googletest installation" FORCE) + FetchContent_MakeAvailable(googletest) diff --git a/cmake/launchdarkly-cpp-clientConfig.cmake b/cmake/launchdarkly-cpp-clientConfig.cmake deleted file mode 100644 index b10a3fd08..000000000 --- a/cmake/launchdarkly-cpp-clientConfig.cmake +++ /dev/null @@ -1,8 +0,0 @@ -get_filename_component(launchdarkly-client_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -include(CMakeFindDependencyMacro) - -# Add 3rd party dependencies here w/ find_package -# End 3rd party depends - - -#include("${CMAKE_CURRENT_LIST_DIR}/launchdarkly-clientTargets.cmake") diff --git a/cmake/launchdarklyConfig.cmake b/cmake/launchdarklyConfig.cmake new file mode 100644 index 000000000..c0e4779e0 --- /dev/null +++ b/cmake/launchdarklyConfig.cmake @@ -0,0 +1,16 @@ +include(CMakeFindDependencyMacro) + +if (NOT DEFINED Boost_USE_STATIC_LIBS) + if (LD_DYNAMIC_LINK_BOOST) + set(Boost_USE_STATIC_LIBS OFF) + else () + set(Boost_USE_STATIC_LIBS ON) + endif () +endif () + +find_dependency(Boost 1.81 COMPONENTS json url coroutine) +find_dependency(OpenSSL) +find_dependency(tl-expected) +find_dependency(certify) + +include(${CMAKE_CURRENT_LIST_DIR}/launchdarklyTargets.cmake) diff --git a/cmake/rfc3339_timestamp.cmake b/cmake/rfc3339_timestamp.cmake index b114f1938..2416875a2 100644 --- a/cmake/rfc3339_timestamp.cmake +++ b/cmake/rfc3339_timestamp.cmake @@ -1,7 +1,7 @@ FetchContent_Declare(timestamp GIT_REPOSITORY https://github.com/chansen/c-timestamp GIT_TAG "b205c407ae6680d23d74359ac00444b80989792f" - ) +) FetchContent_GetProperties(timestamp) if (NOT timestamp_POPULATED) @@ -12,20 +12,20 @@ add_library(timestamp OBJECT ${timestamp_SOURCE_DIR}/timestamp_tm.c ${timestamp_SOURCE_DIR}/timestamp_valid.c ${timestamp_SOURCE_DIR}/timestamp_parse.c - ) +) if (BUILD_SHARED_LIBS) set_target_properties(timestamp PROPERTIES POSITION_INDEPENDENT_CODE 1 C_VISIBILITY_PRESET hidden - ) + ) endif () target_include_directories(timestamp PUBLIC $ $ - ) +) install( TARGETS timestamp - EXPORT ${PROJECT_NAME}-targets + EXPORT ${LD_TARGETS_EXPORT_NAME} ) diff --git a/libs/client-sdk/src/CMakeLists.txt b/libs/client-sdk/src/CMakeLists.txt index d70fb81f8..edcde84b7 100644 --- a/libs/client-sdk/src/CMakeLists.txt +++ b/libs/client-sdk/src/CMakeLists.txt @@ -37,7 +37,6 @@ target_sources(${LIBNAME} PRIVATE flag_manager/context_index.cpp flag_manager/flag_manager.cpp flag_manager/flag_persistence.cpp - bindings/c/sdk.cpp ) @@ -46,22 +45,29 @@ target_link_libraries(${LIBNAME} PRIVATE Boost::headers Boost::json Boost::url launchdarkly::sse launchdarkly::internal foxy) +target_include_directories(${LIBNAME} + PUBLIC + $ + $ +) + +# Minimum C++ standard needed for consuming the public API is C++17. +target_compile_features(${LIBNAME} PUBLIC cxx_std_17) + add_library(launchdarkly::client ALIAS ${LIBNAME}) -# Optional in case only the server SDK is being built. -install(TARGETS ${LIBNAME} OPTIONAL) if (LD_BUILD_SHARED_LIBS AND MSVC) - install(FILES $ DESTINATION bin OPTIONAL) + install(FILES $ DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL) endif () + # Using PUBLIC_HEADERS would flatten the include. # This will preserve it, but dependencies must do the same. install(DIRECTORY "${LaunchDarklyCPPClient_SOURCE_DIR}/include/launchdarkly" - DESTINATION "include" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) -# Need the public headers to build. -target_include_directories(${LIBNAME} PUBLIC ../include) - -# Minimum C++ standard needed for consuming the public API is C++17. -target_compile_features(${LIBNAME} PUBLIC cxx_std_17) +install( + TARGETS ${LIBNAME} OPTIONAL + EXPORT ${LD_TARGETS_EXPORT_NAME} +) diff --git a/libs/common/CMakeLists.txt b/libs/common/CMakeLists.txt index 0423c4b74..d03a4abcc 100644 --- a/libs/common/CMakeLists.txt +++ b/libs/common/CMakeLists.txt @@ -25,7 +25,6 @@ endif () include(FetchContent) include(${CMAKE_FILES}/expected.cmake) -#include(${CMAKE_FILES}/foxy.cmake) # Add main SDK sources. add_subdirectory(src) diff --git a/libs/common/src/CMakeLists.txt b/libs/common/src/CMakeLists.txt index 7be9028c9..cc5c17c98 100644 --- a/libs/common/src/CMakeLists.txt +++ b/libs/common/src/CMakeLists.txt @@ -62,8 +62,6 @@ add_library(${LIBNAME} OBJECT add_library(launchdarkly::common ALIAS ${LIBNAME}) -install(TARGETS ${LIBNAME}) - # Using PUBLIC_HEADERS would flatten the include. # This will preserve it, but dependencies must do the same. install(DIRECTORY "${LaunchDarklyCommonSdk_SOURCE_DIR}/include/launchdarkly" @@ -81,8 +79,16 @@ target_link_libraries(${LIBNAME} OpenSSL::SSL Boost::disable_autolinking) -# Need the public headers to build. -target_include_directories(${LIBNAME} PUBLIC ../include) +target_include_directories(${LIBNAME} + PUBLIC + $ + $ +) # Minimum C++ standard needed for consuming the public API is C++17. target_compile_features(${LIBNAME} PUBLIC cxx_std_17) + +install( + TARGETS ${LIBNAME} + EXPORT ${LD_TARGETS_EXPORT_NAME} +) diff --git a/libs/internal/src/CMakeLists.txt b/libs/internal/src/CMakeLists.txt index a74656eff..af1bd209e 100644 --- a/libs/internal/src/CMakeLists.txt +++ b/libs/internal/src/CMakeLists.txt @@ -56,8 +56,6 @@ target_compile_options(${LIBNAME} PRIVATE -Wno-deprecated-declarations> ) -install(TARGETS ${LIBNAME}) - message(STATUS "LaunchDarklyInternalSdk_SOURCE_DIR=${LaunchDarklyInternalSdk_SOURCE_DIR}") target_link_libraries(${LIBNAME} @@ -65,7 +63,16 @@ target_link_libraries(${LIBNAME} PRIVATE Boost::url Boost::json OpenSSL::SSL Boost::disable_autolinking Boost::headers tl::expected foxy) # Need the public headers to build. -target_include_directories(${LIBNAME} PUBLIC ../include) +target_include_directories(${LIBNAME} + PUBLIC + $ + $ +) # Minimum C++ standard needed for consuming the public API is C++17. target_compile_features(${LIBNAME} PUBLIC cxx_std_17) + +install( + TARGETS ${LIBNAME} + EXPORT ${LD_TARGETS_EXPORT_NAME} +) diff --git a/libs/server-sdk-redis-source/src/CMakeLists.txt b/libs/server-sdk-redis-source/src/CMakeLists.txt index 4b7d130e1..c7c545822 100644 --- a/libs/server-sdk-redis-source/src/CMakeLists.txt +++ b/libs/server-sdk-redis-source/src/CMakeLists.txt @@ -27,21 +27,29 @@ target_link_libraries(${LIBNAME} add_library(launchdarkly::server_redis_source ALIAS ${LIBNAME}) -# Optional in case only the client SDK is being built. -install(TARGETS ${LIBNAME} OPTIONAL) if (LD_BUILD_SHARED_LIBS AND MSVC) - install(FILES $ DESTINATION bin OPTIONAL) + install(FILES $ DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL) endif () # Using PUBLIC_HEADERS would flatten the include. # This will preserve it, but dependencies must do the same. install(DIRECTORY "${LaunchDarklyCPPServerRedisSource_SOURCE_DIR}/include/launchdarkly" - DESTINATION "include" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) # Need the public headers to build. -target_include_directories(${LIBNAME} PUBLIC ../include) +target_include_directories(${LIBNAME} + PUBLIC + $ + $ +) # Minimum C++ standard needed for consuming the public API is C++17. target_compile_features(${LIBNAME} PUBLIC cxx_std_17) + + +install( + TARGETS ${LIBNAME} OPTIONAL + EXPORT ${LD_TARGETS_EXPORT_NAME} +) diff --git a/libs/server-sdk/src/CMakeLists.txt b/libs/server-sdk/src/CMakeLists.txt index a440b79ed..7b93be27f 100644 --- a/libs/server-sdk/src/CMakeLists.txt +++ b/libs/server-sdk/src/CMakeLists.txt @@ -80,20 +80,27 @@ target_link_libraries(${LIBNAME} add_library(launchdarkly::server ALIAS ${LIBNAME}) -# Optional in case only the client SDK is being built. -install(TARGETS ${LIBNAME} OPTIONAL) if (LD_BUILD_SHARED_LIBS AND MSVC) - install(FILES $ DESTINATION bin OPTIONAL) + install(FILES $ DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL) endif () + # Using PUBLIC_HEADERS would flatten the include. # This will preserve it, but dependencies must do the same. - install(DIRECTORY "${LaunchDarklyCPPServer_SOURCE_DIR}/include/launchdarkly" - DESTINATION "include" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) # Need the public headers to build. -target_include_directories(${LIBNAME} PUBLIC ../include) +target_include_directories(${LIBNAME} + PUBLIC + $ + $ +) # Minimum C++ standard needed for consuming the public API is C++17. target_compile_features(${LIBNAME} PUBLIC cxx_std_17) + +install( + TARGETS ${LIBNAME} OPTIONAL + EXPORT ${LD_TARGETS_EXPORT_NAME} +) diff --git a/libs/server-sent-events/CMakeLists.txt b/libs/server-sent-events/CMakeLists.txt index a1daa302b..99763f475 100644 --- a/libs/server-sent-events/CMakeLists.txt +++ b/libs/server-sent-events/CMakeLists.txt @@ -21,14 +21,9 @@ if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) set_property(GLOBAL PROPERTY USE_FOLDERS ON) endif () -#set(CMAKE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_FILES}) - # Needed to fetch external dependencies. include(FetchContent) -#include(${CMAKE_FILES}/foxy.cmake) - add_subdirectory(src) if (LD_BUILD_UNIT_TESTS) diff --git a/libs/server-sent-events/src/CMakeLists.txt b/libs/server-sent-events/src/CMakeLists.txt index be6d9d304..22816de8b 100644 --- a/libs/server-sent-events/src/CMakeLists.txt +++ b/libs/server-sent-events/src/CMakeLists.txt @@ -20,10 +20,18 @@ target_link_libraries(${LIBNAME} add_library(launchdarkly::sse ALIAS ${LIBNAME}) -install(TARGETS ${LIBNAME}) - # Need the public headers to build. -target_include_directories(${LIBNAME} PUBLIC ../include) +target_include_directories(${LIBNAME} + PUBLIC + $ + $ +) # Minimum C++ standard needed for consuming the public API is C++17. target_compile_features(${LIBNAME} PUBLIC cxx_std_17) + + +install( + TARGETS ${LIBNAME} + EXPORT ${LD_TARGETS_EXPORT_NAME} +) diff --git a/scripts/configure-cmake-integration-tests.sh b/scripts/configure-cmake-integration-tests.sh index 531d25712..2336c9b4e 100755 --- a/scripts/configure-cmake-integration-tests.sh +++ b/scripts/configure-cmake-integration-tests.sh @@ -14,7 +14,10 @@ trap cleanup EXIT cmake -G Ninja -D CMAKE_COMPILE_WARNING_AS_ERROR=TRUE \ -D BUILD_TESTING=ON \ + -D LD_BUILD_UNIT_TESTS=ON \ -D LD_CMAKE_INTEGRATION_TESTS=ON \ -D BOOST_ROOT="$BOOST_ROOT" \ -D OPENSSL_ROOT_DIR="$OPENSSL_ROOT_DIR" \ + -D LD_TESTING_SANITIZERS=OFF \ + -D CMAKE_INSTALL_PREFIX="$CMAKE_INSTALL_PREFIX" \ -D LD_BUILD_EXAMPLES=OFF .. diff --git a/vendor/foxy/CMakeLists.txt b/vendor/foxy/CMakeLists.txt index 1ecb76530..a64f767c1 100644 --- a/vendor/foxy/CMakeLists.txt +++ b/vendor/foxy/CMakeLists.txt @@ -24,6 +24,9 @@ project( "Session-based abstractions for Beast + URL parsing and pct-coding" ) +set(CMAKE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +include(${CMAKE_FILES}/certify.cmake) + find_package( Boost ${foxy_minimum_boost_version} REQUIRED @@ -163,8 +166,14 @@ add_library( target_include_directories(test_utils PUBLIC test/include) target_link_libraries(test_utils PUBLIC foxy) -option(BUILD_TESTING "Build Foxy Testsuite" OFF) -if (BUILD_TESTING) +cmake_dependent_option(FOXY_BUILD_TESTING + "Build the C++ unit tests." + ON + "BUILD_TESTING" + OFF +) + +if (FOXY_BUILD_TESTING) include(CTest) find_package(Catch2 CONFIG REQUIRED) @@ -248,3 +257,7 @@ if (FOXY_FUZZ) target_link_options(uri-parser PRIVATE "-fsanitize=fuzzer") endif () +install( + TARGETS foxy + EXPORT ${LD_TARGETS_EXPORT_NAME} +) diff --git a/vendor/foxy/cmake/certify.cmake b/vendor/foxy/cmake/certify.cmake new file mode 100644 index 000000000..d3af6ea7d --- /dev/null +++ b/vendor/foxy/cmake/certify.cmake @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.11) + +include(FetchContent) + +if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24") + # Affects robustness of timestamp checking on FetchContent dependencies. + cmake_policy(SET CMP0135 NEW) +endif () + + +FetchContent_Declare(certify + GIT_REPOSITORY https://github.com/launchdarkly/certify.git + GIT_TAG 7116dd0e609ae44d037aa562736d3d59fce1b637 +) + +# The tests in certify don't compile. +set(PREVIOUS_BUILD_TESTING ${BUILD_TESTING}) +set(BUILD_TESTING OFF) + +FetchContent_MakeAvailable(certify) + +set(BUILD_TESTING ${PREVIOUS_BUILD_TESTING}) + +install( + TARGETS core + EXPORT ${LD_TARGETS_EXPORT_NAME} +)