Skip to content

Commit 35c0fdc

Browse files
Merge #1529: cmake: Fix cache issue when integrating by downstream project
ec4c002 cmake: Simplify `PROJECT_IS_TOP_LEVEL` emulation (Hennadii Stepanov) cae9a7a cmake: Do not set emulated PROJECT_IS_TOP_LEVEL as cache variable (Hennadii Stepanov) Pull request description: As CMake's cache is a global database, modifying it within a project integrated with the `add_subdirectory()` command, which may also include using the `FetchContent` module, could potentially affect downstream projects and sibling ones. ACKs for top commit: real-or-random: utACK ec4c002 theuni: utACK ec4c002 Tree-SHA512: de2c8c583367028d06701f79fc5232b351622c8496d196aad8c22a1ec4e450af53e556a4f6526ed47250f818143a69a12f5fc8cc755c864510e67530dacde66e
2 parents 4392f0f + ec4c002 commit 35c0fdc

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

CMakeLists.txt

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ project(libsecp256k1
1818
)
1919

2020
if(CMAKE_VERSION VERSION_LESS 3.21)
21-
get_directory_property(parent_directory PARENT_DIRECTORY)
22-
if(parent_directory)
23-
set(PROJECT_IS_TOP_LEVEL OFF CACHE INTERNAL "Emulates CMake 3.21+ behavior.")
24-
set(${PROJECT_NAME}_IS_TOP_LEVEL OFF CACHE INTERNAL "Emulates CMake 3.21+ behavior.")
21+
# Emulates CMake 3.21+ behavior.
22+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
23+
set(PROJECT_IS_TOP_LEVEL ON)
24+
set(${PROJECT_NAME}_IS_TOP_LEVEL ON)
2525
else()
26-
set(PROJECT_IS_TOP_LEVEL ON CACHE INTERNAL "Emulates CMake 3.21+ behavior.")
27-
set(${PROJECT_NAME}_IS_TOP_LEVEL ON CACHE INTERNAL "Emulates CMake 3.21+ behavior.")
26+
set(PROJECT_IS_TOP_LEVEL OFF)
27+
set(${PROJECT_NAME}_IS_TOP_LEVEL OFF)
2828
endif()
29-
unset(parent_directory)
3029
endif()
3130

3231
# The library version is based on libtool versioning of the ABI. The set of

0 commit comments

Comments
 (0)