mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-30 11:10:06 -05:00
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.
This commit is contained in:
@@ -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 " ")
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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 ()
|
||||
|
||||
@@ -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 ()
|
||||
|
||||
@@ -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()
|
||||
@@ -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()
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
include(Compiler/SunPro)
|
||||
__compiler_sunpro(ASM)
|
||||
|
||||
set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s )
|
||||
|
||||
set(CMAKE_ASM_VERBOSE_FLAG "-#")
|
||||
|
||||
@@ -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 "-#")
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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=")
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -39,6 +39,7 @@ macro(__windows_compiler_clang_gnu lang)
|
||||
set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP)
|
||||
|
||||
set(CMAKE_${lang}_LINKER_MANIFEST_FLAG " -Xlinker /MANIFESTINPUT:")
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-Werror")
|
||||
|
||||
if("${CMAKE_${lang}_SIMULATE_VERSION}" MATCHES "^([0-9]+)\\.([0-9]+)")
|
||||
math(EXPR MSVC_VERSION "${CMAKE_MATCH_1}*100 + ${CMAKE_MATCH_2}")
|
||||
@@ -189,6 +190,7 @@ if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC"
|
||||
macro(__windows_compiler_clang_base lang)
|
||||
set(_COMPILE_${lang} "${_COMPILE_${lang}_MSVC}")
|
||||
__windows_compiler_msvc(${lang})
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-WX")
|
||||
set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-imsvc ")
|
||||
endmacro()
|
||||
else()
|
||||
|
||||
Reference in New Issue
Block a user