Reputation: 4702
I'd like to add another directory to a target's BUILD_RPATH
property, but I'd like it at the end of the list, so it's searched last, after the other directories that cmake automatically adds to target's BUILD_RPATH
. But there doesn't seem to be way to add to the property after the automatic RPATH directories.
At build time, my system libraries are not in the normal locations, but in a staging area. In order to run uninstalled built binaries, I need to add this staging area to the binaries' RPATHs. And this part is straightforward to do and works fine, like this:
add_executable(mybinary ${BINARY_SOURCES})
set_property(TARGET mybinary APPEND PROPERTY BUILD_RPATH ${STAGING_LIB_DIR})
But mybinary
also uses a library that it built as part of the same project:
add_library(mylib SHARED ${LIB_SOURCES})
target_link_libraries(mybinary PRIVATE mylib)
When mybinary
is run, I'd like it to use the mylib
that was just built and is in ${CMAKE_CURRENT_BINARY_DIR}
, not another copy somewhere else, perhaps in the system library directory from the last time make install
was run to install the project. Or, in my case, a copy of the library in ${STAGING_LIB_DIR}
.
cmake will automatically add ${CMAKE_CURRENT_BINARY_DIR}
, or whatever is appropriate, for any libraries not from the system to the build RPATH of produced binaries. So when one runs mybinary
from the build directory it will search for the mylib
in the build directory.
But the problem is it appends these automatic library directories to whatever I have set BUILD_RPATH
to. So one gets a final RPATH of ${STAGING_LIB_DIR}:${CMAKE_CURRENT_BINARY_DIR}
and the wrong copy of mylib
is used.
Upvotes: 2
Views: 1117
Reputation: 51102
You could set the SKIP_BUILD_RPATH
target property:
SKIP_BUILD_RPATH
is a boolean specifying whether to skip automatic generation of an rpath allowing the target to run from the build tree. This property is initialized by the value of the variableCMAKE_SKIP_BUILD_RPATH
if it is set when a target is created.
And then manually set the RPATH in whatever way/order you would like without worrying about CMake doing additional things to it.
Upvotes: 0