[wip] pass -rpath-link via CMakeToolchain #18068
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CMake itself tries to pass
-rpath
(and-rpath-link
) to the linker (via the compiler). However we know this is not sufficient in some scenarios:-rpath-link
globally for the entire build. This would solve problems such as this [fast-dds] Fix crosscompilation issues conan-center-index#25195 - which are recurrent in Conan Center, not that even with the new CMakeDeps, there are corner cases--sysroot
, CMake only passes-rpath
(even correctly, pointing to the directories in the Conan cache) - but in the presence of a sysroot the linker will re-root them in a way that it won't find them inside the sysroot (and fail)Either:
A)
or
B)
A) does not work when we are crossbuilding and we have a sysroot (because the linker reroots them)
B) does not work when crossbuilding (so the recipe may build fine when doing a native build due to this workaround, but wont fully support crossbuilding when using shared libraries), but even when not crossbuilding, it wont work if using a sysroot, or using a toolchain for a separate distro (think
poco
where os=Linux and arch=x86_64). It also introduces risks of runtime clashes when the libraries for the host are picked up by executables that run at build time.Passing
-rpath-link
via the toolchain would remove the need for workarounds and mitigate all of the cases above, including the corner cases where Conan + (new) CMakeDeps + CMake cannot correctly derive that-rpath-link
is needed.WIP: still needs tests and probably a flag to control behaviour