File: CopyLibs.cmake

package info (click to toggle)
audacity 3.2.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 106,704 kB
  • sloc: cpp: 277,038; ansic: 73,623; lisp: 7,761; python: 3,305; sh: 2,715; perl: 821; xml: 275; makefile: 119
file content (127 lines) | stat: -rw-r--r-- 3,368 bytes parent folder | download
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Copy library during build and, on the Mac, modify the dependent
# library paths.
#
# Defines required:
#
# SRC    source library name
# DST    destination directory
#

# enable IN_LIST operator
cmake_policy(SET CMP0057 NEW)

message( "==================================================================" )
message( "Copying shared libraries:" )
message( "==================================================================" )

# list command no longer ignores empty elements.
cmake_policy( SET CMP0007 NEW )

function( execute )
   list( POP_FRONT ARGV outlist )

   execute_process(
      COMMAND
         ${ARGV}
      OUTPUT_VARIABLE
         cmd_out
#      COMMAND_ECHO STDOUT
      OUTPUT_STRIP_TRAILING_WHITESPACE
   )

#message("OUTPUT\n${cmd_out}")

   # Convert output to list and strip
   string( REPLACE "\n" ";" cmd_out "${cmd_out}" )
   list( TRANSFORM cmd_out STRIP )

   set( ${outlist} ${cmd_out} PARENT_SCOPE )
endfunction()

set( VISITED )
set( postcmds )
function( gather_libs src )
   list( APPEND VISITED "${src}" )
   if( CMAKE_HOST_SYSTEM_NAME MATCHES "Windows" )
      execute( output cmd /k dumpbin /dependents ${src} )

      foreach( line ${output} )
         set( lib ${WXWIN}/${line} )

         if( EXISTS "${lib}" AND NOT "${lib}" IN_LIST VISITED )
            list( APPEND libs ${lib} )

            gather_libs( ${lib} )
         elseif ( EXISTS "${DST}/${line}" AND NOT "${DST}/${line}" IN_LIST VISITED )
            gather_libs( "${DST}/${line}" )
         endif()
      endforeach()
   elseif( CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin" )
      message(STATUS "Checking ${src} for libraries...")

      get_filename_component(dir ${CMAKE_SCRIPT_MODE_FILE} DIRECTORY)

      execute_process( COMMAND
         python3
         "${dir}/../../scripts/build/macOS/fixup_libs.py"
         -i ${WXWIN}
         -o ${DST}
         ${src}
         ECHO_OUTPUT_VARIABLE
         RESULT_VARIABLE
              fixup_status
      )

      if(NOT fixup_status EQUAL 0)
         message(FATAL_ERROR "fixup_status failed with code ${fixup_status}")
      endif()
   elseif( CMAKE_HOST_SYSTEM_NAME MATCHES "Linux" )
      message(STATUS "Executing LD_LIBRARY_PATH='${WXWIN}' ldd ${src}")

      execute( output sh -c "LD_LIBRARY_PATH='${WXWIN}' ldd ${src}" )

      get_filename_component( libname "${src}" NAME )

      foreach( line ${output} )
         string( REGEX REPLACE "(.*) => .* \\(.*$" "\\1" line "${line}" )

         message (STATUS "\tChecking ${line}...")

         set(line "${WXWIN}/${line}")

         if (EXISTS "${line}" AND NOT "${line}" IN_LIST VISITED)
            message (STATUS "\tAdding ${line}...")

            set( lib ${line} )

            list( APPEND libs ${lib} )

            gather_libs( ${lib} )
         endif()

      endforeach()
   endif()

   set( libs ${libs} PARENT_SCOPE )
   set( postcmds ${postcmds} PARENT_SCOPE )
   set( VISITED ${VISITED} PARENT_SCOPE )
endfunction()

gather_libs( "${SRC}" )

list( REMOVE_DUPLICATES postcmds )

foreach( cmd ${postcmds} )
   execute_process(
      COMMAND
         sh -c "${cmd}"
      COMMAND_ECHO STDOUT
   )
endforeach()

# 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()