summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Help/manual/cmake-properties.7.rst1
-rw-r--r--Help/manual/cmake-variables.7.rst1
-rw-r--r--Help/prop_tgt/COMPILE_WARNING_AS_ERROR.rst10
-rw-r--r--Help/release/dev/werror-property.rst8
-rw-r--r--Help/variable/CMAKE_COMPILE_WARNING_AS_ERROR.rst9
-rw-r--r--Modules/Compiler/Fujitsu.cmake1
-rw-r--r--Modules/Compiler/GNU.cmake1
-rw-r--r--Modules/Compiler/Intel.cmake2
-rw-r--r--Modules/Compiler/IntelLLVM.cmake2
-rw-r--r--Modules/Compiler/LCC.cmake1
-rw-r--r--Modules/Compiler/MSVC-C.cmake16
-rw-r--r--Modules/Compiler/MSVC-CXX.cmake17
-rw-r--r--Modules/Compiler/MSVC.cmake25
-rw-r--r--Modules/Compiler/NVHPC.cmake1
-rw-r--r--Modules/Compiler/SunPro-ASM.cmake3
-rw-r--r--Modules/Compiler/SunPro-C.cmake1
-rw-r--r--Modules/Compiler/SunPro-CXX.cmake1
-rw-r--r--Modules/Compiler/SunPro-Fortran.cmake3
-rw-r--r--Modules/Compiler/SunPro.cmake4
-rw-r--r--Modules/Compiler/XL.cmake1
-rw-r--r--Modules/Compiler/XLClang.cmake1
-rw-r--r--Modules/Platform/Windows-Clang.cmake2
-rw-r--r--Source/cmLocalGenerator.cxx9
-rw-r--r--Source/cmTarget.cxx1
-rw-r--r--Tests/RunCMake/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/CompileWarningAsError/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake12
-rw-r--r--Tests/RunCMake/CompileWarningAsError/WarningAsErrorOptions.cmake18
-rw-r--r--Tests/RunCMake/CompileWarningAsError/WerrorOff.cmake8
-rw-r--r--Tests/RunCMake/CompileWarningAsError/WerrorOn-Build-result.txt1
-rw-r--r--Tests/RunCMake/CompileWarningAsError/WerrorOn.cmake13
-rw-r--r--Tests/RunCMake/CompileWarningAsError/err.cxx0
-rw-r--r--Tests/RunCMake/CompileWarningAsError/warn.cxx17
33 files changed, 167 insertions, 27 deletions
diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
index f86fdfe..20b62c5 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -171,6 +171,7 @@ Properties on Targets
/prop_tgt/COMPILE_PDB_NAME_CONFIG
/prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY
/prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG
+ /prop_tgt/COMPILE_WARNING_AS_ERROR
/prop_tgt/CONFIG_OUTPUT_NAME
/prop_tgt/CONFIG_POSTFIX
/prop_tgt/CROSSCOMPILING_EMULATOR
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index 5c66088..80160b6 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -401,6 +401,7 @@ Variables that Control the Build
/variable/CMAKE_BUILD_WITH_INSTALL_RPATH
/variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY
/variable/CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG
+ /variable/CMAKE_COMPILE_WARNING_AS_ERROR
/variable/CMAKE_CONFIG_POSTFIX
/variable/CMAKE_CROSS_CONFIGS
/variable/CMAKE_CTEST_ARGUMENTS
diff --git a/Help/prop_tgt/COMPILE_WARNING_AS_ERROR.rst b/Help/prop_tgt/COMPILE_WARNING_AS_ERROR.rst
new file mode 100644
index 0000000..86a0f7f
--- /dev/null
+++ b/Help/prop_tgt/COMPILE_WARNING_AS_ERROR.rst
@@ -0,0 +1,10 @@
+COMPILE_WARNING_AS_ERROR
+------------------------
+
+.. versionadded:: 3.24
+
+Specify whether to treat warnings on compile as errors.
+If enabled, adds a flag to treat warnings on compile as errors.
+
+This property is initialized by the value of the variable
+:variable:`CMAKE_COMPILE_WARNING_AS_ERROR` if it is set when a target is created.
diff --git a/Help/release/dev/werror-property.rst b/Help/release/dev/werror-property.rst
new file mode 100644
index 0000000..c337df7
--- /dev/null
+++ b/Help/release/dev/werror-property.rst
@@ -0,0 +1,8 @@
+werror-property
+---------------
+
+* Added the Target Property :prop_tgt:`COMPILE_WARNING_AS_ERROR` and the
+ Variable :variable:`CMAKE_COMPILE_WARNING_AS_ERROR` which initializes the
+ Target Property. If :prop_tgt:`COMPILE_WARNING_AS_ERROR` is true, it expands
+ to a different flag depending on the compiler such that any warnings at
+ compile will be treated as errors.
diff --git a/Help/variable/CMAKE_COMPILE_WARNING_AS_ERROR.rst b/Help/variable/CMAKE_COMPILE_WARNING_AS_ERROR.rst
new file mode 100644
index 0000000..56dc6a6
--- /dev/null
+++ b/Help/variable/CMAKE_COMPILE_WARNING_AS_ERROR.rst
@@ -0,0 +1,9 @@
+CMAKE_COMPILE_WARNING_AS_ERROR
+------------------------------
+
+.. versionadded:: 3.24
+
+Specify whether to treat warnings on compile as errors.
+
+This variable is used to initialize the
+:prop_tgt:`COMPILE_WARNING_AS_ERROR` property on all the targets.
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()
diff --git a/Modules/Platform/Windows-Clang.cmake b/Modules/Platform/Windows-Clang.cmake
index 7600c8d..82c4383 100644
--- a/Modules/Platform/Windows-Clang.cmake
+++ b/Modules/Platform/Windows-Clang.cmake
@@ -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()
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 4b0a78b..e2bcea8 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1025,6 +1025,14 @@ void cmLocalGenerator::AddCompileOptions(std::vector<BT<std::string>>& flags,
flags.emplace_back(std::move(compReqFlag));
}
+ // Add Warning as errors flags
+ const cmValue wError = target->GetProperty("COMPILE_WARNING_AS_ERROR");
+ const cmValue wErrorFlag = this->Makefile->GetDefinition(
+ cmStrCat("CMAKE_", lang, "_COMPILE_OPTIONS_WARNING_AS_ERROR"));
+ if (wError.IsOn() && wErrorFlag.IsSet()) {
+ flags.emplace_back(wErrorFlag);
+ }
+
// Add compile flag for the MSVC compiler only.
cmMakefile* mf = this->GetMakefile();
if (cmValue jmc =
@@ -1919,6 +1927,7 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags,
std::string compilerSimulateId = this->Makefile->GetSafeDefinition(
cmStrCat("CMAKE_", lang, "_SIMULATE_ID"));
+
if (lang == "Swift") {
if (cmValue v = target->GetProperty("Swift_LANGUAGE_VERSION")) {
if (cmSystemTools::VersionCompare(
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 646fd7e..80d1940 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -588,6 +588,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
initProp("UNITY_BUILD_UNIQUE_ID");
initProp("OPTIMIZE_DEPENDENCIES");
initProp("EXPORT_COMPILE_COMMANDS");
+ initProp("COMPILE_WARNING_AS_ERROR");
initPropValue("UNITY_BUILD_BATCH_SIZE", "8");
initPropValue("UNITY_BUILD_MODE", "BATCH");
initPropValue("PCH_WARN_INVALID", "ON");
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index dd540ea..07b256c 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -369,6 +369,7 @@ add_RunCMake_test(TargetProperties)
add_RunCMake_test(ToolchainFile)
add_RunCMake_test(find_dependency)
add_RunCMake_test(CompileDefinitions)
+add_RunCMake_test(CompileWarningAsError)
add_RunCMake_test(CompileFeatures -DCMake_NO_C_STANDARD=${CMake_NO_C_STANDARD} -DCMake_NO_CXX_STANDARD=${CMake_NO_CXX_STANDARD})
add_RunCMake_test(Policy)
add_RunCMake_test(PolicyScope)
diff --git a/Tests/RunCMake/CompileWarningAsError/CMakeLists.txt b/Tests/RunCMake/CompileWarningAsError/CMakeLists.txt
new file mode 100644
index 0000000..5ff8d3e
--- /dev/null
+++ b/Tests/RunCMake/CompileWarningAsError/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.23)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake b/Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake
new file mode 100644
index 0000000..059c80f
--- /dev/null
+++ b/Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake
@@ -0,0 +1,12 @@
+include(RunCMake)
+
+function(run_compile_warn test)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
+ set(RunCMake_TEST_OUTPUT_MERGE 1)
+ run_cmake(${test})
+ set(RunCMake_TEST_NO_CLEAN 1)
+ run_cmake_command(${test}-Build ${CMAKE_COMMAND} --build . ${verbose_args})
+endfunction()
+
+run_compile_warn(WerrorOn)
+run_compile_warn(WerrorOff)
diff --git a/Tests/RunCMake/CompileWarningAsError/WarningAsErrorOptions.cmake b/Tests/RunCMake/CompileWarningAsError/WarningAsErrorOptions.cmake
new file mode 100644
index 0000000..ccc6cc5
--- /dev/null
+++ b/Tests/RunCMake/CompileWarningAsError/WarningAsErrorOptions.cmake
@@ -0,0 +1,18 @@
+# add compile options to warning_options to ensure unused-function throws a warning
+# if warning_options is NOT DEFINED, assume compiler doesn't support warning as error
+macro(get_warning_options warning_options)
+ if (CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang|XLClang|IBMClang|LCC|NVCC|IntelLLVM)$")
+ set(${warning_options} "-Wall")
+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"
+ OR (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC"))
+ set(${warning_options} "-W4")
+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
+ set(${warning_options} "-w3")
+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "XL")
+ set(${warning_options} "-qinfo=all")
+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
+ set(${warning_options} "+w;+w2")
+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Fujitsu")
+ set(${warning_options} "SHELL:-w 8")
+ endif()
+endmacro()
diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOff.cmake b/Tests/RunCMake/CompileWarningAsError/WerrorOff.cmake
new file mode 100644
index 0000000..b05d65e
--- /dev/null
+++ b/Tests/RunCMake/CompileWarningAsError/WerrorOff.cmake
@@ -0,0 +1,8 @@
+enable_language(CXX)
+
+include(WarningAsErrorOptions.cmake)
+get_warning_options(warning_options)
+
+add_executable(WerrorOff warn.cxx)
+target_compile_options(WerrorOff PUBLIC "${warning_options}")
+set_target_properties(WerrorOff PROPERTIES COMPILE_WARNING_AS_ERROR OFF)
diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOn-Build-result.txt b/Tests/RunCMake/CompileWarningAsError/WerrorOn-Build-result.txt
new file mode 100644
index 0000000..d197c91
--- /dev/null
+++ b/Tests/RunCMake/CompileWarningAsError/WerrorOn-Build-result.txt
@@ -0,0 +1 @@
+[^0]
diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOn.cmake b/Tests/RunCMake/CompileWarningAsError/WerrorOn.cmake
new file mode 100644
index 0000000..4310333
--- /dev/null
+++ b/Tests/RunCMake/CompileWarningAsError/WerrorOn.cmake
@@ -0,0 +1,13 @@
+enable_language(CXX)
+
+include(WarningAsErrorOptions.cmake)
+get_warning_options(warning_options)
+
+if (DEFINED warning_options)
+ add_executable(WerrorOn warn.cxx)
+ target_compile_options(WerrorOn PUBLIC "${warning_options}")
+ set_target_properties(WerrorOn PROPERTIES COMPILE_WARNING_AS_ERROR ON)
+else()
+ # if no werror option is set for the environment, use err.cxx so that build fails as expected
+ add_executable(WerrorOn err.cxx)
+endif()
diff --git a/Tests/RunCMake/CompileWarningAsError/err.cxx b/Tests/RunCMake/CompileWarningAsError/err.cxx
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/CompileWarningAsError/err.cxx
diff --git a/Tests/RunCMake/CompileWarningAsError/warn.cxx b/Tests/RunCMake/CompileWarningAsError/warn.cxx
new file mode 100644
index 0000000..64a245a
--- /dev/null
+++ b/Tests/RunCMake/CompileWarningAsError/warn.cxx
@@ -0,0 +1,17 @@
+static void unused_function();
+
+#ifdef __SUNPRO_CC
+struct A
+{
+ virtual ~A() throw();
+};
+struct B : public A
+{
+ virtual ~B() throw(int);
+};
+#endif
+
+int main(int unused_argument, char* [])
+{
+ return 1;
+}