Preserve --compile-no-warning-as-error in automatic CMake re-runs

When the build system re-runs `cmake` to regenerate itself, preserve the
`--compile-no-warning-as-error` option if it was used when `cmake` was
last explicitly invoked.  Normally such settings are preserved in the
cache, but the purpose of this option is to be beyond the reach of
project code.
This commit is contained in:
Brad King 2023-05-30 17:23:42 -04:00
parent e0b48284a1
commit da27ff1e96
7 changed files with 38 additions and 18 deletions

View File

@ -2821,6 +2821,9 @@ void cmGlobalGenerator::AddGlobalTarget_EditCache(
std::string edit_cmd = this->GetEditCacheCommand(); std::string edit_cmd = this->GetEditCacheCommand();
if (!edit_cmd.empty()) { if (!edit_cmd.empty()) {
singleLine.push_back(std::move(edit_cmd)); singleLine.push_back(std::move(edit_cmd));
if (this->GetCMakeInstance()->GetIgnoreWarningAsError()) {
singleLine.push_back("--compile-no-warning-as-error");
}
singleLine.push_back("-S$(CMAKE_SOURCE_DIR)"); singleLine.push_back("-S$(CMAKE_SOURCE_DIR)");
singleLine.push_back("-B$(CMAKE_BINARY_DIR)"); singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
gti.Message = "Running CMake cache editor..."; gti.Message = "Running CMake cache editor...";
@ -2854,6 +2857,9 @@ void cmGlobalGenerator::AddGlobalTarget_RebuildCache(
cmCustomCommandLine singleLine; cmCustomCommandLine singleLine;
singleLine.push_back(cmSystemTools::GetCMakeCommand()); singleLine.push_back(cmSystemTools::GetCMakeCommand());
singleLine.push_back("--regenerate-during-build"); singleLine.push_back("--regenerate-during-build");
if (this->GetCMakeInstance()->GetIgnoreWarningAsError()) {
singleLine.push_back("--compile-no-warning-as-error");
}
singleLine.push_back("-S$(CMAKE_SOURCE_DIR)"); singleLine.push_back("-S$(CMAKE_SOURCE_DIR)");
singleLine.push_back("-B$(CMAKE_BINARY_DIR)"); singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
gti.CommandLines.push_back(std::move(singleLine)); gti.CommandLines.push_back(std::move(singleLine));

View File

@ -1816,17 +1816,21 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
if (this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION")) { if (this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION")) {
return; return;
} }
cmake* cm = this->GetCMakeInstance();
const auto& lg = this->LocalGenerators[0]; const auto& lg = this->LocalGenerators[0];
{ {
cmNinjaRule rule("RERUN_CMAKE"); cmNinjaRule rule("RERUN_CMAKE");
rule.Command = rule.Command = cmStrCat(
cmStrCat(this->CMakeCmd(), " --regenerate-during-build -S", this->CMakeCmd(), " --regenerate-during-build",
lg->ConvertToOutputFormat(lg->GetSourceDirectory(), cm->GetIgnoreWarningAsError() ? " --compile-no-warning-as-error" : "",
cmOutputConverter::SHELL), " -S",
" -B", lg->ConvertToOutputFormat(lg->GetSourceDirectory(),
lg->ConvertToOutputFormat(lg->GetBinaryDirectory(), cmOutputConverter::SHELL),
cmOutputConverter::SHELL)); " -B",
lg->ConvertToOutputFormat(lg->GetBinaryDirectory(),
cmOutputConverter::SHELL));
rule.Description = "Re-running CMake..."; rule.Description = "Re-running CMake...";
rule.Comment = "Rule for re-running cmake."; rule.Comment = "Rule for re-running cmake.";
rule.Generator = true; rule.Generator = true;
@ -1850,7 +1854,6 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
reBuild.Variables["pool"] = "console"; reBuild.Variables["pool"] = "console";
} }
cmake* cm = this->GetCMakeInstance();
if (this->SupportsManifestRestat() && cm->DoWriteGlobVerifyTarget()) { if (this->SupportsManifestRestat() && cm->DoWriteGlobVerifyTarget()) {
{ {
cmNinjaRule rule("VERIFY_GLOBS"); cmNinjaRule rule("VERIFY_GLOBS");

View File

@ -354,6 +354,9 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
cmCustomCommandLines commandLines = cmMakeSingleCommandLine( cmCustomCommandLines commandLines = cmMakeSingleCommandLine(
{ cmSystemTools::GetCMakeCommand(), argS, argB, "--check-stamp-list", { cmSystemTools::GetCMakeCommand(), argS, argB, "--check-stamp-list",
stampList, "--vs-solution-file", sln }); stampList, "--vs-solution-file", sln });
if (cm->GetIgnoreWarningAsError()) {
commandLines[0].emplace_back("--compile-no-warning-as-error");
}
// Add the rule. Note that we cannot use the CMakeLists.txt // Add the rule. Note that we cannot use the CMakeLists.txt
// file as the main dependency because it would get // file as the main dependency because it would get

View File

@ -753,14 +753,12 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile(
makefileStream << this->ConvertToRelativeForMake(checkCache) makefileStream << this->ConvertToRelativeForMake(checkCache)
<< ": $(TARGETS)\n"; << ": $(TARGETS)\n";
makefileStream << "\t" makefileStream
<< this->ConvertToRelativeForMake( << "\t" << this->ConvertToRelativeForMake(cmSystemTools::GetCMakeCommand())
cmSystemTools::GetCMakeCommand()) << " -S" << this->ConvertToRelativeForMake(root->GetSourceDirectory())
<< " -S" << " -B" << this->ConvertToRelativeForMake(root->GetBinaryDirectory())
<< this->ConvertToRelativeForMake(root->GetSourceDirectory()) << (cm->GetIgnoreWarningAsError() ? " --compile-no-warning-as-error" : "")
<< " -B" << "\n";
<< this->ConvertToRelativeForMake(root->GetBinaryDirectory())
<< "\n";
} }
static bool objectIdLessThan(const std::unique_ptr<cmXCodeObject>& l, static bool objectIdLessThan(const std::unique_ptr<cmXCodeObject>& l,

View File

@ -828,7 +828,8 @@ void cmLocalUnixMakefileGenerator3::WriteSpecialTargetsBottom(
} }
std::string cmakefileName = "CMakeFiles/Makefile.cmake"; std::string cmakefileName = "CMakeFiles/Makefile.cmake";
std::string runRule = cmStrCat( std::string runRule = cmStrCat(
"$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) " "$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) ",
cm->GetIgnoreWarningAsError() ? "--compile-no-warning-as-error " : "",
"--check-build-system ", "--check-build-system ",
this->ConvertToOutputFormat(cmakefileName, cmOutputConverter::SHELL), this->ConvertToOutputFormat(cmakefileName, cmOutputConverter::SHELL),
" 0"); " 0");
@ -1805,7 +1806,8 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
std::string cmakefileName = "CMakeFiles/Makefile.cmake"; std::string cmakefileName = "CMakeFiles/Makefile.cmake";
{ {
std::string runRule = cmStrCat( std::string runRule = cmStrCat(
"$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) " "$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) ",
cm->GetIgnoreWarningAsError() ? "--compile-no-warning-as-error " : "",
"--check-build-system ", "--check-build-system ",
this->ConvertToOutputFormat(cmakefileName, cmOutputConverter::SHELL), this->ConvertToOutputFormat(cmakefileName, cmOutputConverter::SHELL),
" 1"); " 1");

View File

@ -262,6 +262,10 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
cmCustomCommandLines commandLines = cmCustomCommandLines commandLines =
cmMakeSingleCommandLine({ cmSystemTools::GetCMakeCommand(), argS, argB, cmMakeSingleCommandLine({ cmSystemTools::GetCMakeCommand(), argS, argB,
"--check-stamp-file", stampName }); "--check-stamp-file", stampName });
if (cm->GetIgnoreWarningAsError()) {
commandLines[0].emplace_back("--compile-no-warning-as-error");
}
std::string comment = cmStrCat("Building Custom Rule ", makefileIn); std::string comment = cmStrCat("Building Custom Rule ", makefileIn);
auto cc = cm::make_unique<cmCustomCommand>(); auto cc = cm::make_unique<cmCustomCommand>();
cc->SetOutputs(stampName); cc->SetOutputs(stampName);

View File

@ -5,6 +5,10 @@ function(run_compile_warn test lang extension)
set(RunCMake_TEST_OUTPUT_MERGE 1) set(RunCMake_TEST_OUTPUT_MERGE 1)
run_cmake_with_options(${test}_${lang} "-DLANGUAGE=${lang}" "-DEXTENSION=${extension}" ${ARGN}) run_cmake_with_options(${test}_${lang} "-DLANGUAGE=${lang}" "-DEXTENSION=${extension}" ${ARGN})
set(RunCMake_TEST_NO_CLEAN 1) set(RunCMake_TEST_NO_CLEAN 1)
if(ARGN MATCHES "--compile-no-warning-as-error")
# Cause the build system to re-run CMake to verify that this option is preserved.
run_cmake_command(${test}_${lang}-Touch ${CMAKE_COMMAND} -E touch_nocreate CMakeCache.txt)
endif()
run_cmake_command(${test}_${lang}-Build ${CMAKE_COMMAND} --build . ${verbose_args}) run_cmake_command(${test}_${lang}-Build ${CMAKE_COMMAND} --build . ${verbose_args})
endfunction() endfunction()