mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 00:56:31 +08:00
ARROW-7917: [C++] Find Python 3 in CMake configuration
Use the new FindPython3 package if available.
This commit is contained in:
1 parent
357eb6bb79
commit
7395f83af5
6 files changed
+79
-2
No files matched your search
+6
-1
@@ -137,7 +137,12 @@ endif()
|
||||
include(DefineOptions)
|
||||
|
||||
# Needed for linting targets, etc.
|
||||
find_package(PythonInterp)
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
|
||||
find_package(PythonInterp)
|
||||
else()
|
||||
find_package(Python3)
|
||||
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
|
||||
endif()
|
||||
|
||||
if(ARROW_USE_CCACHE)
|
||||
find_program(CCACHE_FOUND ccache)
|
||||
|
||||
@@ -38,6 +38,20 @@
|
||||
#
|
||||
#============================================================================
|
||||
|
||||
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14.0")
|
||||
# FindPython3Alt.cmake also looks for NumPy, use it.
|
||||
if(NumPy_FIND_REQUIRED)
|
||||
find_package(Python3Alt REQUIRED)
|
||||
else()
|
||||
find_package(Python3Alt)
|
||||
endif()
|
||||
get_target_property(NUMPY_INCLUDE_DIRS Python3::NumPy INTERFACE_INCLUDE_DIRECTORIES)
|
||||
message(STATUS "Found NumPy: ${NUMPY_INCLUDE_DIRS}")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Legacy code below (CMake < 3.14.0)
|
||||
|
||||
# Finding NumPy involves calling the Python interpreter
|
||||
if(NumPy_FIND_REQUIRED)
|
||||
find_package(PythonInterp REQUIRED)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# 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.
|
||||
|
||||
# This module finds the libraries corresponding to the Python 3 interpeter,
|
||||
# and sets the following variables:
|
||||
# - PYTHON_EXECUTABLE
|
||||
# - PYTHON_INCLUDE_DIRS
|
||||
# - PYTHON_LIBRARIES
|
||||
# - PYTHON_OTHER_LIBS
|
||||
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.14.0")
|
||||
# Use deprecated FindPythonInterp package
|
||||
if(Python3Alt_FIND_REQUIRED)
|
||||
find_package(PythonLibsNew REQUIRED)
|
||||
else()
|
||||
find_package(PythonLibsNew)
|
||||
endif()
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(Python3Alt_FIND_REQUIRED)
|
||||
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)
|
||||
else()
|
||||
find_package(Python3 COMPONENTS Interpreter Development NumPy)
|
||||
endif()
|
||||
|
||||
if(NOT Python3_FOUND)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
|
||||
set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
|
||||
set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
|
||||
set(PYTHON_OTHER_LIBS)
|
||||
|
||||
message(STATUS "Found Python 3 libraries: ${PYTHON_LIBRARIES}")
|
||||
|
||||
function(PYTHON_ADD_MODULE _NAME)
|
||||
python3_add_library(${_NAME} ${ARGN})
|
||||
endfunction()
|
||||
@@ -57,6 +57,9 @@
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
# Legacy code for CMake < 3.14.0. The primary point of entry should be
|
||||
# FindPython3Alt.cmake.
|
||||
|
||||
# Use the Python interpreter to find the libs.
|
||||
if(PythonLibsNew_FIND_REQUIRED)
|
||||
find_package(PythonInterp REQUIRED)
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
# arrow_python
|
||||
#
|
||||
|
||||
find_package(PythonLibsNew REQUIRED)
|
||||
find_package(Python3Alt REQUIRED)
|
||||
find_package(NumPy REQUIRED)
|
||||
|
||||
add_custom_target(arrow_python-all)
|
||||
|
||||
@@ -47,6 +47,7 @@ patterns = [
|
||||
'cpp/cmake_modules/FindLz4.cmake',
|
||||
'cpp/cmake_modules/FindParquet.cmake',
|
||||
'cpp/cmake_modules/FindPlasma.cmake',
|
||||
'cpp/cmake_modules/FindPython3Alt.cmake',
|
||||
'cpp/cmake_modules/FindRE2.cmake',
|
||||
'cpp/cmake_modules/FindRapidJSONAlt.cmake',
|
||||
'cpp/cmake_modules/FindSnappyAlt.cmake',
|
||||
|
||||
Reference in new issue
Block a user