-
Notifications
You must be signed in to change notification settings - Fork 38
/
CMakeLists.txt
711 lines (622 loc) · 28.5 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
message(STATUS "Building using CMake version: ${CMAKE_VERSION}")
cmake_minimum_required(VERSION 3.14)
set(NANOARROW_VERSION "0.7.0-SNAPSHOT")
string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" NANOARROW_BASE_VERSION
"${NANOARROW_VERSION}")
project(nanoarrow VERSION "${NANOARROW_BASE_VERSION}")
set(NANOARROW_VERSION_MAJOR "${nanoarrow_VERSION_MAJOR}")
set(NANOARROW_VERSION_MINOR "${nanoarrow_VERSION_MINOR}")
set(NANOARROW_VERSION_PATCH "${nanoarrow_VERSION_PATCH}")
# General options
option(NANOARROW_NAMESPACE "A prefix for exported symbols" OFF)
# Feature options
option(NANOARROW_IPC "Build IPC extension" OFF)
option(NANOARROW_FLATCC_ROOT_DIR "Root directory for flatcc include and lib directories"
OFF)
option(NANOARROW_FLATCC_INCLUDE_DIR "Include directory for flatcc includes" OFF)
option(NANOARROW_FLATCC_LIB_DIR "Library directory that contains libflatccrt.a" OFF)
option(NANOARROW_DEVICE "Build device extension" OFF)
option(NANOARROW_TESTING "Build testng extension" OFF)
option(NANOARROW_DEVICE_WITH_METAL "Build Apple metal libraries" OFF)
option(NANOARROW_DEVICE_WITH_CUDA "Build CUDA libraries" OFF)
# Development options
option(NANOARROW_BUILD_APPS "Build utility applications" OFF)
option(NANOARROW_BUILD_TESTS "Build tests" OFF)
option(NANOARROW_BUILD_TESTS_WITH_ARROW "Build tests that require Arrow" OFF)
option(NANOARROW_BUILD_BENCHMARKS "Build benchmarks" OFF)
option(NANOARROW_BUILD_INTEGRATION_TESTS
"Build cross-implementation Arrow integration tests" OFF)
option(NANOARROW_BUNDLE "Create bundled nanoarrow.h and nanoarrow.c" OFF)
option(NANOARROW_BUNDLE_AS_CPP "Bundle nanoarrow source file as nanoarrow.cc" OFF)
option(NANOARROW_CODE_COVERAGE "Enable coverage reporting" OFF)
option(NANOARROW_ARROW_STATIC
"Use a statically-linked Arrow C++ build when linking tests" OFF)
if(NOT DEFINED CMAKE_C_STANDARD)
if(NANOARROW_IPC)
# flatcc requires C11 for alignas() and static_assert() in flatcc_generated.h
# It may be possible to use C99 mode to build the runtime and/or generated header
# should this cause problems for users.
set(CMAKE_C_STANDARD 11)
else()
set(CMAKE_C_STANDARD 99)
endif()
set(CMAKE_C_STANDARD_REQUIRED ON)
endif()
if(NANOARROW_NAMESPACE)
set(NANOARROW_NAMESPACE_DEFINE "#define NANOARROW_NAMESPACE ${NANOARROW_NAMESPACE}")
else()
set(NANOARROW_NAMESPACE_DEFINE "// #define NANOARROW_NAMESPACE YourNamespaceHere")
endif()
add_library(nanoarrow_coverage_config INTERFACE)
install(TARGETS nanoarrow_coverage_config
DESTINATION lib
EXPORT nanoarrow-exports)
if(NANOARROW_CODE_COVERAGE)
target_compile_options(nanoarrow_coverage_config INTERFACE -O0 -g --coverage)
target_link_options(nanoarrow_coverage_config INTERFACE --coverage)
endif()
# Avoids a warning about timestamps on downloaded files (prefer new policy
# if available))
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.23")
cmake_policy(SET CMP0135 NEW)
endif()
if(NANOARROW_BUNDLE)
message(STATUS "Generating bundled nanoarrow sources using ci/scripts/bundle.py")
find_package(Python3
COMPONENTS Interpreter
REQUIRED)
# Set up arguments to the bundler
set(NANOARROW_BUNDLE_ARGS "--with-ipc" "--with-device" "--with-testing" "--with-flatcc")
if(NANOARROW_BUNDLE_AS_CPP)
list(APPEND NANOARROW_BUNDLE_ARGS "--cpp")
set(NANOARROW_BUILD_SOURCES "${CMAKE_BINARY_DIR}/bundled/src/nanoarrow.cc")
else()
set(NANOARROW_BUILD_SOURCES "${CMAKE_BINARY_DIR}/bundled/src/nanoarrow.c")
endif()
if(NANOARROW_NAMESPACE)
list(APPEND NANOARROW_BUNDLE_ARGS "--symbol-namespace=${NANOARROW_NAMESPACE}")
endif()
# Run the bundler
execute_process(COMMAND ${Python3_EXECUTABLE}
"${CMAKE_CURRENT_SOURCE_DIR}/ci/scripts/bundle.py"
"--output-dir" "${CMAKE_BINARY_DIR}/bundled"
${NANOARROW_BUNDLE_ARGS})
set(NANOARROW_BUILD_INCLUDE_DIR "${CMAKE_BINARY_DIR}/bundled/include")
set(NANOARROW_IPC_BUILD_SOURCES "${CMAKE_BINARY_DIR}/bundled/src/nanoarrow_ipc.c")
set(NANOARROW_DEVICE_BUILD_SOURCES "${CMAKE_BINARY_DIR}/bundled/src/nanoarrow_device.c")
set(NANOARROW_TESTING_BUILD_SOURCES
"${CMAKE_BINARY_DIR}/bundled/src/nanoarrow_testing.cc")
set(NANOARROW_FLATCC_BUILD_SOURCES "${CMAKE_BINARY_DIR}/bundled/src/flatcc.c")
else()
# Generate the version information
configure_file(src/nanoarrow/nanoarrow_config.h.in src/nanoarrow/nanoarrow_config.h)
set(NANOARROW_BUILD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
endif()
# Start the list of headers to install
set(NANOARROW_INSTALL_HEADERS ${NANOARROW_BUILD_INCLUDE_DIR}/nanoarrow/nanoarrow.h
${NANOARROW_BUILD_INCLUDE_DIR}/nanoarrow/nanoarrow.hpp)
# If the bundler didn't already assign the source files for the library, do so here.
# Also handle install() arguments that are different between the bundled and not
# bundled version.
if(NOT NANOARROW_BUNDLE)
set(NANOARROW_BUILD_SOURCES
src/nanoarrow/common/array.c src/nanoarrow/common/schema.c
src/nanoarrow/common/array_stream.c src/nanoarrow/common/utils.c)
install(FILES src/nanoarrow/common/inline_array.h src/nanoarrow/common/inline_buffer.h
src/nanoarrow/common/inline_types.h DESTINATION include/nanoarrow/common)
list(APPEND NANOARROW_INSTALL_HEADERS
"${CMAKE_CURRENT_BINARY_DIR}/src/nanoarrow/nanoarrow_config.h")
endif()
# Add the nanoarrow library target
add_library(nanoarrow ${NANOARROW_BUILD_SOURCES})
target_include_directories(nanoarrow
PUBLIC $<BUILD_INTERFACE:${NANOARROW_BUILD_INCLUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
$<INSTALL_INTERFACE:include>)
install(FILES ${NANOARROW_INSTALL_HEADERS} DESTINATION include/nanoarrow)
if(NANOARROW_IPC)
# Add the flatcc (runtime) dependency
set(FLATCC_RTONLY
ON
CACHE INTERNAL "")
set(FLATCC_REFLECTION
OFF
CACHE INTERNAL "")
# A flatcc installation is unlikely, so default to building the vendored one
if(NOT NANOARROW_FLATCC_INCLUDE_DIR AND NOT NANOARROW_FLATCC_ROOT_DIR)
# If the bundler didn't already assign the source files for the library, do so here
if(NOT NANOARROW_BUNDLE)
set(NANOARROW_FLATCC_BUILD_SOURCES
thirdparty/flatcc/src/runtime/builder.c thirdparty/flatcc/src/runtime/emitter.c
thirdparty/flatcc/src/runtime/verifier.c thirdparty/flatcc/src/runtime/refmap.c)
set(NANOARROW_FLATCC_INCLUDE_DIR
"${CMAKE_CURRENT_LIST_DIR}/thirdparty/flatcc/include")
else()
set(NANOARROW_FLATCC_INCLUDE_DIR "${NANOARROW_BUILD_INCLUDE_DIR}")
endif()
add_library(flatccrt STATIC ${NANOARROW_FLATCC_BUILD_SOURCES})
target_include_directories(flatccrt
PUBLIC $<BUILD_INTERFACE:${NANOARROW_FLATCC_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)
install(TARGETS flatccrt
DESTINATION lib
EXPORT nanoarrow-exports)
elseif(NOT NANOARROW_FLATCC_ROOT_DIR)
add_library(flatccrt STATIC IMPORTED)
set_target_properties(flatccrt
PROPERTIES IMPORTED_LOCATION
"${NANOARROW_FLATCC_LIB_DIR}/libflatccrt.a"
INTERFACE_INCLUDE_DIRECTORIES
"${NANOARROW_FLATCC_INCLUDE_DIR}")
elseif(NOT NANOARROW_FLATCC_INCLUDE_DIR)
set(NANOARROW_FLATCC_INCLUDE_DIR "${NANOARROW_FLATCC_ROOT_DIR}/include")
add_library(flatccrt STATIC IMPORTED)
set_target_properties(flatccrt
PROPERTIES IMPORTED_LOCATION
"${NANOARROW_FLATCC_ROOT_DIR}/lib/libflatccrt.a"
INTERFACE_INCLUDE_DIRECTORIES
"${NANOARROW_FLATCC_INCLUDE_DIR}")
endif()
if(NOT NANOARROW_BUNDLE)
set(NANOARROW_IPC_BUILD_SOURCES
src/nanoarrow/ipc/decoder.c src/nanoarrow/ipc/encoder.c
src/nanoarrow/ipc/reader.c src/nanoarrow/ipc/writer.c)
endif()
add_library(nanoarrow_ipc ${NANOARROW_IPC_BUILD_SOURCES})
target_link_libraries(nanoarrow_ipc
PRIVATE flatccrt
PUBLIC nanoarrow nanoarrow_coverage_config)
target_include_directories(nanoarrow_ipc
PUBLIC $<BUILD_INTERFACE:${NANOARROW_BUILD_INCLUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
$<BUILD_INTERFACE:${NANOARROW_IPC_FLATCC_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)
install(TARGETS nanoarrow_ipc DESTINATION lib)
install(FILES src/nanoarrow/nanoarrow_ipc.h src/nanoarrow/nanoarrow_ipc.hpp
src/nanoarrow/ipc/flatcc_generated.h DESTINATION include/nanoarrow)
install(FILES src/nanoarrow/hpp/array_stream.hpp
src/nanoarrow/hpp/buffer.hpp
src/nanoarrow/hpp/exception.hpp
src/nanoarrow/hpp/operators.hpp
src/nanoarrow/hpp/unique.hpp
src/nanoarrow/hpp/view.hpp
DESTINATION include/nanoarrow/hpp)
endif()
if(NANOARROW_IPC AND (NANOARROW_BUILD_INTEGRATION_TESTS OR NANOARROW_BUILD_TESTS))
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
add_executable(nanoarrow_ipc_integration src/nanoarrow/integration/ipc_integration.cc)
target_include_directories(nanoarrow_ipc_integration
PUBLIC $<BUILD_INTERFACE:${NANOARROW_BUILD_INCLUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
$<INSTALL_INTERFACE:include>)
target_link_libraries(nanoarrow_ipc_integration
PRIVATE nanoarrow_testing nanoarrow_ipc flatccrt
nanoarrow_coverage_config)
endif()
if(NANOARROW_DEVICE)
if(NANOARROW_DEVICE_WITH_METAL)
if(NOT EXISTS "${CMAKE_BINARY_DIR}/metal-cpp")
message(STATUS "Fetching metal-cpp")
file(DOWNLOAD
"https://developer.apple.com/metal/cpp/files/metal-cpp_macOS12_iOS15.zip"
"${CMAKE_BINARY_DIR}/metal-cpp.zip")
file(ARCHIVE_EXTRACT
INPUT
${CMAKE_BINARY_DIR}/metal-cpp.zip
DESTINATION
${CMAKE_BINARY_DIR})
endif()
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_library(METAL_LIBRARY Metal REQUIRED)
message(STATUS "Metal framework found at '${METAL_LIBRARY}'")
find_library(FOUNDATION_LIBRARY Foundation REQUIRED)
message(STATUS "Foundation framework found at '${FOUNDATION_LIBRARY}'")
find_library(QUARTZ_CORE_LIBRARY QuartzCore REQUIRED)
message(STATUS "CoreFoundation framework found at '${QUARTZ_CORE_LIBRARY}'")
set(NANOARROW_DEVICE_INCLUDE_METAL "${CMAKE_BINARY_DIR}/metal-cpp")
add_library(nanoarrow_metal_impl src/nanoarrow/device/metal_impl.cc)
target_link_libraries(nanoarrow_metal_impl
PRIVATE ${METAL_LIBRARY} ${FOUNDATION_LIBRARY}
${QUARTZ_CORE_LIBRARY})
target_include_directories(nanoarrow_metal_impl
PRIVATE ${NANOARROW_DEVICE_INCLUDE_METAL})
install(TARGETS nanoarrow_metal_impl
DESTINATION lib
EXPORT nanoarrow-exports)
set(NANOARROW_DEVICE_SOURCES_METAL src/nanoarrow/device/metal.cc)
set(NANOARROW_DEVICE_DEFS_METAL "NANOARROW_DEVICE_WITH_METAL")
set(NANOARROW_DEVICE_LIBS_METAL nanoarrow_metal_impl)
endif()
if(NANOARROW_DEVICE_WITH_CUDA)
find_package(CUDAToolkit REQUIRED)
set(NANOARROW_DEVICE_SOURCES_CUDA src/nanoarrow/device/cuda.c)
set(NANOARROW_DEVICE_LIBS_CUDA CUDA::cuda_driver)
set(NANOARROW_DEVICE_DEFS_CUDA "NANOARROW_DEVICE_WITH_CUDA")
endif()
# If the bundler didn't already assign the source files for the library, do so here
if(NOT NANOARROW_BUNDLE)
set(NANOARROW_DEVICE_BUILD_SOURCES src/nanoarrow/device/device.c
${NANOARROW_DEVICE_SOURCES_CUDA})
endif()
add_library(nanoarrow_device ${NANOARROW_DEVICE_BUILD_SOURCES}
${NANOARROW_DEVICE_SOURCES_METAL})
target_include_directories(nanoarrow_device
PUBLIC $<BUILD_INTERFACE:${NANOARROW_BUILD_INCLUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
$<BUILD_INTERFACE:${NANOARROW_DEVICE_INCLUDE_METAL}>
$<INSTALL_INTERFACE:include>)
target_compile_definitions(nanoarrow_device PRIVATE ${NANOARROW_DEVICE_DEFS_METAL}
${NANOARROW_DEVICE_DEFS_CUDA})
target_link_libraries(nanoarrow_device
PRIVATE ${NANOARROW_DEVICE_LIBS_CUDA}
${NANOARROW_DEVICE_LIBS_METAL}
PUBLIC nanoarrow nanoarrow_coverage_config)
install(TARGETS nanoarrow_device DESTINATION lib)
install(FILES src/nanoarrow/nanoarrow_device.h src/nanoarrow/nanoarrow_device.hpp
DESTINATION include/nanoarrow)
endif()
if(NANOARROW_TESTING
OR NANOARROW_BUILD_TESTS
OR NANOARROW_BUILD_INTEGRATION_TESTS)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
if(NOT NANOARROW_BUNDLE)
set(NANOARROW_TESTING_BUILD_SOURCES src/nanoarrow/testing/testing.cc)
endif()
add_subdirectory("thirdparty/nlohmann_json")
install(TARGETS nlohmann_json
DESTINATION lib
EXPORT nanoarrow-exports)
add_library(nanoarrow_testing src/nanoarrow/testing/testing.cc)
target_include_directories(nanoarrow_testing
PUBLIC $<BUILD_INTERFACE:${NANOARROW_BUILD_INCLUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
$<INSTALL_INTERFACE:include>)
target_link_libraries(nanoarrow_testing
PRIVATE nlohmann_json::nlohmann_json
PUBLIC nanoarrow nanoarrow_coverage_config)
set_target_properties(nanoarrow_testing PROPERTIES POSITION_INDEPENDENT_CODE ON)
install(FILES src/nanoarrow/nanoarrow_testing.hpp DESTINATION include/nanoarrow)
endif()
# Always build integration test if building tests
if(NANOARROW_BUILD_TESTS OR NANOARROW_BUILD_INTEGRATION_TESTS)
set_target_properties(nanoarrow PROPERTIES POSITION_INDEPENDENT_CODE ON)
add_library(nanoarrow_c_data_integration SHARED
src/nanoarrow/integration/c_data_integration.cc)
target_compile_definitions(nanoarrow_c_data_integration PRIVATE NANOARROW_BUILD_DLL
NANOARROW_EXPORT_DLL)
target_include_directories(nanoarrow_c_data_integration
PUBLIC $<BUILD_INTERFACE:${NANOARROW_BUILD_INCLUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
$<INSTALL_INTERFACE:include>)
target_link_libraries(nanoarrow_c_data_integration PRIVATE nanoarrow_testing)
endif()
# Common configuration for all targets
foreach(target
nanoarrow
nanoarrow_ipc
nanoarrow_device
nanoarrow_testing
nanoarrow_c_data_integration
nanoarrow_ipc_json_integration)
if(TARGET ${target})
# Define the nanoarrow::xxx alias target
add_library(nanoarrow::${target} ALIAS ${target})
# Ensure NANOARROW_DEBUG is defined for debug builds
target_compile_definitions(${target} PUBLIC "$<$<CONFIG:Debug>:NANOARROW_DEBUG>")
# Ensure target is added to nanoarrow-exports
install(TARGETS ${target}
DESTINATION lib
EXPORT nanoarrow-exports)
# For debug builds, ensure we aggressively set compiler warning flags and
# error for any compiler warnings
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(${target}
PRIVATE $<$<CONFIG:Debug>:-Wall
-Werror
-Wextra
-Wpedantic
-Wno-type-limits
-Wmaybe-uninitialized
-Wunused-result
-Wconversion
-Wno-sign-conversion>)
target_compile_options(${target} PRIVATE -Wno-misleading-indentation)
elseif(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_C_COMPILER_ID STREQUAL
"Clang")
target_compile_options(${target}
PRIVATE $<$<CONFIG:Debug>:-Wall
-Werror
-Wextra
-Wpedantic
-Wdocumentation
-Wconversion
-Wno-sign-conversion>)
endif()
endif()
endforeach()
if(NANOARROW_BUILD_TESTS)
set(MEMORYCHECK_COMMAND_OPTIONS
"--leak-check=full --suppressions=${CMAKE_CURRENT_LIST_DIR}/valgrind.supp --error-exitcode=1"
)
include(CTest)
if(NANOARROW_BUILD_TESTS_WITH_ARROW)
find_package(Arrow REQUIRED)
message(STATUS "Arrow version: ${ARROW_VERSION}")
message(STATUS "Arrow SO version: ${ARROW_FULL_SO_VERSION}")
# Give caller the option to link a static version of Arrow C++
if(NANOARROW_ARROW_STATIC)
set(NANOARROW_ARROW_TARGET arrow_static)
else()
set(NANOARROW_ARROW_TARGET arrow_shared)
endif()
# Arrow >= 10.0.0 requires C++17; GTest requires C++11.
# Leave the option open to use an older version of Arrow
# to make it easier to test on old Linux (e.g., Centos7)
if(${ARROW_VERSION} VERSION_GREATER_EQUAL "10.0.0")
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
add_subdirectory("thirdparty/googletest")
# Be sure to keep these tests in sync with src/nanoarrow/meson.build
add_executable(utils_test src/nanoarrow/common/utils_test.cc)
add_executable(buffer_test src/nanoarrow/common/buffer_test.cc)
add_executable(array_test src/nanoarrow/common/array_test.cc)
add_executable(schema_test src/nanoarrow/common/schema_test.cc)
add_executable(array_stream_test src/nanoarrow/common/array_stream_test.cc)
add_executable(nanoarrow_testing_test src/nanoarrow/testing/testing_test.cc)
add_executable(c_data_integration_test
src/nanoarrow/integration/c_data_integration_test.cc)
add_executable(hpp_array_stream src/nanoarrow/hpp/array_stream_test.cc)
add_executable(hpp_buffer src/nanoarrow/hpp/buffer_test.cc)
add_executable(hpp_exception src/nanoarrow/hpp/exception_test.cc)
add_executable(hpp_unique src/nanoarrow/hpp/unique_test.cc)
add_executable(hpp_view src/nanoarrow/hpp/view_test.cc)
target_link_libraries(utils_test
nanoarrow_testing
gtest_main
gmock_main
${NANOARROW_ARROW_TARGET}
nanoarrow_coverage_config)
target_link_libraries(buffer_test nanoarrow gtest_main nanoarrow_coverage_config)
target_link_libraries(array_test
nanoarrow
gtest_main
gmock_main
${NANOARROW_ARROW_TARGET}
nanoarrow_coverage_config)
target_link_libraries(schema_test
nanoarrow
gtest_main
${NANOARROW_ARROW_TARGET}
nanoarrow_coverage_config)
target_link_libraries(array_stream_test
nanoarrow
gtest_main
gmock_main
nanoarrow_coverage_config)
target_link_libraries(nanoarrow_testing_test nanoarrow_testing gtest_main
nanoarrow_coverage_config)
target_link_libraries(c_data_integration_test
nanoarrow
nanoarrow_c_data_integration
gtest_main
nanoarrow_coverage_config)
target_link_libraries(hpp_array_stream
nanoarrow
gtest_main
gmock_main
nanoarrow_coverage_config)
target_link_libraries(hpp_buffer
nanoarrow
gtest_main
gmock_main
nanoarrow_coverage_config)
target_link_libraries(hpp_exception
nanoarrow
gtest_main
gmock_main
nanoarrow_coverage_config)
target_link_libraries(hpp_unique
nanoarrow
gtest_main
gmock_main
nanoarrow_coverage_config)
target_link_libraries(hpp_view
nanoarrow
gtest_main
gmock_main
nanoarrow_coverage_config)
list(APPEND
NanoarrowTests
utils_test
buffer_test
array_test
schema_test
array_stream_test
nanoarrow_testing_test
c_data_integration_test
hpp_array_stream
hpp_buffer
hpp_exception
hpp_unique
hpp_view)
if(Arrow_FOUND)
foreach(test_target ${NanoarrowTests})
target_compile_definitions(${test_target}
PRIVATE -DNANOARROW_BUILD_TESTS_WITH_ARROW)
endforeach()
endif()
include(GoogleTest)
# Some users have reported a timeout with the default value of 5
# Building with -DBUILD_SHARED_LIBS=ON may also help reduce the size of test
# executables.
gtest_discover_tests(utils_test DISCOVERY_TIMEOUT 10)
gtest_discover_tests(buffer_test DISCOVERY_TIMEOUT 10)
gtest_discover_tests(array_test DISCOVERY_TIMEOUT 10)
gtest_discover_tests(schema_test DISCOVERY_TIMEOUT 10)
gtest_discover_tests(array_stream_test DISCOVERY_TIMEOUT 10)
gtest_discover_tests(nanoarrow_testing_test DISCOVERY_TIMEOUT 10)
gtest_discover_tests(c_data_integration_test DISCOVERY_TIMEOUT 10)
gtest_discover_tests(hpp_array_stream)
gtest_discover_tests(hpp_buffer)
gtest_discover_tests(hpp_exception)
gtest_discover_tests(hpp_unique)
gtest_discover_tests(hpp_view)
if(NANOARROW_IPC)
# zlib to decode gzipped integration testing JSON files
# We don't use Arrow C++ for this because building Arrow C++ with zlib
# is not trivial on Windows.
find_package(ZLIB)
if(NOT ZLIB_FOUND)
# Wrapper around FetchContent that better isolates the zlib CMakeLists.txt
message(STATUS "Using FetchContent to build a static zlib")
add_subdirectory(thirdparty/zlib)
endif()
enable_testing()
include(GoogleTest)
foreach(name
decoder
encoder
reader
writer
files
ipc_hpp)
add_executable(nanoarrow_ipc_${name}_test src/nanoarrow/ipc/${name}_test.cc)
target_link_libraries(nanoarrow_ipc_${name}_test
nanoarrow_ipc
nanoarrow
${NANOARROW_ARROW_TARGET}
gtest_main
nanoarrow_coverage_config)
if(NOT (name MATCHES "_hpp_"))
target_link_libraries(nanoarrow_ipc_${name}_test flatccrt)
endif()
if(Arrow_FOUND)
target_compile_definitions(nanoarrow_ipc_${name}_test
PRIVATE -DNANOARROW_BUILD_TESTS_WITH_ARROW)
endif()
gtest_discover_tests(nanoarrow_ipc_${name}_test)
endforeach()
target_link_libraries(nanoarrow_ipc_files_test nanoarrow_testing ZLIB::ZLIB
nanoarrow_coverage_config)
target_link_libraries(nanoarrow_ipc_decoder_test gmock_main)
endif()
if(NANOARROW_DEVICE)
enable_testing()
add_executable(nanoarrow_device_test src/nanoarrow/device/device_test.cc)
add_executable(nanoarrow_device_hpp_test src/nanoarrow/device/device_hpp_test.cc)
target_link_libraries(nanoarrow_device_test
nanoarrow_device
nanoarrow
gtest_main
nanoarrow_coverage_config)
target_link_libraries(nanoarrow_device_hpp_test
nanoarrow_device
nanoarrow
gtest_main
nanoarrow_coverage_config)
if(Arrow_FOUND)
target_compile_definitions(nanoarrow_device_test
PRIVATE -DNANOARROW_BUILD_TESTS_WITH_ARROW)
target_compile_definitions(nanoarrow_device_hpp_test
PRIVATE -DNANOARROW_BUILD_TESTS_WITH_ARROW)
endif()
include(GoogleTest)
gtest_discover_tests(nanoarrow_device_test)
gtest_discover_tests(nanoarrow_device_hpp_test)
if(NANOARROW_DEVICE_WITH_METAL)
add_executable(nanoarrow_device_metal_test src/nanoarrow/device/metal_test.cc)
target_link_libraries(nanoarrow_device_metal_test
nanoarrow_device
nanoarrow
gtest_main
nanoarrow_coverage_config)
if(Arrow_FOUND)
target_compile_definitions(nanoarrow_device_metal_test
PRIVATE -DNANOARROW_BUILD_TESTS_WITH_ARROW)
endif()
gtest_discover_tests(nanoarrow_device_metal_test)
endif()
if(NANOARROW_DEVICE_WITH_CUDA)
add_executable(nanoarrow_device_cuda_test src/nanoarrow/device/cuda_test.cc)
target_link_libraries(nanoarrow_device_cuda_test
nanoarrow_device
nanoarrow
CUDA::cuda_driver
gtest_main
nanoarrow_coverage_config)
if(Arrow_FOUND)
target_compile_definitions(nanoarrow_device_cuda_test
PRIVATE -DNANOARROW_BUILD_TESTS_WITH_ARROW)
endif()
gtest_discover_tests(nanoarrow_device_cuda_test)
endif()
endif()
endif()
if(NANOARROW_BUILD_APPS)
if(NANOARROW_IPC)
add_executable(dump_stream src/apps/dump_stream.c)
target_link_libraries(dump_stream nanoarrow_ipc nanoarrow)
endif()
endif()
if(NANOARROW_BUILD_BENCHMARKS)
add_subdirectory(dev/benchmarks)
endif()
# Generate package files for the build and install trees.
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
foreach(tree_type BUILD INSTALL)
if(tree_type STREQUAL "BUILD")
set(install_location ".")
else()
set(install_location "${CMAKE_INSTALL_LIBDIR}/cmake/nanoarrow")
endif()
set(build_location "${PROJECT_BINARY_DIR}/${install_location}")
write_basic_package_version_file(
"${build_location}/nanoarrow-config-version.cmake"
VERSION ${nanoarrow_VERSION}
# After 1.0.0, we can use `SameMajorVersion` here.
COMPATIBILITY ExactVersion)
configure_package_config_file("${CMAKE_CURRENT_LIST_DIR}/cmake/config.cmake.in"
"${build_location}/nanoarrow-config.cmake"
INSTALL_DESTINATION "${install_location}")
if(tree_type STREQUAL "BUILD")
export(EXPORT nanoarrow-exports
FILE "${build_location}/nanoarrow-targets.cmake"
NAMESPACE nanoarrow::)
else()
install(DIRECTORY "${build_location}/" DESTINATION "${install_location}")
install(EXPORT nanoarrow-exports
DESTINATION "${install_location}"
FILE "nanoarrow-targets.cmake"
NAMESPACE nanoarrow::)
endif()
endforeach()