From 533aea12f11c05448cc41932ab1191382583edff Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 19 Jun 2025 12:16:43 +0100 Subject: [PATCH] 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. --- CMakeLists.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 02abaa970f..3d1c760ecf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,10 +33,13 @@ set(CMAKE_C_EXTENSIONS OFF) #============================= # Configurable options #============================= -option(BUILD_SHARED_LIBS "Build shared libraries." ON) -option(SECP256K1_DISABLE_SHARED "Disable shared library. Overrides BUILD_SHARED_LIBS." OFF) -if(SECP256K1_DISABLE_SHARED) - set(BUILD_SHARED_LIBS OFF) +if(PROJECT_IS_TOP_LEVEL) + option(BUILD_SHARED_LIBS "Build shared libraries." ON) +else() + option(SECP256K1_DISABLE_SHARED "Disable shared library. Overrides BUILD_SHARED_LIBS." OFF) + if(SECP256K1_DISABLE_SHARED) + set(BUILD_SHARED_LIBS OFF) + endif() endif() option(SECP256K1_INSTALL "Enable installation." ${PROJECT_IS_TOP_LEVEL})