Allow to set BUILD_RPATH for targets to a specific folder without having target_link_libraries automatically append to BUILD_RPATH paths to other libraries.
Hi,
A problem I recently encoutered with CMake is that we don't have fully control over BUILD_RPATH
. Here's what I want to do: I want to set BUILD_RPATH
for my targets, or even set CMAKE_BUILD_RPATH
to point to a specific folder. However, I don't want CMake to add other things to my RPATH
when I link libraries.
My use case is that I have a script that copies all shared libraries needed for my project to its binary folder. I then use this binary folder for deployement. It contains all libraries it needs to run. I want my executables to know that all libraries it needs are in the binary folder by setting RPATH
to the binary folder. Otherwise, if the user has Qt installed on his computer in a standard path, it's possible it will get that library instead of the one in the executable's folder. I want to avoid this and have full control over which library it chooses. This is why I need to set RPATH
of my executables to one specific folder.
Here's what I tried:
I tried setting CMAKE_SKIP_RPATH
to TRUE
and then adding the RPATH
with set_target_properties(MyExec PROPERTIES BUILD_RPATH "${CMAKE_BINARY_DIR}/bin")
. This doesn't add any RPATH
. So, I tried setting CMAKE_SKIP_RPATH
to FALSE
and then after I linked all my libraries with target_link_libraries
I do set_target_properties(MyExec PROPERTIES BUILD_RPATH "${CMAKE_BINARY_DIR}/bin")
. This simply adds my binary folder and all other paths to my libraries.
It seems like we need an option like CMAKE_SKIP_AUTOMATIC_RPATH
that would allow users to set RPATH
by themselves if they wished, but wouldn'd automatically add to RPATH
linked libraries.
Is there an existing way that allows to do this? If not, this is a much needed feature.