From cae9a7ad149d359c061372107d212cdcfad5d323 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sat, 11 May 2024 11:05:12 +0100 Subject: [PATCH 1/2] cmake: Do not set emulated PROJECT_IS_TOP_LEVEL as cache variable Otherwise, downstream projects, which integrate the libsecp256k1 library using the `add_subdirectory()` command, will be affected. --- CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88994d828a..27d6e64316 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,13 +18,14 @@ project(libsecp256k1 ) if(CMAKE_VERSION VERSION_LESS 3.21) + # Emulates CMake 3.21+ behavior. get_directory_property(parent_directory PARENT_DIRECTORY) if(parent_directory) - set(PROJECT_IS_TOP_LEVEL OFF CACHE INTERNAL "Emulates CMake 3.21+ behavior.") - set(${PROJECT_NAME}_IS_TOP_LEVEL OFF CACHE INTERNAL "Emulates CMake 3.21+ behavior.") + set(PROJECT_IS_TOP_LEVEL OFF) + set(${PROJECT_NAME}_IS_TOP_LEVEL OFF) else() - set(PROJECT_IS_TOP_LEVEL ON CACHE INTERNAL "Emulates CMake 3.21+ behavior.") - set(${PROJECT_NAME}_IS_TOP_LEVEL ON CACHE INTERNAL "Emulates CMake 3.21+ behavior.") + set(PROJECT_IS_TOP_LEVEL ON) + set(${PROJECT_NAME}_IS_TOP_LEVEL ON) endif() unset(parent_directory) endif() From ec4c002faa350f02919fe0f710279d2922e254a1 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sat, 11 May 2024 11:13:41 +0100 Subject: [PATCH 2/2] cmake: Simplify `PROJECT_IS_TOP_LEVEL` emulation Detecting whether it is the top level by comparing the value of `CMAKE_SOURCE_DIR` with `CMAKE_CURRENT_SOURCE_DIR` is supported by all versions of CMake and is a very common pattern. --- CMakeLists.txt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27d6e64316..fffa123d99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,15 +19,13 @@ project(libsecp256k1 if(CMAKE_VERSION VERSION_LESS 3.21) # Emulates CMake 3.21+ behavior. - get_directory_property(parent_directory PARENT_DIRECTORY) - if(parent_directory) - set(PROJECT_IS_TOP_LEVEL OFF) - set(${PROJECT_NAME}_IS_TOP_LEVEL OFF) - else() + if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(PROJECT_IS_TOP_LEVEL ON) set(${PROJECT_NAME}_IS_TOP_LEVEL ON) + else() + set(PROJECT_IS_TOP_LEVEL OFF) + set(${PROJECT_NAME}_IS_TOP_LEVEL OFF) endif() - unset(parent_directory) endif() # The library version is based on libtool versioning of the ABI. The set of