From e2fda7df32f2182a8b063a69a748a3e6c1fb3669 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Mon, 7 Jun 2021 09:36:02 -0400 Subject: [PATCH 1/4] Better node names for 3p libraries in picture of dependencies --- .../cmake-modules/AudacityFunctions.cmake | 15 ++++++++++++++- src/CMakeLists.txt | 3 +-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cmake-proxies/cmake-modules/AudacityFunctions.cmake b/cmake-proxies/cmake-modules/AudacityFunctions.cmake index afe1ae57c..4a14db612 100644 --- a/cmake-proxies/cmake-modules/AudacityFunctions.cmake +++ b/cmake-proxies/cmake-modules/AudacityFunctions.cmake @@ -301,6 +301,19 @@ function( export_symbol_define var module_name ) set( "${var}" "${symbol}=${value}" PARENT_SCOPE ) endfunction() +# shorten a target name for purposes of generating a dependency graph picture +function( canonicalize_node_name var node ) + # strip generator expressions + string( REGEX REPLACE ".*>.*:(.*)>" "\\1" node "${node}" ) + # omit the "-interface" for alias targets to modules + string( REGEX REPLACE "-interface\$" "" node "${node}" ) + # shorten names of standard libraries or Apple frameworks + string( REGEX REPLACE "^-(l|framework )" "" node "${node}" ) + # shorten paths + get_filename_component( node "${node}" NAME_WE ) + set( "${var}" "${node}" PARENT_SCOPE ) +endfunction() + function( audacity_module_fn NAME SOURCES IMPORT_TARGETS ADDITIONAL_DEFINES ADDITIONAL_LIBRARIES LIBTYPE ) @@ -454,7 +467,7 @@ function( audacity_module_fn NAME SOURCES IMPORT_TARGETS if(IMPORT IN_LIST ACCESS) continue() endif() - string( REGEX REPLACE "-interface\$" "" IMPORT "${IMPORT}" ) + canonicalize_node_name(IMPORT "${IMPORT}") list( APPEND GRAPH_EDGES "\"${TARGET}\" -> \"${IMPORT}\"" ) endforeach() set( GRAPH_EDGES "${GRAPH_EDGES}" PARENT_SCOPE ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b480ff53f..90a878c61 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1365,8 +1365,7 @@ endif() list( APPEND GRAPH_EDGES "Audacity [shape=house]" ) foreach( LIBRARY ${LIBRARIES} ) if (NOT LIBRARY MATCHES "PUBLIC|PRIVATE|INTERFACE") - string( REGEX REPLACE ".*>.*:(.*)>" "\\1" LIBRARY "${LIBRARY}" ) - string( REGEX REPLACE "^-(l|framework )" "" LIBRARY "${LIBRARY}" ) + canonicalize_node_name(LIBRARY "${LIBRARY}") list( APPEND GRAPH_EDGES "\"${TARGET}\" -> \"${LIBRARY}\"" ) endif() endforeach() From cf993fcded764b82ff783e9ce5a8845aa94506e3 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 8 Jun 2021 20:48:46 -0400 Subject: [PATCH 2/4] Revert "CopyLibs.cmake, for macOS: visit unique EDGES (not nodes)..." This reverts commit e785c77226da1cb33f97557e905caf4a579fa318. --- cmake-proxies/cmake-modules/CopyLibs.cmake | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmake-proxies/cmake-modules/CopyLibs.cmake b/cmake-proxies/cmake-modules/CopyLibs.cmake index 7a687a5b1..673b9a6ad 100644 --- a/cmake-proxies/cmake-modules/CopyLibs.cmake +++ b/cmake-proxies/cmake-modules/CopyLibs.cmake @@ -40,8 +40,8 @@ endfunction() set( VISITED ) function( gather_libs src ) + list( APPEND VISITED "${src}" ) if( CMAKE_HOST_SYSTEM_NAME MATCHES "Windows" ) - list( APPEND VISITED "${src}" ) execute( output cmd /k dumpbin /dependents ${src} ) foreach( line ${output} ) @@ -72,8 +72,7 @@ function( gather_libs src ) set( lib "${WXWIN}/${dylib_name}" ) if( NOT lib STREQUAL "${src}" AND NOT line MATCHES "@executable" AND EXISTS "${lib}" - AND NOT "${src}///${lib}" IN_LIST VISITED ) - list( APPEND VISITED "${src}///${lib}" ) + AND NOT "${lib}" IN_LIST VISITED ) message(STATUS "\tProcessing ${lib}...") list( APPEND libs ${lib} ) @@ -89,7 +88,6 @@ function( gather_libs src ) endif() endforeach() elseif( CMAKE_HOST_SYSTEM_NAME MATCHES "Linux" ) - list( APPEND VISITED "${src}" ) message(STATUS "Executing LD_LIBRARY_PATH='${WXWIN}' ldd ${src}") execute( output sh -c "LD_LIBRARY_PATH='${WXWIN}' ldd ${src}" ) From 7346fdac69ca99ba5e581f8c20a40fa024842dbb Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 8 Jun 2021 20:53:02 -0400 Subject: [PATCH 3/4] Re-fix long Mac builds with many libraries, faster & more simply... ... Fix redundant "sh -c". Combine many install_name_tool commands into one for each library or executable. Examine each with otool once only. --- cmake-proxies/cmake-modules/CopyLibs.cmake | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/cmake-proxies/cmake-modules/CopyLibs.cmake b/cmake-proxies/cmake-modules/CopyLibs.cmake index 673b9a6ad..a79811e44 100644 --- a/cmake-proxies/cmake-modules/CopyLibs.cmake +++ b/cmake-proxies/cmake-modules/CopyLibs.cmake @@ -39,6 +39,7 @@ function( execute ) endfunction() set( VISITED ) +set( postcmds ) function( gather_libs src ) list( APPEND VISITED "${src}" ) if( CMAKE_HOST_SYSTEM_NAME MATCHES "Windows" ) @@ -61,7 +62,8 @@ function( gather_libs src ) execute( output otool -L ${src} ) set( libname "${src}" ) - + + set( words ) foreach( line ${output} ) if( line MATCHES "^.*\\.dylib " ) string( REGEX REPLACE "dylib .*" "dylib" line "${line}" ) @@ -71,8 +73,7 @@ function( gather_libs src ) message(STATUS "Checking out ${line}") set( lib "${WXWIN}/${dylib_name}" ) - if( NOT lib STREQUAL "${src}" AND NOT line MATCHES "@executable" AND EXISTS "${lib}" - AND NOT "${lib}" IN_LIST VISITED ) + if( NOT lib STREQUAL "${src}" AND NOT line MATCHES "@executable" AND EXISTS "${lib}" ) message(STATUS "\tProcessing ${lib}...") list( APPEND libs ${lib} ) @@ -81,12 +82,21 @@ function( gather_libs src ) message(STATUS "\t\tAdding ${refname} to ${src}") - list( APPEND postcmds "sh -c 'install_name_tool -change ${line} @executable_path/../Frameworks/${refname} ${src}'" ) + list( APPEND words "-change ${line} @executable_path/../Frameworks/${refname}" ) - gather_libs( ${lib} ) + if( NOT "${lib}" IN_LIST VISITED ) + gather_libs( ${lib} ) + endif() endif() endif() endforeach() + if( words ) + # There is at least one dependency to rename + list( PREPEND words "install_name_tool" ) + list( APPEND words "${src}" ) + string( JOIN " " postcmd ${words} ) + list( APPEND postcmds "${postcmd}" ) + endif() elseif( CMAKE_HOST_SYSTEM_NAME MATCHES "Linux" ) message(STATUS "Executing LD_LIBRARY_PATH='${WXWIN}' ldd ${src}") From 4a2fc192e63955ecf9625c7520033e5549c4ca73 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 8 Jun 2021 22:16:39 -0400 Subject: [PATCH 4/4] Bug2799: mod-script-pipe fails to load on Mac... ... This broke at commit 938bbeb with changes in CMake scripts. This can be fixed by invoking CopyLibs.cmake for modules too. This affects only the macOS build. --- .../cmake-modules/AudacityFunctions.cmake | 9 +++++++++ cmake-proxies/cmake-modules/CopyLibs.cmake | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/cmake-proxies/cmake-modules/AudacityFunctions.cmake b/cmake-proxies/cmake-modules/AudacityFunctions.cmake index 4a14db612..165101289 100644 --- a/cmake-proxies/cmake-modules/AudacityFunctions.cmake +++ b/cmake-proxies/cmake-modules/AudacityFunctions.cmake @@ -359,6 +359,15 @@ function( audacity_module_fn NAME SOURCES IMPORT_TARGETS PREFIX "" FOLDER "modules" # for IDE organization ) + if( CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin" ) + add_custom_command( + TARGET ${TARGET} + COMMAND ${CMAKE_COMMAND} + -D SRC="${_MODDIR}/${TARGET}.so" + -D WXWIN="${_SHARED_PROXY_BASE_PATH}/$" + -P ${AUDACITY_MODULE_PATH}/CopyLibs.cmake + POST_BUILD ) + endif() else() set( ATTRIBUTES "shape=octagon" ) set_target_property_all( ${TARGET} ${DIRECTORY_PROPERTY} "${_SHARED_PROXY_PATH}" ) diff --git a/cmake-proxies/cmake-modules/CopyLibs.cmake b/cmake-proxies/cmake-modules/CopyLibs.cmake index a79811e44..9050acc1c 100644 --- a/cmake-proxies/cmake-modules/CopyLibs.cmake +++ b/cmake-proxies/cmake-modules/CopyLibs.cmake @@ -84,7 +84,13 @@ function( gather_libs src ) list( APPEND words "-change ${line} @executable_path/../Frameworks/${refname}" ) - if( NOT "${lib}" IN_LIST VISITED ) + if( + # Don't do depth first search from modules: assume the fixup + # of .dylib libraries was already done when this function + # was visited for the executable + NOT src MATCHES "\\.so$" + AND NOT "${lib}" IN_LIST VISITED + ) gather_libs( ${lib} ) endif() endif() @@ -141,5 +147,9 @@ foreach( cmd ${postcmds} ) ) endforeach() -list( REMOVE_DUPLICATES libs ) -file( INSTALL ${libs} DESTINATION ${DST} FOLLOW_SYMLINK_CHAIN ) +# This .cmake file is invoked on Darwin for modules too. +# Do the INSTALL only for the executable. +if( NOT SRC MATCHES "\\.so$" ) + list( REMOVE_DUPLICATES libs ) + file( INSTALL ${libs} DESTINATION ${DST} FOLLOW_SYMLINK_CHAIN ) +endif()