Skip to content

Commit 1531631

Browse files
authored
feat: add nlohmann/json library (#63)
1 parent 47549a9 commit 1531631

File tree

4 files changed

+77
-4
lines changed

4 files changed

+77
-4
lines changed

LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,30 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
227227
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
228228
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
229229
SOFTWARE.
230+
231+
--------------------------------------------------------------------------------
232+
233+
3rdparty dependency nlohmann-json is statically linked in certain binary
234+
distributions. nlohmann-json has the following license:
235+
236+
MIT License
237+
238+
Copyright (c) 2013-2022 Niels Lohmann
239+
240+
Permission is hereby granted, free of charge, to any person obtaining a copy
241+
of this software and associated documentation files (the "Software"), to deal
242+
in the Software without restriction, including without limitation the rights
243+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
244+
copies of the Software, and to permit persons to whom the Software is
245+
furnished to do so, subject to the following conditions:
246+
247+
The above copyright notice and this permission notice shall be included in all
248+
copies or substantial portions of the Software.
249+
250+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
251+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
252+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
253+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
254+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
255+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
256+
SOFTWARE.

cmake_modules/IcebergThirdpartyToolchain.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,36 @@ function(resolve_nanoarrow_dependency)
226226
endfunction()
227227

228228
resolve_nanoarrow_dependency()
229+
230+
# ----------------------------------------------------------------------
231+
# nlohmann-json
232+
233+
function(resolve_nlohmann_json_dependency)
234+
prepare_fetchcontent()
235+
236+
set(JSON_BuildTests
237+
OFF
238+
CACHE BOOL "" FORCE)
239+
240+
fetchcontent_declare(nlohmann_json
241+
${FC_DECLARE_COMMON_OPTIONS}
242+
URL "https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz"
243+
)
244+
fetchcontent_makeavailable(nlohmann_json)
245+
246+
set_target_properties(nlohmann_json
247+
PROPERTIES OUTPUT_NAME "iceberg_vendored_nlohmann_json"
248+
POSITION_INDEPENDENT_CODE ON)
249+
if(MSVC_TOOLCHAIN)
250+
set(NLOHMANN_NATVIS_FILE ${nlohmann_json_SOURCE_DIR}/nlohmann_json.natvis)
251+
install(FILES ${NLOHMANN_NATVIS_FILE} DESTINATION .)
252+
endif()
253+
254+
install(TARGETS nlohmann_json
255+
EXPORT iceberg_targets
256+
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
257+
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
258+
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
259+
endfunction()
260+
261+
resolve_nlohmann_json_dependency()

src/iceberg/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ set(ICEBERG_SHARED_BUILD_INTERFACE_LIBS)
3535
set(ICEBERG_STATIC_INSTALL_INTERFACE_LIBS)
3636
set(ICEBERG_SHARED_INSTALL_INTERFACE_LIBS)
3737

38-
list(APPEND ICEBERG_STATIC_BUILD_INTERFACE_LIBS nanoarrow::nanoarrow)
39-
list(APPEND ICEBERG_SHARED_BUILD_INTERFACE_LIBS nanoarrow::nanoarrow)
40-
list(APPEND ICEBERG_STATIC_INSTALL_INTERFACE_LIBS "Iceberg::nanoarrow")
41-
list(APPEND ICEBERG_SHARED_INSTALL_INTERFACE_LIBS "Iceberg::nanoarrow")
38+
list(APPEND ICEBERG_STATIC_BUILD_INTERFACE_LIBS nanoarrow::nanoarrow
39+
nlohmann_json::nlohmann_json)
40+
list(APPEND ICEBERG_SHARED_BUILD_INTERFACE_LIBS nanoarrow::nanoarrow
41+
nlohmann_json::nlohmann_json)
42+
list(APPEND ICEBERG_STATIC_INSTALL_INTERFACE_LIBS "Iceberg::nanoarrow"
43+
"Iceberg::nlohmann_json")
44+
list(APPEND ICEBERG_SHARED_INSTALL_INTERFACE_LIBS "Iceberg::nanoarrow"
45+
"Iceberg::nlohmann_json")
4246

4347
add_iceberg_lib(iceberg
4448
SOURCES

src/iceberg/arrow_c_data_internal.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <string>
2424
#include <utility>
2525

26+
#include <nlohmann/json.hpp>
27+
2628
namespace iceberg::internal {
2729

2830
std::pair<ArrowSchema, ArrowArray> CreateExampleArrowSchemaAndArrayByNanoarrow() {
@@ -73,4 +75,11 @@ std::pair<ArrowSchema, ArrowArray> CreateExampleArrowSchemaAndArrayByNanoarrow()
7375
return {out_schema, out_array};
7476
}
7577

78+
void TestNlohmannJsonCompile() {
79+
nlohmann::json j;
80+
j["name"] = "foo";
81+
j["age"] = 30;
82+
j["city"] = "New York";
83+
}
84+
7685
} // namespace iceberg::internal

0 commit comments

Comments
 (0)