From 9fc3a20d0f2096b4de8d9ff50abd2931f8accf38 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 26 Jan 2023 11:07:08 +0300 Subject: [PATCH] cmake: prevent overriding CMAKE_BUILD_TYPE if it is subdirectory --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 774bd2a03..f834dd2e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,9 @@ else() add_compile_options(-Wall -Werror -O3) endif() -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) +get_directory_property(hasParent PARENT_DIRECTORY) + +if(NOT hasParent AND NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.") set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE) # Set the possible values of build type for cmake-gui