# Install( ... RUNTIME\_DEPENDENCIES ...) doesn't set @RPATH on MacOS

**URL:** https://discourse.cmake.org/t/install-runtime-dependencies-doesnt-set-rpath-on-macos/9260
**Category:** Usage
**Tags:** os:macos
**Created:** [October 23, 2023, 5:42pm UTC](https://discourse.cmake.org/t/install-runtime-dependencies-doesnt-set-rpath-on-macos/9260 "2023-10-23T17:42:14Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![RichS](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@RichS](https://discourse.cmake.org/u/RichS)
#### Post date: [October 23, 2023, 5:42pm UTC](https://discourse.cmake.org/t/install-runtime-dependencies-doesnt-set-rpath-on-macos/9260/1 "2023-10-23T17:42:14Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 23, 2023, 7:04pm UTC](https://discourse.cmake.org/t/install-runtime-dependencies-doesnt-set-rpath-on-macos/9260/2 "2023-10-23T19:04:51Z")

</div>

`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).

---

<div class="post-metadata">

### Author: ![RichS](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@RichS](https://discourse.cmake.org/u/RichS)
#### Post date: [October 23, 2023, 7:49pm UTC](https://discourse.cmake.org/t/install-runtime-dependencies-doesnt-set-rpath-on-macos/9260/3 "2023-10-23T19:49:16Z")

</div>

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