问题
In my CMake project I build a bunch of libraries that are loaded at runtime as plugins. I therefore need to set various RPATHs so that these libraries can be found by the dynamic loading mechanism. I also need the whole thing to be relocatable, because it is part of a Python extension module and so gets copied around by various tools during the build process.
It seems that the proper way to do this is to set the RPATH in a relative fashion by using the special $ORIGIN
variable on Linux, and @loader_path
on OSX. Ok cool, that's fine. But looking through
https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling
it seems like I have to do this manually? CMake does not have any built-in variable like ${ORIGIN}
or something that expands to the correct thing depending on the OS? (and maybe it even varies depending on the linker or something? I have no idea). It just seems like this is the sort of thing that CMake should figure out for me, so I want to check that I'm not missing something before I try to implement the switching myself...
BTW I don't care about Windows, so it doesn't matter if there is some solution that doesn't work for that :).
来源:https://stackoverflow.com/questions/53428219/cmake-rpath-origin-and-loader-path