Skip to content

Commit

Permalink
Handle required version in FindNumPy.cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Hernando Vieites committed Aug 30, 2016
1 parent 8c248b9 commit 5e55011
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# git master

* [507](https://github.com/Eyescale/CMake/pull/507):
Handle required version in FindNumPy.cmake
* [506](https://github.com/Eyescale/CMake/pull/506):
Added CommonPythonTest.cmake to ease adding Python tests to project under
CTest.
Expand Down
29 changes: 16 additions & 13 deletions FindNumPy.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Find the Python NumPy package
# PYTHON_NUMPY_INCLUDE_DIR
# NUMPY_FOUND
# PYTHON_NUMPY_FOUND
# will be set by this script

cmake_minimum_required(VERSION 2.6)
Expand All @@ -10,29 +10,32 @@ if(NOT PYTHON_EXECUTABLE)
find_package(PythonInterp QUIET)
else()
find_package(PythonInterp)
set(_numpy_out 1)
set(__numpy_out 1)
endif()
endif()

if (PYTHON_EXECUTABLE)
# write a python script that finds the numpy path
file(WRITE ${PROJECT_BINARY_DIR}/FindNumpyPath.py
"try: import numpy; print(numpy.get_include())\nexcept:pass\n")

# execute the find script
exec_program("${PYTHON_EXECUTABLE}" ${PROJECT_BINARY_DIR}
ARGS "FindNumpyPath.py"
OUTPUT_VARIABLE NUMPY_PATH)
elseif(_numpy_out)
# Find out the include path
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"try: import numpy; print(numpy.get_include())\nexcept:pass\n"
OUTPUT_VARIABLE __numpy_path)
# And the version
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"try: import numpy; print(numpy.__version__)\nexcept:pass\n"
OUTPUT_VARIABLE __numpy_version)
elseif(__numpy_out)
message(STATUS "Python executable not found.")
endif(PYTHON_EXECUTABLE)

find_path(PYTHON_NUMPY_INCLUDE_DIR numpy/arrayobject.h
HINTS "${NUMPY_PATH}" "${PYTHON_INCLUDE_PATH}")
HINTS "${__numpy_path}" "${PYTHON_INCLUDE_PATH}")

if(PYTHON_NUMPY_INCLUDE_DIR)
set(PYTHON_NUMPY_FOUND 1 CACHE INTERNAL "Python numpy found")
endif(PYTHON_NUMPY_INCLUDE_DIR)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NumPy DEFAULT_MSG PYTHON_NUMPY_INCLUDE_DIR)
find_package_handle_standard_args(NumPy REQUIRED_VARS PYTHON_NUMPY_INCLUDE_DIR
VERSION_VAR __numpy_version)

0 comments on commit 5e55011

Please sign in to comment.