Skip to content

Commit 196faca

Browse files
committed
Try finding RapidJSON with pkg-config before fetching with git
This makes offline builds possible. RapidJSON also installs a CMake config package, but it is an old style package that is unsuitable for cross-compiling. pkg-config handles this better. Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
1 parent 271b3ac commit 196faca

File tree

8 files changed

+31
-23
lines changed

8 files changed

+31
-23
lines changed

CMake/FindRapidJSON.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
find_package(PkgConfig)
2+
if (PKG_CONFIG_FOUND)
3+
pkg_check_modules(RAPIDJSON RapidJSON)
4+
endif()
5+
6+
if (NOT RAPIDJSON_FOUND)
7+
if (NOT rapidjson_POPULATED)
8+
FetchContent_Populate(
9+
rapidjson
10+
GIT_REPOSITORY https://github.com/Tencent/rapidjson.git
11+
GIT_TAG 80b6d1c83402a5785c486603c5611923159d0894
12+
GIT_SUBMODULES ""
13+
)
14+
endif()
15+
FetchContent_GetProperties(rapidjson)
16+
set(RAPIDJSON_INCLUDE_DIRS "${rapidjson_SOURCE_DIR}/include")
17+
endif()
18+
19+
add_definitions("-DRAPIDJSON_HAS_STDSTRING=1")

CMake/Findrapidjson.cmake

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
find_package(CURL REQUIRED)
22
find_package(OpenSSL REQUIRED)
33
find_package(aio REQUIRED)
4-
find_package(rapidjson REQUIRED)
4+
find_package(RapidJSON REQUIRED MODULE)
55

66
link_libraries(rt pthread resolv)
77

@@ -19,7 +19,7 @@ add_library(overlaybd_image_lib
1919
target_include_directories(overlaybd_image_lib PUBLIC
2020
${CURL_INCLUDE_DIRS}
2121
${OPENSSL_INCLUDE_DIR}
22-
${rapidjson_SOURCE_DIR}/include
22+
${RAPIDJSON_INCLUDE_DIRS}
2323
${PHOTON_INCLUDE_DIR}
2424
)
2525

@@ -39,7 +39,7 @@ target_include_directories(overlaybd-tcmu PUBLIC
3939
${TCMU_INCLUDE_DIR}
4040
${CURL_INCLUDE_DIRS}
4141
${OPENSSL_INCLUDE_DIR}
42-
${rapidjson_SOURCE_DIR}/include
42+
${RAPIDJSON_INCLUDE_DIRS}
4343
${PHOTON_INCLUDE_DIR}
4444
)
4545
target_link_libraries(overlaybd-tcmu

src/overlaybd/registryfs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ find_package(CURL REQUIRED)
55
add_library(registryfs_lib STATIC ${SOURCE_REGISTRYFS})
66
target_include_directories(registryfs_lib PUBLIC
77
${CURL_INCLUDE_DIRS}
8-
${rapidjson_SOURCE_DIR}/include
8+
${RAPIDJSON_INCLUDE_DIRS}
99
${PHOTON_INCLUDE_DIR}
1010
)

src/overlaybd/stream_convertor/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ file(GLOB SOURCE_SERV "*.cpp")
33
add_executable(overlaybd-streamConv ${SOURCE_SERV})
44
target_include_directories(overlaybd-streamConv PUBLIC
55
${PHOTON_INCLUDE_DIR}
6-
${rapidjson_SOURCE_DIR}/include
6+
${RAPIDJSON_INCLUDE_DIRS}
77
)
88
target_link_libraries(overlaybd-streamConv
99
photon_static

src/overlaybd/tar/erofs/test/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ target_link_libraries(erofs_simple_test gtest gtest_main pthread photon_static
1212

1313
target_include_directories(erofs_simple_test PUBLIC
1414
${PHOTON_INCLUDE_DIR}
15-
${rapidjson_SOURCE_DIR}/include
15+
${RAPIDJSON_INCLUDE_DIRS}
1616
)
1717

1818
add_test(
@@ -28,7 +28,7 @@ target_link_libraries(erofs_stress_test gtest gtest_main pthread photon_static
2828

2929
target_include_directories(erofs_stress_test PUBLIC
3030
${PHOTON_INCLUDE_DIR}
31-
${rapidjson_SOURCE_DIR}/include
31+
${RAPIDJSON_INCLUDE_DIRS}
3232
)
3333

3434
add_test(

src/test/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ link_directories($ENV{GTEST}/lib)
77
add_executable(image_service_test image_service_test.cpp)
88
target_include_directories(image_service_test PUBLIC
99
${PHOTON_INCLUDE_DIR}
10-
${rapidjson_SOURCE_DIR}/include
10+
${RAPIDJSON_INCLUDE_DIRS}
1111
)
1212
target_link_libraries(image_service_test gtest gtest_main gflags pthread photon_static overlaybd_lib overlaybd_image_lib)
1313

@@ -34,14 +34,14 @@ gtest
3434

3535
target_include_directories(simple_credsrv_test PUBLIC
3636
${PHOTON_INCLUDE_DIR}
37-
${rapidjson_SOURCE_DIR}/include
37+
${RAPIDJSON_INCLUDE_DIRS}
3838
$ENV{GTEST}/googletest/include
3939
)
4040

4141
add_executable(trace_test trace_test.cpp ../tools/comm_func.cpp)
4242
target_include_directories(trace_test PUBLIC
4343
${PHOTON_INCLUDE_DIR}
44-
${rapidjson_SOURCE_DIR}/include
44+
${RAPIDJSON_INCLUDE_DIRS}
4545
)
4646
target_link_libraries(trace_test gtest gtest_main gflags pthread photon_static overlaybd_lib overlaybd_image_lib)
4747

src/tools/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ target_include_directories(overlaybd-zfile PUBLIC ${PHOTON_INCLUDE_DIR})
1717
target_link_libraries(overlaybd-zfile photon_static overlaybd_lib)
1818

1919
add_executable(overlaybd-apply overlaybd-apply.cpp)
20-
target_include_directories(overlaybd-apply PUBLIC ${PHOTON_INCLUDE_DIR} ${rapidjson_SOURCE_DIR}/include)
20+
target_include_directories(overlaybd-apply PUBLIC ${PHOTON_INCLUDE_DIR} ${RAPIDJSON_INCLUDE_DIRS})
2121
target_link_libraries(overlaybd-apply photon_static overlaybd_lib overlaybd_image_lib checksum_lib)
2222
set_target_properties(overlaybd-apply PROPERTIES INSTALL_RPATH "/opt/overlaybd/lib")
2323

2424
add_executable(turboOCI-apply turboOCI-apply.cpp)
25-
target_include_directories(turboOCI-apply PUBLIC ${PHOTON_INCLUDE_DIR} ${rapidjson_SOURCE_DIR}/include)
25+
target_include_directories(turboOCI-apply PUBLIC ${PHOTON_INCLUDE_DIR} ${RAPIDJSON_INCLUDE_DIRS})
2626
target_link_libraries(turboOCI-apply photon_static overlaybd_lib overlaybd_image_lib)
2727
set_target_properties(turboOCI-apply PROPERTIES INSTALL_RPATH "/opt/overlaybd/lib")
2828

0 commit comments

Comments
 (0)