Install( ... RUNTIME_DEPENDENCIES ...) doesn't set @RPATH on MacOS

Using CMake’s install command with the RUNTIME_DEPENDENCIES option correctly bundles a required third party library into my install directory. But it doesn’t set the RPATH for that library. So, post install I have a library reference for my binary that points to a location that won’t exist on a users’s machine:

Here’s how I’m calling Install:

install(TARGETS Xyce COMPONENT Core DESTINATION bin EXPORT XyceTarget
RUNTIME_DEPENDENCIES
DIRECTORIES “/usr/local/” “/opt/local”
LIBRARY DESTINATION lib
COMPONENT Core )

And here is the resulting library dependency of the installed binary:

otool -L _Xyce
Xyce:
@rpath/libxyce.dylib (compatibility version 0.0.0, current version 0.0.0)
/opt/local/lib/libfftw3.3.dylib (compatibility version 10.0.0, current version 10.10.0)

The library in /opt/local has been copied to the install directory’s “lib” subdirectory, but the binary is still linked to the original library location.

I can use a small script to fix this during CPack’s work making the installer with:

install(CODE [[ file( GLOB XyceBinLoc “./_CPack_Packages/Darwin/productbuild/Xyce*/Core/usr/local/Xyce*/bin/Xyce” )
execute_process(COMMAND install_name_tool -change /opt/local/lib/libfftw3.3.dylib @rpath/libfftw3.3.dylib ${XyceBinLoc})
]] )

and then the installed code is correctly linked to the dependent library.
otool -L _Xyce
Xyce:
@rpath/libxyce.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libfftw3.3.dylib (compatibility version 10.0.0, current version 10.10.0)

Is this the expected behavior of install( … RUNTIME_DEPENDENCIES ) ? On our linux machines setting CMAKE_INSTALL_RPATH works as expected, but this doesn’t seem to work under MacOS.

This project sets CMAKE_INSTALL_RPATH with:

if(APPLE)
list(APPEND CMAKE_INSTALL_RPATH “@loader_path/…/lib”)
else()
list(APPEND CMAKE_INSTALL_RPATH “$ORIGIN/…/lib”)
endif()

Any suggestions would be appreciated.

Thanks,
Rich

install(RUNTIME_DEPENDENCIES) does not do any kind of RPATH editing. You’ll need to do that yourself (it’s something I want as well, but have never had time to get around to).

Thanks! I wasn’t sure if I was missing something, so I appreciate the reply.
Rich