Skip to content

Commit

Permalink
add last ditch effort for numpy
Browse files Browse the repository at this point in the history
Apparently not all distributions include a FindNumPy.cmake or similar,
even if numpy is indeed installed. This makes a second effort to find
using python itself

Signed-off-by: Kimball Thurston <[email protected]>
  • Loading branch information
kdt3rd authored and nickrasmussen committed Aug 9, 2018
1 parent 342e0c1 commit 0d35b51
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,37 @@ if (OPENEXR_BUILD_PYTHON_LIBS)

find_package(NumPy)
if(NOT NumPy_FOUND)
message(WARNING "Numpy not found, PyImathNumpy will not be built")

if(NOT PYTHON_EXECUTABLE)
find_package(PythonInterp QUIET)
endif()
if (PYTHON_EXECUTABLE)
# Find out the include path
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"from __future__ import print_function\ntry: import numpy; print(numpy.get_include(), end='')\nexcept:pass\n"
OUTPUT_VARIABLE py_ilmbase_numpy_path)
# And the version
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"from __future__ import print_function\ntry: import numpy; print(numpy.__version__, end='')\nexcept:pass\n"
OUTPUT_VARIABLE py_ilmbase_numpy_version)

find_path(NUMPY_INCLUDE_DIRS numpy/arrayobject.h
HINTS "${py_ilmbase_numpy_path}" "${PYTHON_INCLUDE_PATH}" NO_DEFAULT_PATH)

if(NUMPY_INCLUDE_DIRS)
set(NumPy_FOUND 1 CACHE INTERNAL "Python numpy found")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NumPy REQUIRED_VARS NUMPY_INCLUDE_DIRS
VERSION_VAR py_ilmbase_numpy_version)
else()
message(WARNING "Numpy not found, PyImathNumpy will not be built")
endif()
else ()
message(WARNING "Numpy not found, PyImathNumpy will not be built")
endif ()
endif()
endif()

Expand Down

0 comments on commit 0d35b51

Please sign in to comment.