]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/src/arrow/flight/CMakeLists.txt
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / arrow / flight / CMakeLists.txt
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17
18 add_custom_target(arrow_flight)
19
20 arrow_install_all_headers("arrow/flight")
21
22 set(ARROW_FLIGHT_LINK_LIBS gRPC::grpc++ ${ARROW_PROTOBUF_LIBPROTOBUF})
23
24 if(WIN32)
25 list(APPEND ARROW_FLIGHT_LINK_LIBS ws2_32.lib)
26 endif()
27
28 if(ARROW_TEST_LINKAGE STREQUAL "static")
29 set(ARROW_FLIGHT_TEST_LINK_LIBS
30 arrow_flight_static arrow_flight_testing_static ${ARROW_FLIGHT_STATIC_LINK_LIBS}
31 ${ARROW_TEST_LINK_LIBS})
32 else()
33 set(ARROW_FLIGHT_TEST_LINK_LIBS arrow_flight_shared arrow_flight_testing_shared
34 ${ARROW_TEST_LINK_LIBS})
35 endif()
36
37 # TODO(wesm): Protobuf shared vs static linking
38
39 set(FLIGHT_PROTO_PATH "${ARROW_SOURCE_DIR}/../format")
40 set(FLIGHT_PROTO ${ARROW_SOURCE_DIR}/../format/Flight.proto)
41
42 set(FLIGHT_GENERATED_PROTO_FILES
43 "${CMAKE_CURRENT_BINARY_DIR}/Flight.pb.cc" "${CMAKE_CURRENT_BINARY_DIR}/Flight.pb.h"
44 "${CMAKE_CURRENT_BINARY_DIR}/Flight.grpc.pb.cc"
45 "${CMAKE_CURRENT_BINARY_DIR}/Flight.grpc.pb.h")
46
47 set(PROTO_DEPENDS ${FLIGHT_PROTO} ${ARROW_PROTOBUF_LIBPROTOBUF} gRPC::grpc_cpp_plugin)
48
49 add_custom_command(OUTPUT ${FLIGHT_GENERATED_PROTO_FILES}
50 COMMAND ${ARROW_PROTOBUF_PROTOC} "-I${FLIGHT_PROTO_PATH}"
51 "--cpp_out=${CMAKE_CURRENT_BINARY_DIR}" "${FLIGHT_PROTO}"
52 DEPENDS ${PROTO_DEPENDS} ARGS
53 COMMAND ${ARROW_PROTOBUF_PROTOC} "-I${FLIGHT_PROTO_PATH}"
54 "--grpc_out=${CMAKE_CURRENT_BINARY_DIR}"
55 "--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>"
56 "${FLIGHT_PROTO}")
57
58 set_source_files_properties(${FLIGHT_GENERATED_PROTO_FILES} PROPERTIES GENERATED TRUE)
59
60 add_custom_target(flight_grpc_gen ALL DEPENDS ${FLIGHT_GENERATED_PROTO_FILES})
61
62 # <KLUDGE> -Werror / /WX cause try_compile to fail because there seems to be no
63 # way to pass -isystem $GRPC_INCLUDE_DIR instead of -I$GRPC_INCLUDE_DIR
64 set(CMAKE_CXX_FLAGS_BACKUP "${CMAKE_CXX_FLAGS}")
65 string(REPLACE "/WX" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
66 string(REPLACE "-Werror " " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
67
68 # Probe the version of gRPC being used to see if it supports disabling server
69 # verification when using TLS.
70 function(test_grpc_version DST_VAR DETECT_VERSION TEST_FILE)
71 if(NOT DEFINED ${DST_VAR})
72 message(STATUS "Checking support for TlsCredentialsOptions (gRPC >= ${DETECT_VERSION})..."
73 )
74 get_property(CURRENT_INCLUDE_DIRECTORIES
75 DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
76 PROPERTY INCLUDE_DIRECTORIES)
77 # ARROW-13881: when detecting support, avoid mismatch between
78 # debug flags of gRPC and our probe (which results in LNK2038)
79 set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
80 try_compile(HAS_GRPC_VERSION ${CMAKE_CURRENT_BINARY_DIR}/try_compile
81 SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/try_compile/${TEST_FILE}"
82 CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${CURRENT_INCLUDE_DIRECTORIES}"
83 LINK_LIBRARIES gRPC::grpc++
84 OUTPUT_VARIABLE TLS_CREDENTIALS_OPTIONS_CHECK_OUTPUT CXX_STANDARD 11)
85 if(HAS_GRPC_VERSION)
86 set(${DST_VAR}
87 "${DETECT_VERSION}"
88 CACHE INTERNAL "The detected (approximate) gRPC version.")
89 else()
90 message(STATUS "TlsCredentialsOptions (for gRPC ${DETECT_VERSION}) not found in grpc::experimental."
91 )
92 message(DEBUG "Build output:")
93 list(APPEND CMAKE_MESSAGE_INDENT "${TEST_FILE}: ")
94 message(DEBUG ${TLS_CREDENTIALS_OPTIONS_CHECK_OUTPUT})
95 list(REMOVE_AT CMAKE_MESSAGE_INDENT -1)
96 endif()
97 endif()
98 endfunction()
99
100 if(GRPC_VENDORED)
101 # v1.35.0 -> 1.35
102 string(REGEX MATCH "[0-9]+\\.[0-9]+" GRPC_VERSION "${ARROW_GRPC_BUILD_VERSION}")
103 else()
104 test_grpc_version(GRPC_VERSION "1.36" "check_tls_opts_136.cc")
105 test_grpc_version(GRPC_VERSION "1.34" "check_tls_opts_134.cc")
106 test_grpc_version(GRPC_VERSION "1.32" "check_tls_opts_132.cc")
107 test_grpc_version(GRPC_VERSION "1.27" "check_tls_opts_127.cc")
108 message(STATUS "Found approximate gRPC version: ${GRPC_VERSION} (ARROW_FLIGHT_REQUIRE_TLSCREDENTIALSOPTIONS=${ARROW_FLIGHT_REQUIRE_TLSCREDENTIALSOPTIONS})"
109 )
110 endif()
111 if(GRPC_VERSION EQUAL "1.27")
112 add_definitions(-DGRPC_NAMESPACE_FOR_TLS_CREDENTIALS_OPTIONS=grpc_impl::experimental)
113 elseif(GRPC_VERSION EQUAL "1.32")
114 add_definitions(-DGRPC_NAMESPACE_FOR_TLS_CREDENTIALS_OPTIONS=grpc::experimental)
115 elseif(GRPC_VERSION EQUAL "1.34" OR GRPC_VERSION EQUAL "1.35")
116 add_definitions(-DGRPC_USE_TLS_CHANNEL_CREDENTIALS_OPTIONS
117 -DGRPC_USE_TLS_CHANNEL_CREDENTIALS_OPTIONS_ROOT_CERTS
118 -DGRPC_NAMESPACE_FOR_TLS_CREDENTIALS_OPTIONS=grpc::experimental)
119 elseif(GRPC_VERSION EQUAL "1.36")
120 add_definitions(-DGRPC_USE_TLS_CHANNEL_CREDENTIALS_OPTIONS
121 -DGRPC_NAMESPACE_FOR_TLS_CREDENTIALS_OPTIONS=grpc::experimental)
122 else()
123 message(STATUS "A proper version of gRPC could not be found to support TlsCredentialsOptions in Arrow Flight."
124 )
125 message(STATUS "You may need a newer version of gRPC (>= 1.27), or the gRPC API has changed and Flight must be updated to match."
126 )
127 if(ARROW_FLIGHT_REQUIRE_TLSCREDENTIALSOPTIONS)
128 message(FATAL_ERROR "Halting build since ARROW_FLIGHT_REQUIRE_TLSCREDENTIALSOPTIONS is set."
129 )
130 endif()
131 endif()
132
133 # </KLUDGE> Restore the CXXFLAGS that were modified above
134 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_BACKUP}")
135
136 # Note, we do not compile the generated Protobuf sources directly, instead
137 # compiling then via protocol_internal.cc which contains some gRPC template
138 # overrides to enable Flight-specific optimizations. See comments in
139 # protobuf-internal.cc
140 set(ARROW_FLIGHT_SRCS
141 client.cc
142 client_cookie_middleware.cc
143 client_header_internal.cc
144 internal.cc
145 protocol_internal.cc
146 serialization_internal.cc
147 server.cc
148 server_auth.cc
149 types.cc)
150
151 add_arrow_lib(arrow_flight
152 CMAKE_PACKAGE_NAME
153 ArrowFlight
154 PKG_CONFIG_NAME
155 arrow-flight
156 OUTPUTS
157 ARROW_FLIGHT_LIBRARIES
158 SOURCES
159 ${ARROW_FLIGHT_SRCS}
160 PRECOMPILED_HEADERS
161 "$<$<COMPILE_LANGUAGE:CXX>:arrow/flight/pch.h>"
162 DEPENDENCIES
163 flight_grpc_gen
164 SHARED_LINK_FLAGS
165 ${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt
166 SHARED_LINK_LIBS
167 arrow_shared
168 ${ARROW_FLIGHT_LINK_LIBS}
169 STATIC_LINK_LIBS
170 arrow_static
171 ${ARROW_FLIGHT_LINK_LIBS})
172
173 foreach(LIB_TARGET ${ARROW_FLIGHT_LIBRARIES})
174 target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_FLIGHT_EXPORTING)
175 endforeach()
176
177 # Define arrow_flight_testing library
178 if(ARROW_TESTING)
179 add_arrow_lib(arrow_flight_testing
180 CMAKE_PACKAGE_NAME
181 ArrowFlightTesting
182 PKG_CONFIG_NAME
183 arrow-flight-testing
184 OUTPUTS
185 ARROW_FLIGHT_TESTING_LIBRARIES
186 SOURCES
187 test_integration.cc
188 test_util.cc
189 DEPENDENCIES
190 GTest::gtest
191 flight_grpc_gen
192 arrow_dependencies
193 SHARED_LINK_LIBS
194 arrow_shared
195 arrow_flight_shared
196 arrow_testing_shared
197 ${BOOST_FILESYSTEM_LIBRARY}
198 ${BOOST_SYSTEM_LIBRARY}
199 GTest::gtest
200 STATIC_LINK_LIBS
201 arrow_static
202 arrow_flight_static
203 arrow_testing_static)
204 endif()
205
206 foreach(LIB_TARGET ${ARROW_FLIGHT_TESTING_LIBRARIES})
207 target_compile_definitions(${LIB_TARGET}
208 PRIVATE ARROW_FLIGHT_EXPORTING
209 ${ARROW_BOOST_PROCESS_COMPILE_DEFINITIONS})
210 endforeach()
211
212 add_arrow_test(flight_test
213 STATIC_LINK_LIBS
214 ${ARROW_FLIGHT_TEST_LINK_LIBS}
215 LABELS
216 "arrow_flight")
217
218 # Build test server for unit tests or benchmarks
219 if(ARROW_BUILD_TESTS OR ARROW_BUILD_BENCHMARKS)
220 add_executable(flight-test-server test_server.cc)
221 target_link_libraries(flight-test-server ${ARROW_FLIGHT_TEST_LINK_LIBS}
222 ${GFLAGS_LIBRARIES} GTest::gtest)
223
224 if(ARROW_BUILD_TESTS)
225 add_dependencies(arrow-flight-test flight-test-server)
226 endif()
227
228 add_dependencies(arrow_flight flight-test-server)
229 endif()
230
231 if(ARROW_BUILD_INTEGRATION)
232 add_executable(flight-test-integration-server test_integration_server.cc)
233 target_link_libraries(flight-test-integration-server ${ARROW_FLIGHT_TEST_LINK_LIBS}
234 ${GFLAGS_LIBRARIES} GTest::gtest)
235
236 add_executable(flight-test-integration-client test_integration_client.cc)
237 target_link_libraries(flight-test-integration-client ${ARROW_FLIGHT_TEST_LINK_LIBS}
238 ${GFLAGS_LIBRARIES} GTest::gtest)
239
240 add_dependencies(arrow_flight flight-test-integration-client
241 flight-test-integration-server)
242 add_dependencies(arrow-integration flight-test-integration-client
243 flight-test-integration-server)
244 endif()
245
246 if(ARROW_BUILD_BENCHMARKS)
247 # Perf server for benchmarks
248 set(PERF_PROTO_GENERATED_FILES "${CMAKE_CURRENT_BINARY_DIR}/perf.pb.cc"
249 "${CMAKE_CURRENT_BINARY_DIR}/perf.pb.h")
250
251 add_custom_command(OUTPUT ${PERF_PROTO_GENERATED_FILES}
252 COMMAND ${ARROW_PROTOBUF_PROTOC} "-I${CMAKE_CURRENT_SOURCE_DIR}"
253 "--cpp_out=${CMAKE_CURRENT_BINARY_DIR}" "perf.proto"
254 DEPENDS ${PROTO_DEPENDS})
255
256 add_executable(arrow-flight-perf-server perf_server.cc perf.pb.cc)
257 target_link_libraries(arrow-flight-perf-server ${ARROW_FLIGHT_TEST_LINK_LIBS}
258 ${GFLAGS_LIBRARIES} GTest::gtest)
259
260 add_executable(arrow-flight-benchmark flight_benchmark.cc perf.pb.cc)
261 target_link_libraries(arrow-flight-benchmark ${ARROW_FLIGHT_TEST_LINK_LIBS}
262 ${GFLAGS_LIBRARIES} GTest::gtest)
263
264 add_dependencies(arrow-flight-benchmark arrow-flight-perf-server)
265
266 add_dependencies(arrow_flight arrow-flight-benchmark)
267 endif(ARROW_BUILD_BENCHMARKS)