file(GET_RUNTIME_DEPENDENCIES) does not resolve libraries in @rpath on macOS
I'm trying to use
file(GET_RUNTIME_DEPENDENCIES) to collect the list of all dependencies of an executable. This generally works well on Linux and Windows, but I have some problems on macOS. Some of the libraries are referenced using
@rpath. For some reason, they can not be resolved. I read in the docs of https://cmake.org/cmake/help/latest/command/file.html#get-runtime-dependencies:
On Apple platforms, library resolution works as follows: [...] 4. Otherwise, if the dependency starts with @rpath/, and replacing @rpath/ with one of the RPATH entries of the depending file yields an existing file, the dependency is resolved to that file. Note that RPATH entries that start with @executable_path/ or @loader_path/ also have these items replaced with the appropriate path.
I'm not sure why this does not work for me. Reading the source code of
cmBinUtilsMacOSMachOOToolGetRuntimeDependenciesTool.cxx also did not make it more obvious. Here is what I could find:
One unresolved library is
@rpath/libbz220.127.116.11.dylib. The only such reference comes from
libfreetype.6.17.4.dylib. The dependencies shown from
otool -L are:
/System/Volumes/Data/data/Debug/lib/libfreetype.6.17.4.dylib: @rpath/libfreetype.6.dylib (compatibility version 6.0.0, current version 6.17.4) @rpath/libz.1.dylib (compatibility version 1.0.0, current version 1.2.11) @rpath/libbz18.104.22.168.dylib (compatibility version 1.0.8, current version 1.0.8) @rpath/libpng16.16.dylib (compatibility version 16.0.0, current version 16.37.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.60.1)
I can see that
libbz22.214.171.124.dylib exists in the same directory
libfreetype.6.17.4.dylib. Is there something wrong on my side so that
file(GET_RUNTIME_DEPENDENCIES) does not resolve it?