[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
This commit is contained in:
Victor Perevertkin 2021-04-15 04:52:59 +03:00
parent f0b53998c8
commit d10728a645
No known key found for this signature in database
GPG Key ID: C750B7222E9C7830
4 changed files with 17 additions and 26 deletions

View File

@ -49,6 +49,16 @@ else()
set(WINARCH ${ARCH})
endif()
# set CMAKE_BUILD_TYPE if not set
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to Debug as none was specified.")
set(CMAKE_BUILD_TYPE "Debug" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# Versioning
include(sdk/include/reactos/version.cmake)

View File

@ -1,9 +1,5 @@
#if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# no optimization
add_compile_options(/Ob0 /Od)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_options(/Ox /Ob2 /Ot /Oy /GT)
elseif(OPTIMIZE STREQUAL "1")
add_compile_options(/O1)
@ -12,7 +8,7 @@ elseif(OPTIMIZE STREQUAL "2")
elseif(OPTIMIZE STREQUAL "3")
add_compile_options(/Ot /Ox /GS-)
elseif(OPTIMIZE STREQUAL "4")
add_compile_options(/Os /Ox /GS-)
add_compile_options(/Ob0 /Od)
elseif(OPTIMIZE STREQUAL "5")
add_compile_options(/Gy /Ob2 /Os /Ox /GS-)
endif()
@ -116,8 +112,8 @@ add_compile_options(/wd4018)
add_compile_options(/we4013 /we4020 /we4022 /we4028 /we4047 /we4098 /we4101 /we4113 /we4129 /we4133 /we4163 /we4229 /we4311 /we4312 /we4313 /we4477 /we4603 /we4700 /we4715 /we4716)
# - C4189: local variable initialized but not referenced
# Not in Release mode
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
# Not in Release mode, msbuild generator doesn't like CMAKE_BUILD_TYPE
if(MSVC_IDE OR CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(/we4189)
endif()
@ -130,13 +126,10 @@ if(USE_CLANG_CL)
endif()
# Debugging
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(NOT (_PREFAST_ OR _VS_ANALYZE_))
add_compile_options(/Zi)
endif()
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions("/D NDEBUG")
add_compile_options($<$<CONFIG:Debug>:/Zi>)
endif()
add_compile_definitions($<$<CONFIG:Release>:NDEBUG>)
# Hotpatchable images
if(ARCH STREQUAL "i386")

View File

@ -1,10 +1,4 @@
# Default to Debug for the build type
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
endif()
# pass variables necessary for the toolchain (needed for try_compile)
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ARCH)

View File

@ -1,10 +1,4 @@
# Default to Debug for the build type
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
endif()
# pass variables necessary for the toolchain (needed for try_compile)
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ARCH USE_CLANG_CL)