From e0019c34b45e04c1af77ffdcae5f15b217601602 Mon Sep 17 00:00:00 2001 From: Andrey Kashcheev Date: Fri, 12 Jun 2026 08:36:18 +0200 Subject: [PATCH] Option to embed Boost JSON Option to control whether we should use header-only Boost JSON or as a separate library. Turn on by default. Relates-To: DATASDK-97 Signed-off-by: Andrey Kashcheev --- .github/workflows/psv_pipelines.yml | 16 +++++++++++++++ CMakeLists.txt | 1 + external/boost/CMakeLists.txt | 20 +++++++++++++++---- external/boost/CMakeLists.txt.boost.in | 4 ++-- olp-cpp-sdk-authentication/CMakeLists.txt | 14 ++++++++++++- .../src/utils/BoostJsonSrc.cpp | 2 ++ olp-cpp-sdk-core/CMakeLists.txt | 15 +++++++++++++- olp-cpp-sdk-core/src/utils/BoostJsonSrc.cpp | 2 ++ olp-cpp-sdk-dataservice-read/CMakeLists.txt | 14 ++++++++++++- .../src/utils/BoostJsonSrc.cpp | 2 ++ olp-cpp-sdk-dataservice-write/CMakeLists.txt | 14 ++++++++++++- .../src/utils/BoostJsonSrc.cpp | 2 ++ 12 files changed, 96 insertions(+), 10 deletions(-) diff --git a/.github/workflows/psv_pipelines.yml b/.github/workflows/psv_pipelines.yml index 37a1bd8c6..3a472acf6 100644 --- a/.github/workflows/psv_pipelines.yml +++ b/.github/workflows/psv_pipelines.yml @@ -104,6 +104,22 @@ jobs: run: gcc --version && ./scripts/linux/psv/build_psv.sh shell: bash + psv-linux-22-04-gcc11-build-json-lib: + name: PSV.Linux.22.04.gcc11.OLP_SDK_EMBED_BOOST_JSON + runs-on: ubuntu-22.04 + env: + BUILD_TYPE: RelWithDebInfo + EXTRA_CMAKE_OPTIONS: -DOLP_SDK_EMBED_BOOST_JSON=OFF -DOLP_SDK_ENABLE_TESTING=OFF + steps: + - name: Check out repository + uses: actions/checkout@v4 + - name: Install Ubuntu dependencies + run: sudo apt-get update && sudo apt-get install -y libboost-all-dev ccache libssl-dev libcurl4-openssl-dev --no-install-recommends + shell: bash + - name: Compile project with cmake and ccache + run: gcc --version && ./scripts/linux/psv/build_psv.sh + shell: bash + psv-linux-latest-gcc14-build: name: PSV.Linux.latest.gcc14.Tests runs-on: ubuntu-latest diff --git a/CMakeLists.txt b/CMakeLists.txt index d4bd416dd..96da5cef7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ option(OLP_SDK_NO_EXCEPTION "Disable exception handling" OFF) option(OLP_SDK_USE_STD_OPTIONAL "Use std::optional instead of boost::optional with C++17 and above" OFF) option(OLP_SDK_USE_STD_ANY "Use std::any instead of boost::any with C++17 and above" OFF) option(OLP_SDK_BOOST_THROW_EXCEPTION_EXTERNAL "The boost::throw_exception() is defined externally" OFF) +option(OLP_SDK_EMBED_BOOST_JSON "Use boost.json in header-only mode." ON) option(OLP_SDK_BUILD_EXTERNAL_DEPS "Download and build external dependencies" ON) option(OLP_SDK_BUILD_EXAMPLES "Enable examples targets" OFF) option(OLP_SDK_MSVC_PARALLEL_BUILD_ENABLE "Enable parallel build on MSVC" ON) diff --git a/external/boost/CMakeLists.txt b/external/boost/CMakeLists.txt index 43f9396e9..9d0bae10f 100644 --- a/external/boost/CMakeLists.txt +++ b/external/boost/CMakeLists.txt @@ -34,6 +34,12 @@ endif() set(PATCH_BOOST_CMD "git apply -v ${CMAKE_CURRENT_SOURCE_DIR}/boost_182_json_noexceptions.diff") +# Skip installation if boost is embedded, otherwise install it to a temporary location and use it from there. +set(INSTALL_BOOST_CMD ${CMAKE_COMMAND} -E true) +if (NOT OLP_SDK_EMBED_BOOST_JSON) + set(INSTALL_BOOST_CMD ${B2_CMD} install --with-json --prefix=${CMAKE_CURRENT_BINARY_DIR}/external_boost_install) +endif() + configure_file(CMakeLists.txt.boost.in download/CMakeLists.txt @ONLY) set(CMAKE_VERBOSE_MAKEFILE ON) @@ -52,7 +58,13 @@ if(result) message(FATAL_ERROR "Build step for boost failed: ${result}") endif() -# We are using boost header only, we don't care about libs -set(EXTERNAL_BOOST_ROOT ${CMAKE_CURRENT_BINARY_DIR}/external_boost PARENT_SCOPE) -set(EXTERNAL_BOOST_ROOT_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/external_boost PARENT_SCOPE) -set(EXTERNAL_BOOST_ROOT_LIB dummy_path PARENT_SCOPE) +if (OLP_SDK_EMBED_BOOST_JSON) + set(EXTERNAL_BOOST_ROOT ${CMAKE_CURRENT_BINARY_DIR}/external_boost PARENT_SCOPE) + set(EXTERNAL_BOOST_ROOT_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/external_boost PARENT_SCOPE) + # We are using boost header only, we don't care about libs + set(EXTERNAL_BOOST_ROOT_LIB dummy_path PARENT_SCOPE) +else() + set(EXTERNAL_BOOST_ROOT ${CMAKE_CURRENT_BINARY_DIR}/external_boost_install PARENT_SCOPE) + set(EXTERNAL_BOOST_ROOT_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/external_boost_install/include PARENT_SCOPE) + set(EXTERNAL_BOOST_ROOT_LIB ${CMAKE_CURRENT_BINARY_DIR}/external_boost_install/lib PARENT_SCOPE) +endif () diff --git a/external/boost/CMakeLists.txt.boost.in b/external/boost/CMakeLists.txt.boost.in index cbf5a4080..e1a9de6bd 100644 --- a/external/boost/CMakeLists.txt.boost.in +++ b/external/boost/CMakeLists.txt.boost.in @@ -76,7 +76,7 @@ ExternalProject_Add(boost-download BUILD_IN_SOURCE 1 UPDATE_COMMAND "" CONFIGURE_COMMAND @BOOTSTRAP_CMD@ - BUILD_COMMAND "@B2_CMD@" headers - INSTALL_COMMAND "" + BUILD_COMMAND "@B2_CMD@" headers @BOOST_LIBRARIES_ARG@ + INSTALL_COMMAND "@INSTALL_BOOST_CMD@" TEST_COMMAND "" ) diff --git a/olp-cpp-sdk-authentication/CMakeLists.txt b/olp-cpp-sdk-authentication/CMakeLists.txt index 253f3e22c..e84c837fd 100644 --- a/olp-cpp-sdk-authentication/CMakeLists.txt +++ b/olp-cpp-sdk-authentication/CMakeLists.txt @@ -18,7 +18,11 @@ project(olp-cpp-sdk-authentication VERSION 1.25.0) set(DESCRIPTION "C++ API library for accessing HERE Account authentication service") -find_package(Boost REQUIRED) +if (OLP_SDK_EMBED_BOOST_JSON) + find_package(Boost REQUIRED) +else () + find_package(Boost COMPONENTS json REQUIRED) +endif() file(GLOB_RECURSE AUTHENTICATION_INC "include/*.h*") file(GLOB_RECURSE AUTHENTICATION_SRC "src/*.*") @@ -56,6 +60,14 @@ if(BUILD_SHARED_LIBS) PUBLIC AUTHENTICATION_SHARED_LIBRARY) endif() +if (OLP_SDK_EMBED_BOOST_JSON) + target_compile_definitions(${PROJECT_NAME} + PRIVATE OLP_SDK_EMBED_BOOST_JSON) +else () + target_link_libraries(${PROJECT_NAME} + PRIVATE Boost::json) +endif() + target_compile_definitions(${PROJECT_NAME} PRIVATE BOOST_ALL_NO_LIB diff --git a/olp-cpp-sdk-authentication/src/utils/BoostJsonSrc.cpp b/olp-cpp-sdk-authentication/src/utils/BoostJsonSrc.cpp index 017758210..5697dacbd 100644 --- a/olp-cpp-sdk-authentication/src/utils/BoostJsonSrc.cpp +++ b/olp-cpp-sdk-authentication/src/utils/BoostJsonSrc.cpp @@ -17,4 +17,6 @@ * License-Filename: LICENSE */ +#if defined(OLP_SDK_EMBED_BOOST_JSON) #include +#endif diff --git a/olp-cpp-sdk-core/CMakeLists.txt b/olp-cpp-sdk-core/CMakeLists.txt index 6f91dd14b..8e3a242e0 100644 --- a/olp-cpp-sdk-core/CMakeLists.txt +++ b/olp-cpp-sdk-core/CMakeLists.txt @@ -19,7 +19,12 @@ project(olp-cpp-sdk-core VERSION 1.25.0) set(DESCRIPTION "Core network and utility library for the HERE OLP SDK C++") -find_package(Boost REQUIRED) +if (OLP_SDK_EMBED_BOOST_JSON) + find_package(Boost REQUIRED) +else () + find_package(Boost COMPONENTS json REQUIRED) +endif() + find_package(Threads REQUIRED) if(OLP_SDK_ENABLE_DEFAULT_CACHE) @@ -456,6 +461,14 @@ if (OLP_SDK_USE_STD_ANY) PUBLIC OLP_SDK_USE_STD_ANY) endif() +if (OLP_SDK_EMBED_BOOST_JSON) + target_compile_definitions(${PROJECT_NAME} + PRIVATE OLP_SDK_EMBED_BOOST_JSON) +else () + target_link_libraries(${PROJECT_NAME} + PRIVATE Boost::json) +endif() + target_compile_definitions(${PROJECT_NAME} PRIVATE BOOST_ALL_NO_LIB) target_compile_definitions(${PROJECT_NAME} PRIVATE BOOST_JSON_NO_LIB) diff --git a/olp-cpp-sdk-core/src/utils/BoostJsonSrc.cpp b/olp-cpp-sdk-core/src/utils/BoostJsonSrc.cpp index 017758210..5697dacbd 100644 --- a/olp-cpp-sdk-core/src/utils/BoostJsonSrc.cpp +++ b/olp-cpp-sdk-core/src/utils/BoostJsonSrc.cpp @@ -17,4 +17,6 @@ * License-Filename: LICENSE */ +#if defined(OLP_SDK_EMBED_BOOST_JSON) #include +#endif diff --git a/olp-cpp-sdk-dataservice-read/CMakeLists.txt b/olp-cpp-sdk-dataservice-read/CMakeLists.txt index 8cf487abd..b2395802f 100644 --- a/olp-cpp-sdk-dataservice-read/CMakeLists.txt +++ b/olp-cpp-sdk-dataservice-read/CMakeLists.txt @@ -22,7 +22,11 @@ file(GLOB_RECURSE INC "include/*.h*") file(GLOB_RECURSE SRC "src/*.*") -find_package(Boost REQUIRED) +if (OLP_SDK_EMBED_BOOST_JSON) + find_package(Boost REQUIRED) +else () + find_package(Boost COMPONENTS json REQUIRED) +endif() add_library(${PROJECT_NAME} ${SRC} @@ -53,6 +57,14 @@ if(BUILD_SHARED_LIBS) PUBLIC DATASERVICE_READ_SHARED_LIBRARY) endif() +if (OLP_SDK_EMBED_BOOST_JSON) + target_compile_definitions(${PROJECT_NAME} + PRIVATE OLP_SDK_EMBED_BOOST_JSON) +else () + target_link_libraries(${PROJECT_NAME} + PRIVATE Boost::json) +endif() + # install component file(GLOB API_HEADERS "include/olp/dataservice/read/*.h") file(GLOB MODEL_HEADERS "include/olp/dataservice/read/model/*.h") diff --git a/olp-cpp-sdk-dataservice-read/src/utils/BoostJsonSrc.cpp b/olp-cpp-sdk-dataservice-read/src/utils/BoostJsonSrc.cpp index 017758210..5697dacbd 100644 --- a/olp-cpp-sdk-dataservice-read/src/utils/BoostJsonSrc.cpp +++ b/olp-cpp-sdk-dataservice-read/src/utils/BoostJsonSrc.cpp @@ -17,4 +17,6 @@ * License-Filename: LICENSE */ +#if defined(OLP_SDK_EMBED_BOOST_JSON) #include +#endif diff --git a/olp-cpp-sdk-dataservice-write/CMakeLists.txt b/olp-cpp-sdk-dataservice-write/CMakeLists.txt index a0932360d..2a8771908 100644 --- a/olp-cpp-sdk-dataservice-write/CMakeLists.txt +++ b/olp-cpp-sdk-dataservice-write/CMakeLists.txt @@ -18,7 +18,11 @@ project(olp-cpp-sdk-dataservice-write VERSION 1.25.0) set(DESCRIPTION "C++ API library for writing data to OLP") -find_package(Boost REQUIRED) +if (OLP_SDK_EMBED_BOOST_JSON) + find_package(Boost REQUIRED) +else () + find_package(Boost COMPONENTS json REQUIRED) +endif() set(OLP_SDK_DATASERVICE_WRITE_API_HEADERS ./include/olp/dataservice/write/DataServiceWriteApi.h @@ -189,6 +193,14 @@ target_compile_definitions(${PROJECT_NAME} BOOST_ALL_NO_LIB BOOST_JSON_NO_LIB) +if (OLP_SDK_EMBED_BOOST_JSON) + target_compile_definitions(${PROJECT_NAME} + PRIVATE OLP_SDK_EMBED_BOOST_JSON) +else () + target_link_libraries(${PROJECT_NAME} + PRIVATE Boost::json) +endif() + # Used also in the package config file set(PROJECT_LIBS olp-cpp-sdk-core) diff --git a/olp-cpp-sdk-dataservice-write/src/utils/BoostJsonSrc.cpp b/olp-cpp-sdk-dataservice-write/src/utils/BoostJsonSrc.cpp index 017758210..5697dacbd 100644 --- a/olp-cpp-sdk-dataservice-write/src/utils/BoostJsonSrc.cpp +++ b/olp-cpp-sdk-dataservice-write/src/utils/BoostJsonSrc.cpp @@ -17,4 +17,6 @@ * License-Filename: LICENSE */ +#if defined(OLP_SDK_EMBED_BOOST_JSON) #include +#endif