From 4d5b6eb50fe8dd9951d914076838785f8144a4f6 Mon Sep 17 00:00:00 2001 From: PatTheMav Date: Fri, 16 Jun 2023 21:09:52 +0200 Subject: [PATCH] cmake: Disable automatic sorting of compiler flags Also restores original order of compiler flags and more explicitly splits up flags for the specific languages in which they take effect. Notice that ObjC and ObjC++ follow a slightly stricter set of rules than C and C++, which is reflected by this fix. --- cmake/macos/compilerconfig.cmake | 120 ++++++++++++++++--------------- 1 file changed, 62 insertions(+), 58 deletions(-) diff --git a/cmake/macos/compilerconfig.cmake b/cmake/macos/compilerconfig.cmake index dd78ee9c3cae73..6ec013621dbe1e 100644 --- a/cmake/macos/compilerconfig.cmake +++ b/cmake/macos/compilerconfig.cmake @@ -30,78 +30,81 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) # Add default C and C++ compiler options if Xcode generator is not used if(NOT XCODE) - set(_obs_c_options - # cmake-format: sortable + set(_obs_common_options -fno-strict-aliasing - -Wbool-conversion - -Wcomma - -Wconstant-conversion - -Wdeprecated-declarations - -Wempty-body - -Wenum-conversion -Werror - -Werror=block-capture-autoreleasing - -Werror=return-type - -Wextra - -Wformat - -Wformat-security - -Wfour-char-constants - -Winfinite-recursion - -Wint-conversion - -Wnewline-eof - -Wno-conversion - -Wno-error=shorten-64-to-32 - -Wno-float-conversion - -Wno-implicit-fallthrough - -Wno-missing-braces + -Wno-trigraphs -Wno-missing-field-initializers -Wno-missing-prototypes - -Wno-semicolon-before-method-body - -Wno-shadow - -Wno-sign-conversion - -Wno-trigraphs - -Wno-unknown-pragmas - -Wno-unused-function - -Wno-unused-label - -Wnon-literal-null-conversion - -Wobjc-literal-conversion - -Wparentheses - -Wpointer-sign + -Werror=return-type + -Wunreachable-code -Wquoted-include-in-framework-header - -Wshorten-64-to-32 - -Wsign-compare - -Wstrict-prototypes + -Wno-missing-braces + -Wparentheses -Wswitch - -Wuninitialized - -Wunreachable-code + -Wno-unused-function + -Wno-unused-label -Wunused-parameter - -Wunused-value -Wunused-variable - -Wvla) + -Wunused-value + -Wempty-body + -Wuninitialized + -Wno-unknown-pragmas + -Wfour-char-constants + -Wconstant-conversion + -Wno-conversion + -Wint-conversion + -Wbool-conversion + -Wenum-conversion + -Wnon-literal-null-conversion + -Wsign-compare + -Wshorten-64-to-32 + -Wpointer-sign + -Wnewline-eof + -Wno-implicit-fallthrough + -Wdeprecated-declarations + -Wno-sign-conversion + -Winfinite-recursion + -Wcomma + -Wno-strict-prototypes + -Wno-semicolon-before-method-body + -Wformat-security + -Wvla + -Wno-error=shorten-64-to-32) + + set(_obs_c_options ${_obs_common_options} -Wno-shadow -Wno-float-conversion) set(_obs_cxx_options - # cmake-format: sortable - -Warc-repeated-use-of-weak - -Wconversion - -Wdeprecated-implementations - -Wduplicate-method-match - -Wfloat-conversion - -Wfour-char-constants - -Wimplicit-retain-self + ${_obs_common_options} + -Wno-non-virtual-dtor + -Wno-overloaded-virtual + -Wno-exit-time-destructors + -Wno-shadow -Winvalid-offsetof -Wmove - -Wno-arc-maybe-repeated-use-of-weak - -Wno-exit-time-destructors + -Werror=block-capture-autoreleasing + -Wrange-loop-analysis) + + set(_obs_objc_options + ${_obs_common_options} -Wno-implicit-atomic-properties - -Wno-non-virtual-dtor -Wno-objc-interface-ivars - -Wno-overloaded-virtual + -Warc-repeated-use-of-weak + -Wno-arc-maybe-repeated-use-of-weak + -Wimplicit-retain-self + -Wduplicate-method-match + -Wshadow + -Wfloat-conversion + -Wobjc-literal-conversion -Wno-selector -Wno-strict-selector-match + -Wundeclared-selector + -Wdeprecated-implementations -Wprotocol - -Wrange-loop-analysis - -Wshadow - -Wundeclared-selector) + -Werror=block-capture-autoreleasing + -Wrange-loop-analysis) + + set(_obs_objcxx_options ${_obs_objc_options} -Wno-non-virtual-dtor) # Enable stripping of dead symbols when not building for Debug configuration set(_release_configs RelWithDebInfo Release MinSizeRel) @@ -109,8 +112,9 @@ if(NOT XCODE) add_link_options(LINKER:-dead_strip) endif() - add_compile_options("$<$:${_obs_c_options}>" - "$<$:${_obs_c_options} ${_obs_cxx_options}>") + add_compile_options( + "$<$:${_obs_c_options}>" "$<$:${_obs_cxx_options}>" + "$<$:${_obs_objc_options}>" "$<$:${_obs_objcxx_options}>") option(ENABLE_COMPILER_TRACE "Enable clang time-trace (requires Ninja)" OFF) mark_as_advanced(ENABLE_COMPILER_TRACE) @@ -128,4 +132,4 @@ if(NOT XCODE) set(CMAKE_COLOR_DIAGNOSTICS ON) endif() -add_compile_definitions("$<$,$>:DEBUG;_DEBUG>") +add_compile_definitions("$<$,$>:DEBUG;_DEBUG>")