[Bf-blender-cvs] [010f44b855c] master: Fix several issues with handling of numpy in CMake.

Bastien Montagne noreply at git.blender.org
Mon Dec 14 16:47:20 CET 2020


Commit: 010f44b855cab664126975543e0e760576202d85
Author: Bastien Montagne
Date:   Mon Dec 14 16:40:00 2020 +0100
Branches: master
https://developer.blender.org/rB010f44b855cab664126975543e0e760576202d85

Fix several issues with handling of numpy in CMake.

Issues were:
* Abusing of `WITH_PYTHON_INSTALL_NUMPY` by both Audaspace and
  Mantaflow.
    - `PYTHON_INSTALL` options only decide whether we copy python (and
      some extra modules) in our Blender installation. On linux it
      makes much more sense to use global python installation.
    - Now we have instead a proper `WITH_PYTHON_NUMPY`
* Bad assumptions regarding path of headers relative to path of python
  module.
    - In current Debian testing, modules are under `python3.9`
      directory, while headers are under `python3` directory.
    - Now we properly `find_path` for headers as well, modifying
      `find_python_package` to take an optional argument for headers.

Note that the required changes done to `extern` libraries are in
blender-specific files that do not exist upstream.

Differential Revision: https://developer.blender.org/D9773

===================================================================

M	CMakeLists.txt
M	build_files/cmake/macros.cmake
M	extern/audaspace/blender_config.cmake
M	extern/mantaflow/CMakeLists.txt

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0d7cf4e325c..c8ae562f6ad 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -347,16 +347,21 @@ if(UNIX AND NOT APPLE)
 endif()
 
 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
+
+if((WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE) OR WITH_MOD_FLUID)
+  option(WITH_PYTHON_NUMPY "Include NumPy in Blender (used by Audaspace and Mantaflow)"  ON)
+endif()
+
 if(WIN32 OR APPLE)
   # Windows and macOS have this bundled with Python libraries.
-elseif(WITH_PYTHON_INSTALL OR (WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE))
+elseif(WITH_PYTHON_INSTALL OR WITH_PYTHON_NUMPY)
   set(PYTHON_NUMPY_PATH            "" CACHE PATH "Path to python site-packages or dist-packages containing 'numpy' module")
   mark_as_advanced(PYTHON_NUMPY_PATH)
-  set(PYTHON_NUMPY_INCLUDE_DIRS ${PYTHON_NUMPY_PATH}/numpy/core/include CACHE PATH "Path to the include directory of the numpy module")
+  set(PYTHON_NUMPY_INCLUDE_DIRS    "" CACHE PATH "Path to the include directory of the NumPy module")
   mark_as_advanced(PYTHON_NUMPY_INCLUDE_DIRS)
 endif()
 if(WITH_PYTHON_INSTALL)
-  option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
+  option(WITH_PYTHON_INSTALL_NUMPY "Copy system NumPy into the blender install folder"  ON)
 
   if(UNIX AND NOT APPLE)
     option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
@@ -1621,19 +1626,16 @@ if(WITH_PYTHON)
 
   if(WIN32 OR APPLE)
     # Windows and macOS have this bundled with Python libraries.
-  elseif((WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY) OR (WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE))
+  elseif((WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY) OR WITH_PYTHON_NUMPY)
     if(("${PYTHON_NUMPY_PATH}" STREQUAL "") OR (${PYTHON_NUMPY_PATH} MATCHES NOTFOUND))
-      find_python_package(numpy)
-      unset(PYTHON_NUMPY_INCLUDE_DIRS CACHE)
-      set(PYTHON_NUMPY_INCLUDE_DIRS ${PYTHON_NUMPY_PATH}/numpy/core/include CACHE PATH "Path to the include directory of the numpy module")
-      mark_as_advanced(PYTHON_NUMPY_INCLUDE_DIRS)
+      find_python_package(numpy "core/include")
     endif()
   endif()
 
   if(WIN32 OR APPLE)
     # pass, we have this in lib/python/site-packages
   elseif(WITH_PYTHON_INSTALL_REQUESTS)
-    find_python_package(requests)
+    find_python_package(requests "")
   endif()
 endif()
 
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 202b44f611c..9febeaa6889 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -1139,6 +1139,7 @@ endfunction()
 
 function(find_python_package
   package
+  relative_include_dir
   )
 
   string(TOUPPER ${package} _upper_package)
@@ -1170,7 +1171,10 @@ function(find_python_package
         dist-packages
         vendor-packages
        NO_DEFAULT_PATH
+       DOC
+         "Path to python site-packages or dist-packages containing '${package}' module"
     )
+    mark_as_advanced(PYTHON_${_upper_package}_PATH)
 
     if(NOT EXISTS "${PYTHON_${_upper_package}_PATH}")
       message(WARNING
@@ -1188,6 +1192,50 @@ function(find_python_package
       set(WITH_PYTHON_INSTALL_${_upper_package} OFF PARENT_SCOPE)
     else()
       message(STATUS "${package} found at '${PYTHON_${_upper_package}_PATH}'")
+      
+      if(NOT "${relative_include_dir}" STREQUAL "")
+        set(_relative_include_dir "${package}/${relative_include_dir}")
+        unset(PYTHON_${_upper_package}_INCLUDE_DIRS CACHE)
+        find_path(PYTHON_${_upper_package}_INCLUDE_DIRS
+          NAMES
+            "${_relative_include_dir}"
+          HINTS
+            "${PYTHON_LIBPATH}/"
+            "${PYTHON_LIBPATH}/python${PYTHON_VERSION}/"
+            "${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/"
+          PATH_SUFFIXES
+            "site-packages/"
+            "dist-packages/"
+            "vendor-packages/"
+          NO_DEFAULT_PATH
+          DOC
+            "Path to python site-packages or dist-packages containing '${package}' module header files"
+        )
+        mark_as_advanced(PYTHON_${_upper_package}_INCLUDE_DIRS)
+
+        if(NOT EXISTS "${PYTHON_${_upper_package}_INCLUDE_DIRS}")
+          message(WARNING
+            "Python package '${package}' include dir path could not be found in:\n"
+            "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/${_relative_include_dir}', "
+            "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/site-packages/${_relative_include_dir}', "
+            "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/${_relative_include_dir}', "
+            "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/${_relative_include_dir}', "
+            "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/vendor-packages/${_relative_include_dir}', "
+            "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/vendor-packages/${_relative_include_dir}', "
+            "\n"
+            "The 'WITH_PYTHON_${_upper_package}' option will be disabled.\n"
+            "The build will be usable, only add-ons that depend on this package won't be functional."
+          )
+          set(WITH_PYTHON_${_upper_package} OFF PARENT_SCOPE)
+        else()
+          set(_temp "${PYTHON_${_upper_package}_INCLUDE_DIRS}/${package}/${relative_include_dir}")
+          unset(PYTHON_${_upper_package}_INCLUDE_DIRS CACHE)
+          set(PYTHON_${_upper_package}_INCLUDE_DIRS "${_temp}"
+              CACHE PATH "Path to the include directory of the ${package} module")
+
+          message(STATUS "${package} include files found at '${PYTHON_${_upper_package}_INCLUDE_DIRS}'")
+        endif()
+      endif()
     endif()
   endif()
 endfunction()
diff --git a/extern/audaspace/blender_config.cmake b/extern/audaspace/blender_config.cmake
index 1f8f85b9868..12810e2b044 100644
--- a/extern/audaspace/blender_config.cmake
+++ b/extern/audaspace/blender_config.cmake
@@ -24,6 +24,6 @@ set(JACK_FOUND ${WITH_JACK})
 set(LIBSNDFILE_FOUND ${WITH_CODEC_SNDFILE})
 set(OPENAL_FOUND ${WITH_OPENAL})
 set(PYTHONLIBS_FOUND TRUE)
-set(NUMPY_FOUND TRUE)
+set(NUMPY_FOUND ${WITH_PYTHON_NUMPY})
 set(NUMPY_INCLUDE_DIRS ${PYTHON_NUMPY_INCLUDE_DIRS})
 set(SDL_FOUND ${WITH_SDL})
diff --git a/extern/mantaflow/CMakeLists.txt b/extern/mantaflow/CMakeLists.txt
index ee155ee8636..ccf272650e3 100644
--- a/extern/mantaflow/CMakeLists.txt
+++ b/extern/mantaflow/CMakeLists.txt
@@ -85,7 +85,7 @@ if(WIN32)
   add_definitions(-D_USE_MATH_DEFINES)
 endif()
 
-if(WITH_MANTA_NUMPY AND WITH_PYTHON_INSTALL_NUMPY)
+if(WITH_MANTA_NUMPY AND WITH_PYTHON_NUMPY)
   add_definitions(-DNUMPY=1)
 endif()
 
@@ -109,7 +109,7 @@ set(INC_SYS
   ${ZLIB_INCLUDE_DIRS}
 )
 
-if(WITH_MANTA_NUMPY AND WITH_PYTHON_INSTALL_NUMPY)
+if(WITH_MANTA_NUMPY AND WITH_PYTHON_NUMPY)
   list(APPEND INC_SYS
     ${PYTHON_NUMPY_INCLUDE_DIRS}
   )
@@ -255,8 +255,7 @@ if(WITH_MANTA_DEPENDENCIES)
     ${MANTA_DEP}/cnpy/cnpy.h
   )
 endif()
-
-if(WITH_MANTA_NUMPY AND WITH_PYTHON_INSTALL_NUMPY)
+if(WITH_MANTA_NUMPY AND WITH_PYTHON_NUMPY)
   list(APPEND SRC
     ${MANTA_PP}/plugin/numpyconvert.cpp
     ${MANTA_PP}/plugin/tfplugins.cpp



More information about the Bf-blender-cvs mailing list