On Fri, May 12, 2023 at 11:12:03 -0700, Andrew Kaster wrote:
> - Create a python script that walks the output of otool -L and generates
> the list as part of the build, just before bundling the data. This is
> similar to what the CMake build currently does by recursively walking the
> LINK_LIBRARIES property of each executable/library and deduplicating the
> lists at the end.
Note that CMake has `file(GET_RUNTIME_DEPENDENCIES)` which now walks the
metadata in the libraries themselves. This helps to ensure that library
references in the binaries are actually correct. It's basically a port
of the first part of these scripts (`fixup_bundle.*.py`):
https://gitlab.kitware.com/paraview/common-superbuild/-/tree/master/cmake/scripts
where the second part is not yet implemented (fixing binary references
once bundled to point to each other consistently).
Note that I do *not* recommend using `otool -L` (or `ldd`) for the
following reasons:
- cross-compile is harder as you now need to juggle `--sysroot`-style
bits in cooperation with the dynamic loader tool in use (and massage
paths afterwards)
- you do not know by what mechanism each path was found (e.g., the above
scripts explicitly ignore things like `DYLD_LIBRARY_PATH` because the
libraries should work on their own) and therefore how to "fixup" each
intra-library reference (and library id on macOS) is not well-defined)
- it is recursive (you want to be able to stop at certain libraries that
you expect to just be there in general and ignore *their*
dependencies unless also directly referenced by your code; usually
more relevant on Linux with optional deps of system libraries or
Windows where you want to ignore many system DLLs)
--Ben