]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/cmake_modules/FindPython3Alt.cmake
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / arrow / cpp / cmake_modules / FindPython3Alt.cmake
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 # This module finds the libraries corresponding to the Python 3 interpreter
19 # and the NumPy package, and sets the following variables:
20 # - PYTHON_EXECUTABLE
21 # - PYTHON_INCLUDE_DIRS
22 # - PYTHON_LIBRARIES
23 # - PYTHON_OTHER_LIBS
24 # - NUMPY_INCLUDE_DIRS
25
26 # Need CMake 3.15 or later for Python3_FIND_STRATEGY
27 if(${CMAKE_VERSION} VERSION_LESS "3.15.0")
28 # Use deprecated Python- and NumPy-finding code
29 if(Python3Alt_FIND_REQUIRED)
30 find_package(PythonLibsNew REQUIRED)
31 find_package(NumPy REQUIRED)
32 else()
33 find_package(PythonLibsNew)
34 find_package(NumPy)
35 endif()
36 find_package_handle_standard_args(
37 Python3Alt REQUIRED_VARS PYTHON_EXECUTABLE PYTHON_INCLUDE_DIRS NUMPY_INCLUDE_DIRS)
38 return()
39 endif()
40
41 if(${CMAKE_VERSION} VERSION_LESS "3.18.0" OR ARROW_BUILD_TESTS)
42 # When building arrow-python-test, we need libpython to be present, so ask for
43 # the full "Development" component. Also ask for it on CMake < 3.18,
44 # where "Development.Module" is not available.
45 if(Python3Alt_FIND_REQUIRED)
46 find_package(Python3
47 COMPONENTS Interpreter Development NumPy
48 REQUIRED)
49 else()
50 find_package(Python3 COMPONENTS Interpreter Development NumPy)
51 endif()
52 else()
53 if(Python3Alt_FIND_REQUIRED)
54 find_package(Python3
55 COMPONENTS Interpreter Development.Module NumPy
56 REQUIRED)
57 else()
58 find_package(Python3 COMPONENTS Interpreter Development.Module NumPy)
59 endif()
60 endif()
61
62 if(NOT Python3_FOUND)
63 return()
64 endif()
65
66 set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
67 set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
68 set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
69 set(PYTHON_OTHER_LIBS)
70
71 get_target_property(NUMPY_INCLUDE_DIRS Python3::NumPy INTERFACE_INCLUDE_DIRECTORIES)
72
73 # CMake's python3_add_library() doesn't apply the required extension suffix,
74 # detect it ourselves.
75 # (https://gitlab.kitware.com/cmake/cmake/issues/20408)
76 execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
77 "from distutils import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
78 RESULT_VARIABLE _PYTHON_RESULT
79 OUTPUT_VARIABLE _PYTHON_STDOUT
80 ERROR_VARIABLE _PYTHON_STDERR)
81
82 if(NOT _PYTHON_RESULT MATCHES 0)
83 if(Python3Alt_FIND_REQUIRED)
84 message(FATAL_ERROR "Python 3 config failure:\n${_PYTHON_STDERR}")
85 endif()
86 endif()
87
88 string(STRIP ${_PYTHON_STDOUT} _EXT_SUFFIX)
89
90 function(PYTHON_ADD_MODULE name)
91 python3_add_library(${name} MODULE ${ARGN})
92 set_target_properties(${name} PROPERTIES SUFFIX ${_EXT_SUFFIX})
93 endfunction()
94
95 find_package_handle_standard_args(
96 Python3Alt REQUIRED_VARS PYTHON_EXECUTABLE PYTHON_INCLUDE_DIRS NUMPY_INCLUDE_DIRS)