Skip to content

Commit 533aea1

Browse files
committed
cmake: Avoid contaminating parent project's cache with BUILD_SHARED_LIBS
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. This change: 1. Sets the `BUILD_SHARED_LIBS` cache variable only when libsecp256k1 is the top-level project. 2. Uses the `SECP256K1_DISABLE_SHARED` cache variable only when libsecp256k1 is included as a subproject.
1 parent 95db29b commit 533aea1

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ set(CMAKE_C_EXTENSIONS OFF)
3333
#=============================
3434
# Configurable options
3535
#=============================
36-
option(BUILD_SHARED_LIBS "Build shared libraries." ON)
37-
option(SECP256K1_DISABLE_SHARED "Disable shared library. Overrides BUILD_SHARED_LIBS." OFF)
38-
if(SECP256K1_DISABLE_SHARED)
39-
set(BUILD_SHARED_LIBS OFF)
36+
if(PROJECT_IS_TOP_LEVEL)
37+
option(BUILD_SHARED_LIBS "Build shared libraries." ON)
38+
else()
39+
option(SECP256K1_DISABLE_SHARED "Disable shared library. Overrides BUILD_SHARED_LIBS." OFF)
40+
if(SECP256K1_DISABLE_SHARED)
41+
set(BUILD_SHARED_LIBS OFF)
42+
endif()
4043
endif()
4144

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

0 commit comments

Comments
 (0)