Enable CMake user option BUILD_SHARED_LIB
#366
Merged
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".