mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-27 03:08:35 -06:00
cmake: Enable --warn-uninitialized inside string(CONFIGURE) and configure_file
Fixes: #18489
This commit is contained in:
@@ -92,9 +92,11 @@ const char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
|
|||||||
return this->AddString(ostr.str());
|
return this->AddString(ostr.str());
|
||||||
}
|
}
|
||||||
const char* value = this->Makefile->GetDefinition(var);
|
const char* value = this->Makefile->GetDefinition(var);
|
||||||
if (!value && !this->RemoveEmpty) {
|
if (!value) {
|
||||||
this->Makefile->MaybeWarnUninitialized(var, this->FileName);
|
this->Makefile->MaybeWarnUninitialized(var, this->FileName);
|
||||||
return nullptr;
|
if (!this->RemoveEmpty) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (this->EscapeQuotes && value) {
|
if (this->EscapeQuotes && value) {
|
||||||
return this->AddString(cmSystemTools::EscapeQuotes(value));
|
return this->AddString(cmSystemTools::EscapeQuotes(value));
|
||||||
|
|||||||
@@ -2522,9 +2522,9 @@ const std::string& cmMakefile::ExpandVariablesInString(
|
|||||||
// Suppress variable watches to avoid calling hooks twice. Suppress new
|
// Suppress variable watches to avoid calling hooks twice. Suppress new
|
||||||
// dereferences since the OLD behavior is still what is actually used.
|
// dereferences since the OLD behavior is still what is actually used.
|
||||||
this->SuppressSideEffects = true;
|
this->SuppressSideEffects = true;
|
||||||
newError = ExpandVariablesInStringNew(
|
newError = ExpandVariablesInStringNew(newErrorstr, newResult,
|
||||||
newErrorstr, newResult, escapeQuotes, noEscapes, atOnly, filename,
|
escapeQuotes, noEscapes, atOnly,
|
||||||
line, removeEmpty, replaceAt);
|
filename, line, replaceAt);
|
||||||
this->SuppressSideEffects = false;
|
this->SuppressSideEffects = false;
|
||||||
CM_FALLTHROUGH;
|
CM_FALLTHROUGH;
|
||||||
}
|
}
|
||||||
@@ -2537,9 +2537,9 @@ const std::string& cmMakefile::ExpandVariablesInString(
|
|||||||
case cmPolicies::REQUIRED_ALWAYS:
|
case cmPolicies::REQUIRED_ALWAYS:
|
||||||
// Messaging here would be *very* verbose.
|
// Messaging here would be *very* verbose.
|
||||||
case cmPolicies::NEW:
|
case cmPolicies::NEW:
|
||||||
mtype = ExpandVariablesInStringNew(errorstr, source, escapeQuotes,
|
mtype =
|
||||||
noEscapes, atOnly, filename, line,
|
ExpandVariablesInStringNew(errorstr, source, escapeQuotes, noEscapes,
|
||||||
removeEmpty, replaceAt);
|
atOnly, filename, line, replaceAt);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2726,7 +2726,7 @@ bool cmMakefile::IsProjectFile(const char* filename) const
|
|||||||
cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
|
cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
|
||||||
std::string& errorstr, std::string& source, bool escapeQuotes,
|
std::string& errorstr, std::string& source, bool escapeQuotes,
|
||||||
bool noEscapes, bool atOnly, const char* filename, long line,
|
bool noEscapes, bool atOnly, const char* filename, long line,
|
||||||
bool removeEmpty, bool replaceAt) const
|
bool replaceAt) const
|
||||||
{
|
{
|
||||||
// This method replaces ${VAR} and @VAR@ where VAR is looked up
|
// This method replaces ${VAR} and @VAR@ where VAR is looked up
|
||||||
// with GetDefinition(), if not found in the map, nothing is expanded.
|
// with GetDefinition(), if not found in the map, nothing is expanded.
|
||||||
@@ -2783,7 +2783,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
|
|||||||
} else {
|
} else {
|
||||||
varresult = value;
|
varresult = value;
|
||||||
}
|
}
|
||||||
} else if (!removeEmpty && !this->SuppressSideEffects) {
|
} else if (!this->SuppressSideEffects) {
|
||||||
this->MaybeWarnUninitialized(lookup, filename);
|
this->MaybeWarnUninitialized(lookup, filename);
|
||||||
}
|
}
|
||||||
result.replace(var.loc, result.size() - var.loc, varresult);
|
result.replace(var.loc, result.size() - var.loc, varresult);
|
||||||
@@ -2896,7 +2896,12 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
|
|||||||
if (filename && variable == lineVar) {
|
if (filename && variable == lineVar) {
|
||||||
varresult = std::to_string(line);
|
varresult = std::to_string(line);
|
||||||
} else {
|
} else {
|
||||||
varresult = this->GetSafeDefinition(variable);
|
const std::string* def = this->GetDef(variable);
|
||||||
|
if (def) {
|
||||||
|
varresult = *def;
|
||||||
|
} else if (!this->SuppressSideEffects) {
|
||||||
|
this->MaybeWarnUninitialized(variable, filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (escapeQuotes) {
|
if (escapeQuotes) {
|
||||||
|
|||||||
@@ -990,7 +990,7 @@ private:
|
|||||||
cmake::MessageType ExpandVariablesInStringNew(
|
cmake::MessageType ExpandVariablesInStringNew(
|
||||||
std::string& errorstr, std::string& source, bool escapeQuotes,
|
std::string& errorstr, std::string& source, bool escapeQuotes,
|
||||||
bool noEscapes, bool atOnly, const char* filename, long line,
|
bool noEscapes, bool atOnly, const char* filename, long line,
|
||||||
bool removeEmpty, bool replaceAt) const;
|
bool replaceAt) const;
|
||||||
/**
|
/**
|
||||||
* Old version of GetSourceFileWithOutput(const std::string&) kept for
|
* Old version of GetSourceFileWithOutput(const std::string&) kept for
|
||||||
* backward-compatibility. It implements a linear search and support
|
* backward-compatibility. It implements a linear search and support
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ set(RunCMake_TEST_OPTIONS --trace-expand --warn-uninitialized)
|
|||||||
run_cmake(trace-expand-warn-uninitialized)
|
run_cmake(trace-expand-warn-uninitialized)
|
||||||
unset(RunCMake_TEST_OPTIONS)
|
unset(RunCMake_TEST_OPTIONS)
|
||||||
|
|
||||||
set(RunCMake_TEST_OPTIONS --warn-uninitialized)
|
set(RunCMake_TEST_OPTIONS -Wno-deprecated --warn-uninitialized)
|
||||||
run_cmake(warn-uninitialized)
|
run_cmake(warn-uninitialized)
|
||||||
unset(RunCMake_TEST_OPTIONS)
|
unset(RunCMake_TEST_OPTIONS)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,53 @@
|
|||||||
^CMake Warning \(dev\) at warn-uninitialized.cmake:1 \(set\):
|
^CMake Warning \(dev\) at warn-uninitialized.cmake:3 \(set\):
|
||||||
uninitialized variable 'WARN_FROM_NORMAL_CMAKE_FILE'
|
uninitialized variable 'OLD_WARN_FROM_NORMAL_CMAKE_FILE_INSIDE_BRACES'
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
This warning is for project developers. Use -Wno-dev to suppress it.
|
||||||
|
|
||||||
|
CMake Warning \(dev\) at warn-uninitialized.cmake:4 \(set\):
|
||||||
|
uninitialized variable 'OLD_WARN_FROM_NORMAL_CMAKE_FILE_IN_ATS'
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
This warning is for project developers. Use -Wno-dev to suppress it.
|
||||||
|
|
||||||
|
CMake Warning \(dev\) at warn-uninitialized.cmake:5 \(string\):
|
||||||
|
uninitialized variable 'OLD_WARN_FROM_STRING_CONFIGURE_INSIDE_BRACES'
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
This warning is for project developers. Use -Wno-dev to suppress it.
|
||||||
|
|
||||||
|
CMake Warning \(dev\) at warn-uninitialized.cmake:7 \(configure_file\):
|
||||||
|
uninitialized variable 'OLD_WARN_FROM_CONFIGURE_FILE_INSIDE_AT'
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
This warning is for project developers. Use -Wno-dev to suppress it.
|
||||||
|
|
||||||
|
CMake Warning \(dev\) at warn-uninitialized.cmake:8 \(string\):
|
||||||
|
uninitialized variable 'OLD_WARN_FROM_STRING_CONFIGURE_INSIDE_AT'
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
This warning is for project developers. Use -Wno-dev to suppress it.
|
||||||
|
|
||||||
|
CMake Warning \(dev\) at warn-uninitialized.cmake:13 \(set\):
|
||||||
|
uninitialized variable 'NEW_WARN_FROM_NORMAL_CMAKE_FILE_INSIDE_BRACES'
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
This warning is for project developers. Use -Wno-dev to suppress it.
|
||||||
|
|
||||||
|
CMake Warning \(dev\) at warn-uninitialized.cmake:14 \(string\):
|
||||||
|
uninitialized variable 'NEW_WARN_FROM_STRING_CONFIGURE_INSIDE_BRACES'
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
This warning is for project developers. Use -Wno-dev to suppress it.
|
||||||
|
|
||||||
|
CMake Warning \(dev\) at warn-uninitialized.cmake:16 \(configure_file\):
|
||||||
|
uninitialized variable 'NEW_WARN_FROM_CONFIGURE_FILE_INSIDE_AT'
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
|
This warning is for project developers. Use -Wno-dev to suppress it.
|
||||||
|
|
||||||
|
CMake Warning \(dev\) at warn-uninitialized.cmake:17 \(string\):
|
||||||
|
uninitialized variable 'NEW_WARN_FROM_STRING_CONFIGURE_INSIDE_AT'
|
||||||
Call Stack \(most recent call first\):
|
Call Stack \(most recent call first\):
|
||||||
CMakeLists.txt:3 \(include\)
|
CMakeLists.txt:3 \(include\)
|
||||||
This warning is for project developers. Use -Wno-dev to suppress it.$
|
This warning is for project developers. Use -Wno-dev to suppress it.$
|
||||||
|
|||||||
@@ -1 +1,18 @@
|
|||||||
set(FOO "${WARN_FROM_NORMAL_CMAKE_FILE}")
|
cmake_policy(PUSH)
|
||||||
|
cmake_policy(SET CMP0053 OLD)
|
||||||
|
set(FOO "${OLD_WARN_FROM_NORMAL_CMAKE_FILE_INSIDE_BRACES}")
|
||||||
|
set(FOO "@OLD_WARN_FROM_NORMAL_CMAKE_FILE_IN_ATS@")
|
||||||
|
string(CONFIGURE "\${OLD_WARN_FROM_STRING_CONFIGURE_INSIDE_BRACES}" OUT1)
|
||||||
|
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/file1.in "\@OLD_WARN_FROM_CONFIGURE_FILE_INSIDE_AT\@")
|
||||||
|
configure_file(${CMAKE_CURRENT_BINARY_DIR}/file1.in file1.out)
|
||||||
|
string(CONFIGURE "\@OLD_WARN_FROM_STRING_CONFIGURE_INSIDE_AT\@" OUT2)
|
||||||
|
cmake_policy(POP)
|
||||||
|
|
||||||
|
cmake_policy(PUSH)
|
||||||
|
cmake_policy(SET CMP0053 NEW)
|
||||||
|
set(FOO "${NEW_WARN_FROM_NORMAL_CMAKE_FILE_INSIDE_BRACES}")
|
||||||
|
string(CONFIGURE "\${NEW_WARN_FROM_STRING_CONFIGURE_INSIDE_BRACES}" OUT3)
|
||||||
|
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/file2.in "\@NEW_WARN_FROM_CONFIGURE_FILE_INSIDE_AT\@")
|
||||||
|
configure_file(${CMAKE_CURRENT_BINARY_DIR}/file2.in file2.out)
|
||||||
|
string(CONFIGURE "@NEW_WARN_FROM_STRING_CONFIGURE_INSIDE_AT@" OUT4)
|
||||||
|
cmake_policy(POP)
|
||||||
|
|||||||
Reference in New Issue
Block a user