]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/cmake_modules/FindNumPy.cmake
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / arrow / cpp / cmake_modules / FindNumPy.cmake
1 # - Find the NumPy libraries
2 # This module finds if NumPy is installed, and sets the following variables
3 # indicating where it is.
4 #
5 # TODO: Update to provide the libraries and paths for linking npymath lib.
6 #
7 # NUMPY_FOUND - was NumPy found
8 # NUMPY_VERSION - the version of NumPy found as a string
9 # NUMPY_VERSION_MAJOR - the major version number of NumPy
10 # NUMPY_VERSION_MINOR - the minor version number of NumPy
11 # NUMPY_VERSION_PATCH - the patch version number of NumPy
12 # NUMPY_VERSION_DECIMAL - e.g. version 1.6.1 is 10601
13 # NUMPY_INCLUDE_DIRS - path to the NumPy include files
14
15 #============================================================================
16 # Copyright 2012 Continuum Analytics, Inc.
17 #
18 # MIT License
19 #
20 # Permission is hereby granted, free of charge, to any person obtaining
21 # a copy of this software and associated documentation files
22 # (the "Software"), to deal in the Software without restriction, including
23 # without limitation the rights to use, copy, modify, merge, publish,
24 # distribute, sublicense, and/or sell copies of the Software, and to permit
25 # persons to whom the Software is furnished to do so, subject to
26 # the following conditions:
27 #
28 # The above copyright notice and this permission notice shall be included
29 # in all copies or substantial portions of the Software.
30 #
31 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
32 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
34 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
35 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
36 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
37 # OTHER DEALINGS IN THE SOFTWARE.
38 #
39 #============================================================================
40
41 # Legacy code for CMake < 3.15.0. The primary point of entry should be
42 # FindPython3Alt.cmake.
43
44 if(NOT PYTHONINTERP_FOUND)
45 set(NUMPY_FOUND FALSE)
46 return()
47 endif()
48
49 execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
50 "import numpy as n; print(n.__version__); print(n.get_include());"
51 RESULT_VARIABLE _NUMPY_SEARCH_SUCCESS
52 OUTPUT_VARIABLE _NUMPY_VALUES_OUTPUT
53 ERROR_VARIABLE _NUMPY_ERROR_VALUE
54 OUTPUT_STRIP_TRAILING_WHITESPACE)
55
56 if(NOT _NUMPY_SEARCH_SUCCESS MATCHES 0)
57 if(NumPy_FIND_REQUIRED)
58 message(FATAL_ERROR
59 "NumPy import failure:\n${_NUMPY_ERROR_VALUE}")
60 endif()
61 set(NUMPY_FOUND FALSE)
62 return()
63 endif()
64
65 # Convert the process output into a list
66 string(REGEX REPLACE ";" "\\\\;" _NUMPY_VALUES ${_NUMPY_VALUES_OUTPUT})
67 string(REGEX REPLACE "\n" ";" _NUMPY_VALUES ${_NUMPY_VALUES})
68 list(GET _NUMPY_VALUES 0 NUMPY_VERSION)
69 list(GET _NUMPY_VALUES 1 NUMPY_INCLUDE_DIRS)
70
71 string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" _VER_CHECK "${NUMPY_VERSION}")
72 if("${_VER_CHECK}" STREQUAL "")
73 # The output from Python was unexpected. Raise an error always
74 # here, because we found NumPy, but it appears to be corrupted somehow.
75 message(FATAL_ERROR
76 "Requested version and include path from NumPy, got instead:\n${_NUMPY_VALUES_OUTPUT}\n")
77 return()
78 endif()
79
80 # Make sure all directory separators are '/'
81 string(REGEX REPLACE "\\\\" "/" NUMPY_INCLUDE_DIRS ${NUMPY_INCLUDE_DIRS})
82
83 # Get the major and minor version numbers
84 string(REGEX REPLACE "\\." ";" _NUMPY_VERSION_LIST ${NUMPY_VERSION})
85 list(GET _NUMPY_VERSION_LIST 0 NUMPY_VERSION_MAJOR)
86 list(GET _NUMPY_VERSION_LIST 1 NUMPY_VERSION_MINOR)
87 list(GET _NUMPY_VERSION_LIST 2 NUMPY_VERSION_PATCH)
88 string(REGEX MATCH "[0-9]*" NUMPY_VERSION_PATCH ${NUMPY_VERSION_PATCH})
89 math(EXPR NUMPY_VERSION_DECIMAL
90 "(${NUMPY_VERSION_MAJOR} * 10000) + (${NUMPY_VERSION_MINOR} * 100) + ${NUMPY_VERSION_PATCH}")
91
92 find_package_message(NUMPY
93 "Found NumPy: version \"${NUMPY_VERSION}\" ${NUMPY_INCLUDE_DIRS}"
94 "${NUMPY_INCLUDE_DIRS}${NUMPY_VERSION}")
95
96 set(NUMPY_FOUND TRUE)