1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
From: Benjamin Drung <benjamin.drung@canonical.com>
Date: Thu, 22 Sep 2022 19:52:43 +0200
Subject: Fix rpath for private libraries on Linux
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>
---
CMakeLists.txt | 1 +
cmake-proxies/cmake-modules/AudacityFunctions.cmake | 18 ++++++++++++++++++
modules/scripting/mod-script-pipe/CMakeLists.txt | 1 +
src/CMakeLists.txt | 5 -----
4 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cb15882..9caa0e2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -438,6 +438,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" )
diff --git a/cmake-proxies/cmake-modules/AudacityFunctions.cmake b/cmake-proxies/cmake-modules/AudacityFunctions.cmake
index dee6dcd..6c76c1b 100644
--- a/cmake-proxies/cmake-modules/AudacityFunctions.cmake
+++ b/cmake-proxies/cmake-modules/AudacityFunctions.cmake
@@ -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)
diff --git a/modules/scripting/mod-script-pipe/CMakeLists.txt b/modules/scripting/mod-script-pipe/CMakeLists.txt
index 64cfdd8..a892d95 100644
--- a/modules/scripting/mod-script-pipe/CMakeLists.txt
+++ b/modules/scripting/mod-script-pipe/CMakeLists.txt
@@ -24,3 +24,4 @@ set( LIBRARIES
)
audacity_module( mod-script-pipe "${SOURCES}" "${LIBRARIES}"
"${DEFINES}" "" )
+install_audacity_module( mod-script-pipe )
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fcf2d72..ba1da19 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1414,11 +1414,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" )
|