fix cross-compilation issue with Numpy
authorVincent Rabaud <vrabaud@aldebaran-robotics.com>
Mon, 20 Jan 2014 09:23:46 +0000 (10:23 +0100)
committerVincent Rabaud <vrabaud@aldebaran-robotics.com>
Tue, 21 Jan 2014 09:07:19 +0000 (10:07 +0100)
cmake/OpenCVDetectPython.cmake

index 3326bcd..8c488e6 100644 (file)
@@ -80,14 +80,29 @@ if(PYTHON_EXECUTABLE)
     endif()
     SET(PYTHON_PACKAGES_PATH "${_PYTHON_PACKAGES_PATH}" CACHE PATH "Where to install the python packages.")
 
-    if(NOT PYTHON_NUMPY_INCLUDE_DIR)
-      # Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy
-      execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print numpy.distutils.misc_util.get_numpy_include_dirs()[0]"
-                      RESULT_VARIABLE PYTHON_NUMPY_PROCESS
-                      OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIR
-                      OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if(NOT CMAKE_CROSSCOMPILING)
+      if(NOT PYTHON_NUMPY_INCLUDE_DIR)
+        # Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy
+        execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print numpy.distutils.misc_util.get_numpy_include_dirs()[0]"
+                        RESULT_VARIABLE PYTHON_NUMPY_PROCESS
+                        OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIR
+                        OUTPUT_STRIP_TRAILING_WHITESPACE)
 
-      if(PYTHON_NUMPY_PROCESS EQUAL 0)
+        if(PYTHON_NUMPY_PROCESS EQUAL 0)
+          file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIR}" _PYTHON_NUMPY_INCLUDE_DIR)
+          set(PYTHON_NUMPY_INCLUDE_DIR ${_PYTHON_NUMPY_INCLUDE_DIR} CACHE PATH "Path to numpy headers")
+        endif()
+      endif()
+    else()
+      if(NOT PYTHON_NUMPY_INCLUDE_DIR)
+        message(STATUS "Cannot probe for Python/Numpy support (because we are cross-compiling OpenCV)")
+        message(STATUS "If you want to enable Python/Numpy support, set the following variables:")
+        message(STATUS "  PYTHON_EXECUTABLE")
+        message(STATUS "  PYTHON_INCLUDE_DIR")
+        message(STATUS "  PYTHON_LIBRARY")
+        message(STATUS "  PYTHON_NUMPY_INCLUDE_DIR")
+        message(STATUS "  PYTHON_NUMPY_VERSION")
+      else()
         file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIR}" _PYTHON_NUMPY_INCLUDE_DIR)
         set(PYTHON_NUMPY_INCLUDE_DIR ${_PYTHON_NUMPY_INCLUDE_DIR} CACHE PATH "Path to numpy headers")
       endif()
@@ -95,10 +110,16 @@ if(PYTHON_EXECUTABLE)
 
     if(PYTHON_NUMPY_INCLUDE_DIR)
       set(PYTHON_USE_NUMPY TRUE)
-      execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print numpy.version.version"
+      if(NOT CMAKE_CROSSCOMPILING)
+        execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print numpy.version.version"
                         RESULT_VARIABLE PYTHON_NUMPY_PROCESS
                         OUTPUT_VARIABLE PYTHON_NUMPY_VERSION
                         OUTPUT_STRIP_TRAILING_WHITESPACE)
+      else()
+        if(NOT PYTHON_NUMPY_VERSION)
+          set(PYTHON_NUMPY_VERSION "undefined - cannot be probed because of the cross-compilation")
+        endif()
+      endif()
     endif()
   endif(NOT ANDROID AND NOT IOS)