Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: link static target to static dependencies #536

Merged
merged 2 commits into from
May 10, 2023
Merged

Conversation

adammoody
Copy link
Contributor

@adammoody adammoody commented Feb 24, 2023

This PR makes the following changes:

  • Update the SCR CMake build targets so that scr::scr links to the shared objects for SCR and its dependent libraries while scr::scr-static links to the static libraries of SCR and its dependencies (where available).
  • Describe how to use scrConfig.cmake in the application integration section of the SCR docs.

The current PR implements the second option listed below, which was copied from a related PR #529.

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 (not libscr.so) we link libscr.a to the .a builds of all components. If we build libscr.so, then we link everything to .so, including linking libscr.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 have scr::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 our scrConfig.cmake script smart enough to have that target point at either libscr.so or libscr.a depending on how the user has set BUILD_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 of libscr by setting BUILD_SHARED_LIBS during their application build.

@adammoody adammoody force-pushed the statictarget branch 3 times, most recently from ca7a8bf to 8695be1 Compare May 9, 2023 23:51
@mcfadden8
Copy link
Collaborator

mcfadden8 commented May 10, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants