Enable CMake user option BUILD_SHARED_LIB#366
Merged
fbergmann merged 2 commits intosbmlteam:developmentfrom Aug 5, 2024
Merged
Enable CMake user option BUILD_SHARED_LIB#366fbergmann merged 2 commits intosbmlteam:developmentfrom
BUILD_SHARED_LIB#366fbergmann merged 2 commits intosbmlteam:developmentfrom
Conversation
fbergmann
reviewed
Aug 5, 2024
Member
fbergmann
left a comment
There was a problem hiding this comment.
Thanks for the PR, I agree we should honor the BUILD_SHARED_LIBS option if specified. But we should not set a default. I'll make slight changes so that
- if BUILD_SHARED_LIBS is defined and TRUE, only the shared lib is built,
- if it is defined and FALSE only the static one is built
- if not defined the build behavior is the same as before (building both by default, or honoring LIBSBML_SKIP variables)
that should solve your issue, and not change the behavior for anyone else.
fbergmann
approved these changes
Aug 5, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
The CMake configuration does not respect the user option "-DBUILD_SHARED_LIB=<ON/OFF>". Package managers (and users) commonly use this main configuration option to decide whether to build the project as a shared or static library. Specifically, library build systems for dependencies of R-packages expect the
BUILD_SHARED_LIBoption: (Windows build system, MacOS build system).Generally, the
BUILD_SHARED_LIBvariable directly affects the commandadd_library()if no type (SHAREDorSTATIC) is given to the function. Instead ofBUILD_SHARED_LIB, libsbml's CMake setup seems to use the non-canonical optionsLIBSBML_SKIP_SHARED_LIBRARYandLIBSBML_SKIP_STATIC_LIBRARY:https://github.com/sbmlteam/libsbml/blob/a3e217851f18d3c5e8e2b0082fb98176738491e8/src/CMakeLists.txt#L512C1-L513C2
https://github.com/sbmlteam/libsbml/blob/a3e217851f18d3c5e8e2b0082fb98176738491e8/src/CMakeLists.txt#L462C1-L464C2
Motivation and Context
Although I think the libsbml-specific shared/static build config options (LIBSBML_SKIP_<SHARED/STATIC>_LIBRARY) are totally fine, I would suggest enabling the widespread user option
BUILD_SHARED_LIBas well, which would make libsbml also more accessible and easier to implement for developers of packages and toolchains.Types of changes
Checklist:
Testing
I tested the new option manually using the CMake GUI in Windows. It worked as expected: Shared library build can be skipped with the new option "-DBUILD_SHARED_LIB=OFF".