1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright Contributors to the OpenEXR Project.
4 if(TARGET Python2::Interpreter)
6 COMMAND ${Python2_EXECUTABLE} -c
7 "from __future__ import print_function\ntry: import numpy; print(numpy.get_include(), end='')\nexcept: import sys; sys.exit(1)\n"
8 RESULT_VARIABLE _NUMPY2_RESULT
9 OUTPUT_VARIABLE py_imath_numpy2_path
10 OUTPUT_STRIP_TRAILING_WHITESPACE)
12 if(NOT _NUMPY2_RESULT MATCHES 0)
13 set(NumPy_Py2_FOUND FALSE CACHE INTERNAL "Python2 numpy libraries not found")
14 message(WARNING "Unable to import numpy using python ${Python2_VERSION}")
17 COMMAND ${Python2_EXECUTABLE} -c
18 "from __future__ import print_function\ntry: import numpy; print(numpy.__version__, end='')\nexcept: import sys; sys.exit(1)\n"
19 RESULT_VARIABLE _NUMPY2_RESULT
20 OUTPUT_VARIABLE py_imath_numpy2_version
21 OUTPUT_STRIP_TRAILING_WHITESPACE)
23 if(NOT _NUMPY2_RESULT MATCHES 0)
24 set(NumPy_Py2_FOUND FALSE CACHE INTERNAL "Python2 numpy libraries not found")
25 message(WARNING "Found numpy module in python ${Python2_VERSION}, but no version information")
27 find_path(NumPy_Py2_INCLUDE_DIRS numpy/arrayobject.h
28 HINTS "${py_imath_numpy2_path}" "${Python2_INCLUDE_DIRS}"
31 if(NumPy_Py2_INCLUDE_DIRS)
32 set(NumPy_Py2_FOUND TRUE CACHE INTERNAL "Python2 numpy found")
33 set(NumPy_Py2_VERSION ${py_imath_numpy2_version})
34 add_library(NumPy_Py2 INTERFACE IMPORTED GLOBAL)
35 target_include_directories(NumPy_Py2 INTERFACE ${NumPy_Py2_INCLUDE_DIRS})
36 add_library(Python2::ImathNumPy ALIAS NumPy_Py2)
37 message(STATUS "Found NumPy ${NumPy_Py2_VERSION} for Python ${Python2_VERSION}: ${NumPy_Py2_INCLUDE_DIRS}")
39 set(NumPy_Py2_FOUND FALSE CACHE INTERNAL "Python2 numpy libraries not found")
40 message(WARNING "Found numpy version ${py_imath_numpy2_version} in python ${Python2_VERSION}, but unable to locate header files")
46 if(TARGET Python3::Interpreter)
48 COMMAND ${Python3_EXECUTABLE} -c
49 "from __future__ import print_function\ntry: import numpy; print(numpy.get_include(), end='')\nexcept: import sys; sys.exit(1)\n"
50 RESULT_VARIABLE _NUMPY3_RESULT
51 OUTPUT_VARIABLE py_imath_numpy3_path
52 OUTPUT_STRIP_TRAILING_WHITESPACE)
54 if(NOT _NUMPY3_RESULT MATCHES 0)
55 set(NumPy_Py3_FOUND FALSE CACHE INTERNAL "Python3 numpy libraries not found")
56 message(WARNING "Unable to import numpy using python ${Python3_VERSION}")
59 COMMAND ${Python3_EXECUTABLE} -c
60 "from __future__ import print_function\ntry: import numpy; print(numpy.__version__, end='')\nexcept: import sys; sys.exit(1)\n"
61 RESULT_VARIABLE _NUMPY3_RESULT
62 OUTPUT_VARIABLE py_imath_numpy3_version
63 OUTPUT_STRIP_TRAILING_WHITESPACE)
65 if(NOT _NUMPY3_RESULT MATCHES 0)
66 set(NumPy_Py3_FOUND FALSE CACHE INTERNAL "Python3 numpy libraries not found")
67 message(WARNING "Found numpy module in python ${Python3_VERSION}, but no version information")
69 find_path(NumPy_Py3_INCLUDE_DIRS numpy/arrayobject.h
70 HINTS "${py_imath_numpy3_path}" "${Python3_INCLUDE_DIRS}"
73 if(NumPy_Py3_INCLUDE_DIRS)
74 set(NumPy_Py3_FOUND TRUE CACHE INTERNAL "Python3 numpy found")
75 set(NumPy_Py3_VERSION ${py_imath_numpy3_version})
76 add_library(NumPy_Py3 INTERFACE IMPORTED GLOBAL)
77 target_include_directories(NumPy_Py3 INTERFACE ${NumPy_Py3_INCLUDE_DIRS})
78 add_library(Python3::ImathNumPy ALIAS NumPy_Py3)
79 message(STATUS "Found NumPy ${NumPy_Py3_VERSION} for Python ${Python3_VERSION}: ${NumPy_Py3_INCLUDE_DIRS}")
81 set(NumPy_Py3_FOUND FALSE CACHE INTERNAL "Python3 numpy libraries not found")
82 message(WARNING "Found numpy version ${py_imath_numpy3_version} in python ${Python3_VERSION}, but unable to locate header files")