cmake: select static dependency targets in static link #529
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.
When trying a full static build and using the new cmake package config files to specify dependencies, we hit problems where some targets are looking for non-static targets of dependencies (which are not installed when the components are build static-only). This is closely related to the problem reported in: #513
One option is to support two link options, where we have the static-only link specify the static targets of all dependencies. So if we only build
libscr.a
(notlibscr.so
) we linklibscr.a
to the.a
builds of all components. If we buildlibscr.so
, then we link everything to.so
, including linkinglibscr.a
to the.so
versions of all components. That is the approach this PR takes. Similar changes need to be done for all components if we opt for this route. I have those ready.As a second option, we could change this so that
scr::scr
points at the shared objects for all dependencies and havescr::scr-static
point to the-static
versions of all dependencies.As yet a third option, the article linked below suggests a way in which we'd only provide a single
scr::scr
target and then to make ourscrConfig.cmake
script smart enough to have that target point at eitherlibscr.so
orlibscr.a
depending on how the user has setBUILD_SHARED_LIBS
:https://alexreinking.com/blog/building-a-dual-shared-and-static-library-with-cmake.html
That's nice since the end user only needs to link to
scr::scr
but they can flip between shared and static versions oflibscr
by settingBUILD_SHARED_LIBS
during their application build.