summaryrefslogtreecommitdiffstats
path: root/Source/cmFindPackageCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-03-14 13:35:31 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-03-14 13:35:45 (GMT)
commitd45992e63309b465d423f5430d8d78aade5117e3 (patch)
treef8eb065965135a3191a4e74717f599c605668c10 /Source/cmFindPackageCommand.cxx
parentdb4f4ad24e9a0ec8e0cb22b6b0204173d06e1cf8 (diff)
parent49167cf68fcfea201e4e81824baadf8bef413e4c (diff)
downloadCMake-d45992e63309b465d423f5430d8d78aade5117e3.zip
CMake-d45992e63309b465d423f5430d8d78aade5117e3.tar.gz
CMake-d45992e63309b465d423f5430d8d78aade5117e3.tar.bz2
Merge topic 'recursion-limit'
49167cf68f Source: Adjust stack sizes and recursion limits to work together 9504cef8c4 Tests: Allow RunCMake.MaxRecursionDepth to test public-facing default limit 60ef076bac find_package: Enforce maximum nesting depth below maximum recursion depth 89b69bf1ad Add CMAKE_MAXIMUM_RECURSION_DEPTH environment variable 395895bda7 cmMakefile: Factor out helper to get recursion depth limit 88bc8dfc14 cmMakefile: Store recursion depth limit as size_t fcad8d0630 cmMakefile: Improve parsing of CMAKE_MAXIMUM_RECURSION_DEPTH variable 497f7d5c1a Tests: Simplify option passing to RunCMake.MaxRecursionDepth cases Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !8307
Diffstat (limited to 'Source/cmFindPackageCommand.cxx')
-rw-r--r--Source/cmFindPackageCommand.cxx15
1 files changed, 15 insertions, 0 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index 4024dff..c228cde 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -977,6 +977,21 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
}
}
+ // Limit package nesting depth well below the recursion depth limit because
+ // find_package nesting uses more stack space than normal recursion.
+ {
+ static std::size_t const findPackageDepthMinMax = 100;
+ std::size_t const findPackageDepthMax = std::max(
+ this->Makefile->GetRecursionDepthLimit() / 2, findPackageDepthMinMax);
+ std::size_t const findPackageDepth =
+ this->Makefile->FindPackageRootPathStack.size() + 1;
+ if (findPackageDepth > findPackageDepthMax) {
+ this->SetError(cmStrCat("maximum nesting depth of ", findPackageDepthMax,
+ " exceeded."));
+ return false;
+ }
+ }
+
this->PushFindPackageRootPathStack();
this->SetModuleVariables(components, componentVarDefs);