Closed mfwitten closed 5 months ago
The rpath should be set to ${CMAKE_INSTALL_FULL_LIBDIR}
to make absolute libdirs work.
Then we should consider not adding an rpath for system library directories, see FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
in the CMake Wiki. Alternatively, we could make this feature optional.
Thank you for the help, @nwellnhof.
I forcibly pushed 2 commits to replace the old one:
MACOSX_RPATH
.The following text was added to the original commit message:
[...]
There is some intelligence behind whether 'rpath' is set at all:
* If a shared object (e.g., 'libcmark') is going to be installed
in a standard location, then such location is not added to 'rpath'.
* A non-standard installation will cause 'rpath' to include at least
the following path provided by cmake:
"${CMAKE_INSTALL_FULL_LIBDIR}"
* Also, cmake has been instructed to append any non-standard path
to 'rpath' if cmake is aware of an external dependency from
such a path.
Of course, this will only help on a system that supports an 'rpath'
feature known to cmake; for example, Windows has no such feature,
and so all of this will presumably be ignored when building under
that system.
EDIT: In the commit log, I accidentally wrote CMAKE_INSTALL_PREFIX_FULL_LIBDIR
instead of CMAKE_INSTALL_FULL_LIBDIR
. I have addressed the mistake, and forcibly pushed the fixed commit here.
I think I have hit all the buttons this time. 🤞
rpath
.libcmark
will essentially never have an rpath
.cmark
will basically have no rpath
when statically linked.cmake
may still add paths to each rpath
as necessary.Looks good to me.
I pushed a slightly modified version; as described in the commit log:
If
CMAKE_INSTALL_RPATH
is set, then it is used; this allows the user to set a single, overriding value the expected way.
Essentially:
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9170bf3..21c1763 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,9 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) set(CMAKE_INCLUDE_CURRENT_DIR ON) +if (DEFINED CMAKE_INSTALL_RPATH) + set(Base_rpath "${CMAKE_INSTALL_RPATH}") +else() if(BUILD_SHARED_LIBS) set(p "${CMAKE_INSTALL_FULL_LIBDIR}") list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${p}" i) @@ -76,6 +79,7 @@ if(BUILD_SHARED_LIBS) set(Base_rpath "${p}") endif() endif() +endif() # Append non-standard external dependency directories, if any. set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
Sorry, I forgot about this. @nwellnhof if it still looks good to you I will merge this.
Looks good.
Before this commit, the
cmark
executable didn’t inform the dynamic linker where to look for thelibcmark
shared object; this becomes an irritation whenlibcmark
is installed in an unorthodox location:Because of this commit, the
cmark
executable’srpath
[0][1] setting (or equivalent) is set upon installation, thereby providing the required search directory:In particular,
rpath
is set to the following value:Of course, this will only help on a system that supports an
rpath
feature known tocmake
. Windows has no such feature anyway, apparently.