set CMAKE_BUILD_TYPE only in top-level project (#3480)

This commit is contained in:
Ashish Ahuja
2025-11-01 21:25:59 +05:30
committed by GitHub
parent 486b55554f
commit dd3ca04a7a

View File

@@ -19,7 +19,11 @@ include(GNUInstallDirs)
# Set default build to release
# ---------------------------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
# Set CMAKE_BUILD_TYPE only if this project is top-level
if((DEFINED PROJECT_IS_TOP_LEVEL AND PROJECT_IS_TOP_LEVEL)
OR (NOT DEFINED PROJECT_IS_TOP_LEVEL AND CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR))
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
endif()
endif()
# ---------------------------------------------------------------------------------------