From dd3ca04a7abdb2ce3085874d7f6b9fa512b3438a Mon Sep 17 00:00:00 2001 From: Ashish Ahuja Date: Sat, 1 Nov 2025 21:25:59 +0530 Subject: [PATCH] set CMAKE_BUILD_TYPE only in top-level project (#3480) --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 882aa90e..bca70042 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 "Release" CACHE STRING "Choose Release or Debug" FORCE) + # 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() # ---------------------------------------------------------------------------------------