diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeLists.txt | 10 | ||||
-rw-r--r-- | Source/CTest/cmCTestRunScriptCommand.cxx | 3 | ||||
-rw-r--r-- | Source/CTest/cmCTestScriptHandler.cxx | 12 | ||||
-rw-r--r-- | Source/CTest/cmCTestScriptHandler.h | 5 | ||||
-rw-r--r-- | Source/cmConfigure.cmake.h.in | 1 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 3 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 2 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 43 | ||||
-rw-r--r-- | Source/cmMakefile.h | 4 |
9 files changed, 78 insertions, 5 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 9e753e6..c73c6df 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -31,6 +31,16 @@ else() set(CMAKE_USE_ELF_PARSER) endif() +if(NOT CMake_DEFAULT_RECURSION_LIMIT) + if(DEFINED ENV{DASHBOARD_TEST_FROM_CTEST}) + set(CMake_DEFAULT_RECURSION_LIMIT 100) + elseif(MINGW) + set(CMake_DEFAULT_RECURSION_LIMIT 400) + else() + set(CMake_DEFAULT_RECURSION_LIMIT 1000) + endif() +endif() + if(APPLE) set(CMAKE_USE_MACH_PARSER 1) endif() diff --git a/Source/CTest/cmCTestRunScriptCommand.cxx b/Source/CTest/cmCTestRunScriptCommand.cxx index 238284a..a7e47d3 100644 --- a/Source/CTest/cmCTestRunScriptCommand.cxx +++ b/Source/CTest/cmCTestRunScriptCommand.cxx @@ -39,7 +39,8 @@ bool cmCTestRunScriptCommand::InitialPass(std::vector<std::string> const& args, ++i; } else { int ret; - cmCTestScriptHandler::RunScript(this->CTest, args[i].c_str(), !np, &ret); + cmCTestScriptHandler::RunScript(this->CTest, this->Makefile, + args[i].c_str(), !np, &ret); std::ostringstream str; str << ret; this->Makefile->AddDefinition(returnVariable, str.str().c_str()); diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index f417f53..b949023 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -78,6 +78,7 @@ cmCTestScriptHandler::cmCTestScriptHandler() this->EmptyBinDir = false; this->EmptyBinDirOnce = false; this->Makefile = nullptr; + this->ParentMakefile = nullptr; this->CMake = nullptr; this->GlobalGenerator = nullptr; @@ -117,6 +118,7 @@ void cmCTestScriptHandler::Initialize() delete this->Makefile; this->Makefile = nullptr; + this->ParentMakefile = nullptr; delete this->GlobalGenerator; this->GlobalGenerator = nullptr; @@ -292,6 +294,10 @@ void cmCTestScriptHandler::CreateCMake() snapshot.GetDirectory().SetCurrentSource(cwd); snapshot.GetDirectory().SetCurrentBinary(cwd); this->Makefile = new cmMakefile(this->GlobalGenerator, snapshot); + if (this->ParentMakefile) { + this->Makefile->SetRecursionDepth( + this->ParentMakefile->GetRecursionDepth()); + } this->CMake->SetProgressCallback(ctestScriptProgressCallback, this->CTest); @@ -891,11 +897,13 @@ void cmCTestScriptHandler::RestoreBackupDirectories() } } -bool cmCTestScriptHandler::RunScript(cmCTest* ctest, const char* sname, - bool InProcess, int* returnValue) +bool cmCTestScriptHandler::RunScript(cmCTest* ctest, cmMakefile* mf, + const char* sname, bool InProcess, + int* returnValue) { cmCTestScriptHandler* sh = new cmCTestScriptHandler(); sh->SetCTestInstance(ctest); + sh->ParentMakefile = mf; sh->AddConfigurationScript(sname, InProcess); int res = sh->ProcessHandler(); if (returnValue) { diff --git a/Source/CTest/cmCTestScriptHandler.h b/Source/CTest/cmCTestScriptHandler.h index cf0762e..d93b5f8 100644 --- a/Source/CTest/cmCTestScriptHandler.h +++ b/Source/CTest/cmCTestScriptHandler.h @@ -72,8 +72,8 @@ public: /* * Run a script */ - static bool RunScript(cmCTest* ctest, const char* script, bool InProcess, - int* returnValue); + static bool RunScript(cmCTest* ctest, cmMakefile* mf, const char* script, + bool InProcess, int* returnValue); int RunCurrentScript(); /* @@ -166,6 +166,7 @@ private: std::chrono::steady_clock::time_point ScriptStartTime; cmMakefile* Makefile; + cmMakefile* ParentMakefile; cmGlobalGenerator* GlobalGenerator; cmake* CMake; }; diff --git a/Source/cmConfigure.cmake.h.in b/Source/cmConfigure.cmake.h.in index c80439b..9d00c21 100644 --- a/Source/cmConfigure.cmake.h.in +++ b/Source/cmConfigure.cmake.h.in @@ -20,6 +20,7 @@ #cmakedefine CMAKE_USE_ELF_PARSER #cmakedefine CMAKE_USE_MACH_PARSER #cmakedefine CMake_HAVE_CXX_MAKE_UNIQUE +#define CMake_DEFAULT_RECURSION_LIMIT @CMake_DEFAULT_RECURSION_LIMIT@ #define CMAKE_BIN_DIR "/@CMAKE_BIN_DIR@" #define CMAKE_DATA_DIR "/@CMAKE_DATA_DIR@" diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index b2b0e38..acd666f 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -98,6 +98,8 @@ cmGlobalGenerator::cmGlobalGenerator(cmake* cm) this->ConfigureDoneCMP0026AndCMP0024 = false; this->FirstTimeProgress = 0.0f; + this->RecursionDepth = 0; + cm->GetState()->SetIsGeneratorMultiConfig(false); cm->GetState()->SetMinGWMake(false); cm->GetState()->SetMSYSShell(false); @@ -1166,6 +1168,7 @@ void cmGlobalGenerator::Configure() this->CMakeInstance->GetHomeOutputDirectory()); cmMakefile* dirMf = new cmMakefile(this, snapshot); + dirMf->SetRecursionDepth(this->RecursionDepth); this->Makefiles.push_back(dirMf); this->IndexMakefile(dirMf); diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 36d3d10..fa16180 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -432,6 +432,8 @@ public: std::string MakeSilentFlag; + int RecursionDepth; + protected: typedef std::vector<cmLocalGenerator*> GeneratorVector; // for a project collect all its targets by following depend diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 500776e..ca5047a 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -45,6 +45,8 @@ #include "cm_sys_stat.h" #include "cmake.h" +#include "cmConfigure.h" // IWYU pragma: keep + #ifdef CMAKE_BUILD_WITH_CMAKE # include "cmVariableWatch.h" #endif @@ -83,6 +85,7 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator, this->StateSnapshot = this->StateSnapshot.GetState()->CreatePolicyScopeSnapshot( this->StateSnapshot); + this->RecursionDepth = 0; // Enter a policy level for this directory. this->PushPolicy(); @@ -333,12 +336,14 @@ public: cmListFileContext const& lfc = cmListFileContext::FromCommandContext( cc, this->Makefile->StateSnapshot.GetExecutionListFile()); this->Makefile->Backtrace = this->Makefile->Backtrace.Push(lfc); + ++this->Makefile->RecursionDepth; this->Makefile->ExecutionStatusStack.push_back(&status); } ~cmMakefileCall() { this->Makefile->ExecutionStatusStack.pop_back(); + --this->Makefile->RecursionDepth; this->Makefile->Backtrace = this->Makefile->Backtrace.Pop(); } @@ -361,6 +366,24 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, cmMakefileCall stack_manager(this, lff, status); static_cast<void>(stack_manager); + // Check for maximum recursion depth. + int depth = CMake_DEFAULT_RECURSION_LIMIT; + const char* depthStr = this->GetDefinition("CMAKE_MAXIMUM_RECURSION_DEPTH"); + if (depthStr) { + std::istringstream s(depthStr); + int d; + if (s >> d) { + depth = d; + } + } + if (this->RecursionDepth > depth) { + std::ostringstream e; + e << "Maximum recursion depth of " << depth << " exceeded"; + this->IssueMessage(MessageType::FATAL_ERROR, e.str()); + cmSystemTools::SetFatalErrorOccured(); + return false; + } + // Lookup the command prototype. if (cmCommand* proto = this->GetState()->GetCommandByExactName(lff.Name.Lower)) { @@ -1369,6 +1392,9 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent) // Imported targets. this->ImportedTargets = parent->ImportedTargets; + + // Recursion depth. + this->RecursionDepth = parent->RecursionDepth; } void cmMakefile::PushFunctionScope(std::string const& fileName, @@ -2725,6 +2751,16 @@ bool cmMakefile::IsProjectFile(const char* filename) const cmake::GetCMakeFilesDirectory())); } +int cmMakefile::GetRecursionDepth() const +{ + return this->RecursionDepth; +} + +void cmMakefile::SetRecursionDepth(int recursionDepth) +{ + this->RecursionDepth = recursionDepth; +} + MessageType cmMakefile::ExpandVariablesInStringNew( std::string& errorstr, std::string& source, bool escapeQuotes, bool noEscapes, bool atOnly, const char* filename, long line, @@ -3388,6 +3424,7 @@ int cmMakefile::TryCompile(const std::string& srcdir, this->IsSourceFileTryCompile = false; return 1; } + gg->RecursionDepth = this->RecursionDepth; cm.SetGlobalGenerator(gg); // do a configure @@ -3407,6 +3444,12 @@ int cmMakefile::TryCompile(const std::string& srcdir, cmStateEnums::STRING); } } + const char* recursionDepth = + this->GetDefinition("CMAKE_MAXIMUM_RECURSION_DEPTH"); + if (recursionDepth) { + cm.AddCacheEntry("CMAKE_MAXIMUM_RECURSION_DEPTH", recursionDepth, + "Maximum recursion depth", cmStateEnums::STRING); + } // if cmake args were provided then pass them in if (cmakeArgs) { // FIXME: Workaround to ignore unused CLI variables in try-compile. diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index e88bb0b..2bd44e2 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -870,6 +870,9 @@ public: const char* sourceFilename) const; bool IsProjectFile(const char* filename) const; + int GetRecursionDepth() const; + void SetRecursionDepth(int recursionDepth); + protected: // add link libraries and directories to the target void AddGlobalLinkInformation(cmTarget& target); @@ -930,6 +933,7 @@ protected: private: cmStateSnapshot StateSnapshot; cmListFileBacktrace Backtrace; + int RecursionDepth; void ReadListFile(cmListFile const& listFile, const std::string& filenametoread); |