The CMake cache is global in scope. Therefore, setting the standard cache variable BUILD_SHARED_LIBS
can inadvertently affect the behavior of a parent project.
Consider configuring Bitcoin Core without explicit setting BUILD_SHARED_LIBS
:
0$ cmake -B build -DBUILD_KERNEL_LIB=ON
According to CMake’s documentation, this should configure libbitcoinkernel
as STATIC
.
However, that’s not the case:
0$ cmake --build build -t libbitcoinkernel
1[143/143] Linking CXX shared library lib/libbitcoinkernel.so
This PR:
- Sets the
BUILD_SHARED_LIBS
cache variable only whenlibsecp256k1
is the top-level project. - Uses the
SECP256K1_DISABLE_SHARED
cache variable only whenlibsecp256k1
is included as a subproject.
Alternatively, the entire code block can be dropped. In that case:
- The CMake-base build system will build a static library by default.
- During integration into a parent project, the static library can be forced as demonstrated here.