From 6af6170b684d9ba29d01d1075d22c5530664a6d5 Mon Sep 17 00:00:00 2001 From: lhchavez Date: Sat, 5 Jan 2019 20:50:42 -0800 Subject: Make ENABLE_WERROR actually work This change explicitly adds -Werror to the CFLAGS. Due to the way that the ADD_C_FLAG_IF_SUPPORTED() macro was mangling the flag name to convert it into a define name, any warning that had a dash in its name was not being correctly enabled. Additionally, any flag that is enabled implicitly by the compiler (like -Wunused-result and -Wdeprecated-declarations) would not cause an error unless they were explicitly enabled with the ENABLE_WARNINGS() macro. --- cmake/Modules/AddCFlagIfSupported.cmake | 6 ++++-- cmake/Modules/EnableWarnings.cmake | 13 +++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cmake/Modules/AddCFlagIfSupported.cmake b/cmake/Modules/AddCFlagIfSupported.cmake index 1d6181cac..b7aaa7910 100644 --- a/cmake/Modules/AddCFlagIfSupported.cmake +++ b/cmake/Modules/AddCFlagIfSupported.cmake @@ -7,7 +7,8 @@ INCLUDE(CheckCCompilerFlag) MACRO(ADD_C_FLAG _FLAG) STRING(TOUPPER ${_FLAG} UPCASE) - STRING(REGEX REPLACE "^-" "" UPCASE_PRETTY ${UPCASE}) + STRING(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE}) + STRING(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY}) CHECK_C_COMPILER_FLAG(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED) IF(IS_${UPCASE_PRETTY}_SUPPORTED) @@ -19,7 +20,8 @@ ENDMACRO() MACRO(ADD_C_FLAG_IF_SUPPORTED _FLAG) STRING(TOUPPER ${_FLAG} UPCASE) - STRING(REGEX REPLACE "^-" "" UPCASE_PRETTY ${UPCASE}) + STRING(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE}) + STRING(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY}) CHECK_C_COMPILER_FLAG(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED) IF(IS_${UPCASE_PRETTY}_SUPPORTED) diff --git a/cmake/Modules/EnableWarnings.cmake b/cmake/Modules/EnableWarnings.cmake index e7d7d3986..72e1523c4 100644 --- a/cmake/Modules/EnableWarnings.cmake +++ b/cmake/Modules/EnableWarnings.cmake @@ -1,14 +1,11 @@ MACRO(ENABLE_WARNINGS flag) - IF(ENABLE_WERROR) - ADD_C_FLAG_IF_SUPPORTED(-Werror=${flag}) - ELSE() - ADD_C_FLAG_IF_SUPPORTED(-W${flag}) - ENDIF() + ADD_C_FLAG_IF_SUPPORTED(-W${flag}) ENDMACRO() MACRO(DISABLE_WARNINGS flag) ADD_C_FLAG_IF_SUPPORTED(-Wno-${flag}) - IF(ENABLE_WERROR) - ADD_C_FLAG_IF_SUPPORTED(-Wno-error=${flag}) - ENDIF() ENDMACRO() + +IF(ENABLE_WERROR) + ADD_C_FLAG_IF_SUPPORTED(-Werror) +ENDIF() -- cgit v1.2.1