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
9 # http://www.apache.org/licenses/LICENSE-2.0
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
18 add_custom_target(arrow_flight)
20 arrow_install_all_headers("arrow/flight")
22 set(ARROW_FLIGHT_LINK_LIBS gRPC::grpc++ ${ARROW_PROTOBUF_LIBPROTOBUF})
25 list(APPEND ARROW_FLIGHT_LINK_LIBS ws2_32.lib)
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})
33 set(ARROW_FLIGHT_TEST_LINK_LIBS arrow_flight_shared arrow_flight_testing_shared
34 ${ARROW_TEST_LINK_LIBS})
37 # TODO(wesm): Protobuf shared vs static linking
39 set(FLIGHT_PROTO_PATH "${ARROW_SOURCE_DIR}/../format")
40 set(FLIGHT_PROTO ${ARROW_SOURCE_DIR}/../format/Flight.proto)
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")
47 set(PROTO_DEPENDS ${FLIGHT_PROTO} ${ARROW_PROTOBUF_LIBPROTOBUF} gRPC::grpc_cpp_plugin)
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>"
58 set_source_files_properties(${FLIGHT_GENERATED_PROTO_FILES} PROPERTIES GENERATED TRUE)
60 add_custom_target(flight_grpc_gen ALL DEPENDS ${FLIGHT_GENERATED_PROTO_FILES})
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}")
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})..."
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)
88 CACHE INTERNAL "The detected (approximate) gRPC version.")
90 message(STATUS "TlsCredentialsOptions (for gRPC ${DETECT_VERSION}) not found in grpc::experimental."
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)
102 string(REGEX MATCH "[0-9]+\\.[0-9]+" GRPC_VERSION "${ARROW_GRPC_BUILD_VERSION}")
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})"
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)
123 message(STATUS "A proper version of gRPC could not be found to support TlsCredentialsOptions in Arrow Flight."
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."
127 if(ARROW_FLIGHT_REQUIRE_TLSCREDENTIALSOPTIONS)
128 message(FATAL_ERROR "Halting build since ARROW_FLIGHT_REQUIRE_TLSCREDENTIALSOPTIONS is set."
133 # </KLUDGE> Restore the CXXFLAGS that were modified above
134 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_BACKUP}")
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
142 client_cookie_middleware.cc
143 client_header_internal.cc
146 serialization_internal.cc
151 add_arrow_lib(arrow_flight
157 ARROW_FLIGHT_LIBRARIES
161 "$<$<COMPILE_LANGUAGE:CXX>:arrow/flight/pch.h>"
165 ${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt
168 ${ARROW_FLIGHT_LINK_LIBS}
171 ${ARROW_FLIGHT_LINK_LIBS})
173 foreach(LIB_TARGET ${ARROW_FLIGHT_LIBRARIES})
174 target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_FLIGHT_EXPORTING)
177 # Define arrow_flight_testing library
179 add_arrow_lib(arrow_flight_testing
185 ARROW_FLIGHT_TESTING_LIBRARIES
197 ${BOOST_FILESYSTEM_LIBRARY}
198 ${BOOST_SYSTEM_LIBRARY}
203 arrow_testing_static)
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})
212 add_arrow_test(flight_test
214 ${ARROW_FLIGHT_TEST_LINK_LIBS}
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)
224 if(ARROW_BUILD_TESTS)
225 add_dependencies(arrow-flight-test flight-test-server)
228 add_dependencies(arrow_flight flight-test-server)
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)
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)
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)
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")
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})
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)
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)
264 add_dependencies(arrow-flight-benchmark arrow-flight-perf-server)
266 add_dependencies(arrow_flight arrow-flight-benchmark)
267 endif(ARROW_BUILD_BENCHMARKS)