Skip to content

Commit dd3ca04

Browse files
authored
set CMAKE_BUILD_TYPE only in top-level project (#3480)
1 parent 486b555 commit dd3ca04

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ include(GNUInstallDirs)
1919
# Set default build to release
2020
# ---------------------------------------------------------------------------------------
2121
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
22-
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
22+
# Set CMAKE_BUILD_TYPE only if this project is top-level
23+
if((DEFINED PROJECT_IS_TOP_LEVEL AND PROJECT_IS_TOP_LEVEL)
24+
OR (NOT DEFINED PROJECT_IS_TOP_LEVEL AND CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR))
25+
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
26+
endif()
2327
endif()
2428

2529
# ---------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)