Skip to content

Commit ec4c002

Browse files
committed
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.
1 parent cae9a7a commit ec4c002

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

CMakeLists.txt

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ project(libsecp256k1
1919

2020
if(CMAKE_VERSION VERSION_LESS 3.21)
2121
# Emulates CMake 3.21+ behavior.
22-
get_directory_property(parent_directory PARENT_DIRECTORY)
23-
if(parent_directory)
24-
set(PROJECT_IS_TOP_LEVEL OFF)
25-
set(${PROJECT_NAME}_IS_TOP_LEVEL OFF)
26-
else()
22+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
2723
set(PROJECT_IS_TOP_LEVEL ON)
2824
set(${PROJECT_NAME}_IS_TOP_LEVEL ON)
25+
else()
26+
set(PROJECT_IS_TOP_LEVEL OFF)
27+
set(${PROJECT_NAME}_IS_TOP_LEVEL OFF)
2928
endif()
30-
unset(parent_directory)
3129
endif()
3230

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

0 commit comments

Comments
 (0)