diff options
author | Martin Duffy <martin.duffy@kitware.com> | 2022-04-21 19:29:05 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-05-06 16:14:37 (GMT) |
commit | 76a08cd25332b74627802df8817068219b89161d (patch) | |
tree | a349756534c11634ac1fc919793801c78fbec612 /Modules/Compiler | |
parent | de802fc5a35780581948f7638f0f22c3974922dd (diff) | |
download | CMake-76a08cd25332b74627802df8817068219b89161d.zip CMake-76a08cd25332b74627802df8817068219b89161d.tar.gz CMake-76a08cd25332b74627802df8817068219b89161d.tar.bz2 |
COMPILE_WARNING_AS_ERROR: Add options to treat warnings as errors
Add `COMPILE_WARNING_AS_ERROR` target property and supporting
`CMAKE_COMPILE_WARNING_AS_ERROR` variable.
`COMPILE_WARNING_AS_ERROR` is initialized by
`CMAKE_COMPILE_WARNING_AS_ERROR`. It is a boolean variable. If it is
true, it expands to a different flag depending on the compiler such that
any warnings at compile will be treated as errors.
Supports compiler ids that I could find a relevant flag for.
Diffstat (limited to 'Modules/Compiler')
-rw-r--r-- | Modules/Compiler/Fujitsu.cmake | 1 | ||||
-rw-r--r-- | Modules/Compiler/GNU.cmake | 1 | ||||
-rw-r--r-- | Modules/Compiler/Intel.cmake | 2 | ||||
-rw-r--r-- | Modules/Compiler/IntelLLVM.cmake | 2 | ||||
-rw-r--r-- | Modules/Compiler/LCC.cmake | 1 | ||||
-rw-r--r-- | Modules/Compiler/MSVC-C.cmake | 16 | ||||
-rw-r--r-- | Modules/Compiler/MSVC-CXX.cmake | 17 | ||||
-rw-r--r-- | Modules/Compiler/MSVC.cmake | 25 | ||||
-rw-r--r-- | Modules/Compiler/NVHPC.cmake | 1 | ||||
-rw-r--r-- | Modules/Compiler/SunPro-ASM.cmake | 3 | ||||
-rw-r--r-- | Modules/Compiler/SunPro-C.cmake | 1 | ||||
-rw-r--r-- | Modules/Compiler/SunPro-CXX.cmake | 1 | ||||
-rw-r--r-- | Modules/Compiler/SunPro-Fortran.cmake | 3 | ||||
-rw-r--r-- | Modules/Compiler/SunPro.cmake | 4 | ||||
-rw-r--r-- | Modules/Compiler/XL.cmake | 1 | ||||
-rw-r--r-- | Modules/Compiler/XLClang.cmake | 1 |
16 files changed, 53 insertions, 27 deletions
diff --git a/Modules/Compiler/Fujitsu.cmake b/Modules/Compiler/Fujitsu.cmake index 78495cb..55c2aa4 100644 --- a/Modules/Compiler/Fujitsu.cmake +++ b/Modules/Compiler/Fujitsu.cmake @@ -11,6 +11,7 @@ include(Compiler/CMakeCommonCompilerMacros) macro(__compiler_fujitsu lang) set(CMAKE_${lang}_VERBOSE_FLAG "-###") + set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-cwno") # Initial configuration flags string(APPEND CMAKE_${lang}_FLAGS_INIT " ") diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake index 2eef532..c5946f0 100644 --- a/Modules/Compiler/GNU.cmake +++ b/Modules/Compiler/GNU.cmake @@ -18,6 +18,7 @@ set(__pch_header_OBJCXX "objective-c++-header") macro(__compiler_gnu lang) # Feature flags. set(CMAKE_${lang}_VERBOSE_FLAG "-v") + set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-Werror") set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC") set (_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO) if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4) diff --git a/Modules/Compiler/Intel.cmake b/Modules/Compiler/Intel.cmake index 9a760c8..20989d2 100644 --- a/Modules/Compiler/Intel.cmake +++ b/Modules/Compiler/Intel.cmake @@ -13,6 +13,7 @@ include(Compiler/CMakeCommonCompilerMacros) if(CMAKE_HOST_WIN32) # MSVC-like macro(__compiler_intel lang) + set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-Werror-all") endmacro() else() # GNU-like @@ -24,6 +25,7 @@ else() string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Os") string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3") string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g") + set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-Werror-all") set(CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "${CMAKE_${lang}_COMPILER}") if(CMAKE_${lang}_COMPILER_ARG1) diff --git a/Modules/Compiler/IntelLLVM.cmake b/Modules/Compiler/IntelLLVM.cmake index 14b7ad8..c344f32 100644 --- a/Modules/Compiler/IntelLLVM.cmake +++ b/Modules/Compiler/IntelLLVM.cmake @@ -20,6 +20,7 @@ if(CMAKE_HOST_WIN32) macro(__compiler_intel_llvm lang) if(NOT "x${lang}" STREQUAL "xFortran") set(CMAKE_${lang}_COMPILE_OPTIONS_INVALID_PCH -Winvalid-pch) + set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-WX") endif() endmacro() else() @@ -38,6 +39,7 @@ else() set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE") set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_${lang}_COMPILE_OPTIONS_PIE} "-pie") set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "-no-pie") + set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-Werror") set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC") set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared") diff --git a/Modules/Compiler/LCC.cmake b/Modules/Compiler/LCC.cmake index 8353ab6..bdee9a6 100644 --- a/Modules/Compiler/LCC.cmake +++ b/Modules/Compiler/LCC.cmake @@ -18,6 +18,7 @@ set(__pch_header_OBJCXX "objective-c++-header") macro(__compiler_lcc lang) # Feature flags. set(CMAKE_${lang}_VERBOSE_FLAG "-v") + set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-Werror") set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC") set (_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO) set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE") diff --git a/Modules/Compiler/MSVC-C.cmake b/Modules/Compiler/MSVC-C.cmake index df3691c..6bf6b4e 100644 --- a/Modules/Compiler/MSVC-C.cmake +++ b/Modules/Compiler/MSVC-C.cmake @@ -1,6 +1,9 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. +include(Compiler/MSVC) +__compiler_msvc(C) + include(Compiler/CMakeCommonCompilerMacros) if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.27) @@ -67,16 +70,3 @@ else() endif() set(CMAKE_C_COMPILE_OPTIONS_EXPLICIT_LANGUAGE -TC) -set(CMAKE_C_CLANG_TIDY_DRIVER_MODE "cl") -set(CMAKE_C_INCLUDE_WHAT_YOU_USE_DRIVER_MODE "cl") - -# /JMC "Just My Code" is only supported by MSVC 19.05 onward. -if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.05) - set(CMAKE_C_COMPILE_OPTIONS_JMC "-JMC") -endif() - -# The `/external:I` flag was made non-experimental in 19.29.30036.3. -if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.29.30036.3) - set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-external:I") - set(_CMAKE_INCLUDE_SYSTEM_FLAG_C_WARNING "-external:W0 ") -endif () diff --git a/Modules/Compiler/MSVC-CXX.cmake b/Modules/Compiler/MSVC-CXX.cmake index 17cbc3c..75165fd 100644 --- a/Modules/Compiler/MSVC-CXX.cmake +++ b/Modules/Compiler/MSVC-CXX.cmake @@ -1,10 +1,10 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -include(Compiler/CMakeCommonCompilerMacros) +include(Compiler/MSVC) +__compiler_msvc(CXX) -set(CMAKE_CXX_CLANG_TIDY_DRIVER_MODE "cl") -set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE_DRIVER_MODE "cl") +include(Compiler/CMakeCommonCompilerMacros) if ((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.0.24215.1 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10) OR @@ -76,14 +76,3 @@ elseif (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0) _record_compiler_features(CXX "" CMAKE_CXX_COMPILE_FEATURES) endmacro() endif() - -# /JMC "Just My Code" is only supported by MSVC 19.05 onward. -if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.05) - set(CMAKE_CXX_COMPILE_OPTIONS_JMC "-JMC") -endif() - -# The `/external:I` flag was made non-experimental in 19.29.30036.3. -if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.29.30036.3) - set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-external:I") - set(_CMAKE_INCLUDE_SYSTEM_FLAG_CXX_WARNING "-external:W0 ") -endif () diff --git a/Modules/Compiler/MSVC.cmake b/Modules/Compiler/MSVC.cmake new file mode 100644 index 0000000..154b657 --- /dev/null +++ b/Modules/Compiler/MSVC.cmake @@ -0,0 +1,25 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +# This module is shared by multiple languages; use include blocker. +if(__COMPILER_MSVC) + return() +endif() +set(__COMPILER_MSVC 1) + +macro(__compiler_msvc lang) + set(CMAKE_${lang}_CLANG_TIDY_DRIVER_MODE "cl") + set(CMAKE_${lang}_INCLUDE_WHAT_YOU_USE_DRIVER_MODE "cl") + set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-WX") + + # /JMC "Just My Code" is only supported by MSVC 19.05 onward. + if (CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 19.05) + set(CMAKE_${lang}_COMPILE_OPTIONS_JMC "-JMC") + endif() + + # The `/external:I` flag was made non-experimental in 19.29.30036.3. + if (CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 19.29.30036.3) + set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-external:I") + set(_CMAKE_INCLUDE_SYSTEM_FLAG_${lang}_WARNING "-external:W0 ") + endif () +endmacro() diff --git a/Modules/Compiler/NVHPC.cmake b/Modules/Compiler/NVHPC.cmake index b51bb43..21d0665 100644 --- a/Modules/Compiler/NVHPC.cmake +++ b/Modules/Compiler/NVHPC.cmake @@ -13,4 +13,5 @@ include(Compiler/PGI) macro(__compiler_nvhpc lang) # Logic specific to NVHPC. set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ") + set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "--Werror all-warnings") endmacro() diff --git a/Modules/Compiler/SunPro-ASM.cmake b/Modules/Compiler/SunPro-ASM.cmake index 0d67400..fc0f2fa 100644 --- a/Modules/Compiler/SunPro-ASM.cmake +++ b/Modules/Compiler/SunPro-ASM.cmake @@ -1,3 +1,6 @@ +include(Compiler/SunPro) +__compiler_sunpro(ASM) + set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s ) set(CMAKE_ASM_VERBOSE_FLAG "-#") diff --git a/Modules/Compiler/SunPro-C.cmake b/Modules/Compiler/SunPro-C.cmake index 7a406ac..b06719d 100644 --- a/Modules/Compiler/SunPro-C.cmake +++ b/Modules/Compiler/SunPro-C.cmake @@ -2,6 +2,7 @@ # file Copyright.txt or https://cmake.org/licensing for details. include(Compiler/SunPro) +__compiler_sunpro(C) set(CMAKE_C_VERBOSE_FLAG "-#") diff --git a/Modules/Compiler/SunPro-CXX.cmake b/Modules/Compiler/SunPro-CXX.cmake index aa8a9c5..f835f2d 100644 --- a/Modules/Compiler/SunPro-CXX.cmake +++ b/Modules/Compiler/SunPro-CXX.cmake @@ -2,6 +2,7 @@ # file Copyright.txt or https://cmake.org/licensing for details. include(Compiler/SunPro) +__compiler_sunpro(CXX) set(CMAKE_CXX_VERBOSE_FLAG "-v") diff --git a/Modules/Compiler/SunPro-Fortran.cmake b/Modules/Compiler/SunPro-Fortran.cmake index 0ba5015..d336980 100644 --- a/Modules/Compiler/SunPro-Fortran.cmake +++ b/Modules/Compiler/SunPro-Fortran.cmake @@ -1,3 +1,6 @@ +include(Compiler/SunPro) +__compiler_sunpro(Fortran) + set(CMAKE_Fortran_VERBOSE_FLAG "-v") set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixed") set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free") diff --git a/Modules/Compiler/SunPro.cmake b/Modules/Compiler/SunPro.cmake index 52da39a..331cdfc 100644 --- a/Modules/Compiler/SunPro.cmake +++ b/Modules/Compiler/SunPro.cmake @@ -8,3 +8,7 @@ endif() set(__COMPILER_SUNPRO 1) include(Compiler/CMakeCommonCompilerMacros) + +macro(__compiler_sunpro lang) + set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-errwarn=%all") +endmacro() diff --git a/Modules/Compiler/XL.cmake b/Modules/Compiler/XL.cmake index 8b9d4a9..844fcfd 100644 --- a/Modules/Compiler/XL.cmake +++ b/Modules/Compiler/XL.cmake @@ -15,6 +15,7 @@ macro(__compiler_xl lang) set(CMAKE_${lang}_VERBOSE_FLAG "-V") set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-qpic") set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-qpic") + set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-qhalt=i") set(CMAKE_${lang}_RESPONSE_FILE_FLAG "-qoptfile=") set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "-qoptfile=") diff --git a/Modules/Compiler/XLClang.cmake b/Modules/Compiler/XLClang.cmake index cdf0fdc..8c3e5e9 100644 --- a/Modules/Compiler/XLClang.cmake +++ b/Modules/Compiler/XLClang.cmake @@ -17,6 +17,7 @@ macro(__compiler_xlclang lang) set(CMAKE_${lang}_VERBOSE_FLAG "-V") set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC") set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIC") + set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-Werror") set(CMAKE_${lang}_RESPONSE_FILE_FLAG "@") set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "@") endmacro() |