summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.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/cmMakefile.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/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx56
1 files changed, 42 insertions, 14 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 3fcc7f7..fc82c14 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -67,6 +67,24 @@
# include "cmVariableWatch.h"
#endif
+#ifndef __has_feature
+# define __has_feature(x) 0
+#endif
+
+// Select a recursion limit that fits within the stack size.
+// See stack size flags in '../CompileFlags.cmake'.
+#ifndef CMake_DEFAULT_RECURSION_LIMIT
+# if __has_feature(address_sanitizer)
+# define CMake_DEFAULT_RECURSION_LIMIT 400
+# elif defined(_MSC_VER) && defined(_DEBUG)
+# define CMake_DEFAULT_RECURSION_LIMIT 600
+# elif defined(__ibmxl__) && defined(__linux)
+# define CMake_DEFAULT_RECURSION_LIMIT 600
+# else
+# define CMake_DEFAULT_RECURSION_LIMIT 1000
+# endif
+#endif
+
class cmMessenger;
cmDirectoryId::cmDirectoryId(std::string s)
@@ -99,7 +117,6 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator,
this->StateSnapshot =
this->StateSnapshot.GetState()->CreatePolicyScopeSnapshot(
this->StateSnapshot);
- this->RecursionDepth = 0;
// Enter a policy level for this directory.
this->PushPolicy();
@@ -454,18 +471,10 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
static_cast<void>(stack_manager);
// Check for maximum recursion depth.
- int depth = CMake_DEFAULT_RECURSION_LIMIT;
- cmValue depthStr = this->GetDefinition("CMAKE_MAXIMUM_RECURSION_DEPTH");
- if (depthStr) {
- std::istringstream s(*depthStr);
- int d;
- if (s >> d) {
- depth = d;
- }
- }
- 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;
@@ -2865,12 +2874,31 @@ bool cmMakefile::IsProjectFile(const char* filename) const
!cmSystemTools::IsSubDirectory(filename, "/CMakeFiles"));
}
-int cmMakefile::GetRecursionDepth() const
+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;
+ }
+ } else if (cm::optional<std::string> depthEnv =
+ cmSystemTools::GetEnvVar("CMAKE_MAXIMUM_RECURSION_DEPTH")) {
+ unsigned long depthUL;
+ if (cmStrToULong(*depthEnv, &depthUL)) {
+ depth = depthUL;
+ }
+ }
+ return depth;
+}
+
+size_t cmMakefile::GetRecursionDepth() const
{
return this->RecursionDepth;
}
-void cmMakefile::SetRecursionDepth(int recursionDepth)
+void cmMakefile::SetRecursionDepth(size_t recursionDepth)
{
this->RecursionDepth = recursionDepth;
}