summaryrefslogtreecommitdiff
path: root/Source/cmGlobalGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-03-07 13:31:25 -0500
committerBrad King <brad.king@kitware.com>2016-03-07 13:52:38 -0500
commit72e0dc58d3caf63a57975e97ce13c5dc4b38cf9b (patch)
treec4011b95d6067e77f6074026d4ad9d5b381eee5b /Source/cmGlobalGenerator.cxx
parent8256d021c8324779c7269658a094848ebeafb82e (diff)
downloadcmake-72e0dc58d3caf63a57975e97ce13c5dc4b38cf9b.tar.gz
Diagnose recursive project/enable_language without crashing (#15999)
Calling `project()` or `enable_language()` from a toolchain file will infinitely recurse since those commands load the toolchain file. Diagnose and reject this case with an error message instead of crashing when the stack eventually overflows.
Diffstat (limited to 'Source/cmGlobalGenerator.cxx')
-rw-r--r--Source/cmGlobalGenerator.cxx21
1 files changed, 21 insertions, 0 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 848028ff31..c6284069e4 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -398,6 +398,21 @@ cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages,
return;
}
+ std::set<std::string> cur_languages(languages.begin(), languages.end());
+ for (std::set<std::string>::iterator li = cur_languages.begin();
+ li != cur_languages.end(); ++li)
+ {
+ if (!this->LanguagesInProgress.insert(*li).second)
+ {
+ std::ostringstream e;
+ e << "Language '" << *li << "' is currently being enabled. "
+ "Recursive call not allowed.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ cmSystemTools::SetFatalErrorOccured();
+ return;
+ }
+ }
+
if(this->TryCompileOuterMakefile)
{
// In a try-compile we can only enable languages provided by caller.
@@ -823,6 +838,12 @@ cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages,
{
cmSystemTools::SetFatalErrorOccured();
}
+
+ for (std::set<std::string>::iterator li = cur_languages.begin();
+ li != cur_languages.end(); ++li)
+ {
+ this->LanguagesInProgress.erase(*li);
+ }
}
//----------------------------------------------------------------------------