Skip to content

Commit 5a64c61

Browse files
Option to embed Boost JSON (#1701)
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 <ext-andrey.kashcheev@here.com>
1 parent f723858 commit 5a64c61

12 files changed

Lines changed: 96 additions & 10 deletions

File tree

.github/workflows/psv_pipelines.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ jobs:
104104
run: gcc --version && ./scripts/linux/psv/build_psv.sh
105105
shell: bash
106106

107+
psv-linux-22-04-gcc11-build-json-lib:
108+
name: PSV.Linux.22.04.gcc11.OLP_SDK_EMBED_BOOST_JSON
109+
runs-on: ubuntu-22.04
110+
env:
111+
BUILD_TYPE: RelWithDebInfo
112+
EXTRA_CMAKE_OPTIONS: -DOLP_SDK_EMBED_BOOST_JSON=OFF -DOLP_SDK_ENABLE_TESTING=OFF
113+
steps:
114+
- name: Check out repository
115+
uses: actions/checkout@v4
116+
- name: Install Ubuntu dependencies
117+
run: sudo apt-get update && sudo apt-get install -y libboost-all-dev ccache libssl-dev libcurl4-openssl-dev --no-install-recommends
118+
shell: bash
119+
- name: Compile project with cmake and ccache
120+
run: gcc --version && ./scripts/linux/psv/build_psv.sh
121+
shell: bash
122+
107123
psv-linux-latest-gcc14-build:
108124
name: PSV.Linux.latest.gcc14.Tests
109125
runs-on: ubuntu-latest

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ option(OLP_SDK_NO_EXCEPTION "Disable exception handling" OFF)
4040
option(OLP_SDK_USE_STD_OPTIONAL "Use std::optional instead of boost::optional with C++17 and above" OFF)
4141
option(OLP_SDK_USE_STD_ANY "Use std::any instead of boost::any with C++17 and above" OFF)
4242
option(OLP_SDK_BOOST_THROW_EXCEPTION_EXTERNAL "The boost::throw_exception() is defined externally" OFF)
43+
option(OLP_SDK_EMBED_BOOST_JSON "Use boost.json in header-only mode." ON)
4344
option(OLP_SDK_BUILD_EXTERNAL_DEPS "Download and build external dependencies" ON)
4445
option(OLP_SDK_BUILD_EXAMPLES "Enable examples targets" OFF)
4546
option(OLP_SDK_MSVC_PARALLEL_BUILD_ENABLE "Enable parallel build on MSVC" ON)

external/boost/CMakeLists.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ endif()
3434

3535
set(PATCH_BOOST_CMD "git apply -v ${CMAKE_CURRENT_SOURCE_DIR}/boost_182_json_noexceptions.diff")
3636

37+
# Skip installation if boost is embedded, otherwise install it to a temporary location and use it from there.
38+
set(INSTALL_BOOST_CMD ${CMAKE_COMMAND} -E true)
39+
if (NOT OLP_SDK_EMBED_BOOST_JSON)
40+
set(INSTALL_BOOST_CMD ${B2_CMD} install --with-json --prefix=${CMAKE_CURRENT_BINARY_DIR}/external_boost_install)
41+
endif()
42+
3743
configure_file(CMakeLists.txt.boost.in download/CMakeLists.txt @ONLY)
3844

3945
set(CMAKE_VERBOSE_MAKEFILE ON)
@@ -52,7 +58,13 @@ if(result)
5258
message(FATAL_ERROR "Build step for boost failed: ${result}")
5359
endif()
5460

55-
# We are using boost header only, we don't care about libs
56-
set(EXTERNAL_BOOST_ROOT ${CMAKE_CURRENT_BINARY_DIR}/external_boost PARENT_SCOPE)
57-
set(EXTERNAL_BOOST_ROOT_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/external_boost PARENT_SCOPE)
58-
set(EXTERNAL_BOOST_ROOT_LIB dummy_path PARENT_SCOPE)
61+
if (OLP_SDK_EMBED_BOOST_JSON)
62+
set(EXTERNAL_BOOST_ROOT ${CMAKE_CURRENT_BINARY_DIR}/external_boost PARENT_SCOPE)
63+
set(EXTERNAL_BOOST_ROOT_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/external_boost PARENT_SCOPE)
64+
# We are using boost header only, we don't care about libs
65+
set(EXTERNAL_BOOST_ROOT_LIB dummy_path PARENT_SCOPE)
66+
else()
67+
set(EXTERNAL_BOOST_ROOT ${CMAKE_CURRENT_BINARY_DIR}/external_boost_install PARENT_SCOPE)
68+
set(EXTERNAL_BOOST_ROOT_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/external_boost_install/include PARENT_SCOPE)
69+
set(EXTERNAL_BOOST_ROOT_LIB ${CMAKE_CURRENT_BINARY_DIR}/external_boost_install/lib PARENT_SCOPE)
70+
endif ()

external/boost/CMakeLists.txt.boost.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ ExternalProject_Add(boost-download
7676
BUILD_IN_SOURCE 1
7777
UPDATE_COMMAND ""
7878
CONFIGURE_COMMAND @BOOTSTRAP_CMD@
79-
BUILD_COMMAND "@B2_CMD@" headers
80-
INSTALL_COMMAND ""
79+
BUILD_COMMAND "@B2_CMD@" headers @BOOST_LIBRARIES_ARG@
80+
INSTALL_COMMAND "@INSTALL_BOOST_CMD@"
8181
TEST_COMMAND ""
8282
)

olp-cpp-sdk-authentication/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
project(olp-cpp-sdk-authentication VERSION 1.25.0)
1919
set(DESCRIPTION "C++ API library for accessing HERE Account authentication service")
2020

21-
find_package(Boost REQUIRED)
21+
if (OLP_SDK_EMBED_BOOST_JSON)
22+
find_package(Boost REQUIRED)
23+
else ()
24+
find_package(Boost COMPONENTS json REQUIRED)
25+
endif()
2226

2327
file(GLOB_RECURSE AUTHENTICATION_INC "include/*.h*")
2428
file(GLOB_RECURSE AUTHENTICATION_SRC "src/*.*")
@@ -56,6 +60,14 @@ if(BUILD_SHARED_LIBS)
5660
PUBLIC AUTHENTICATION_SHARED_LIBRARY)
5761
endif()
5862

63+
if (OLP_SDK_EMBED_BOOST_JSON)
64+
target_compile_definitions(${PROJECT_NAME}
65+
PRIVATE OLP_SDK_EMBED_BOOST_JSON)
66+
else ()
67+
target_link_libraries(${PROJECT_NAME}
68+
PRIVATE Boost::json)
69+
endif()
70+
5971
target_compile_definitions(${PROJECT_NAME}
6072
PRIVATE
6173
BOOST_ALL_NO_LIB

olp-cpp-sdk-authentication/src/utils/BoostJsonSrc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717
* License-Filename: LICENSE
1818
*/
1919

20+
#if defined(OLP_SDK_EMBED_BOOST_JSON)
2021
#include <boost/json/src.hpp>
22+
#endif

olp-cpp-sdk-core/CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
project(olp-cpp-sdk-core VERSION 1.25.0)
2020
set(DESCRIPTION "Core network and utility library for the HERE OLP SDK C++")
2121

22-
find_package(Boost REQUIRED)
22+
if (OLP_SDK_EMBED_BOOST_JSON)
23+
find_package(Boost REQUIRED)
24+
else ()
25+
find_package(Boost COMPONENTS json REQUIRED)
26+
endif()
27+
2328
find_package(Threads REQUIRED)
2429

2530
if(OLP_SDK_ENABLE_DEFAULT_CACHE)
@@ -456,6 +461,14 @@ if (OLP_SDK_USE_STD_ANY)
456461
PUBLIC OLP_SDK_USE_STD_ANY)
457462
endif()
458463

464+
if (OLP_SDK_EMBED_BOOST_JSON)
465+
target_compile_definitions(${PROJECT_NAME}
466+
PRIVATE OLP_SDK_EMBED_BOOST_JSON)
467+
else ()
468+
target_link_libraries(${PROJECT_NAME}
469+
PRIVATE Boost::json)
470+
endif()
471+
459472
target_compile_definitions(${PROJECT_NAME} PRIVATE BOOST_ALL_NO_LIB)
460473
target_compile_definitions(${PROJECT_NAME} PRIVATE BOOST_JSON_NO_LIB)
461474

olp-cpp-sdk-core/src/utils/BoostJsonSrc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717
* License-Filename: LICENSE
1818
*/
1919

20+
#if defined(OLP_SDK_EMBED_BOOST_JSON)
2021
#include <boost/json/src.hpp>
22+
#endif

olp-cpp-sdk-dataservice-read/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ file(GLOB_RECURSE INC "include/*.h*")
2222
file(GLOB_RECURSE SRC "src/*.*")
2323

2424

25-
find_package(Boost REQUIRED)
25+
if (OLP_SDK_EMBED_BOOST_JSON)
26+
find_package(Boost REQUIRED)
27+
else ()
28+
find_package(Boost COMPONENTS json REQUIRED)
29+
endif()
2630

2731
add_library(${PROJECT_NAME}
2832
${SRC}
@@ -53,6 +57,14 @@ if(BUILD_SHARED_LIBS)
5357
PUBLIC DATASERVICE_READ_SHARED_LIBRARY)
5458
endif()
5559

60+
if (OLP_SDK_EMBED_BOOST_JSON)
61+
target_compile_definitions(${PROJECT_NAME}
62+
PRIVATE OLP_SDK_EMBED_BOOST_JSON)
63+
else ()
64+
target_link_libraries(${PROJECT_NAME}
65+
PRIVATE Boost::json)
66+
endif()
67+
5668
# install component
5769
file(GLOB API_HEADERS "include/olp/dataservice/read/*.h")
5870
file(GLOB MODEL_HEADERS "include/olp/dataservice/read/model/*.h")

olp-cpp-sdk-dataservice-read/src/utils/BoostJsonSrc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717
* License-Filename: LICENSE
1818
*/
1919

20+
#if defined(OLP_SDK_EMBED_BOOST_JSON)
2021
#include <boost/json/src.hpp>
22+
#endif

0 commit comments

Comments
 (0)