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
22 find_package(Python3Alt REQUIRED)
24 add_custom_target(arrow_python-all)
25 add_custom_target(arrow_python)
26 add_custom_target(arrow_python-tests)
27 add_dependencies(arrow_python-all arrow_python arrow_python-tests)
48 set_source_files_properties(init.cc PROPERTIES SKIP_PRECOMPILE_HEADERS ON
49 SKIP_UNITY_BUILD_INCLUSION ON)
52 list(APPEND ARROW_PYTHON_SRCS filesystem.cc)
55 set(ARROW_PYTHON_DEPENDENCIES arrow_dependencies)
57 if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
58 set_property(SOURCE pyarrow.cc
60 PROPERTY COMPILE_FLAGS " -Wno-cast-qual ")
63 set(ARROW_PYTHON_SHARED_LINK_LIBS arrow_shared)
65 list(APPEND ARROW_PYTHON_SHARED_LINK_LIBS ${PYTHON_LIBRARIES} ${PYTHON_OTHER_LIBS})
68 set(ARROW_PYTHON_INCLUDES ${NUMPY_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS})
70 add_arrow_lib(arrow_python
78 "$<$<COMPILE_LANGUAGE:CXX>:arrow/python/pch.h>"
80 ARROW_PYTHON_LIBRARIES
82 ${ARROW_PYTHON_DEPENDENCIES}
84 ${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt
86 ${ARROW_PYTHON_SHARED_LINK_LIBS}
90 "${ARROW_PYTHON_INCLUDES}")
92 add_dependencies(arrow_python ${ARROW_PYTHON_LIBRARIES})
94 foreach(LIB_TARGET ${ARROW_PYTHON_LIBRARIES})
95 target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_PYTHON_EXPORTING)
98 if(ARROW_BUILD_STATIC AND MSVC)
99 target_compile_definitions(arrow_python_static PUBLIC ARROW_STATIC)
102 if(ARROW_FLIGHT AND ARROW_BUILD_SHARED)
103 # Must link to shared libarrow_flight: we don't want to link more than one
104 # copy of gRPC into the eventual Cython shared object, otherwise gRPC calls
105 # fail with weird errors due to multiple copies of global static state (The
106 # other solution is to link gRPC shared everywhere instead of statically only
108 add_arrow_lib(arrow_python_flight
116 ARROW_PYFLIGHT_LIBRARIES
120 ${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt
127 "${ARROW_PYTHON_INCLUDES}")
129 add_dependencies(arrow_python ${ARROW_PYFLIGHT_LIBRARIES})
131 foreach(LIB_TARGET ${ARROW_PYFLIGHT_LIBRARIES})
132 target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_PYFLIGHT_EXPORTING)
135 if(ARROW_BUILD_STATIC AND MSVC)
136 target_compile_definitions(arrow_python_flight_static PUBLIC ARROW_STATIC)
140 if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
141 # Clang, be quiet. Python C API has lots of macros
142 set_property(SOURCE ${ARROW_PYTHON_SRCS}
144 PROPERTY COMPILE_FLAGS -Wno-parentheses-equality)
147 arrow_install_all_headers("arrow/python")
149 # ----------------------------------------------------------------------
151 if(ARROW_BUILD_TESTS)
152 add_library(arrow_python_test_main STATIC util/test_main.cc)
154 target_link_libraries(arrow_python_test_main GTest::gtest)
155 target_include_directories(arrow_python_test_main SYSTEM
156 PUBLIC ${ARROW_PYTHON_INCLUDES})
159 target_link_libraries(arrow_python_test_main ${CMAKE_DL_LIBS})
160 set_target_properties(arrow_python_test_main PROPERTIES LINK_FLAGS
161 "-undefined dynamic_lookup")
163 target_link_libraries(arrow_python_test_main pthread ${CMAKE_DL_LIBS})
166 if(ARROW_TEST_LINKAGE STREQUAL shared)
167 set(ARROW_PYTHON_TEST_LINK_LIBS arrow_python_test_main arrow_python_shared
168 arrow_testing_shared arrow_shared)
170 set(ARROW_PYTHON_TEST_LINK_LIBS arrow_python_test_main arrow_python_static
171 arrow_testing_static arrow_static)
174 add_arrow_test(python_test
176 "${ARROW_PYTHON_TEST_LINK_LIBS}"
180 "${ARROW_PYTHON_INCLUDES}"