mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-22 16:07:49 +08:00
COMPILE_WARNING_AS_ERROR: Add command-line option
Add command-line option `--compile-no-warning-as-error` to ignore value of `COMPILE_WARNING_AS_ERROR`. Issue: #19085
This commit is contained in:
@@ -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.
|
||||
|
||||
|
@@ -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.
|
||||
|
@@ -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.
|
||||
|
@@ -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;
|
||||
} }
|
||||
};
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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: "
|
||||
|
@@ -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")
|
||||
|
@@ -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)
|
Reference in New Issue
Block a user