Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
pkgsStatic: set BUILD_SHARED_LIBS=OFF for cmake #76659
Motivation for this change
While reviewing #75798 I've noticed a repetitive pattern of setting BUILD_SHARED_LIBS=OFF for many of the cmake builds. It makes sense to just set it for all builds.
CMake has a BUILD_SHARED_LIBS option which governs the behaviour of the add_library() function in case when the library type is not specified. Its default value is "OFF" meaning default to STATIC. It is not uncommon to explicitly redefine the option:
option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF)
This adds the BUILD_SHARED_LIBS option to the list of options in the CMake gui. There is a different variation of the redefinition where the default value is changed to "ON".
Some packages allow to provide both shared and static libraries. Additional custom options are defined to facilitate this. These options may or may not break the default convention for the BUILD_SHARED_LIBS.
Here are a few data points for nixpkgs:
This PR should help with 39 cases where we enabled building of shared libraries. It will also help in cases when the default value of the BUILD_STATIC_LIBS option was changed to "ON"
See @orivej comments on this:
from #56391 (comment)
It may still be okay to just enable it in the static overlay though. The above PR was doing this for everything.
Yes, I was considering doing that. I've also seen other other custom options like