I always run my executable in the build tree (I don't run it from a cmake "install"). A library, let's call it fruit
, is built as a framework:
add_library( fruit SHARED ${FRUIT_SOURCES} )
set_target_properties( fruit PROPERTIES FRAMEWORK TRUE)
set_target_properties( fruit PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_NAME_DIR "@rpath/Frameworks" )
Now I want to set a custom rpath for main application (called executable
) with cmake. I thought I could use the INSTALL_RPATH
target property of executable
to define my rpaths for the generated program, but this seems to only work for an installed executable (remember I always run my application in the cmake build folder):
# this rpath is not shown in the generated executable (otool -l -v executable):
set_target_properties( executable PROPERTIES INSTALL_RPATH "@executable_path/lib/" )
How define/add a rpath item to the program generated in the build tree?
PS. This library fruit
is just an example of my actual problem. The library is created in a sub cmake project (a git submodule) which adds the BUILD_WITH_INSTALL_RPATH
property to the library. But I have the possibility to change the code for this project. Is there a better way to let my executable work in the build tree?
This is not an answer to the main question, but I figured out an answer to the post scriptum. This is a better solution than the one searced for in the main question, but I let that question persist.
The code is taken from here. Also see this blog post.