How to set the LC_LOAD_DYLIB of a shared library in a cmake project

979 Views Asked by At

I have a CMake project for macOS which generates an executable in an app bundle and has a few dylibs as dependencies. However, I've noticed that some dylibs come with a shared library identification name that's not convenient, and require calling install_name_tool in a postbuild step to fix it. Here's an example of how these dylibs are being referred in the App Bundle's executable:

(...)
Load command 27
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name @rpath/libFoo.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 0.0.0
compatibility version 0.0.0
Load command 28
          cmd LC_LOAD_DYLIB
      cmdsize 48
         name libBar.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 0.0.0
compatibility version 0.0.0
Load command 29
          cmd LC_LOAD_DYLIB
      cmdsize 40
         name libBaz.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 1.0.0
compatibility version 1.0.0
(...)

As I'm generating a macOS Application Bundle I'd prefer if the executable refers to each of these libraries as @executable_path/../Frameworks/libFoo.dylib.

Does anyone know if CMake offers any way to specify these without having to calling install_name_tool in a ad-hoc postbuild target?

0

There are 0 best solutions below