forked from apache/arrow-nanoarrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
277 lines (245 loc) · 12.1 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
# 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)
if(NOT DEFINED CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
set(NANOARROW_VERSION "0.4.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}")
option(NANOARROW_BUILD_TESTS "Build tests" 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_NAMESPACE "A prefix for exported symbols" OFF)
option(NANOARROW_ARROW_STATIC
"Use a statically-linked Arrow C++ build when linking tests" OFF)
if(NANOARROW_NAMESPACE)
set(NANOARROW_NAMESPACE_DEFINE "#define NANOARROW_NAMESPACE ${NANOARROW_NAMESPACE}")
else()
set(NANOARROW_NAMESPACE_DEFINE "// #define NANOARROW_NAMESPACE YourNamespaceHere")
endif()
option(NANOARROW_CODE_COVERAGE "Enable coverage reporting" OFF)
add_library(coverage_config INTERFACE)
configure_file(src/nanoarrow/nanoarrow_config.h.in generated/nanoarrow_config.h)
if(NANOARROW_BUNDLE)
# Combine all headers into amalgamation/nanoarrow.h in the build directory
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/amalgamation)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/amalgamation/nanoarrow)
set(NANOARROW_H_TEMP ${CMAKE_BINARY_DIR}/amalgamation/nanoarrow/nanoarrow.h)
file(READ ${CMAKE_BINARY_DIR}/generated/nanoarrow_config.h SRC_FILE_CONTENTS)
file(WRITE ${NANOARROW_H_TEMP} "${SRC_FILE_CONTENTS}")
file(READ src/nanoarrow/nanoarrow_types.h SRC_FILE_CONTENTS)
file(APPEND ${NANOARROW_H_TEMP} "${SRC_FILE_CONTENTS}")
file(READ src/nanoarrow/nanoarrow.h SRC_FILE_CONTENTS)
file(APPEND ${NANOARROW_H_TEMP} "${SRC_FILE_CONTENTS}")
file(READ src/nanoarrow/buffer_inline.h SRC_FILE_CONTENTS)
file(APPEND ${NANOARROW_H_TEMP} "${SRC_FILE_CONTENTS}")
file(READ src/nanoarrow/array_inline.h SRC_FILE_CONTENTS)
file(APPEND ${NANOARROW_H_TEMP} "${SRC_FILE_CONTENTS}")
# Remove includes that aren't needed when the headers are concatenated
file(READ ${NANOARROW_H_TEMP} SRC_FILE_CONTENTS)
string(REGEX REPLACE "#include \"[a-z_.]+\"" "" SRC_FILE_CONTENTS
"${SRC_FILE_CONTENTS}")
file(WRITE ${NANOARROW_H_TEMP} "${SRC_FILE_CONTENTS}")
# Copy nanoarrow.hpp
set(NANOARROW_HPP_TEMP ${CMAKE_BINARY_DIR}/amalgamation/nanoarrow/nanoarrow.hpp)
file(READ src/nanoarrow/nanoarrow.hpp SRC_FILE_CONTENTS)
file(WRITE ${NANOARROW_HPP_TEMP} "${SRC_FILE_CONTENTS}")
# Copy nanoarrow_testing.hpp
set(NANOARROW_TESTING_HPP_TEMP
${CMAKE_BINARY_DIR}/amalgamation/nanoarrow/nanoarrow_testing.hpp)
file(READ src/nanoarrow/nanoarrow_testing.hpp SRC_FILE_CONTENTS)
file(WRITE ${NANOARROW_TESTING_HPP_TEMP} "${SRC_FILE_CONTENTS}")
# Combine all source files into amalgamation/nanoarrow.c in the build directory
if(NANOARROW_BUNDLE_AS_CPP)
set(NANOARROW_C_TEMP ${CMAKE_BINARY_DIR}/amalgamation/nanoarrow/nanoarrow.cc)
else()
set(NANOARROW_C_TEMP ${CMAKE_BINARY_DIR}/amalgamation/nanoarrow/nanoarrow.c)
endif()
file(READ src/nanoarrow/utils.c SRC_FILE_CONTENTS)
file(WRITE ${NANOARROW_C_TEMP} "${SRC_FILE_CONTENTS}")
file(READ src/nanoarrow/schema.c SRC_FILE_CONTENTS)
file(APPEND ${NANOARROW_C_TEMP} "${SRC_FILE_CONTENTS}")
file(READ src/nanoarrow/array.c SRC_FILE_CONTENTS)
file(APPEND ${NANOARROW_C_TEMP} "${SRC_FILE_CONTENTS}")
file(READ src/nanoarrow/array_stream.c SRC_FILE_CONTENTS)
file(APPEND ${NANOARROW_C_TEMP} "${SRC_FILE_CONTENTS}")
# Add a library that the tests can link against (but don't install it)
if(NANOARROW_BUILD_TESTS)
include_directories(${CMAKE_BINARY_DIR}/amalgamation)
add_library(nanoarrow ${NANOARROW_C_TEMP})
target_compile_definitions(nanoarrow PUBLIC "$<$<CONFIG:Debug>:NANOARROW_DEBUG>")
endif()
# Install the amalgamated header and source
install(FILES ${NANOARROW_H_TEMP} ${NANOARROW_C_TEMP} ${NANOARROW_HPP_TEMP}
${NANOARROW_TESTING_HPP_TEMP} DESTINATION ".")
else()
add_library(nanoarrow src/nanoarrow/array.c src/nanoarrow/schema.c
src/nanoarrow/array_stream.c src/nanoarrow/utils.c)
target_include_directories(nanoarrow
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>)
target_include_directories(nanoarrow
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated>
)
target_compile_definitions(nanoarrow PUBLIC "$<$<CONFIG:Debug>:NANOARROW_DEBUG>")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(nanoarrow
PRIVATE -Wall
-Werror
-Wextra
-Wno-type-limits
-Wno-unused-parameter
-Wmaybe-uninitialized
-Wpedantic
-Wunused-result)
elseif(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_C_COMPILER_ID STREQUAL
"Clang")
target_compile_options(nanoarrow
PRIVATE -Wall
-Werror
-Wextra
-Wdocumentation
-Wno-unused-parameter
-Wshorten-64-to-32)
endif()
endif()
install(TARGETS nanoarrow DESTINATION lib)
install(DIRECTORY src/
DESTINATION include
FILES_MATCHING
PATTERN "*.h")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/generated/nanoarrow_config.h
DESTINATION include/nanoarrow)
endif()
# Always build integration test if building tests
if(NANOARROW_BUILD_TESTS OR NANOARROW_BUILD_INTEGRATION_TESTS)
include(FetchContent)
fetchcontent_declare(nlohmann_json
URL https://github.com/nlohmann/json/archive/refs/tags/v3.11.2.zip
URL_HASH SHA256=95651d7d1fcf2e5c3163c3d37df6d6b3e9e5027299e6bd050d157322ceda9ac9
)
fetchcontent_makeavailable(nlohmann_json)
add_library(nanoarrow_c_data_integration SHARED
src/nanoarrow/integration/c_data_integration.cc)
target_include_directories(nanoarrow_c_data_integration
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>)
target_link_libraries(nanoarrow_c_data_integration PRIVATE nanoarrow nlohmann_json)
endif()
if(NANOARROW_BUILD_TESTS)
set(MEMORYCHECK_COMMAND_OPTIONS
"--leak-check=full --suppressions=${CMAKE_CURRENT_LIST_DIR}/valgrind.supp --error-exitcode=1"
)
include(CTest)
find_package(Arrow REQUIRED)
message(STATUS "Arrow version: ${ARROW_VERSION}")
message(STATUS "Arrow SO version: ${ARROW_FULL_SO_VERSION}")
# 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)
# 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()
# 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()
# Use an old version of googletest if we have to to support gcc 4.8
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_VERSION
VERSION_GREATER_EQUAL "5.0.0")
fetchcontent_declare(googletest
URL https://github.com/google/googletest/archive/release-1.11.0.zip
URL_HASH SHA256=353571c2440176ded91c2de6d6cd88ddd41401d14692ec1f99e35d013feda55a
)
else()
fetchcontent_declare(googletest
URL https://github.com/google/googletest/archive/release-1.10.0.zip
URL_HASH SHA256=94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91
)
endif()
fetchcontent_makeavailable(googletest)
add_executable(utils_test src/nanoarrow/utils_test.cc)
add_executable(buffer_test src/nanoarrow/buffer_test.cc)
add_executable(array_test src/nanoarrow/array_test.cc)
add_executable(schema_test src/nanoarrow/schema_test.cc)
add_executable(array_stream_test src/nanoarrow/array_stream_test.cc)
add_executable(nanoarrow_hpp_test src/nanoarrow/nanoarrow_hpp_test.cc)
add_executable(nanoarrow_testing_test src/nanoarrow/nanoarrow_testing_test.cc)
add_executable(c_data_integration_test
src/nanoarrow/integration/c_data_integration_test.cc)
if(NANOARROW_CODE_COVERAGE)
target_compile_options(coverage_config INTERFACE -O0 -g --coverage)
target_link_options(coverage_config INTERFACE --coverage)
target_link_libraries(nanoarrow coverage_config)
endif()
target_link_libraries(utils_test
nanoarrow
gtest_main
${NANOARROW_ARROW_TARGET}
coverage_config)
target_link_libraries(buffer_test nanoarrow gtest_main coverage_config)
target_link_libraries(array_test
nanoarrow
gtest_main
${NANOARROW_ARROW_TARGET}
coverage_config)
target_link_libraries(schema_test
nanoarrow
gtest_main
${NANOARROW_ARROW_TARGET}
coverage_config)
target_link_libraries(array_stream_test nanoarrow gtest_main coverage_config)
target_link_libraries(nanoarrow_hpp_test nanoarrow gtest_main coverage_config)
target_link_libraries(nanoarrow_testing_test
nanoarrow
gtest_main
nlohmann_json::nlohmann_json
coverage_config)
target_link_libraries(c_data_integration_test nanoarrow nanoarrow_c_data_integration
gtest_main)
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_hpp_test DISCOVERY_TIMEOUT 10)
gtest_discover_tests(nanoarrow_testing_test DISCOVERY_TIMEOUT 10)
gtest_discover_tests(c_data_integration_test DISCOVERY_TIMEOUT 10)
endif()