Fix rpath for private libraries on Linux
authorBenjamin Drung <benjamin.drung@canonical.com>
Thu, 22 Sep 2022 17:52:43 +0000 (19:52 +0200)
committerDennis Braun <snd@debian.org>
Mon, 17 Mar 2025 21:54:47 +0000 (22:54 +0100)
Installing audacity on Linux will produce private libraries that have
`RUNPATH` set to the build directory instead of the installation
directory.

The root cause is that the library directory is copied to the
installation directory without touching the libraries. The cmake wiki
says in RPATH handling caveats [1]: "Since install-side RPATH tweaking
is an operation that is done by target-specific installation handling,
any target that should have its install RPATH changed (e.g. to
`CMAKE_INSTALL_RPATH`) needs to end up in the installation via an
`install(TARGETS ...)` signature and not via directory-based copying."

So replace `install(DIRECTORY ...)` by individual `install(TARGETS ...)`
for the libraries and modules. Then cmake will replace the `RUNPATH` to
`$ORIGIN/../lib/audacity`, which is still incorrect. Therefore set
`INSTALL_RPATH` explicitly.

Fixes: https://github.com/audacity/audacity/issues/3289
Forwarded: https://github.com/audacity/audacity/pull/3671
[1] https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#caveats
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
Gbp-Pq: Name Fix-rpath-for-private-libraries-on-Linux.patch

CMakeLists.txt
cmake-proxies/cmake-modules/AudacityFunctions.cmake
modules/scripting/mod-script-pipe/CMakeLists.txt
src/CMakeLists.txt

index 2e91683610b79cd5e4cd95cb1b27491fab44b3f9..2e838c3b824e998d594f4c36fac086a125297302 100644 (file)
@@ -431,6 +431,7 @@ set( INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" )
 set( _LIBDIR "${CMAKE_INSTALL_LIBDIR}" )
 set( _DATADIR "${CMAKE_INSTALL_DATADIR}" )
 set( _PKGLIB "${_LIBDIR}/audacity" )
+set( _PKGMODULE "${_PKGLIB}/modules" )
 set( _PKGDATA "${_DATADIR}/audacity/" )
 set( _MANDIR "${CMAKE_INSTALL_MANDIR}" )
 set( _MODDIR "${_PKGLIB}/modules" )
index dee6dcd25b95c1a10e333e52e2c5966eb33361a9..6c76c1b3200be2a6b6242c686c336cbd40ae5dda 100644 (file)
@@ -470,6 +470,17 @@ function ( make_interface_alias TARGET REAL_LIBTYTPE )
    endif()
 endfunction()
 
+# Call install(TARGETS...) only on Linux systems (i.e. exclude MacOS and Windows)
+macro( install_target_linux target destination )
+   if( NOT "${CMAKE_GENERATOR}" MATCHES "Xcode|Visual Studio*" AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin" )
+      install( TARGETS "${target}" DESTINATION "${destination}" )
+   endif()
+endmacro()
+
+macro( install_audacity_module target )
+   install_target_linux( "${target}" "${_PKGMODULE}" )
+endmacro()
+
 function( audacity_module_fn NAME SOURCES IMPORT_TARGETS
    ADDITIONAL_DEFINES ADDITIONAL_LIBRARIES LIBTYPE )
 
@@ -513,6 +524,7 @@ function( audacity_module_fn NAME SOURCES IMPORT_TARGETS
          PROPERTIES
             PREFIX ""
             FOLDER "modules" # for IDE organization
+            INSTALL_RPATH "$ORIGIN/.."
       )
 
       if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows|Darwin" )
@@ -597,6 +609,12 @@ function( audacity_module_fn NAME SOURCES IMPORT_TARGETS
    collect_edges( ${TARGET} "${IMPORT_TARGETS}" ${LIBTYPE} )
    set( GRAPH_EDGES "${GRAPH_EDGES}" PARENT_SCOPE )
 
+   # Note: Some modules set EXCLUDE_FROM_ALL afterwards to not be installed.
+   # Therefore only install libraries, but not modules here.
+   if( NOT REAL_LIBTYPE STREQUAL "MODULE" )
+      install_target_linux( "${TARGET}" "${_PKGLIB}" )
+   endif()
+
    # collect unit test targets if they are present
    if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
       add_subdirectory(tests)
index 64cfdd8d08119c67d30a9529682e84470fc29caf..a892d95cc53815df2c51011187ffb7dfdc722b30 100644 (file)
@@ -24,3 +24,4 @@ set( LIBRARIES
 )
 audacity_module( mod-script-pipe "${SOURCES}" "${LIBRARIES}"
    "${DEFINES}" "" )
+install_audacity_module( mod-script-pipe )
index 6df0c3e1aa330e5a9d053db46d427882693fd685..cc13e7df80ac939d8bd73fa7661bf4332650aa08 100644 (file)
@@ -1412,11 +1412,6 @@ else()
                RUNTIME
                RESOURCE DESTINATION "${_PKGDATA}" )
 
-      install( DIRECTORY "${_DEST}/${_LIBDIR}/"
-               DESTINATION "${_LIBDIR}"
-               USE_SOURCE_PERMISSIONS
-               FILES_MATCHING PATTERN "*.so*" )
-
       install( FILES "${_INTDIR}/audacity.desktop"
                DESTINATION "${_DATADIR}/applications" )