diff options
-rw-r--r-- | Help/manual/cmake.1.rst | 5 | ||||
-rw-r--r-- | Help/release/dev/werror-property.rst | 5 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 12 | ||||
-rw-r--r-- | Source/cmake.cxx | 8 | ||||
-rw-r--r-- | Source/cmake.h | 3 | ||||
-rw-r--r-- | Source/cmakemain.cxx | 3 | ||||
-rw-r--r-- | Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake | 3 | ||||
-rw-r--r-- | Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore.cmake | 8 |
8 files changed, 41 insertions, 6 deletions
diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 3ef7b3f..bf51db1 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -426,6 +426,11 @@ Options in :variable:`CMAKE_SOURCE_DIR` and :variable:`CMAKE_BINARY_DIR`. This flag tells CMake to warn about other files as well. +``--compile-no-warning-as-error`` + Ignore target property :prop_tgt:`COMPILE_WARNING_AS_ERROR` and variable + :variable:`CMAKE_COMPILE_WARNING_AS_ERROR`, preventing warnings from being + treated as errors on compile. + ``--profiling-output=<path>`` Used in conjunction with ``--profiling-format`` to output to a given path. diff --git a/Help/release/dev/werror-property.rst b/Help/release/dev/werror-property.rst index c337df7..84c825f 100644 --- a/Help/release/dev/werror-property.rst +++ b/Help/release/dev/werror-property.rst @@ -6,3 +6,8 @@ werror-property 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. + +* :manual:`cmake(1)` gained the command-line option + ``--compile-no-warning-as-error`` which causes the values of + the :prop_tgt:`COMPILE_WARNING_AS_ERROR` target property and + :variable:`CMAKE_COMPILE_WARNING_AS_ERROR` variable to be ignored. diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 42abf8e..d226af9 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1026,11 +1026,13 @@ void cmLocalGenerator::AddCompileOptions(std::vector<BT<std::string>>& flags, } // 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); + if (!this->GetCMakeInstance()->GetIgnoreWarningAsError()) { + 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. diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 5bfc4c8..4997602 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -1092,6 +1092,14 @@ void cmake::SetArgs(const std::vector<std::string>& args) << "uninitialized variables.\n"; state->SetCheckSystemVars(true); return true; + } }, + CommandArgument{ + "--compile-no-warning-as-error", CommandArgument::Values::Zero, + [](std::string const&, cmake* state) -> bool { + std::cout << "Ignoring COMPILE_WARNING_AS_ERROR target property and " + << "CMAKE_COMPILE_WARNING_AS_ERROR variable.\n"; + state->SetIgnoreWarningAsError(true); + return true; } } }; diff --git a/Source/cmake.h b/Source/cmake.h index c2bbff7..3c6af17 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -534,6 +534,8 @@ public: void SetWarnUnusedCli(bool b) { this->WarnUnusedCli = b; } bool GetCheckSystemVars() const { return this->CheckSystemVars; } void SetCheckSystemVars(bool b) { this->CheckSystemVars = b; } + bool GetIgnoreWarningAsError() const { return this->IgnoreWarningAsError; } + void SetIgnoreWarningAsError(bool b) { this->IgnoreWarningAsError = b; } void MarkCliAsUsed(const std::string& variable); @@ -686,6 +688,7 @@ private: bool WarnUninitialized = false; bool WarnUnusedCli = true; bool CheckSystemVars = false; + bool IgnoreWarningAsError = false; std::map<std::string, bool> UsedCliVariables; std::string CMakeEditCommand; std::string CXXEnvironment; diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 96bf845..19ac6ca 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -110,6 +110,9 @@ const char* cmDocumentationOptions[][2] = { { "--check-system-vars", "Find problems with variable usage in system " "files." }, + { "--compile-no-warning-as-error", + "Ignore COMPILE_WARNING_AS_ERROR property and " + "CMAKE_COMPILE_WARNING_AS_ERROR variable." }, # if !defined(CMAKE_BOOTSTRAP) { "--profiling-format=<fmt>", "Output data for profiling CMake scripts. Supported formats: " diff --git a/Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake b/Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake index 059c80f..a532f72 100644 --- a/Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompileWarningAsError/RunCMakeTest.cmake @@ -3,10 +3,11 @@ 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}) + run_cmake_with_options(${test} ${ARGN}) 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) +run_compile_warn(WerrorOnIgnore "--compile-no-warning-as-error") diff --git a/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore.cmake b/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore.cmake new file mode 100644 index 0000000..1f7ccdb --- /dev/null +++ b/Tests/RunCMake/CompileWarningAsError/WerrorOnIgnore.cmake @@ -0,0 +1,8 @@ +enable_language(CXX) + +include(WarningAsErrorOptions.cmake) +get_warning_options(warning_options) + +add_executable(WerrorOn warn.cxx) +target_compile_options(WerrorOn PUBLIC "${warning_options}") +set_target_properties(WerrorOn PROPERTIES COMPILE_WARNING_AS_ERROR ON) |