|
| 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 | +# Finding NumPy involves calling the Python interpreter |
| 42 | +if(NumPy_FIND_REQUIRED) |
| 43 | + find_package(PythonInterp REQUIRED) |
| 44 | +else() |
| 45 | + find_package(PythonInterp) |
| 46 | +endif() |
| 47 | + |
| 48 | +if(NOT PYTHONINTERP_FOUND) |
| 49 | + set(NUMPY_FOUND FALSE) |
| 50 | +endif() |
| 51 | + |
| 52 | +execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" |
| 53 | + "import numpy as n; print(n.__version__); print(n.get_include());" |
| 54 | + RESULT_VARIABLE _NUMPY_SEARCH_SUCCESS |
| 55 | + OUTPUT_VARIABLE _NUMPY_VALUES |
| 56 | + ERROR_VARIABLE _NUMPY_ERROR_VALUE |
| 57 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 58 | + |
| 59 | +if(NOT _NUMPY_SEARCH_SUCCESS MATCHES 0) |
| 60 | + if(NumPy_FIND_REQUIRED) |
| 61 | + message(FATAL_ERROR |
| 62 | + "NumPy import failure:\n${_NUMPY_ERROR_VALUE}") |
| 63 | + endif() |
| 64 | + set(NUMPY_FOUND FALSE) |
| 65 | +endif() |
| 66 | + |
| 67 | +# Convert the process output into a list |
| 68 | +string(REGEX REPLACE ";" "\\\\;" _NUMPY_VALUES ${_NUMPY_VALUES}) |
| 69 | +string(REGEX REPLACE "\n" ";" _NUMPY_VALUES ${_NUMPY_VALUES}) |
| 70 | +list(GET _NUMPY_VALUES 0 NUMPY_VERSION) |
| 71 | +list(GET _NUMPY_VALUES 1 NUMPY_INCLUDE_DIRS) |
| 72 | + |
| 73 | +# Make sure all directory separators are '/' |
| 74 | +string(REGEX REPLACE "\\\\" "/" NUMPY_INCLUDE_DIRS ${NUMPY_INCLUDE_DIRS}) |
| 75 | + |
| 76 | +# Get the major and minor version numbers |
| 77 | +string(REGEX REPLACE "\\." ";" _NUMPY_VERSION_LIST ${NUMPY_VERSION}) |
| 78 | +list(GET _NUMPY_VERSION_LIST 0 NUMPY_VERSION_MAJOR) |
| 79 | +list(GET _NUMPY_VERSION_LIST 1 NUMPY_VERSION_MINOR) |
| 80 | +list(GET _NUMPY_VERSION_LIST 2 NUMPY_VERSION_PATCH) |
| 81 | +string(REGEX MATCH "[0-9]*" NUMPY_VERSION_PATCH ${NUMPY_VERSION_PATCH}) |
| 82 | +math(EXPR NUMPY_VERSION_DECIMAL |
| 83 | + "(${NUMPY_VERSION_MAJOR} * 10000) + (${NUMPY_VERSION_MINOR} * 100) + ${NUMPY_VERSION_PATCH}") |
| 84 | + |
| 85 | +find_package_message(NUMPY |
| 86 | + "Found NumPy: version \"${NUMPY_VERSION}\" ${NUMPY_INCLUDE_DIRS}" |
| 87 | + "${NUMPY_INCLUDE_DIRS}${NUMPY_VERSION}") |
| 88 | + |
| 89 | +set(NUMPY_FOUND TRUE) |
0 commit comments