[Bf-blender-cvs] [659bcb3b102] tmp_libupdate_34: Set rpaths for all libraries in harvest step

Brecht Van Lommel noreply at git.blender.org
Wed Aug 24 20:22:21 CEST 2022


Commit: 659bcb3b1023c30e2ce5daa0836f71f52f67c9e6
Author: Brecht Van Lommel
Date:   Wed Aug 24 16:12:33 2022 +0200
Branches: tmp_libupdate_34
https://developer.blender.org/rB659bcb3b1023c30e2ce5daa0836f71f52f67c9e6

Set rpaths for all libraries in harvest step

Each library has different logic here. Instead of trying to patch code or
find the right build options for each, set rpath ourselves.

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

M	build_files/build_environment/cmake/harvest.cmake
M	build_files/build_environment/cmake/opensubdiv.cmake
M	build_files/build_environment/cmake/openvdb.cmake
M	build_files/build_environment/cmake/usd.cmake
A	build_files/build_environment/darwin/set_rpath.py
M	build_files/build_environment/patches/usd.diff

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

diff --git a/build_files/build_environment/cmake/harvest.cmake b/build_files/build_environment/cmake/harvest.cmake
index 99bc0e6661e..845ddab9ce9 100644
--- a/build_files/build_environment/cmake/harvest.cmake
+++ b/build_files/build_environment/cmake/harvest.cmake
@@ -57,23 +57,53 @@ 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)
+# Set rpath on shared libraries to $ORIGIN since all will be installed in the same
+# lib folder, and remove any absolute paths.
+#
+# 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.
+if(APPLE)
+  set(set_rpath_cmd python3 ${CMAKE_CURRENT_SOURCE_DIR}/darwin/set_rpath.py @loader_path)
+else()
+  set(set_rpath_cmd patchelf --set-rpath $ORIGIN)
+endif()
+
+function(harvest_rpath_lib from to pattern)
+  harvest(${from} ${to} ${pattern})
+
+  install(CODE "\
+    cmake_policy(SET CMP0009 NEW)\n
+    file(GLOB_RECURSE shared_libs ${HARVEST_TARGET}/${to}/${pattern}) \n
+    foreach(f \${shared_libs}) \n
+      if(NOT IS_SYMLINK \${f})\n
+        execute_process(COMMAND ${set_rpath_cmd} \${f}) \n
+      endif()\n
+    endforeach()")
+endfunction()
+
+# Set rpath on utility binaries assuming they are run from their install location.
+function(harvest_rpath_bin from to pattern)
+  harvest(${from} ${to} ${pattern})
+
+  install(CODE "\
+    file(GLOB_RECURSE shared_libs ${HARVEST_TARGET}/${to}/${pattern}) \n
+    foreach(f \${shared_libs}) \n
+      execute_process(COMMAND ${set_rpath_cmd}/../lib; \${f}) \n
+    endforeach()")
+endfunction()
+
+# Set rpath on Python module to point to the shared libraries folder in the Blender
+# installation.
+function(harvest_rpath_python from to pattern)
   harvest(${from} ${to} ${pattern})
 
   install(CODE "\
-    file(GLOB_RECURSE shared_libs ${HARVEST_TARGET}/${to}/${pattern}\.so) \n
+    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
+      execute_process(COMMAND ${set_rpath_cmd}/\${relative_dir}../lib \${f}) \n
     endforeach()")
 endfunction()
 
@@ -83,7 +113,7 @@ harvest(alembic/bin alembic/bin "*")
 harvest(brotli/include brotli/include "*.h")
 harvest(brotli/lib brotli/lib "*.a")
 harvest(boost/include boost/include "*")
-harvest(boost/lib boost/lib "*${SHAREDLIBEXT}*")
+harvest_rpath_lib(boost/lib boost/lib "*${SHAREDLIBEXT}*")
 harvest(imath/include imath/include "*.h")
 harvest(imath/lib imath/lib "*.a")
 harvest(ffmpeg/include ffmpeg/include "*.h")
@@ -161,11 +191,11 @@ harvest(embree/lib embree/lib "*.a")
 harvest(openjpeg/include/openjpeg-${OPENJPEG_SHORT_VERSION} openjpeg/include "*.h")
 harvest(openjpeg/lib openjpeg/lib "*.a")
 harvest(opensubdiv/include opensubdiv/include "*.h")
-harvest(opensubdiv/lib opensubdiv/lib "*${SHAREDLIBEXT}*")
+harvest_rpath_lib(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_with_rpath(openvdb/lib/python${PYTHON_SHORT_VERSION} python/lib/python${PYTHON_SHORT_VERSION} "*pyopenvdb*")
+harvest_rpath_lib(openvdb/lib openvdb/lib "*${SHAREDLIBEXT}*")
+harvest_rpath_python(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")
@@ -186,7 +216,7 @@ harvest(sndfile/lib sndfile/lib "*.a")
 harvest(spnav/include spnav/include "*.h")
 harvest(spnav/lib spnav/lib "*.a")
 harvest(tbb/include tbb/include "*.h")
-harvest(tbb/lib/libtbb${SHAREDLIBEXT} tbb/lib/libtbb${SHAREDLIBEXT})
+harvest_rpath_lib(tbb/lib tbb/lib "libtbb${SHAREDLIBEXT}")
 harvest(theora/lib ffmpeg/lib "*.a")
 harvest(tiff/include tiff/include "*.h")
 harvest(tiff/lib tiff/lib "*.a")
@@ -199,9 +229,9 @@ harvest(aom/lib ffmpeg/lib "*.a")
 harvest(webp/lib webp/lib "*.a")
 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_rpath_lib(usd/lib usd/lib "libusd_usd_ms${SHAREDLIBEXT}")
 harvest(usd/lib/usd usd/lib/usd "*")
-harvest_with_rpath(usd/lib/python/pxr python/lib/python${PYTHON_SHORT_VERSION}/site-packages/pxr "*")
+harvest_rpath_python(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")
diff --git a/build_files/build_environment/cmake/opensubdiv.cmake b/build_files/build_environment/cmake/opensubdiv.cmake
index a42c7b4f4d4..4f643868bfb 100644
--- a/build_files/build_environment/cmake/opensubdiv.cmake
+++ b/build_files/build_environment/cmake/opensubdiv.cmake
@@ -34,15 +34,6 @@ else()
     -DTBB_INCLUDE_DIR=${LIBDIR}/tbb/include
     -DTBB_tbb_LIBRARY=${LIBDIR}/tbb/lib/${LIBPREFIX}tbb${SHAREDLIBEXT}
   )
-  if(APPLE)
-    set(OPENSUBDIV_EXTRA_ARGS
-      ${OPENSUBDIV_EXTRA_ARGS}
-      # Ensure opensubdiv library itself will be referenced with @rpath.
-      -DCMAKE_MACOSX_RPATH=ON
-      # Avoid adding absolute LC_RPATH.
-      -DCMAKE_SKIP_RPATH=ON
-    )
-  endif()
 endif()
 
 ExternalProject_Add(external_opensubdiv
diff --git a/build_files/build_environment/cmake/openvdb.cmake b/build_files/build_environment/cmake/openvdb.cmake
index 9939b5943c0..bd008287f75 100644
--- a/build_files/build_environment/cmake/openvdb.cmake
+++ b/build_files/build_environment/cmake/openvdb.cmake
@@ -35,7 +35,6 @@ set(OPENVDB_EXTRA_ARGS
   -DOPENVDB_PYTHON_WRAP_ALL_GRID_TYPES=ON
   -DUSE_NUMPY=ON
   -DPython_EXECUTABLE=${PYTHON_BINARY}
-  -DOPENVDB_ENABLE_RPATH=OFF
 
   # OPENVDB_AX Disabled for now as it adds ~25MB distribution wise
   # with no blender code depending on it, seems wasteful.
@@ -45,15 +44,6 @@ set(OPENVDB_EXTRA_ARGS
   # -DLLVM_DIR=${LIBDIR}/llvm/lib/cmake/llvm
 )
 
-if(UNIX AND NOT APPLE)
-  # OpenVDB sets absolute rpaths, so disable OPENVDB_ENABLE_RPATH and add our
-  # own relocatable rpath.
-  set(OPENVDB_EXTRA_ARGS
-    ${OPENVDB_EXTRA_ARGS}
-    -DCMAKE_INSTALL_RPATH=\$ORIGIN
-  )
-endif()
-
 ExternalProject_Add(openvdb
   URL file://${PACKAGE_DIR}/${OPENVDB_FILE}
   DOWNLOAD_DIR ${DOWNLOAD_DIR}
diff --git a/build_files/build_environment/cmake/usd.cmake b/build_files/build_environment/cmake/usd.cmake
index 60d5a392358..207a1f9911a 100644
--- a/build_files/build_environment/cmake/usd.cmake
+++ b/build_files/build_environment/cmake/usd.cmake
@@ -22,27 +22,15 @@ if(WIN32)
     list(APPEND USD_PLATFORM_FLAGS -DPXR_USE_DEBUG_PYTHON=ON)
     list(APPEND USD_PLATFORM_FLAGS -DOPENVDB_LIBRARY=${libdir}/openvdb/lib/openvdb_d.lib)
   endif()
-elseif(APPLE)
+elseif(UNIX)
   # Workaround USD not linking correctly with static Python library, where it would embed
   # part of the interpret in the USD library. Allow undefined Python symbols and replace
   # Python library with TBB so it doesn't complain about missing library.
   set(USD_SHARED_LINKER_FLAGS "-Xlinker -undefined -Xlinker dynamic_lookup")
   set(USD_PLATFORM_FLAGS
-    ${USD_PLATFORM_FLAGS}
     -DPYTHON_INCLUDE_DIR=${LIBDIR}/python/include/python${PYTHON_SHORT_VERSION}/
     -DPYTHON_LIBRARY=${LIBDIR}/tbb/lib/${LIBPREFIX}${TBB_LIBRARY}${SHAREDLIBEXT}
-    -DCMAKE_SHARED_LINKER_FLAGS=${USD_SHARED_LINKER_FLAGS}
-    # Avoid adding absolute LC_RPATH, macOS adds relative by default.
-    -DCMAKE_SKIP_RPATH=ON
    )
-else()
-  set(USD_PLATFORM_FLAGS
-    -DPYTHON_INCLUDE_DIR=${LIBDIR}/python/include/python${PYTHON_SHORT_VERSION}/
-    -DPYTHON_LIBRARY=${LIBDIR}/tbb/lib/${LIBPREFIX}${TBB_LIBRARY}${SHAREDLIBEXT}
-    # Set relocatable rpath.
-    -DCMAKE_INSTALL_RPATH=\$ORIGIN
-    -DCMAKE_SKIP_RPATH=OFF
-  )
 endif()
 
 set(USD_EXTRA_ARGS
diff --git a/build_files/build_environment/darwin/set_rpath.py b/build_files/build_environment/darwin/set_rpath.py
new file mode 100644
index 00000000000..190e619a5ba
--- /dev/null
+++ b/build_files/build_environment/darwin/set_rpath.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python3
+# macOS utility to remove all rpaths and add a new one.
+
+import subprocess
+import sys
+
+rpath = sys.argv[1]
+file = sys.argv[2]
+
+# Find existing rpaths and delete them one by one.
+p = subprocess.run(['otool', '-l', file], capture_output=True)
+tokens = p.stdout.split()
+
+for i, token in enumerate(tokens):
+    if token == b'LC_RPATH':
+        old_rpath = tokens[i + 4]
+        subprocess.run(['install_name_tool', '-delete_rpath', old_rpath, file])
+
+subprocess.run(['install_name_tool', '-add_rpath', rpath, file])
diff --git a/build_files/build_environment/patches/usd.diff b/build_files/build_environment/patches/usd.diff
index 2965edc4482..f627d2726ab 100644
--- a/build_files/build_environment/patches/usd.diff
+++ b/build_files/build_environment/patches/usd.diff
@@ -1,18 +1,3 @@
---- a/cmake/macros/Private.cmake	2022-08-16 20:19:10.458300059 +0200
-+++ b/cmake/macros/Private.cmake	2022-08-16 20:19:22.930536130 +0200
-@@ -632,12 +632,6 @@
-             list(APPEND final "${path}")
-         endif()
-     endforeach()
--
--    set_target_properties(${NAME}
--        PROPERTIES
--            INSTALL_RPATH_USE_LINK_PATH TRUE
--            INSTALL_RPATH "${final}"
--    )
- endfunction()
- 
- # Split the library (target) names in libs into internal-t

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list