Update build system to properly play with numpy
authorAlexey Shvetsov <alexxy@omrb.pnpi.spb.ru>
Sat, 6 Dec 2014 15:57:55 +0000 (18:57 +0300)
committerAlexey Shvetsov <alexxy@omrb.pnpi.spb.ru>
Sat, 6 Dec 2014 15:57:55 +0000 (18:57 +0300)
Change-Id: Ice8528d5cae222a4a0356e461ee4e25502c2d72e
Signed-off-by: Alexey Shvetsov <alexxy@omrb.pnpi.spb.ru>
cmake/FindNumPy.cmake [new file with mode: 0644]
src/python/CMakeLists.txt

diff --git a/cmake/FindNumPy.cmake b/cmake/FindNumPy.cmake
new file mode 100644 (file)
index 0000000..eafed16
--- /dev/null
@@ -0,0 +1,102 @@
+# - Find the NumPy libraries\r
+# This module finds if NumPy is installed, and sets the following variables\r
+# indicating where it is.\r
+#\r
+# TODO: Update to provide the libraries and paths for linking npymath lib.\r
+#\r
+#  NUMPY_FOUND               - was NumPy found\r
+#  NUMPY_VERSION             - the version of NumPy found as a string\r
+#  NUMPY_VERSION_MAJOR       - the major version number of NumPy\r
+#  NUMPY_VERSION_MINOR       - the minor version number of NumPy\r
+#  NUMPY_VERSION_PATCH       - the patch version number of NumPy\r
+#  NUMPY_VERSION_DECIMAL     - e.g. version 1.6.1 is 10601\r
+#  NUMPY_INCLUDE_DIRS        - path to the NumPy include files\r
+\r
+#============================================================================\r
+# Copyright 2012 Continuum Analytics, Inc.\r
+#\r
+# MIT License\r
+#\r
+# Permission is hereby granted, free of charge, to any person obtaining\r
+# a copy of this software and associated documentation files\r
+# (the "Software"), to deal in the Software without restriction, including\r
+# without limitation the rights to use, copy, modify, merge, publish,\r
+# distribute, sublicense, and/or sell copies of the Software, and to permit\r
+# persons to whom the Software is furnished to do so, subject to\r
+# the following conditions:\r
+#\r
+# The above copyright notice and this permission notice shall be included\r
+# in all copies or substantial portions of the Software.\r
+#\r
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR\r
+# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\r
+# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r
+# OTHER DEALINGS IN THE SOFTWARE.\r
+#\r
+#============================================================================\r
+\r
+# Finding NumPy involves calling the Python interpreter\r
+if(NumPy_FIND_REQUIRED)\r
+    find_package(PythonInterp REQUIRED)\r
+else()\r
+    find_package(PythonInterp)\r
+endif()\r
+\r
+if(NOT PYTHONINTERP_FOUND)\r
+    set(NUMPY_FOUND FALSE)\r
+    return()\r
+endif()\r
+\r
+execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"\r
+    "import numpy as n; print(n.__version__); print(n.get_include());"\r
+    RESULT_VARIABLE _NUMPY_SEARCH_SUCCESS\r
+    OUTPUT_VARIABLE _NUMPY_VALUES_OUTPUT\r
+    ERROR_VARIABLE _NUMPY_ERROR_VALUE\r
+    OUTPUT_STRIP_TRAILING_WHITESPACE)\r
+\r
+if(NOT _NUMPY_SEARCH_SUCCESS MATCHES 0)\r
+    if(NumPy_FIND_REQUIRED)\r
+        message(FATAL_ERROR\r
+            "NumPy import failure:\n${_NUMPY_ERROR_VALUE}")\r
+    endif()\r
+    set(NUMPY_FOUND FALSE)\r
+    return()\r
+endif()\r
+\r
+# Convert the process output into a list\r
+string(REGEX REPLACE ";" "\\\\;" _NUMPY_VALUES ${_NUMPY_VALUES_OUTPUT})\r
+string(REGEX REPLACE "\n" ";" _NUMPY_VALUES ${_NUMPY_VALUES})\r
+# Just in case there is unexpected output from the Python command.\r
+list(GET _NUMPY_VALUES -2 NUMPY_VERSION)\r
+list(GET _NUMPY_VALUES -1 NUMPY_INCLUDE_DIRS)\r
+\r
+string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" _VER_CHECK "${NUMPY_VERSION}")\r
+if("${_VER_CHECK}" STREQUAL "")\r
+    # The output from Python was unexpected. Raise an error always\r
+    # here, because we found NumPy, but it appears to be corrupted somehow.\r
+    message(FATAL_ERROR\r
+        "Requested version and include path from NumPy, got instead:\n${_NUMPY_VALUES_OUTPUT}\n")\r
+    return()\r
+endif()\r
+\r
+# Make sure all directory separators are '/'\r
+string(REGEX REPLACE "\\\\" "/" NUMPY_INCLUDE_DIRS ${NUMPY_INCLUDE_DIRS})\r
+\r
+# Get the major and minor version numbers\r
+string(REGEX REPLACE "\\." ";" _NUMPY_VERSION_LIST ${NUMPY_VERSION})\r
+list(GET _NUMPY_VERSION_LIST 0 NUMPY_VERSION_MAJOR)\r
+list(GET _NUMPY_VERSION_LIST 1 NUMPY_VERSION_MINOR)\r
+list(GET _NUMPY_VERSION_LIST 2 NUMPY_VERSION_PATCH)\r
+string(REGEX MATCH "[0-9]*" NUMPY_VERSION_PATCH ${NUMPY_VERSION_PATCH})\r
+math(EXPR NUMPY_VERSION_DECIMAL\r
+    "(${NUMPY_VERSION_MAJOR} * 10000) + (${NUMPY_VERSION_MINOR} * 100) + ${NUMPY_VERSION_PATCH}")\r
+\r
+find_package_message(NUMPY\r
+    "Found NumPy: version \"${NUMPY_VERSION}\" ${NUMPY_INCLUDE_DIRS}"\r
+    "${NUMPY_INCLUDE_DIRS}${NUMPY_VERSION}")\r
+\r
+set(NUMPY_FOUND TRUE)\r
+\r
index a1e256547ba724f41a0355d1ccdb55d4dda53700..a81c956c34be7a3d452392f3fb978c33aa21f378 100644 (file)
@@ -34,6 +34,7 @@
 #
 
 find_package(PythonLibrary REQUIRED)
+find_package(NumPy REQUIRED)
 find_package(SIP REQUIRED)
 
 include(SIPMacros)
@@ -44,7 +45,7 @@ include_directories(
     ${SIP_INCLUDE_DIR}
     ${GROMACS_INCLUDE_DIRS}
     ${CMAKE_SOURCE_DIR}/src/python/include
-    ${PYTHON_SITE_PACKAGES_INSTALL_DIR}/numpy/core/include
+    ${NUMPY_INCLUDE_DIRS}   
 )
 
 add_definitions(-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION)