Skip to content

Commit 419ad27

Browse files
nullccxsynullccxsy
andauthored
feat: support installed nlohmann-json and nanoarrow (#209)
- Updated the dependencies installation command to include `nlohmann-json` and `nanoarrow`. - Refactored the `IcebergThirdpartyToolchain.cmake` to improve handling of `nanoarrow` and `nlohmann_json` dependencies, allowing for better integration and installation based on their availability. --------- Co-authored-by: nullccxsy <[email protected]>
1 parent ad3430f commit 419ad27

File tree

3 files changed

+75
-27
lines changed

3 files changed

+75
-27
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ jobs:
8282
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
8383
with:
8484
fetch-depth: 0
85-
- name: Install ZLIB
85+
- name: Install dependencies
8686
shell: cmd
8787
run: |
88-
vcpkg install zlib:x64-windows
88+
vcpkg install zlib:x64-windows nlohmann-json:x64-windows nanoarrow:x64-windows
8989
- name: Build Iceberg
9090
shell: cmd
9191
run: |

cmake_modules/IcebergThirdpartyToolchain.cmake

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,41 @@ function(resolve_nanoarrow_dependency)
239239
fetchcontent_declare(nanoarrow
240240
${FC_DECLARE_COMMON_OPTIONS}
241241
URL "https://dlcdn.apache.org/arrow/apache-arrow-nanoarrow-0.7.0/apache-arrow-nanoarrow-0.7.0.tar.gz"
242-
)
242+
FIND_PACKAGE_ARGS
243+
NAMES
244+
nanoarrow
245+
CONFIG)
243246
fetchcontent_makeavailable(nanoarrow)
244247

245-
set_target_properties(nanoarrow_static
246-
PROPERTIES OUTPUT_NAME "iceberg_vendored_nanoarrow"
247-
POSITION_INDEPENDENT_CODE ON)
248-
install(TARGETS nanoarrow_static
249-
EXPORT iceberg_targets
250-
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
251-
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
252-
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
248+
if(nanoarrow_SOURCE_DIR)
249+
if(NOT TARGET nanoarrow::nanoarrow_static)
250+
add_library(nanoarrow::nanoarrow_static INTERFACE IMPORTED)
251+
target_link_libraries(nanoarrow::nanoarrow_static INTERFACE nanoarrow_static)
252+
target_include_directories(nanoarrow::nanoarrow_static
253+
INTERFACE ${nanoarrow_BINARY_DIR}
254+
${nanoarrow_SOURCE_DIR})
255+
endif()
256+
257+
set(NANOARROW_VENDORED TRUE)
258+
set_target_properties(nanoarrow_static
259+
PROPERTIES OUTPUT_NAME "iceberg_vendored_nanoarrow"
260+
POSITION_INDEPENDENT_CODE ON)
261+
install(TARGETS nanoarrow_static
262+
EXPORT iceberg_targets
263+
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
264+
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
265+
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
266+
else()
267+
set(NANOARROW_VENDORED FALSE)
268+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES nanoarrow)
269+
endif()
270+
271+
set(ICEBERG_SYSTEM_DEPENDENCIES
272+
${ICEBERG_SYSTEM_DEPENDENCIES}
273+
PARENT_SCOPE)
274+
set(NANOARROW_VENDORED
275+
${NANOARROW_VENDORED}
276+
PARENT_SCOPE)
253277
endfunction()
254278

255279
# ----------------------------------------------------------------------
@@ -265,22 +289,46 @@ function(resolve_nlohmann_json_dependency)
265289
fetchcontent_declare(nlohmann_json
266290
${FC_DECLARE_COMMON_OPTIONS}
267291
URL "https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz"
268-
)
292+
FIND_PACKAGE_ARGS
293+
NAMES
294+
nlohmann_json
295+
CONFIG)
269296
fetchcontent_makeavailable(nlohmann_json)
270297

271-
set_target_properties(nlohmann_json
272-
PROPERTIES OUTPUT_NAME "iceberg_vendored_nlohmann_json"
273-
POSITION_INDEPENDENT_CODE ON)
274-
if(MSVC_TOOLCHAIN)
275-
set(NLOHMANN_NATVIS_FILE ${nlohmann_json_SOURCE_DIR}/nlohmann_json.natvis)
276-
install(FILES ${NLOHMANN_NATVIS_FILE} DESTINATION .)
298+
if(nlohmann_json_SOURCE_DIR)
299+
if(NOT TARGET nlohmann_json::nlohmann_json)
300+
add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED)
301+
target_link_libraries(nlohmann_json::nlohmann_json INTERFACE nlohmann_json)
302+
target_include_directories(nlohmann_json::nlohmann_json
303+
INTERFACE ${nlohmann_json_BINARY_DIR}
304+
${nlohmann_json_SOURCE_DIR})
305+
endif()
306+
307+
set(NLOHMANN_JSON_VENDORED TRUE)
308+
set_target_properties(nlohmann_json
309+
PROPERTIES OUTPUT_NAME "iceberg_vendored_nlohmann_json"
310+
POSITION_INDEPENDENT_CODE ON)
311+
if(MSVC_TOOLCHAIN)
312+
set(NLOHMANN_NATVIS_FILE ${nlohmann_json_SOURCE_DIR}/nlohmann_json.natvis)
313+
install(FILES ${NLOHMANN_NATVIS_FILE} DESTINATION .)
314+
endif()
315+
316+
install(TARGETS nlohmann_json
317+
EXPORT iceberg_targets
318+
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
319+
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
320+
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
321+
else()
322+
set(NLOHMANN_JSON_VENDORED FALSE)
323+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES nlohmann_json)
277324
endif()
278325

279-
install(TARGETS nlohmann_json
280-
EXPORT iceberg_targets
281-
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
282-
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
283-
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
326+
set(ICEBERG_SYSTEM_DEPENDENCIES
327+
${ICEBERG_SYSTEM_DEPENDENCIES}
328+
PARENT_SCOPE)
329+
set(NLOHMANN_JSON_VENDORED
330+
${NLOHMANN_JSON_VENDORED}
331+
PARENT_SCOPE)
284332
endfunction()
285333

286334
# ----------------------------------------------------------------------

src/iceberg/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ list(APPEND
7272
ZLIB::ZLIB)
7373
list(APPEND
7474
ICEBERG_STATIC_INSTALL_INTERFACE_LIBS
75-
"Iceberg::nanoarrow_static"
76-
"Iceberg::nlohmann_json"
75+
"$<IF:$<BOOL:${NANOARROW_VENDORED}>,Iceberg::nanoarrow_static,$<IF:$<TARGET_EXISTS:nanoarrow::nanoarrow_static>,nanoarrow::nanoarrow_static,nanoarrow::nanoarrow_shared>>"
76+
"$<IF:$<BOOL:${NLOHMANN_JSON_VENDORED}>,Iceberg::nlohmann_json,$<IF:$<TARGET_EXISTS:nlohmann_json::nlohmann_json>,nlohmann_json::nlohmann_json,nlohmann_json::nlohmann_json>>"
7777
"$<IF:$<BOOL:${SPDLOG_VENDORED}>,Iceberg::spdlog,spdlog::spdlog>")
7878
list(APPEND
7979
ICEBERG_SHARED_INSTALL_INTERFACE_LIBS
80-
"Iceberg::nanoarrow_shared"
81-
"Iceberg::nlohmann_json"
80+
"$<IF:$<BOOL:${NANOARROW_VENDORED}>,Iceberg::nanoarrow_shared,$<IF:$<TARGET_EXISTS:nanoarrow::nanoarrow_shared>,nanoarrow::nanoarrow_shared,nanoarrow::nanoarrow_static>>"
81+
"$<IF:$<BOOL:${NLOHMANN_JSON_VENDORED}>,Iceberg::nlohmann_json,$<IF:$<TARGET_EXISTS:nlohmann_json::nlohmann_json>,nlohmann_json::nlohmann_json,nlohmann_json::nlohmann_json>>"
8282
"$<IF:$<BOOL:${SPDLOG_VENDORED}>,Iceberg::spdlog,spdlog::spdlog>")
8383

8484
add_iceberg_lib(iceberg

0 commit comments

Comments
 (0)