-
Notifications
You must be signed in to change notification settings - Fork 915
/
get_arrow.cmake
372 lines (345 loc) · 13.3 KB
/
get_arrow.cmake
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
# =============================================================================
# Copyright (c) 2020-2024, NVIDIA CORPORATION.
#
# Licensed 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.
# =============================================================================
# Finding arrow is far more complex than it should be, and as a result we violate multiple linting
# rules aiming to limit complexity. Since all our other CMake scripts conform to expectations
# without undue difficulty, disabling those rules for just this function is our best approach for
# now. The spacing between this comment, the cmake-lint directives, and the function docstring is
# necessary to prevent cmake-format from trying to combine the lines.
# cmake-lint: disable=R0912,R0913,R0915
include_guard(GLOBAL)
# This function finds arrow and sets any additional necessary environment variables.
function(find_and_configure_arrow VERSION BUILD_STATIC EXCLUDE_FROM_ALL ENABLE_PARQUET)
if(BUILD_STATIC)
if(TARGET arrow_static)
set(ARROW_FOUND
TRUE
PARENT_SCOPE
)
set(ARROW_LIBRARIES
arrow_static
PARENT_SCOPE
)
return()
endif()
else()
if(TARGET arrow_shared)
set(ARROW_FOUND
TRUE
PARENT_SCOPE
)
set(ARROW_LIBRARIES
arrow_shared
PARENT_SCOPE
)
return()
endif()
endif()
if(NOT ARROW_SIMD_LEVEL)
set(ARROW_SIMD_LEVEL "NONE")
endif()
if(BUILD_STATIC)
set(ARROW_BUILD_STATIC ON)
set(ARROW_BUILD_SHARED OFF)
# Turn off CPM using `find_package` so we always download and make sure we get proper static
# library.
set(CPM_DOWNLOAD_Arrow TRUE)
# By default ARROW will try to search for a static version of OpenSSL which is a bad idea given
# that shared linking is advised for critical components like SSL. If a static build is
# requested, we honor ARROW's default of static linking, but users may consider setting
# ARROW_OPENSSL_USE_SHARED even in static builds.
else()
set(ARROW_BUILD_SHARED ON)
set(ARROW_BUILD_STATIC OFF)
# By default ARROW will try to search for a static version of OpenSSL which is a bad idea given
# that shared linking is advised for critical components like SSL
set(ARROW_OPENSSL_USE_SHARED ON)
endif()
set(ARROW_PARQUET_OPTIONS "")
if(ENABLE_PARQUET)
# Arrow's logic to build Boost from source is busted, so we have to get it from the system.
list(APPEND ARROW_PARQUET_OPTIONS "BOOST_SOURCE SYSTEM")
list(APPEND ARROW_PARQUET_OPTIONS "Thrift_SOURCE BUNDLED")
list(APPEND ARROW_PARQUET_OPTIONS "ARROW_DEPENDENCY_SOURCE AUTO")
endif()
rapids_cpm_find(
Arrow ${VERSION}
GLOBAL_TARGETS arrow_shared parquet_shared arrow_acero_shared arrow_dataset_shared arrow_static
parquet_static arrow_acero_static arrow_dataset_static
CPM_ARGS
GIT_REPOSITORY https://github.com/apache/arrow.git
GIT_TAG apache-arrow-${VERSION}
GIT_SHALLOW TRUE SOURCE_SUBDIR cpp
EXCLUDE_FROM_ALL ${EXCLUDE_FROM_ALL}
OPTIONS "CMAKE_VERBOSE_MAKEFILE ON"
"ARROW_ACERO ON"
"ARROW_IPC ON"
"ARROW_DATASET ON"
"ARROW_WITH_BACKTRACE ON"
"ARROW_CXXFLAGS -w"
"ARROW_JEMALLOC OFF"
"ARROW_S3 OFF"
"ARROW_ORC OFF"
${ARROW_PARQUET_OPTIONS}
"ARROW_PARQUET ${ENABLE_PARQUET}"
"ARROW_FILESYSTEM ON"
"ARROW_PYTHON OFF"
# Arrow modifies CMake's GLOBAL RULE_LAUNCH_COMPILE unless this is off
"ARROW_USE_CCACHE OFF"
"ARROW_SIMD_LEVEL ${ARROW_SIMD_LEVEL}"
"ARROW_BUILD_STATIC ${ARROW_BUILD_STATIC}"
"ARROW_BUILD_SHARED ${ARROW_BUILD_SHARED}"
"ARROW_POSITION_INDEPENDENT_CODE ON"
"ARROW_DEPENDENCY_USE_SHARED ${ARROW_BUILD_SHARED}"
"ARROW_BOOST_USE_SHARED ${ARROW_BUILD_SHARED}"
"ARROW_BROTLI_USE_SHARED ${ARROW_BUILD_SHARED}"
"ARROW_GFLAGS_USE_SHARED ${ARROW_BUILD_SHARED}"
"ARROW_GRPC_USE_SHARED ${ARROW_BUILD_SHARED}"
"ARROW_PROTOBUF_USE_SHARED ${ARROW_BUILD_SHARED}"
"ARROW_ZSTD_USE_SHARED ${ARROW_BUILD_SHARED}"
"xsimd_SOURCE AUTO"
)
set(ARROW_FOUND
TRUE
PARENT_SCOPE
)
if(BUILD_STATIC)
set(ARROW_LIBRARIES arrow_static)
else()
set(ARROW_LIBRARIES arrow_shared)
endif()
# Arrow_DIR: set if CPM found Arrow on the system/conda/etc.
if(Arrow_DIR)
# This extra find_package is necessary because rapids_cpm_find does not propagate all the
# variables from find_package that we might need. This is especially problematic when
# rapids_cpm_find builds from source.
find_package(Arrow REQUIRED QUIET)
if(ENABLE_PARQUET)
# Setting Parquet_DIR is conditional because parquet may be installed independently of arrow.
if(NOT Parquet_DIR)
# Set this to enable `find_package(Parquet)`
set(Parquet_DIR "${Arrow_DIR}")
endif()
# Set this to enable `find_package(ArrowDataset)`. This will call find_package(ArrowAcero) for
# us
set(ArrowDataset_DIR "${Arrow_DIR}")
find_package(ArrowDataset REQUIRED QUIET)
endif()
# Arrow_ADDED: set if CPM downloaded Arrow from Github
elseif(Arrow_ADDED)
# Copy these files so we can avoid adding paths in Arrow_BINARY_DIR to
# target_include_directories. That defeats ccache.
file(INSTALL "${Arrow_BINARY_DIR}/src/arrow/util/config.h"
DESTINATION "${Arrow_SOURCE_DIR}/cpp/src/arrow/util"
)
if(ENABLE_PARQUET)
file(INSTALL "${Arrow_BINARY_DIR}/src/parquet/parquet_version.h"
DESTINATION "${Arrow_SOURCE_DIR}/cpp/src/parquet"
)
endif()
# Arrow populates INTERFACE_INCLUDE_DIRECTORIES for the `arrow_static` and `arrow_shared`
# targets in FindArrow, so for static source-builds, we have to do it after-the-fact.
#
# This only works because we know exactly which components we're using. Don't forget to update
# this list if we add more!
#
foreach(ARROW_LIBRARY ${ARROW_LIBRARIES})
target_include_directories(
${ARROW_LIBRARY}
INTERFACE "$<BUILD_INTERFACE:${Arrow_SOURCE_DIR}/cpp/src>"
"$<BUILD_INTERFACE:${Arrow_SOURCE_DIR}/cpp/src/generated>"
"$<BUILD_INTERFACE:${Arrow_SOURCE_DIR}/cpp/thirdparty/hadoop/include>"
"$<BUILD_INTERFACE:${Arrow_SOURCE_DIR}/cpp/thirdparty/flatbuffers/include>"
)
endforeach()
else()
set(ARROW_FOUND
FALSE
PARENT_SCOPE
)
message(FATAL_ERROR "CUDF: Arrow library not found or downloaded.")
endif()
if(Arrow_ADDED)
set(arrow_code_string
[=[
if (TARGET cudf::arrow_shared AND (NOT TARGET arrow_shared))
add_library(arrow_shared ALIAS cudf::arrow_shared)
endif()
if (TARGET cudf::arrow_static AND (NOT TARGET arrow_static))
add_library(arrow_static ALIAS cudf::arrow_static)
endif()
if (NOT TARGET arrow::flatbuffers)
add_library(arrow::flatbuffers INTERFACE IMPORTED)
endif()
if (NOT TARGET arrow::hadoop)
add_library(arrow::hadoop INTERFACE IMPORTED)
endif()
]=]
)
if(ENABLE_PARQUET)
string(
APPEND
arrow_code_string
"
find_package(Boost)
if (NOT TARGET Boost::headers)
add_library(Boost::headers INTERFACE IMPORTED)
endif()
"
)
endif()
if(NOT TARGET xsimd)
string(
APPEND
arrow_code_string
"
if(NOT TARGET arrow::xsimd)
add_library(arrow::xsimd INTERFACE IMPORTED)
target_include_directories(arrow::xsimd INTERFACE \"${Arrow_BINARY_DIR}/xsimd_ep/src/xsimd_ep-install/include\")
endif()
"
)
endif()
rapids_cmake_install_lib_dir(lib_dir)
if(TARGET arrow_static)
get_target_property(interface_libs arrow_static INTERFACE_LINK_LIBRARIES)
# The `arrow_static` library is leaking a dependency on the object libraries it was built with
# we need to remove this from the interface, since keeping them around would cause duplicate
# symbols and CMake export errors
if(interface_libs MATCHES "arrow_array" AND interface_libs MATCHES "arrow_compute")
string(REPLACE "BUILD_INTERFACE:" "BUILD_LOCAL_INTERFACE:" interface_libs
"${interface_libs}"
)
set_target_properties(arrow_static PROPERTIES INTERFACE_LINK_LIBRARIES "${interface_libs}")
get_target_property(interface_libs arrow_static INTERFACE_LINK_LIBRARIES)
endif()
endif()
include(rapids-export)
if(NOT EXCLUDE_FROM_ALL)
rapids_export(
BUILD Arrow
VERSION ${VERSION}
EXPORT_SET arrow_targets
GLOBAL_TARGETS arrow_shared arrow_static
NAMESPACE cudf::
FINAL_CODE_BLOCK arrow_code_string
)
if(ENABLE_PARQUET)
set(arrow_acero_code_string
[=[
if (TARGET cudf::arrow_acero_shared AND (NOT TARGET arrow_acero_shared))
add_library(arrow_acero_shared ALIAS cudf::arrow_acero_shared)
endif()
if (TARGET cudf::arrow_acero_static AND (NOT TARGET arrow_acero_static))
add_library(arrow_acero_static ALIAS cudf::arrow_acero_static)
endif()
]=]
)
rapids_export(
BUILD ArrowAcero
VERSION ${VERSION}
EXPORT_SET arrow_acero_targets
GLOBAL_TARGETS arrow_acero_shared arrow_acero_static
NAMESPACE cudf::
FINAL_CODE_BLOCK arrow_acero_code_string
)
set(arrow_dataset_code_string
[=[
if (TARGET cudf::arrow_dataset_shared AND (NOT TARGET arrow_dataset_shared))
add_library(arrow_dataset_shared ALIAS cudf::arrow_dataset_shared)
endif()
if (TARGET cudf::arrow_dataset_static AND (NOT TARGET arrow_dataset_static))
add_library(arrow_dataset_static ALIAS cudf::arrow_dataset_static)
endif()
]=]
)
rapids_export(
BUILD ArrowDataset
VERSION ${VERSION}
EXPORT_SET arrow_dataset_targets
GLOBAL_TARGETS arrow_dataset_shared arrow_dataset_static
NAMESPACE cudf::
FINAL_CODE_BLOCK arrow_dataset_code_string
)
set(parquet_code_string
[=[
if (TARGET cudf::parquet_shared AND (NOT TARGET parquet_shared))
add_library(parquet_shared ALIAS cudf::parquet_shared)
endif()
if (TARGET cudf::parquet_static AND (NOT TARGET parquet_static))
add_library(parquet_static ALIAS cudf::parquet_static)
endif()
]=]
)
rapids_export(
BUILD Parquet
VERSION ${VERSION}
EXPORT_SET parquet_targets
GLOBAL_TARGETS parquet_shared parquet_static
NAMESPACE cudf::
FINAL_CODE_BLOCK parquet_code_string
)
endif()
endif()
endif()
if(NOT EXCLUDE_FROM_ALL)
# We generate the arrow-configfiles when we built arrow locally, so always do `find_dependency`
rapids_export_package(BUILD Arrow cudf-exports)
rapids_export_package(INSTALL Arrow cudf-exports)
if(ENABLE_PARQUET)
rapids_export_package(BUILD Parquet cudf-exports)
rapids_export_package(BUILD ArrowDataset cudf-exports)
endif()
include("${rapids-cmake-dir}/export/find_package_root.cmake")
rapids_export_find_package_root(
BUILD Arrow [=[${CMAKE_CURRENT_LIST_DIR}]=] EXPORT_SET cudf-exports
)
rapids_export_find_package_root(
BUILD Parquet [=[${CMAKE_CURRENT_LIST_DIR}]=]
EXPORT_SET cudf-exports
CONDITION ENABLE_PARQUET
)
rapids_export_find_package_root(
BUILD ArrowDataset [=[${CMAKE_CURRENT_LIST_DIR}]=]
EXPORT_SET cudf-exports
CONDITION ENABLE_PARQUET
)
endif()
set(ARROW_LIBRARIES
"${ARROW_LIBRARIES}"
PARENT_SCOPE
)
endfunction()
if(NOT DEFINED CUDF_VERSION_Arrow)
set(CUDF_VERSION_Arrow
# This version must be kept in sync with the libarrow version pinned for builds in
# dependencies.yaml.
16.1.0
CACHE STRING "The version of Arrow to find (or build)"
)
endif()
# Default to static arrow builds
if(NOT DEFINED CUDF_USE_ARROW_STATIC)
set(CUDF_USE_ARROW_STATIC ON)
endif()
# Default to excluding from installation since we generally privately and statically link Arrow.
if(NOT DEFINED CUDF_EXCLUDE_ARROW_FROM_ALL)
set(CUDF_EXCLUDE_ARROW_FROM_ALL OFF)
endif()
if(NOT DEFINED CUDF_ENABLE_ARROW_PARQUET)
set(CUDF_ENABLE_ARROW_PARQUET OFF)
endif()
find_and_configure_arrow(
${CUDF_VERSION_Arrow} ${CUDF_USE_ARROW_STATIC} ${CUDF_EXCLUDE_ARROW_FROM_ALL}
${CUDF_ENABLE_ARROW_PARQUET}
)