[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}) set(WINARCH ${ARCH})
endif() 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 # Versioning
include(sdk/include/reactos/version.cmake) include(sdk/include/reactos/version.cmake)

View file

@ -1,9 +1,5 @@
#if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# no optimization
add_compile_options(/Ob0 /Od)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_options(/Ox /Ob2 /Ot /Oy /GT) add_compile_options(/Ox /Ob2 /Ot /Oy /GT)
elseif(OPTIMIZE STREQUAL "1") elseif(OPTIMIZE STREQUAL "1")
add_compile_options(/O1) add_compile_options(/O1)
@ -12,7 +8,7 @@ elseif(OPTIMIZE STREQUAL "2")
elseif(OPTIMIZE STREQUAL "3") elseif(OPTIMIZE STREQUAL "3")
add_compile_options(/Ot /Ox /GS-) add_compile_options(/Ot /Ox /GS-)
elseif(OPTIMIZE STREQUAL "4") elseif(OPTIMIZE STREQUAL "4")
add_compile_options(/Os /Ox /GS-) add_compile_options(/Ob0 /Od)
elseif(OPTIMIZE STREQUAL "5") elseif(OPTIMIZE STREQUAL "5")
add_compile_options(/Gy /Ob2 /Os /Ox /GS-) add_compile_options(/Gy /Ob2 /Os /Ox /GS-)
endif() 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) 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 # - C4189: local variable initialized but not referenced
# Not in Release mode # Not in Release mode, msbuild generator doesn't like CMAKE_BUILD_TYPE
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release") if(MSVC_IDE OR CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(/we4189) add_compile_options(/we4189)
endif() endif()
@ -130,13 +126,10 @@ if(USE_CLANG_CL)
endif() endif()
# Debugging # Debugging
if(CMAKE_BUILD_TYPE STREQUAL "Debug") if(NOT (_PREFAST_ OR _VS_ANALYZE_))
if(NOT (_PREFAST_ OR _VS_ANALYZE_)) add_compile_options($<$<CONFIG:Debug>:/Zi>)
add_compile_options(/Zi)
endif()
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions("/D NDEBUG")
endif() endif()
add_compile_definitions($<$<CONFIG:Release>:NDEBUG>)
# Hotpatchable images # Hotpatchable images
if(ARCH STREQUAL "i386") 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) # pass variables necessary for the toolchain (needed for try_compile)
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ARCH) 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) # pass variables necessary for the toolchain (needed for try_compile)
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ARCH USE_CLANG_CL) set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ARCH USE_CLANG_CL)