From c5766bb2c48634925c8685b779ec814edc43d17b Mon Sep 17 00:00:00 2001 From: Matan Breizman Date: Tue, 4 Feb 2025 10:24:43 +0000 Subject: [PATCH] CMakeLists: Fallback to RelWithDebInfo Currently, if .git exists, we set CMAKE_BUILD_TYPE=Debug. Otherwise, we leave it empty and no optimization flags will be used. With this change, the fallback CMAKE_BUILD_TYPE is set to RelWithDebInfo instead. From CMAKE_BUILD_TYPE manual: The default value is often an empty string, but this is usually not desirable and one of the other standard build types is usually more appropriate. Note: One notable change is that -DNDEBUG will now be defined. Signed-off-by: Matan Breizman --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ded471e2ded1..9d81e8f391b96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,12 +16,14 @@ if(NOT CMAKE_BUILD_TYPE) if (EXISTS "${CMAKE_SOURCE_DIR}/.git") message(WARNING "CMAKE_BUILD_TYPE not specified, assuming CMAKE_BUILD_TYPE=Debug because .git exists.") set(default_build_type "Debug") - set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE - STRING "Default BUILD_TYPE is Debug, other options are: RelWithDebInfo, Release, and MinSizeRel." FORCE) else() - message(WARNING "CMAKE_BUILD_TYPE not specified, leaving unset because .git does NOT exist.") + message(WARNING "CMAKE_BUILD_TYPE not specified, setting to RelWithDebInfo because .git does NOT exist.") + set(default_build_type "RelWithDebInfo") endif() + set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE + STRING "BUILD_TYPE is ${default_build_type}, other options are: RelWithDebInfo, Release, and MinSizeRel." FORCE) endif() +message(STATUS "BUILD_TYPE is ${CMAKE_BUILD_TYPE}") if(CMAKE_SYSTEM_NAME MATCHES "Linux") set(LINUX ON) -- 2.39.5