cmMakefile: Factor out helper to get recursion depth limit

This commit is contained in:
Brad King 2023-03-13 11:20:21 -04:00
parent 88bc8dfc14
commit 395895bda7
2 changed files with 18 additions and 10 deletions

View File

@ -453,17 +453,10 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
static_cast<void>(stack_manager);
// Check for maximum recursion depth.
size_t depth = CMake_DEFAULT_RECURSION_LIMIT;
if (cmValue depthStr =
this->GetDefinition("CMAKE_MAXIMUM_RECURSION_DEPTH")) {
unsigned long depthUL;
if (cmStrToULong(depthStr.GetCStr(), &depthUL)) {
depth = depthUL;
}
}
if (this->RecursionDepth > depth) {
size_t depthLimit = this->GetRecursionDepthLimit();
if (this->RecursionDepth > depthLimit) {
std::ostringstream e;
e << "Maximum recursion depth of " << depth << " exceeded";
e << "Maximum recursion depth of " << depthLimit << " exceeded";
this->IssueMessage(MessageType::FATAL_ERROR, e.str());
cmSystemTools::SetFatalErrorOccurred();
return false;
@ -2863,6 +2856,19 @@ bool cmMakefile::IsProjectFile(const char* filename) const
!cmSystemTools::IsSubDirectory(filename, "/CMakeFiles"));
}
size_t cmMakefile::GetRecursionDepthLimit() const
{
size_t depth = CMake_DEFAULT_RECURSION_LIMIT;
if (cmValue depthStr =
this->GetDefinition("CMAKE_MAXIMUM_RECURSION_DEPTH")) {
unsigned long depthUL;
if (cmStrToULong(depthStr.GetCStr(), &depthUL)) {
depth = depthUL;
}
}
return depth;
}
size_t cmMakefile::GetRecursionDepth() const
{
return this->RecursionDepth;

View File

@ -1023,6 +1023,8 @@ public:
const char* sourceFilename) const;
bool IsProjectFile(const char* filename) const;
size_t GetRecursionDepthLimit() const;
size_t GetRecursionDepth() const;
void SetRecursionDepth(size_t recursionDepth);