From 4e6a1a81a96e96e3da65b7fbb35123c24a4b30a3 Mon Sep 17 00:00:00 2001 From: Dmitry Vedenko Date: Tue, 25 May 2021 20:21:55 +0300 Subject: [PATCH] Updates the way shared libraries are hadled 1. We put all shared libraries into one place. Both conan and locally built 2. We invoke CopyLibs to copy the libraries to a proper location and to correctly set the RPATH Fixes CopyLibs script on Windows Fixes CopyLibs.cmake for Linux Fixes CopyLibs on macOS Fixes CopyLibs on macOS --- CMakeLists.txt | 5 +++++ .../cmake-modules/AudacityDependencies.cmake | 8 ++++---- .../cmake-modules/AudacityFunctions.cmake | 4 ++-- cmake-proxies/cmake-modules/CopyLibs.cmake | 14 ++++++++++---- src/CMakeLists.txt | 10 +++------- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d806c186f..aea174b1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -257,11 +257,16 @@ endif() # Where the final product is stored set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) +set ( _SHARED_PROXY_BASE "shared" ) +set ( _SHARED_PROXY_BASE_PATH "${CMAKE_BINARY_DIR}/${_SHARED_PROXY_BASE}") + # Define the non-install and executable paths if( CMAKE_CONFIGURATION_TYPES ) set( _DESTDIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}" ) + set( _SHARED_PROXY_PATH "${_SHARED_PROXY_BASE_PATH}/${CMAKE_CFG_INTDIR}") else() set( _DESTDIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE}" ) + set( _SHARED_PROXY_PATH "${_SHARED_PROXY_BASE_PATH}/${CMAKE_BUILD_TYPE}") endif() set( _DEST "${_DESTDIR}" ) diff --git a/cmake-proxies/cmake-modules/AudacityDependencies.cmake b/cmake-proxies/cmake-modules/AudacityDependencies.cmake index 995520907..2923c01e4 100644 --- a/cmake-proxies/cmake-modules/AudacityDependencies.cmake +++ b/cmake-proxies/cmake-modules/AudacityDependencies.cmake @@ -199,10 +199,10 @@ function ( _conan_install build_type ) GENERATORS cmake_find_package_multi BUILD_REQUIRES ${CONAN_BUILD_REQUIRES} ${CONAN_CONFIG_OPTIONS} - IMPORTS "bin, *.dll -> ./bin/shared/${build_type} @ keep_path=False" - IMPORTS "lib, *.dll -> ./bin/shared/${build_type} @ keep_path=False" - IMPORTS "lib, *.dylib -> ./lib/shared/${build_type} @ keep_path=False" - IMPORTS "lib, *.so* -> ./lib/shared/${build_type} @ keep_path=False" + IMPORTS "bin, *.dll -> ./${_SHARED_PROXY_BASE}/${build_type} @ keep_path=False" + IMPORTS "lib, *.dll -> ./${_SHARED_PROXY_BASE}/${build_type} @ keep_path=False" + IMPORTS "lib, *.dylib -> ./${_SHARED_PROXY_BASE}/${build_type} @ keep_path=False" + IMPORTS "lib, *.so* -> ./${_SHARED_PROXY_BASE}/${build_type} @ keep_path=False" OPTIONS ${CONAN_PACKAGE_OPTIONS} ) diff --git a/cmake-proxies/cmake-modules/AudacityFunctions.cmake b/cmake-proxies/cmake-modules/AudacityFunctions.cmake index de0cde569..51e2b48f1 100644 --- a/cmake-proxies/cmake-modules/AudacityFunctions.cmake +++ b/cmake-proxies/cmake-modules/AudacityFunctions.cmake @@ -348,7 +348,7 @@ function( audacity_module_fn NAME SOURCES IMPORT_TARGETS ) else() set( ATTRIBUTES "shape=octagon" ) - set_target_property_all( ${TARGET} ${DIRECTORY_PROPERTY} "${_EXEDIR}" ) + set_target_property_all( ${TARGET} ${DIRECTORY_PROPERTY} "${_SHARED_PROXY_PATH}" ) set_target_properties( ${TARGET} PROPERTIES PREFIX "" @@ -379,7 +379,7 @@ function( audacity_module_fn NAME SOURCES IMPORT_TARGETS foreach( IMPORT ${IMPORT_TARGETS} ) list( APPEND LIBRARIES "${IMPORT}" ) endforeach() - + list( APPEND LIBRARIES ${ADDITIONAL_LIBRARIES} ) # list( TRANSFORM SOURCES PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/" ) diff --git a/cmake-proxies/cmake-modules/CopyLibs.cmake b/cmake-proxies/cmake-modules/CopyLibs.cmake index ec0f74fed..2b057b2eb 100644 --- a/cmake-proxies/cmake-modules/CopyLibs.cmake +++ b/cmake-proxies/cmake-modules/CopyLibs.cmake @@ -45,6 +45,8 @@ function( gather_libs src ) list( APPEND libs ${lib} ) gather_libs( ${lib} ) + elseif ( EXISTS "${DST}/${line}" ) + gather_libs( "${DST}/${line}" ) endif() endforeach() elseif( CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin" ) @@ -57,7 +59,11 @@ function( gather_libs src ) foreach( line ${output} ) if( line MATCHES "^.*\\.dylib " ) string( REGEX REPLACE "dylib .*" "dylib" line "${line}" ) - set( lib "${WXWIN}/${line}" ) + + get_filename_component( dylib_name "${line}" NAME) + + message(STATUS "Checking out ${line}") + set( lib "${WXWIN}/${dylib_name}" ) if( NOT lib STREQUAL "${src}" AND NOT line MATCHES "@executable" AND EXISTS "${lib}") message(STATUS "\tProcessing ${lib}...") @@ -68,7 +74,7 @@ function( gather_libs src ) message(STATUS "\t\tAdding ${refname} to ${src}") - list( APPEND postcmds "sh -c 'install_name_tool -change ${refname} @executable_path/../Frameworks/${refname} ${src}'" ) + list( APPEND postcmds "sh -c 'install_name_tool -change ${line} @executable_path/../Frameworks/${refname} ${src}'" ) gather_libs( ${lib} ) endif() @@ -82,10 +88,10 @@ function( gather_libs src ) get_filename_component( libname "${src}" NAME ) foreach( line ${output} ) - message (STATUS "\tChecking ${line}...") - string( REGEX REPLACE "(.*) => .* \\(.*$" "\\1" line "${line}" ) + message (STATUS "\tChecking ${line}...") + set(line "${WXWIN}/${line}") if (EXISTS "${line}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 41a3fcc2c..23c555f45 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1130,10 +1130,6 @@ if( CMAKE_SYSTEM_NAME MATCHES "Windows" ) # Copy over the wxWidgets DLLs - # Convert the paths to native - file( TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/bin/shared" libdir ) - file( TO_NATIVE_PATH "${_EXEDIR}" exedir ) - # Copy the required wxWidgets libs into the bundle add_custom_command( TARGET @@ -1141,7 +1137,7 @@ if( CMAKE_SYSTEM_NAME MATCHES "Windows" ) COMMAND ${CMAKE_COMMAND} -D SRC="${_EXEDIR}/Audacity.exe" -D DST="${_EXEDIR}" - -D WXWIN="${libdir}/$/" + -D WXWIN="${_SHARED_PROXY_BASE_PATH}/$/" -P ${AUDACITY_MODULE_PATH}/CopyLibs.cmake POST_BUILD ) @@ -1226,7 +1222,7 @@ elseif( CMAKE_SYSTEM_NAME MATCHES "Darwin" ) COMMAND ${CMAKE_COMMAND} -D SRC="${_EXEDIR}/Audacity" -D DST="${_PKGLIB}" - -D WXWIN="${CMAKE_BINARY_DIR}/lib/shared/$" + -D WXWIN="${_SHARED_PROXY_BASE_PATH}/$" -P ${AUDACITY_MODULE_PATH}/CopyLibs.cmake POST_BUILD ) @@ -1292,7 +1288,7 @@ else() COMMAND ${CMAKE_COMMAND} -D SRC="${_EXEDIR}/audacity" -D DST="${_DEST}/${_PKGLIB}" - -D WXWIN="${CMAKE_BINARY_DIR}/lib/shared/$" + -D WXWIN="${_SHARED_PROXY_BASE_PATH}/$" -P ${AUDACITY_MODULE_PATH}/CopyLibs.cmake POST_BUILD )