[Bf-blender-cvs] [bf21a78103a] tmp_libupdate_34: More rpath changes for Linux

Brecht Van Lommel noreply at git.blender.org
Wed Aug 17 15:36:30 CEST 2022


Commit: bf21a78103a176ca46eb53ef7dd23483c9f19929
Author: Brecht Van Lommel
Date:   Wed Aug 17 14:21:54 2022 +0200
Branches: tmp_libupdate_34
https://developer.blender.org/rBbf21a78103a176ca46eb53ef7dd23483c9f19929

More rpath changes for Linux

* Change rpath of Python modules instead of Python executable, to solve issues
  with indirect dependency loading on Linux.
* Simplify build step rpath on Linux, only need absolute path to lib install dir.

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

M	build_files/build_environment/cmake/harvest.cmake
M	build_files/cmake/platform/platform_apple.cmake
M	build_files/cmake/platform/platform_unix.cmake

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

diff --git a/build_files/build_environment/cmake/harvest.cmake b/build_files/build_environment/cmake/harvest.cmake
index 4dac94b61a5..0a13a023851 100644
--- a/build_files/build_environment/cmake/harvest.cmake
+++ b/build_files/build_environment/cmake/harvest.cmake
@@ -60,6 +60,26 @@ function(harvest from to)
   endif()
 endfunction()
 
+# Set rpath on Python module to point to the shared libraries folder in the
+# Blender installation. Ideally this would be done as part of the Blender build
+# since it makes assumptions about where the files will be installed. However it
+# would add patchelf as a new dependency for building.
+function(harvest_with_rpath from to pattern)
+  harvest(${from} ${to} ${pattern})
+
+  install(CODE "\
+    file(GLOB_RECURSE shared_libs ${HARVEST_TARGET}/${to}/${pattern}\.so) \n
+    foreach(f \${shared_libs}) \n
+      get_filename_component(f_dir \${f} DIRECTORY) \n
+      file(RELATIVE_PATH relative_dir \${f_dir} ${HARVEST_TARGET}) \n
+      if(APPLE) \n
+        execute_process(COMMAND install_name_tool -add_rpath @loader_path/\${relative_dir}lib \${f}) \n
+      else() \n
+        execute_process(COMMAND patchelf --set-rpath $ORIGIN/\${relative_dir}../lib \${f}) \n
+      endif() \n
+    endforeach()")
+endfunction()
+
 harvest(alembic/include alembic/include "*.h")
 harvest(alembic/lib/libAlembic.a alembic/lib/libAlembic.a)
 harvest(alembic/bin alembic/bin "*")
@@ -148,7 +168,7 @@ harvest(opensubdiv/lib opensubdiv/lib "*${SHAREDLIBEXT}*")
 harvest(openvdb/include/openvdb openvdb/include/openvdb "*.h")
 harvest(openvdb/include/nanovdb openvdb/include/nanovdb "*.h")
 harvest(openvdb/lib openvdb/lib "*${SHAREDLIBEXT}*")
-harvest(openvdb/lib/python${PYTHON_SHORT_VERSION} python/lib/python${PYTHON_SHORT_VERSION} "*")
+harvest_with_rpath(openvdb/lib/python${PYTHON_SHORT_VERSION} python/lib/python${PYTHON_SHORT_VERSION} "*pyopenvdb*")
 harvest(xr_openxr_sdk/include/openxr xr_openxr_sdk/include/openxr "*.h")
 harvest(xr_openxr_sdk/lib xr_openxr_sdk/lib "*.a")
 harvest(osl/bin osl/bin "oslc")
@@ -184,7 +204,7 @@ harvest(webp/include webp/include "*.h")
 harvest(usd/include usd/include "*.h")
 harvest(usd/lib/libusd_usd_ms${SHAREDLIBEXT} usd/lib/libusd_usd_ms${SHAREDLIBEXT})
 harvest(usd/lib/usd usd/lib/usd "*")
-harvest(usd/lib/python/pxr python/lib/python${PYTHON_SHORT_VERSION}/site-packages/pxr "*")
+harvest_with_rpath(usd/lib/python/pxr python/lib/python${PYTHON_SHORT_VERSION}/site-packages/pxr "*")
 harvest(usd/plugin usd/plugin "*")
 harvest(potrace/include potrace/include "*.h")
 harvest(potrace/lib potrace/lib "*.a")
@@ -201,19 +221,4 @@ if(UNIX AND NOT APPLE)
   harvest(igc dpcpp/lib/igc "*")
   harvest(ocloc dpcpp/lib/ocloc "*")
 endif()
-
-# Set rpath so Python standalone executable can find shared libraries shipped
-# with Blender. This makes assumptions about the directory layout of Blender
-# installation and would ideally be done as part of the Blender build. However
-# it would add patchelf as a new dependency required to build.
-set(_python_executable_install_path ${HARVEST_TARGET}/python/bin/python${PYTHON_SHORT_VERSION})
-message(STATUS ${_python_executable_install_path})
-if(APPLE)
-  install(
-    CODE "execute_process(COMMAND install_name_tool -add_rpath @loader_path/../../lib ${_python_executable_install_path})")
-else()
-  install(
-    CODE "execute_process(COMMAND patchelf --set-rpath $ORIGIN/../../../lib ${_python_executable_install_path})")
-endif()
-
 endif()
diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake
index eae39b2580b..0d5b0625f86 100644
--- a/build_files/cmake/platform/platform_apple.cmake
+++ b/build_files/cmake/platform/platform_apple.cmake
@@ -520,16 +520,17 @@ if(WITH_COMPILER_CCACHE)
   endif()
 endif()
 
-# 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 ${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")
 
+# 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 is needed because
+# these can be in different folders, and because the build and install folder may be
+# different.
+set(CMAKE_SKIP_BUILD_RPATH FALSE)
+list(APPEND CMAKE_BUILD_RPATH ${PLATFORM_BUNDLED_LIBRARY_DIRS})
+
 # Same as `CFBundleIdentifier` in Info.plist.
 set(CMAKE_XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "org.blenderfoundation.blender")
diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake
index e404a3b105e..9404d0f7148 100644
--- a/build_files/cmake/platform/platform_unix.cmake
+++ b/build_files/cmake/platform/platform_unix.cmake
@@ -80,12 +80,9 @@ endmacro()
 # Utility to install precompiled shared libraries.
 macro(add_bundled_libraries library)
   if(EXISTS ${LIBDIR})
-    set(_library_dir ${LIBDIR}/${library}/lib)
-    file(GLOB _all_library_versions ${_library_dir}/*\.so*)
+    file(GLOB _all_library_versions ${LIBDIR}/${library}/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()
 
@@ -992,18 +989,13 @@ endfunction()
 
 CONFIGURE_ATOMIC_LIB_IF_NEEDED()
 
-# 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.
-#
-# This trick however does not work for executables like blender_test that uses
-# USD and openvdb which have indirect dependencies. For these cases also add the
-# absolute path to where libs will be installed, since they only need to work
-# after the install step.
-set(CMAKE_SKIP_BUILD_RPATH FALSE)
-list(APPEND CMAKE_BUILD_RPATH $ORIGIN/lib ${CMAKE_INSTALL_PREFIX_WITH_CONFIG}/lib ${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.
+# rpath to the relative path where the install step will copy the shared libraries.
 set(CMAKE_SKIP_INSTALL_RPATH FALSE)
 list(APPEND CMAKE_INSTALL_RPATH $ORIGIN/lib)
+
+# For executables that are built but not installed (mainly tests) we set an absolute
+# rpath to the lib folder. This is needed because these can be in different folders,
+# and because the build and install folder may be different.
+set(CMAKE_SKIP_BUILD_RPATH FALSE)
+list(APPEND CMAKE_BUILD_RPATH $ORIGIN/lib ${CMAKE_INSTALL_PREFIX_WITH_CONFIG}/lib)



More information about the Bf-blender-cvs mailing list