Skip to content

Commit d10728a

Browse files
committed
[CMAKE] Rely less on CMAKE_BUILD_TYPE variable
Having conditional statements with CMAKE_BUILD_TYPE is an antipattern See https://stackoverflow.com/questions/66079007/having-conditional-statements-on-build-type-variable-a-good-design We use both single- and multi-config generators (Ninja and VS), so we can't really rely on CMAKE_BUILD_TYPE, because it's not always set. This commit alters some conditional flags to use <$CONFIG:...> generator expression, but is still not complete. Also, our default optimization level (4) now has what was always a de-facto flags
1 parent f0b5399 commit d10728a

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ else()
4949
set(WINARCH ${ARCH})
5050
endif()
5151

52+
# set CMAKE_BUILD_TYPE if not set
53+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
54+
message(STATUS "Setting build type to Debug as none was specified.")
55+
set(CMAKE_BUILD_TYPE "Debug" CACHE
56+
STRING "Choose the type of build." FORCE)
57+
# Set the possible values of build type for cmake-gui
58+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
59+
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
60+
endif()
61+
5262
# Versioning
5363
include(sdk/include/reactos/version.cmake)
5464

sdk/cmake/msvc.cmake

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11

2-
#if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
3-
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
4-
# no optimization
5-
add_compile_options(/Ob0 /Od)
6-
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
2+
if(CMAKE_BUILD_TYPE STREQUAL "Release")
73
add_compile_options(/Ox /Ob2 /Ot /Oy /GT)
84
elseif(OPTIMIZE STREQUAL "1")
95
add_compile_options(/O1)
@@ -12,7 +8,7 @@ elseif(OPTIMIZE STREQUAL "2")
128
elseif(OPTIMIZE STREQUAL "3")
139
add_compile_options(/Ot /Ox /GS-)
1410
elseif(OPTIMIZE STREQUAL "4")
15-
add_compile_options(/Os /Ox /GS-)
11+
add_compile_options(/Ob0 /Od)
1612
elseif(OPTIMIZE STREQUAL "5")
1713
add_compile_options(/Gy /Ob2 /Os /Ox /GS-)
1814
endif()
@@ -116,8 +112,8 @@ add_compile_options(/wd4018)
116112
add_compile_options(/we4013 /we4020 /we4022 /we4028 /we4047 /we4098 /we4101 /we4113 /we4129 /we4133 /we4163 /we4229 /we4311 /we4312 /we4313 /we4477 /we4603 /we4700 /we4715 /we4716)
117113

118114
# - C4189: local variable initialized but not referenced
119-
# Not in Release mode
120-
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
115+
# Not in Release mode, msbuild generator doesn't like CMAKE_BUILD_TYPE
116+
if(MSVC_IDE OR CMAKE_BUILD_TYPE STREQUAL "Debug")
121117
add_compile_options(/we4189)
122118
endif()
123119

@@ -130,13 +126,10 @@ if(USE_CLANG_CL)
130126
endif()
131127

132128
# Debugging
133-
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
134-
if(NOT (_PREFAST_ OR _VS_ANALYZE_))
135-
add_compile_options(/Zi)
136-
endif()
137-
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
138-
add_definitions("/D NDEBUG")
129+
if(NOT (_PREFAST_ OR _VS_ANALYZE_))
130+
add_compile_options($<$<CONFIG:Debug>:/Zi>)
139131
endif()
132+
add_compile_definitions($<$<CONFIG:Release>:NDEBUG>)
140133

141134
# Hotpatchable images
142135
if(ARCH STREQUAL "i386")

toolchain-gcc.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11

2-
# Default to Debug for the build type
3-
if(NOT DEFINED CMAKE_BUILD_TYPE)
4-
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
5-
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
6-
endif()
7-
82
# pass variables necessary for the toolchain (needed for try_compile)
93
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ARCH)
104

toolchain-msvc.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11

2-
# Default to Debug for the build type
3-
if(NOT DEFINED CMAKE_BUILD_TYPE)
4-
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
5-
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
6-
endif()
7-
82
# pass variables necessary for the toolchain (needed for try_compile)
93
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ARCH USE_CLANG_CL)
104

0 commit comments

Comments
 (0)