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. - Removes the
SECP256K1_DISABLE_SHARED
cache variable. This enables parent projects that include libsecp256k1 as a subproject to rely solely on standard CMake variables for configuring the library type. During integration into a parent project, the static library can be forced as demonstrated here.