[CMAKE] Get rid of add_compile_flags

Use add_compile_options and the like instead
This commit is contained in:
Jérôme Gardou 2020-09-21 12:16:02 +02:00 committed by Jérôme Gardou
parent 84621b3634
commit 00ed72d7e8
26 changed files with 158 additions and 198 deletions

View file

@ -48,19 +48,3 @@ function(add_target_link_flags _module _flags)
endif()
add_target_property(${_module} LINK_FLAGS ${_flags})
endfunction()
# add_compile_flags
# Add or replace compiler flags in the global scope for either all source
# files or only those of the specified language.
#
# Examples:
# add_compile_flags("-pedantic -O5")
function(add_compile_flags _flags)
if(${ARGC} GREATER 1)
message(FATAL_ERROR "Excess arguments to add_compile_flags! Args ${ARGN}")
endif()
# Adds the compiler flag for all code files: C, C++, and assembly
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flags}" PARENT_SCOPE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flags}" PARENT_SCOPE)
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${_flags}" PARENT_SCOPE)
endfunction()

View file

@ -35,18 +35,17 @@ if(USE_DUMMY_PSEH)
endif()
if(STACK_PROTECTOR)
add_compile_flags(${MODULE} "-fstack-protector-all")
add_compile_options(-fstack-protector-all)
endif()
# Compiler Core
add_compile_flags("-pipe -fms-extensions -fno-strict-aliasing")
add_compile_options(-pipe -fms-extensions -fno-strict-aliasing)
# Prevent GCC from searching any of the default directories.
# The case for C++ is handled through the reactos_c++ INTERFACE library
add_compile_options("$<$<NOT:$<COMPILE_LANGUAGE:CXX>>:-nostdinc>")
add_compile_flags("-mstackrealign")
add_compile_flags("-fno-aggressive-loop-optimizations")
add_compile_options(-mstackrealign -fno-aggressive-loop-optimizations)
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-std=gnu99;-Wno-microsoft>")
@ -72,81 +71,81 @@ endif()
# Debugging
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
if(SEPARATE_DBG)
add_compile_flags("-gdwarf-2 -ggdb")
add_compile_options(-gdwarf-2 -ggdb)
else()
add_compile_flags("-gdwarf-2 -gstrict-dwarf")
if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_compile_flags("-femit-struct-debug-detailed=none -feliminate-unused-debug-symbols")
add_compile_options(-gdwarf-2 -gstrict-dwarf)
if(NOT CMAKE_C_COMPILER_ID STREQUAL Clang)
add_compile_options(-femit-struct-debug-detailed=none -feliminate-unused-debug-symbols)
endif()
endif()
endif()
# Tuning
if(ARCH STREQUAL "i386")
add_compile_flags("-march=${OARCH} -mtune=${TUNE}")
add_compile_options(-march=${OARCH} -mtune=${TUNE})
else()
add_compile_flags("-march=${OARCH}")
add_compile_options(-march=${OARCH})
endif()
# Warnings, errors
if((NOT CMAKE_BUILD_TYPE STREQUAL "Release") AND (NOT CMAKE_C_COMPILER_ID STREQUAL "Clang"))
add_compile_flags("-Werror")
if((NOT CMAKE_BUILD_TYPE STREQUAL "Release") AND (NOT CMAKE_C_COMPILER_ID STREQUAL Clang))
add_compile_options(-Werror)
endif()
add_compile_flags("-Wall -Wpointer-arith")
add_compile_flags("-Wno-char-subscripts -Wno-multichar -Wno-unused-value")
add_compile_flags("-Wno-unused-const-variable")
add_compile_flags("-Wno-unused-local-typedefs")
add_compile_flags("-Wno-deprecated")
add_compile_options(-Wall -Wpointer-arith)
add_compile_options(-Wno-char-subscripts -Wno-multichar -Wno-unused-value)
add_compile_options(-Wno-unused-const-variable)
add_compile_options(-Wno-unused-local-typedefs)
add_compile_options(-Wno-deprecated)
if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_compile_flags("-Wno-maybe-uninitialized")
add_compile_options(-Wno-maybe-uninitialized)
endif()
if(ARCH STREQUAL "amd64")
add_compile_flags("-Wno-format")
add_compile_options(-Wno-format)
elseif(ARCH STREQUAL "arm")
add_compile_flags("-Wno-attributes")
add_compile_options(-Wno-attributes)
endif()
# Optimizations
# FIXME: Revisit this to see if we even need these levels
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_flags("-O2 -DNDEBUG")
add_compile_options(-O2 -DNDEBUG)
else()
if(OPTIMIZE STREQUAL "1")
add_compile_flags("-Os -ftracer")
add_compile_options(-Os -ftracer)
elseif(OPTIMIZE STREQUAL "2")
add_compile_flags("-Os")
add_compile_options(-Os)
elseif(OPTIMIZE STREQUAL "3")
add_compile_flags("-Og")
add_compile_options(-Og)
elseif(OPTIMIZE STREQUAL "4")
add_compile_flags("-O1")
add_compile_options(-O1)
elseif(OPTIMIZE STREQUAL "5")
add_compile_flags("-O2")
add_compile_options(-O2)
elseif(OPTIMIZE STREQUAL "6")
add_compile_flags("-O3")
add_compile_options(-O3)
elseif(OPTIMIZE STREQUAL "7")
add_compile_flags("-Ofast")
add_compile_options(-Ofast)
endif()
endif()
# Link-time code generation
if(LTCG)
add_compile_flags("-flto -fno-fat-lto-objects")
add_compile_options(-flto -fno-fat-lto-objects)
endif()
if(ARCH STREQUAL "i386")
add_compile_flags("-fno-optimize-sibling-calls -fno-omit-frame-pointer")
add_compile_options(-fno-optimize-sibling-calls -fno-omit-frame-pointer)
if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_compile_flags("-mpreferred-stack-boundary=3 -fno-set-stack-executable")
add_compile_options(-mpreferred-stack-boundary=3 -fno-set-stack-executable)
endif()
# FIXME: this doesn't work. CMAKE_BUILD_TYPE is always "Debug"
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_flags("-momit-leaf-frame-pointer")
add_compile_options(-momit-leaf-frame-pointer)
endif()
elseif(ARCH STREQUAL "amd64")
add_compile_flags("-mpreferred-stack-boundary=4")
add_compile_options(-mpreferred-stack-boundary=4)
endif()
# Other

View file

@ -2,32 +2,29 @@
#if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# no optimization
add_compile_flags("/Ob0 /Od")
add_compile_options(/Ob0 /Od)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_flags("/Ox /Ob2 /Ot /Oy /GT")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:REF /OPT:ICF")
add_compile_options(/Ox /Ob2 /Ot /Oy /GT)
elseif(OPTIMIZE STREQUAL "1")
add_compile_flags("/O1")
add_compile_options(/O1)
elseif(OPTIMIZE STREQUAL "2")
add_compile_flags("/O2")
add_compile_options(/O2)
elseif(OPTIMIZE STREQUAL "3")
add_compile_flags("/Ot /Ox /GS-")
add_compile_options(/Ot /Ox /GS-)
elseif(OPTIMIZE STREQUAL "4")
add_compile_flags("/Os /Ox /GS-")
add_compile_options(/Os /Ox /GS-)
elseif(OPTIMIZE STREQUAL "5")
add_compile_flags("/Gy /Ob2 /Os /Ox /GS-")
add_compile_options(/Gy /Ob2 /Os /Ox /GS-)
endif()
# Always use string pooling: this helps reducing the binaries size since a lot
# of redundancy come from the usage of __FILE__ / __RELFILE__ in the debugging
# helper macros. Note also that GCC builds use string pooling by default.
add_compile_flags("/GF")
add_compile_options(/GF)
# Enable function level linking and comdat folding
add_compile_flags("/Gy")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /OPT:REF /OPT:ICF")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /OPT:REF /OPT:ICF")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:REF /OPT:ICF")
add_compile_options(/Gy)
add_link_options(/OPT:REF /OPT:ICF)
if(ARCH STREQUAL "i386")
add_definitions(/DWIN32 /D_WINDOWS)
@ -37,12 +34,11 @@ add_definitions(/Dinline=__inline /D__STDC__=1)
# Ignore any "standard" include paths, and do not use any default CRT library.
if(NOT USE_CLANG_CL)
add_compile_flags("/X /Zl")
add_compile_options(/X /Zl)
endif()
# Disable RTTI, exception handling and buffer security checks by default.
# These require run-time support that may not always be available.
add_compile_flags("/GS-")
# Disable buffer security checks by default.
add_compile_options(/GS-)
if(USE_CLANG_CL)
set(CMAKE_CL_SHOWINCLUDES_PREFIX "Note: including file: ")
@ -53,29 +49,29 @@ endif()
if(ARCH STREQUAL "i386")
# Clang's IA32 means i386, which doesn't have cmpxchg8b
if(USE_CLANG_CL)
add_compile_flags("-march=${OARCH}")
add_compile_options(-march=${OARCH})
else()
add_compile_flags("/arch:IA32")
add_compile_options(/arch:IA32)
endif()
endif()
# VS 12+ requires /FS when used in parallel compilations
if(NOT MSVC_IDE)
add_compile_flags("/FS")
add_compile_options(/FS)
endif()
# VS14+ tries to use thread-safe initialization
add_compile_flags("/Zc:threadSafeInit-")
add_compile_options(/Zc:threadSafeInit-)
# HACK: Disable use of __CxxFrameHandler4 on VS 16.3+ (x64 only)
# See https://developercommunity.visualstudio.com/content/problem/746534/visual-c-163-runtime-uses-an-unsupported-api-for-u.html
if(ARCH STREQUAL "amd64" AND MSVC_VERSION GREATER 1922)
add_compile_flags("/d2FH4-")
add_link_options("/d2:-FH4-")
add_compile_options(/d2FH4-)
add_link_options(/d2:-FH4-)
endif()
# Generate Warnings Level 3
add_compile_flags("/W3")
add_compile_options(/W3)
# Disable overly sensitive warnings as well as those that generally aren't
# useful to us.
@ -84,10 +80,10 @@ add_compile_flags("/W3")
# - C4800: forcing value to bool 'true' or 'false' (performance warning)
# - C4200: nonstandard extension used : zero-sized array in struct/union
# - C4214: nonstandard extension used : bit field types other than int
add_compile_flags("/wd4244 /wd4290 /wd4800 /wd4200 /wd4214")
add_compile_options(/wd4244 /wd4290 /wd4800 /wd4200 /wd4214)
# FIXME: Temporarily disable C4018 until we fix more of the others. CORE-10113
add_compile_flags("/wd4018")
add_compile_options(/wd4018)
# The following warnings are treated as errors:
# - C4013: implicit function declaration
@ -122,19 +118,17 @@ endif()
# Enable warnings above the default level, but don't treat them as errors:
# - C4115: named type definition in parentheses
add_compile_flags("/w14115")
add_compile_options(/w14115)
if(USE_CLANG_CL)
add_compile_options("$<$<COMPILE_LANGUAGE:C,CXX>:-nostdinc;-Wno-multichar;-Wno-char-subscripts;-Wno-microsoft-enum-forward-reference;-Wno-pragma-pack;-Wno-microsoft-anon-tag;-Wno-parentheses-equality;-Wno-unknown-pragmas>")
endif()
# Debugging
#if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(NOT (_PREFAST_ OR _VS_ANALYZE_))
add_compile_flags("/Zi")
add_compile_options(/Zi)
endif()
#elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions("/D NDEBUG")
endif()
@ -155,12 +149,11 @@ endif()
if(RUNTIME_CHECKS)
add_definitions(-D__RUNTIME_CHECKS__)
add_compile_flags("/RTC1")
add_compile_options(/RTC1)
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE ${_hotpatch_link_flag} /IGNORE:4039")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE ${_hotpatch_link_flag} /IGNORE:4104 /IGNORE:4039")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE ${_hotpatch_link_flag} /IGNORE:4039")
add_link_options(/MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE ${_hotpatch_link_flag} /IGNORE:4039)
set(CMAKE_MSVC_RUNTIME_LIBRARY "")
# HACK: Remove the /implib argument, implibs are generated separately
@ -202,7 +195,7 @@ endif()
if(_VS_ANALYZE_)
message("VS static analysis enabled!")
add_compile_flags("/analyze")
add_compile_options(/analyze)
elseif(_PREFAST_)
message("PREFAST enabled!")
set(CMAKE_C_COMPILE_OBJECT "prefast <CMAKE_C_COMPILER> ${CMAKE_START_TEMP_FILE} ${CMAKE_CL_NOLOGO} <INCLUDES> <FLAGS> <DEFINES> /Fo<OBJECT> -c <SOURCE>${CMAKE_END_TEMP_FILE}"