Skip to content

Commit 20e3b44

Browse files
Merge #1688: cmake: Avoid contaminating parent project's cache with BUILD_SHARED_LIBS
7b07b22 cmake: Avoid contaminating parent project's cache with BUILD_SHARED_LIBS (Hennadii Stepanov) Pull request description: 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`: ``` $ cmake -B build -DBUILD_KERNEL_LIB=ON ``` According to CMake’s documentation, this should configure `libbitcoinkernel` as `STATIC`. However, that's not the case: ``` $ cmake --build build -t libbitcoinkernel [143/143] Linking CXX shared library lib/libbitcoinkernel.so ``` This PR: 1. Sets the `BUILD_SHARED_LIBS` cache variable only when `libsecp256k1` is the top-level project. 2. 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](bitcoin-core/minisketch#75 (comment)). ACKs for top commit: purpleKarrot: ACK 7b07b22 theuni: utACK 7b07b22 Tree-SHA512: 399a02e86093656ce70d9a0292a1f30834bcc5b9cf0f77d6465adc5e8a4d8e779684adedc40942eb931fed857399e4176a23fdbdf45f277184b28159fbc932d2
2 parents 2c076d9 + 7b07b22 commit 20e3b44

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ set(CMAKE_C_EXTENSIONS OFF)
3434
#=============================
3535
# Configurable options
3636
#=============================
37-
option(BUILD_SHARED_LIBS "Build shared libraries." ON)
38-
option(SECP256K1_DISABLE_SHARED "Disable shared library. Overrides BUILD_SHARED_LIBS." OFF)
39-
if(SECP256K1_DISABLE_SHARED)
40-
set(BUILD_SHARED_LIBS OFF)
37+
if(libsecp256k1_IS_TOP_LEVEL)
38+
option(BUILD_SHARED_LIBS "Build shared libraries." ON)
4139
endif()
4240

4341
option(SECP256K1_INSTALL "Enable installation." ${PROJECT_IS_TOP_LEVEL})

0 commit comments

Comments
 (0)