[Bf-blender-cvs] [a44f59a961a] tmp_libupdate_34: Blender build system changes for new shared libraries and modules on Linux/macOS

Brecht Van Lommel noreply at git.blender.org
Tue Aug 16 20:47:27 CEST 2022


Commit: a44f59a961af946cce128e51f7f8e6a749e309b8
Author: Brecht Van Lommel
Date:   Mon Aug 15 23:58:54 2022 +0200
Branches: tmp_libupdate_34
https://developer.blender.org/rBa44f59a961af946cce128e51f7f8e6a749e309b8

Blender build system changes for new shared libraries and modules on Linux/macOS

PLATFORM_BUNDLED_LIBRARY_DIRS is added to the rpath for the build steps so
no libraries have to be copied.

PLATFORM_BUNDLED_LIBRARIES are copied to the lib folder in the install step.
The Blender gets its rpath point to this lib older as part of the install
step. The Python executable already contains an rpath to the lib folder.

For site packages installation on Linux, just copy over the entire library
directory as we do for macOS to simplify things.

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

M	build_files/build_environment/cmake/check_software.cmake
M	build_files/cmake/Modules/FindOpenSubdiv.cmake
M	build_files/cmake/Modules/FindOpenVDB.cmake
M	build_files/cmake/Modules/FindPythonLibsUnix.cmake
M	build_files/cmake/Modules/FindTBB.cmake
M	build_files/cmake/Modules/FindUSD.cmake
M	build_files/cmake/platform/platform_apple.cmake
M	build_files/cmake/platform/platform_unix.cmake
M	intern/cycles/cmake/macros.cmake
M	source/blender/io/usd/CMakeLists.txt
M	source/creator/CMakeLists.txt

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

diff --git a/build_files/build_environment/cmake/check_software.cmake b/build_files/build_environment/cmake/check_software.cmake
index 080c1e52973..08820a234b7 100644
--- a/build_files/build_environment/cmake/check_software.cmake
+++ b/build_files/build_environment/cmake/check_software.cmake
@@ -12,6 +12,7 @@ if(UNIX)
     automake
     bison
     ${_libtoolize_name}
+    patchelf
     pkg-config
     tclsh
     yasm
@@ -54,7 +55,7 @@ if(UNIX)
       "  ${_software_missing}\n"
       "\n"
       "On Debian and Ubuntu:\n"
-      "  apt install autoconf automake libtool yasm tcl ninja-build meson python3-mako\n"
+      "  apt install autoconf automake libtool yasm tcl ninja-build meson python3-mako patchelf\n"
       "\n"
       "On macOS (with homebrew):\n"
       "  brew install autoconf automake bison flex libtool pkg-config yasm\n"
diff --git a/build_files/cmake/Modules/FindOpenSubdiv.cmake b/build_files/cmake/Modules/FindOpenSubdiv.cmake
index 37a2cddf3de..76daeccef1c 100644
--- a/build_files/cmake/Modules/FindOpenSubdiv.cmake
+++ b/build_files/cmake/Modules/FindOpenSubdiv.cmake
@@ -69,6 +69,7 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSubdiv DEFAULT_MSG
     _opensubdiv_LIBRARIES OPENSUBDIV_INCLUDE_DIR)
 
 IF(OPENSUBDIV_FOUND)
+  get_filename_component(OPENSUBDIV_LIBRARY_DIR ${OPENSUBDIV_OSDCPU_LIBRARY} DIRECTORY)
   SET(OPENSUBDIV_LIBRARIES ${_opensubdiv_LIBRARIES})
   SET(OPENSUBDIV_INCLUDE_DIRS ${OPENSUBDIV_INCLUDE_DIR})
 
@@ -90,6 +91,7 @@ ENDIF()
 
 MARK_AS_ADVANCED(
   OPENSUBDIV_INCLUDE_DIR
+  OPENSUBDIV_LIBRARY_DIR
 )
 FOREACH(COMPONENT ${_opensubdiv_FIND_COMPONENTS})
   STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
diff --git a/build_files/cmake/Modules/FindOpenVDB.cmake b/build_files/cmake/Modules/FindOpenVDB.cmake
index ed5c3778596..60f5316824f 100644
--- a/build_files/cmake/Modules/FindOpenVDB.cmake
+++ b/build_files/cmake/Modules/FindOpenVDB.cmake
@@ -49,12 +49,14 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenVDB DEFAULT_MSG
     OPENVDB_LIBRARY OPENVDB_INCLUDE_DIR)
 
 IF(OPENVDB_FOUND)
+  GET_FILENAME_COMPONENT(OPENVDB_LIBRARY_DIR ${OPENVDB_LIBRARY} DIRECTORY)
   SET(OPENVDB_LIBRARIES ${OPENVDB_LIBRARY})
   SET(OPENVDB_INCLUDE_DIRS ${OPENVDB_INCLUDE_DIR})
 ENDIF()
 
 MARK_AS_ADVANCED(
   OPENVDB_INCLUDE_DIR
+  OPENVDB_LIBRARY_DIR
   OPENVDB_LIBRARY
 )
 
diff --git a/build_files/cmake/Modules/FindPythonLibsUnix.cmake b/build_files/cmake/Modules/FindPythonLibsUnix.cmake
index 1e88621303f..64218942a77 100644
--- a/build_files/cmake/Modules/FindPythonLibsUnix.cmake
+++ b/build_files/cmake/Modules/FindPythonLibsUnix.cmake
@@ -13,6 +13,7 @@
 #
 # This module defines
 #  PYTHON_VERSION
+#  PYTHON_VERSION_NO_DOTS
 #  PYTHON_INCLUDE_DIRS
 #  PYTHON_INCLUDE_CONFIG_DIRS
 #  PYTHON_LIBRARIES
@@ -58,11 +59,11 @@ IF(DEFINED PYTHON_LIBPATH)
   SET(_IS_LIB_PATH_DEF ON)
 ENDIF()
 
-STRING(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
+STRING(REPLACE "." "" PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
 
 SET(_python_SEARCH_DIRS
   ${PYTHON_ROOT_DIR}
-  "$ENV{HOME}/py${_PYTHON_VERSION_NO_DOTS}"
+  "$ENV{HOME}/py${PYTHON_VERSION_NO_DOTS}"
   "/opt/lib/python-${PYTHON_VERSION}"
 )
 
@@ -205,7 +206,6 @@ IF(PYTHONLIBSUNIX_FOUND)
   )
 ENDIF()
 
-UNSET(_PYTHON_VERSION_NO_DOTS)
 UNSET(_PYTHON_ABI_FLAGS)
 UNSET(_python_SEARCH_DIRS)
 
diff --git a/build_files/cmake/Modules/FindTBB.cmake b/build_files/cmake/Modules/FindTBB.cmake
index ad7a1a218f8..3b0fe0900e9 100644
--- a/build_files/cmake/Modules/FindTBB.cmake
+++ b/build_files/cmake/Modules/FindTBB.cmake
@@ -49,6 +49,7 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(TBB DEFAULT_MSG
     TBB_LIBRARY TBB_INCLUDE_DIR)
 
 IF(TBB_FOUND)
+  GET_FILENAME_COMPONENT(TBB_LIBRARY_DIR ${TBB_LIBRARY} DIRECTORY)
   SET(TBB_LIBRARIES ${TBB_LIBRARY})
   SET(TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR})
 ELSE()
@@ -57,5 +58,6 @@ ENDIF()
 
 MARK_AS_ADVANCED(
   TBB_INCLUDE_DIR
+  TBB_LIBRARY_DIR
   TBB_LIBRARY
 )
diff --git a/build_files/cmake/Modules/FindUSD.cmake b/build_files/cmake/Modules/FindUSD.cmake
index 0fd5f06bb35..52d33f2b6ab 100644
--- a/build_files/cmake/Modules/FindUSD.cmake
+++ b/build_files/cmake/Modules/FindUSD.cmake
@@ -55,7 +55,7 @@ ELSE()
   FIND_PACKAGE_HANDLE_STANDARD_ARGS(USD DEFAULT_MSG USD_LIBRARY USD_INCLUDE_DIR)
 
   IF(USD_FOUND)
-    get_filename_component(USD_LIBRARY_DIR ${USD_LIBRARY} DIRECTORY)
+    GET_FILENAME_COMPONENT(USD_LIBRARY_DIR ${USD_LIBRARY} DIRECTORY)
     SET(USD_INCLUDE_DIRS ${USD_INCLUDE_DIR})
     set(USD_LIBRARIES ${USD_LIBRARY})
   ENDIF()
diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake
index 1eb3a8d33c7..63990eaacd5 100644
--- a/build_files/cmake/platform/platform_apple.cmake
+++ b/build_files/cmake/platform/platform_apple.cmake
@@ -21,6 +21,18 @@ function(print_found_status
   endif()
 endfunction()
 
+# Utility to install shared libraries.
+macro(add_bundled_libraries library)
+  if(EXISTS ${LIBDIR})
+    set(_library_dir ${LIBDIR}/${library})
+    file(GLOB _all_library_versions ${_library_dir}/lib/*\.dylib*)
+    list(APPEND PLATFORM_BUNDLED_LIBRARIES ${_all_library_versions})
+    list(APPEND PLATFORM_BUNDLED_LIBRARY_DIRS ${_library_dir})
+    unset(_all_library_versions)
+    unset(_library_dir)
+ endif()
+endmacro()
+
 # ------------------------------------------------------------------------
 # Find system provided libraries.
 
@@ -81,7 +93,9 @@ endif()
 
 if(WITH_USD)
   find_package(USD)
-  if(NOT USD_FOUND)
+  if(USD_FOUND)
+    add_bundled_libraries(usd)
+  else()
     message(STATUS "USD not found, disabling WITH_USD")
     set(WITH_USD OFF)
   endif()
@@ -89,6 +103,7 @@ endif()
 
 if(WITH_OPENSUBDIV)
   find_package(OpenSubdiv)
+  add_bundled_libraries(opensubdiv)
 endif()
 
 if(WITH_CODEC_SNDFILE)
@@ -114,6 +129,7 @@ endif()
 if(WITH_PYTHON)
   # Use precompiled libraries by default.
   set(PYTHON_VERSION 3.10)
+  set(PYTHON_VERSION_NO_DOTS 310)
   if(NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
     # Normally cached but not since we include them with blender.
     set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")
@@ -258,11 +274,8 @@ if(WITH_BOOST)
   if(WITH_INTERNATIONAL)
     list(APPEND _boost_FIND_COMPONENTS locale)
   endif()
-  if(WITH_OPENVDB)
-    list(APPEND _boost_FIND_COMPONENTS iostreams)
-  endif()
   if(WITH_USD)
-    list(APPEND _boost_FIND_COMPONENTS python310)
+    list(APPEND _boost_FIND_COMPONENTS python${PYTHON_VERSION_NO_DOTS})
   endif()
   find_package(Boost COMPONENTS ${_boost_FIND_COMPONENTS})
 
@@ -270,6 +283,8 @@ if(WITH_BOOST)
   set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
   set(BOOST_DEFINITIONS)
 
+  add_bundled_libraries(boost)
+
   mark_as_advanced(Boost_LIBRARIES)
   mark_as_advanced(Boost_INCLUDE_DIRS)
   unset(_boost_FIND_COMPONENTS)
@@ -313,6 +328,7 @@ endif()
 if(WITH_OPENVDB)
   find_package(OpenVDB)
   set(OPENVDB_DEFINITIONS)
+  add_bundled_libraries(openvdb)
 endif()
 
 if(WITH_NANOVDB)
@@ -386,7 +402,9 @@ endif()
 
 if(WITH_TBB)
   find_package(TBB)
-  if(NOT TBB_FOUND)
+  if(TBB_FOUND)
+    add_bundled_libraries(tbb)
+  else()
     message(WARNING "TBB not found, disabling WITH_TBB")
     set(WITH_TBB OFF)
   endif()
@@ -412,6 +430,7 @@ if(WITH_OPENMP)
     set(OpenMP_LIBRARY_DIR "${LIBDIR}/openmp/lib/")
     set(OpenMP_LINKER_FLAGS "-L'${OpenMP_LIBRARY_DIR}' -lomp")
     set(OpenMP_LIBRARY "${OpenMP_LIBRARY_DIR}/libomp.dylib")
+    add_bundled_libraries(openmp)
   endif()
 endif()
 
@@ -501,21 +520,14 @@ if(WITH_COMPILER_CCACHE)
   endif()
 endif()
 
-# For binaries that are built but not installed (also not distributed) (datatoc,
-# makesdna, tests, etc.), we add an rpath to the OpenMP library dir through
-# CMAKE_BUILD_RPATH. This avoids having to make many copies of the dylib next to each binary.
-#
-# For the installed Python module and installed Blender executable, CMAKE_INSTALL_RPATH
-# is modified to find the dylib in an adjacent folder. Install step puts the libraries there.
+# For binaries that are built but not installed (like makesdan or tests), we add
+# the original directory of all shared libraries to the rpath. This avoids having
+# to install them as part of the build step.
 set(CMAKE_SKIP_BUILD_RPATH FALSE)
-list(APPEND CMAKE_BUILD_RPATH "${OpenMP_LIBRARY_DIR}")
-if(WITH_TBB)
-  list(APPEND CMAKE_BUILD_RPATH "${TBB_LIBRARY_DIR}")
-endif()
-if(WITH_USD)
-  list(APPEND CMAKE_BUILD_RPATH "${USD_LIBRARY_DIR}")
-endif()
+list(APPEND CMAKE_BUILD_RPATH ${PLATFORM_BUNDLED_LIBRARY_DIRS})
 
+# For the installed Python module and installed Blender executable, we set the
+# rpath to the location where install step will copy the shared libraries.
 set(CMAKE_SKIP_INSTALL_RPATH FALSE)
 list(APPEND CMAKE_INSTALL_RPATH "@loader_path/../Resources/${BLENDER_VERSION}/lib")
 
diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake
index 9b992cfbabf..97c2663ecbd 100644
--- a/build_files/cmake/platform/platform_unix.cmake
+++ b/build_files/cmake/platform/platform_unix.cmake
@@ -81,6 +81,19 @@ macro(find_package_wrapper)
   endif()
 endmacro()
 
+# Utility to install shared libraries, all that exist in the precompiled
+# library folder will be copied.
+macro(add_bundled_libraries library)
+  if(EXISTS ${LIBDIR})
+    set(_library_dir ${LIBDIR}/${library})
+    file(GLOB _all_library_versions ${_library_dir}/lib/*\.so*)
+    list(APPEND PLATFORM_BUNDLED_LIBRARIES ${_all_library_versions})
+    list(APPEND PLATFORM_BUNDLED_LIBRARY_DIRS ${_library_dir})
+    unset(_all_library_versions)
+    unset(_library_dir)
+ endif()
+endmacro()
+
 # ----------------------------------------------------------------------------
 # Precompiled Libraries
 #
@@ -306,18 +319,22 @@ if(WITH_CYCLES_DEVICE_ONEAPI)
 endif()
 
 if(WITH_OPENVDB)
-  find_package_wrapper(OpenVDB)
+  find_package(OpenVDB)
 
-  if(NOT OPENVDB_FOUND)
+  if(OPENVDB_FOUND)
+    add_bundled_libraries(openvdb)
+
+    if(NOT EXISTS ${LIBDIR})
+      find_package_wrapper(Blosc)
+      if(NOT BLOSC_FOUND)
+        set(WITH_OPENVDB_BLOSC OFF)
+        message(STATUS "Blosc not found, disabling it for OpenVBD")
+      endif()
+    endif()
+  else()
     set(WITH_OPENVDB OFF)
     set(WITH_OPENVDB_BLOSC OFF)
     message(STATUS "OpenVDB not found

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list