From 37ba3691eb56e208793e0f566c83df23bad8f19e Mon Sep 17 00:00:00 2001 From: Stephen Herbein Date: Sat, 22 Dec 2018 22:49:08 -0800 Subject: [PATCH] python: add FindNumPy cmake module adds support for numpy installations that aren't in system directories --- python/CMakeLists.txt | 5 +++- python/eyescale-cmake/FindNumPy.cmake | 41 +++++++++++++++++++++++++++ python/eyescale-cmake/LICENSE.txt | 26 +++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 python/eyescale-cmake/FindNumPy.cmake create mode 100644 python/eyescale-cmake/LICENSE.txt diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index c1e3f51f7..4400ad0dc 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,14 +1,17 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/scikit-build-cmake) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/eyescale-cmake) include(UseCython) include(FindPythonExtensions) - +include(FindNumPy) find_package(PythonInterp REQUIRED) find_package(PythonLibs REQUIRED) find_package(PythonExtensions REQUIRED) find_package(Cython REQUIRED) +find_package(NumPy REQUIRED) include_directories(${ZFP_SOURCE_DIR}/include) +include_directories(${PYTHON_NUMPY_INCLUDE_DIR}) # cannot reuse the zfp target, use _zfp instead add_cython_target(_zfp zfp.pyx C PY2) diff --git a/python/eyescale-cmake/FindNumPy.cmake b/python/eyescale-cmake/FindNumPy.cmake new file mode 100644 index 000000000..8aba4e696 --- /dev/null +++ b/python/eyescale-cmake/FindNumPy.cmake @@ -0,0 +1,41 @@ +# Find the Python NumPy package +# PYTHON_NUMPY_INCLUDE_DIR +# PYTHON_NUMPY_FOUND +# will be set by this script + +# cmake_minimum_required(VERSION 2.6) + +if(NOT PYTHON_EXECUTABLE) + if(NumPy_FIND_QUIETLY) + find_package(PythonInterp QUIET) + else() + find_package(PythonInterp) + set(__numpy_out 1) + endif() +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 __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 __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}" NO_DEFAULT_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 REQUIRED_VARS PYTHON_NUMPY_INCLUDE_DIR + VERSION_VAR __numpy_version) diff --git a/python/eyescale-cmake/LICENSE.txt b/python/eyescale-cmake/LICENSE.txt new file mode 100644 index 000000000..307d54e59 --- /dev/null +++ b/python/eyescale-cmake/LICENSE.txt @@ -0,0 +1,26 @@ +Unless otherwise noted in the file, all files in this directory are +licensed under the BSD license, reproduced below. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. +- Neither the name of Eyescale Software GmbH nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE.