浏览代码

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 <[email protected]>
Acked-by: buildbot <[email protected]>
Merge-request: !8307
Brad King 2 年之前
父节点
当前提交
d45992e633
共有 61 个文件被更改,包括 459 次插入70 次删除
  1. 8 7
      CompileFlags.cmake
  2. 10 0
      Help/envvar/CMAKE_MAXIMUM_RECURSION_DEPTH.rst
  3. 1 0
      Help/manual/cmake-env-variables.7.rst
  4. 2 0
      Help/variable/CMAKE_MAXIMUM_RECURSION_DEPTH.rst
  5. 0 14
      Source/CMakeLists.txt
  6. 1 1
      Source/cmConfigure.cmake.h.in
  7. 15 0
      Source/cmFindPackageCommand.cxx
  8. 0 2
      Source/cmGlobalGenerator.cxx
  9. 1 1
      Source/cmGlobalGenerator.h
  10. 42 14
      Source/cmMakefile.cxx
  11. 5 3
      Source/cmMakefile.h
  12. 3 0
      Tests/EnforceConfig.cmake.in
  13. 28 16
      Tests/RunCMake/MaxRecursionDepth/RunCMakeTest.cmake
  14. 1 0
      Tests/RunCMake/MaxRecursionDepth/ctest_read_custom_files-env-result.txt
  15. 34 0
      Tests/RunCMake/MaxRecursionDepth/ctest_read_custom_files-env-stderr.txt
  16. 1 0
      Tests/RunCMake/MaxRecursionDepth/ctest_read_custom_files-invalid-env-result.txt
  17. 5 0
      Tests/RunCMake/MaxRecursionDepth/ctest_read_custom_files-invalid-env-stderr.txt
  18. 5 3
      Tests/RunCMake/MaxRecursionDepth/find_package-default-script-stderr.txt
  19. 3 3
      Tests/RunCMake/MaxRecursionDepth/find_package-default-stderr.txt
  20. 1 0
      Tests/RunCMake/MaxRecursionDepth/find_package-env-result.txt
  21. 1 0
      Tests/RunCMake/MaxRecursionDepth/find_package-env-script-result.txt
  22. 21 0
      Tests/RunCMake/MaxRecursionDepth/find_package-env-script-stderr.txt
  23. 21 0
      Tests/RunCMake/MaxRecursionDepth/find_package-env-stderr.txt
  24. 1 0
      Tests/RunCMake/MaxRecursionDepth/find_package-invalid-env-result.txt
  25. 1 0
      Tests/RunCMake/MaxRecursionDepth/find_package-invalid-env-script-result.txt
  26. 7 0
      Tests/RunCMake/MaxRecursionDepth/find_package-invalid-env-script-stderr.txt
  27. 5 0
      Tests/RunCMake/MaxRecursionDepth/find_package-invalid-env-stderr.txt
  28. 5 3
      Tests/RunCMake/MaxRecursionDepth/find_package-invalid-var-script-stderr.txt
  29. 3 3
      Tests/RunCMake/MaxRecursionDepth/find_package-invalid-var-stderr.txt
  30. 1 0
      Tests/RunCMake/MaxRecursionDepth/function-env-result.txt
  31. 1 0
      Tests/RunCMake/MaxRecursionDepth/function-env-script-result.txt
  32. 21 0
      Tests/RunCMake/MaxRecursionDepth/function-env-script-stderr.txt
  33. 21 0
      Tests/RunCMake/MaxRecursionDepth/function-env-stderr.txt
  34. 1 0
      Tests/RunCMake/MaxRecursionDepth/function-invalid-env-result.txt
  35. 1 0
      Tests/RunCMake/MaxRecursionDepth/function-invalid-env-script-result.txt
  36. 5 0
      Tests/RunCMake/MaxRecursionDepth/function-invalid-env-script-stderr.txt
  37. 5 0
      Tests/RunCMake/MaxRecursionDepth/function-invalid-env-stderr.txt
  38. 1 0
      Tests/RunCMake/MaxRecursionDepth/include-env-result.txt
  39. 1 0
      Tests/RunCMake/MaxRecursionDepth/include-env-script-result.txt
  40. 21 0
      Tests/RunCMake/MaxRecursionDepth/include-env-script-stderr.txt
  41. 21 0
      Tests/RunCMake/MaxRecursionDepth/include-env-stderr.txt
  42. 1 0
      Tests/RunCMake/MaxRecursionDepth/include-invalid-env-result.txt
  43. 1 0
      Tests/RunCMake/MaxRecursionDepth/include-invalid-env-script-result.txt
  44. 5 0
      Tests/RunCMake/MaxRecursionDepth/include-invalid-env-script-stderr.txt
  45. 5 0
      Tests/RunCMake/MaxRecursionDepth/include-invalid-env-stderr.txt
  46. 1 0
      Tests/RunCMake/MaxRecursionDepth/macro-env-result.txt
  47. 1 0
      Tests/RunCMake/MaxRecursionDepth/macro-env-script-result.txt
  48. 21 0
      Tests/RunCMake/MaxRecursionDepth/macro-env-script-stderr.txt
  49. 21 0
      Tests/RunCMake/MaxRecursionDepth/macro-env-stderr.txt
  50. 1 0
      Tests/RunCMake/MaxRecursionDepth/macro-invalid-env-result.txt
  51. 1 0
      Tests/RunCMake/MaxRecursionDepth/macro-invalid-env-script-result.txt
  52. 5 0
      Tests/RunCMake/MaxRecursionDepth/macro-invalid-env-script-stderr.txt
  53. 5 0
      Tests/RunCMake/MaxRecursionDepth/macro-invalid-env-stderr.txt
  54. 1 0
      Tests/RunCMake/MaxRecursionDepth/variable_watch-env-result.txt
  55. 1 0
      Tests/RunCMake/MaxRecursionDepth/variable_watch-env-script-result.txt
  56. 22 0
      Tests/RunCMake/MaxRecursionDepth/variable_watch-env-script-stderr.txt
  57. 22 0
      Tests/RunCMake/MaxRecursionDepth/variable_watch-env-stderr.txt
  58. 1 0
      Tests/RunCMake/MaxRecursionDepth/variable_watch-invalid-env-result.txt
  59. 1 0
      Tests/RunCMake/MaxRecursionDepth/variable_watch-invalid-env-script-result.txt
  60. 6 0
      Tests/RunCMake/MaxRecursionDepth/variable_watch-invalid-env-script-stderr.txt
  61. 6 0
      Tests/RunCMake/MaxRecursionDepth/variable_watch-invalid-env-stderr.txt

+ 8 - 7
CompileFlags.cmake

@@ -8,7 +8,7 @@ if(WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "Intel")
   set(_INTEL_WINDOWS 1)
 endif()
 
-if(WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "Clang"
+if(WIN32 AND CMAKE_C_COMPILER_ID MATCHES "^(Clang|IntelLLVM)$"
    AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
   set(_CLANG_MSVC_WINDOWS 1)
 endif()
@@ -22,18 +22,19 @@ if(MSVC OR _INTEL_WINDOWS OR _CLANG_MSVC_WINDOWS)
 else()
 endif()
 
-if(MSVC)
-  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_CXX_LINKER_WRAPPER_FLAG}-stack:10000000")
-endif()
-
 # MSVC 14.28 enables C5105, but the Windows SDK 10.0.18362.0 triggers it.
 if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 19.28)
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wd5105")
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd5105")
 endif()
 
-if(_CLANG_MSVC_WINDOWS AND "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
-  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker -stack:20000000")
+# Use a stack size large enough for CMake_DEFAULT_RECURSION_LIMIT.
+if(MSVC)
+  string(APPEND CMAKE_EXE_LINKER_FLAGS " ${CMAKE_CXX_LINKER_WRAPPER_FLAG}-stack:10000000")
+elseif(MINGW OR MSYS OR CYGWIN)
+  string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,--stack,10000000")
+elseif(_CLANG_MSVC_WINDOWS AND "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
+  string(APPEND CMAKE_EXE_LINKER_FLAGS " -Xlinker -stack:20000000")
 endif()
 
 #silence duplicate symbol warnings on AIX

+ 10 - 0
Help/envvar/CMAKE_MAXIMUM_RECURSION_DEPTH.rst

@@ -0,0 +1,10 @@
+CMAKE_MAXIMUM_RECURSION_DEPTH
+-----------------------------
+
+.. versionadded:: 3.27
+
+.. include:: ENV_VAR.txt
+
+Maximum recursion depth for CMake scripts.  This environment variable is
+used if the :variable:`CMAKE_MAXIMUM_RECURSION_DEPTH` variable is not set.
+See that variable's documentation for details.

+ 1 - 0
Help/manual/cmake-env-variables.7.rst

@@ -20,6 +20,7 @@ Environment Variables that Change Behavior
 .. toctree::
    :maxdepth: 1
 
+   /envvar/CMAKE_MAXIMUM_RECURSION_DEPTH
    /envvar/CMAKE_PREFIX_PATH
    /envvar/SSL_CERT_DIR
    /envvar/SSL_CERT_FILE

+ 2 - 0
Help/variable/CMAKE_MAXIMUM_RECURSION_DEPTH.rst

@@ -33,3 +33,5 @@ Calling any of the following commands increases the recursion depth:
   depth)
 * Reading or writing variables that are being watched by a
   :command:`variable_watch`
+
+See also the :envvar:`CMAKE_MAXIMUM_RECURSION_DEPTH` environment variable.

+ 0 - 14
Source/CMakeLists.txt

@@ -11,20 +11,6 @@ endif()
 
 include(CheckIncludeFile)
 
-if(NOT CMake_DEFAULT_RECURSION_LIMIT)
-  if(DEFINED ENV{DASHBOARD_TEST_FROM_CTEST})
-    set(CMake_DEFAULT_RECURSION_LIMIT 100)
-  elseif(MINGW OR MSYS)
-    set(CMake_DEFAULT_RECURSION_LIMIT 400)
-  elseif(WIN32 AND CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "ARM64")
-    set(CMake_DEFAULT_RECURSION_LIMIT 400)
-  elseif(WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "IntelLLVM")
-    set(CMake_DEFAULT_RECURSION_LIMIT 600)
-  else()
-    set(CMake_DEFAULT_RECURSION_LIMIT 1000)
-  endif()
-endif()
-
 if(APPLE)
   set(CMake_USE_MACH_PARSER 1)
 endif()

+ 1 - 1
Source/cmConfigure.cmake.h.in

@@ -23,7 +23,7 @@
 #cmakedefine CMake_USE_MACH_PARSER
 #cmakedefine CMake_USE_XCOFF_PARSER
 #cmakedefine CMAKE_USE_WMAKE
-#define CMake_DEFAULT_RECURSION_LIMIT @CMake_DEFAULT_RECURSION_LIMIT@
+#cmakedefine CMake_DEFAULT_RECURSION_LIMIT @CMake_DEFAULT_RECURSION_LIMIT@
 #define CMAKE_BIN_DIR "/@CMAKE_BIN_DIR@"
 #define CMAKE_DATA_DIR "/@CMAKE_DATA_DIR@"
 #define CMAKE_DOC_DIR "/@CMAKE_DOC_DIR@"

+ 15 - 0
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);

+ 0 - 2
Source/cmGlobalGenerator.cxx

@@ -110,8 +110,6 @@ 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);

+ 1 - 1
Source/cmGlobalGenerator.h

@@ -586,7 +586,7 @@ public:
 
   std::string MakeSilentFlag;
 
-  int RecursionDepth;
+  size_t RecursionDepth = 0;
 
   virtual void GetQtAutoGenConfigs(std::vector<std::string>& configs) const
   {

+ 42 - 14
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;
 }

+ 5 - 3
Source/cmMakefile.h

@@ -1023,8 +1023,10 @@ public:
                               const char* sourceFilename) const;
   bool IsProjectFile(const char* filename) const;
 
-  int GetRecursionDepth() const;
-  void SetRecursionDepth(int recursionDepth);
+  size_t GetRecursionDepthLimit() const;
+
+  size_t GetRecursionDepth() const;
+  void SetRecursionDepth(size_t recursionDepth);
 
   std::string NewDeferId() const;
   bool DeferCall(std::string id, std::string fileName, cmListFileFunction lff);
@@ -1090,7 +1092,7 @@ protected:
 private:
   cmStateSnapshot StateSnapshot;
   cmListFileBacktrace Backtrace;
-  int RecursionDepth;
+  size_t RecursionDepth = 0;
 
   struct DeferCommand
   {

+ 3 - 0
Tests/EnforceConfig.cmake.in

@@ -35,5 +35,8 @@ unset(ENV{CMAKE_GENERATOR_PLATFORM})
 unset(ENV{CMAKE_GENERATOR_TOOLSET})
 unset(ENV{CMAKE_EXPORT_COMPILE_COMMANDS})
 
+# Verify that our module implementations do not recurse too much.
+set(ENV{CMAKE_MAXIMUM_RECURSION_DEPTH} 100)
+
 @TEST_HOME_ENV_CODE@
 @TEST_WARN_VS_CODE@

+ 28 - 16
Tests/RunCMake/MaxRecursionDepth/RunCMakeTest.cmake

@@ -1,26 +1,42 @@
 include(RunCMake)
 include(RunCTest)
 
-function(run_cmake_recursive name)
-  set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name})
-  run_cmake(${name}-default)
-  unset(RunCMake_TEST_OPTIONS)
-  set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name} -DCMAKE_MAXIMUM_RECURSION_DEPTH=10)
-  run_cmake(${name}-var)
-  unset(RunCMake_TEST_OPTIONS)
-  set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name} -DCMAKE_MAXIMUM_RECURSION_DEPTH=a)
-  run_cmake(${name}-invalid-var)
-  unset(RunCMake_TEST_OPTIONS)
+# Isolate this test from the caller's environment.
+unset(ENV{CMAKE_MAXIMUM_RECURSION_DEPTH})
 
+function(run_cmake_recursive name)
+  run_cmake_with_options(${name}-default "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name})
   run_cmake_command(${name}-default-script ${CMAKE_COMMAND} "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name} -P "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt")
+
+  set(ENV{CMAKE_MAXIMUM_RECURSION_DEPTH} 5) # overridden, not used
+  run_cmake_with_options(${name}-var "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name} -DCMAKE_MAXIMUM_RECURSION_DEPTH=10)
+  run_cmake_with_options(${name}-invalid-var "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name} -DCMAKE_MAXIMUM_RECURSION_DEPTH=a)
   run_cmake_command(${name}-var-script ${CMAKE_COMMAND} "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name} -DCMAKE_MAXIMUM_RECURSION_DEPTH=10 -P "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt")
   run_cmake_command(${name}-invalid-var-script ${CMAKE_COMMAND} "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name} -DCMAKE_MAXIMUM_RECURSION_DEPTH=a -P "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt")
+
+  set(ENV{CMAKE_MAXIMUM_RECURSION_DEPTH} 10)
+  run_cmake_with_options(${name}-env "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name})
+  run_cmake_command(${name}-env-script ${CMAKE_COMMAND} "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name} -P "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt")
+
+  set(ENV{CMAKE_MAXIMUM_RECURSION_DEPTH} a)
+  run_cmake_with_options(${name}-invalid-env "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name})
+  run_cmake_command(${name}-invalid-env-script ${CMAKE_COMMAND} "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name} -P "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt")
+
+  unset(ENV{CMAKE_MAXIMUM_RECURSION_DEPTH})
 endfunction()
 
 function(run_ctest_recursive name)
   run_ctest(${name}-default "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name})
   run_ctest(${name}-var "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name} -DCMAKE_MAXIMUM_RECURSION_DEPTH=10)
   run_ctest(${name}-invalid-var "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name} -DCMAKE_MAXIMUM_RECURSION_DEPTH=a)
+
+  set(ENV{CMAKE_MAXIMUM_RECURSION_DEPTH} 10)
+  run_ctest(${name}-env "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name})
+
+  set(ENV{CMAKE_MAXIMUM_RECURSION_DEPTH} a)
+  run_ctest(${name}-invalid-env "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=${name})
+
+  unset(ENV{CMAKE_MAXIMUM_RECURSION_DEPTH})
 endfunction()
 
 run_cmake_recursive(function)
@@ -32,12 +48,8 @@ run_cmake_recursive(variable_watch)
 # We run these tests separately and only with a small limit because they are
 # taxing and slow. The "implicit" and "invalid" cases are already thoroughly
 # covered by the other tests above.
-set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=add_subdirectory -DCMAKE_MAXIMUM_RECURSION_DEPTH=10)
-run_cmake(add_subdirectory-var)
-unset(RunCMake_TEST_OPTIONS)
-set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=try_compile -DCMAKE_MAXIMUM_RECURSION_DEPTH=10)
-run_cmake(try_compile-var)
-unset(RunCMake_TEST_OPTIONS)
+run_cmake_with_options(add_subdirectory-var "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=add_subdirectory -DCMAKE_MAXIMUM_RECURSION_DEPTH=10)
+run_cmake_with_options(try_compile-var "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" -DTEST_NAME=try_compile -DCMAKE_MAXIMUM_RECURSION_DEPTH=10)
 
 run_ctest_recursive(ctest_read_custom_files)
 

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/ctest_read_custom_files-env-result.txt

@@ -0,0 +1 @@
+(-1|255)

+ 34 - 0
Tests/RunCMake/MaxRecursionDepth/ctest_read_custom_files-env-stderr.txt

@@ -0,0 +1,34 @@
+^2
+3
+4
+5
+6
+7
+8
+9
+10
+CMake Error at .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake:1 \(message\):
+  Maximum recursion depth of 10 exceeded
+Call Stack \(most recent call first\):
+  .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake:3 \(ctest_read_custom_files\)
+  .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake:3 \(ctest_read_custom_files\)
+  .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake:3 \(ctest_read_custom_files\)
+  .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake:3 \(ctest_read_custom_files\)
+  .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake:3 \(ctest_read_custom_files\)
+  .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake:3 \(ctest_read_custom_files\)
+  .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake:3 \(ctest_read_custom_files\)
+  .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake:3 \(ctest_read_custom_files\)
+  .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake:3 \(ctest_read_custom_files\)
+  .*/Tests/RunCMake/MaxRecursionDepth/ctest_read_custom_files-env/test\.cmake:10 \(ctest_read_custom_files\)
+
+
+Problem reading custom configuration: .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake
+Problem reading custom configuration: .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake
+Problem reading custom configuration: .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake
+Problem reading custom configuration: .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake
+Problem reading custom configuration: .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake
+Problem reading custom configuration: .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake
+Problem reading custom configuration: .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake
+Problem reading custom configuration: .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake
+Problem reading custom configuration: .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake
+Problem reading custom configuration: .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake$

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/ctest_read_custom_files-invalid-env-result.txt

@@ -0,0 +1 @@
+(-1|255)

+ 5 - 0
Tests/RunCMake/MaxRecursionDepth/ctest_read_custom_files-invalid-env-stderr.txt

@@ -0,0 +1,5 @@
+[0-9]+
+CMake Error at .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake:1 \(message\):
+  Maximum recursion depth of [0-9]+ exceeded
+Call Stack \(most recent call first\):
+  .*/Tests/RunCMake/MaxRecursionDepth/CTestCustom\.cmake:3 \(ctest_read_custom_files\)

+ 5 - 3
Tests/RunCMake/MaxRecursionDepth/find_package-default-script-stderr.txt

@@ -1,5 +1,7 @@
 [0-9]+
-CMake Error at .*/FindRecursivePackage\.cmake:1 \(message\):
-  Maximum recursion depth of [0-9]+ exceeded
+CMake Error at [^
+]*/Tests/RunCMake/MaxRecursionDepth/FindRecursivePackage.cmake:[0-9]+ \(find_package\):
+  find_package maximum nesting depth of [0-9]+ exceeded.
 Call Stack \(most recent call first\):
-  .*/FindRecursivePackage\.cmake:3 \(find_package\)
+  [^
+]*/Tests/RunCMake/MaxRecursionDepth/FindRecursivePackage.cmake:[0-9]+ \(find_package\)

+ 3 - 3
Tests/RunCMake/MaxRecursionDepth/find_package-default-stderr.txt

@@ -1,5 +1,5 @@
 [0-9]+
-CMake Error at FindRecursivePackage\.cmake:1 \(message\):
-  Maximum recursion depth of [0-9]+ exceeded
+CMake Error at FindRecursivePackage.cmake:[0-9]+ \(find_package\):
+  find_package maximum nesting depth of [0-9]+ exceeded.
 Call Stack \(most recent call first\):
-  FindRecursivePackage\.cmake:3 \(find_package\)
+  FindRecursivePackage.cmake:[0-9]+ \(find_package\)

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/find_package-env-result.txt

@@ -0,0 +1 @@
+1

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/find_package-env-script-result.txt

@@ -0,0 +1 @@
+1

+ 21 - 0
Tests/RunCMake/MaxRecursionDepth/find_package-env-script-stderr.txt

@@ -0,0 +1,21 @@
+^3
+4
+5
+6
+7
+8
+9
+10
+CMake Error at .*/FindRecursivePackage\.cmake:1 \(message\):
+  Maximum recursion depth of 10 exceeded
+Call Stack \(most recent call first\):
+  .*/FindRecursivePackage\.cmake:3 \(find_package\)
+  .*/FindRecursivePackage\.cmake:3 \(find_package\)
+  .*/FindRecursivePackage\.cmake:3 \(find_package\)
+  .*/FindRecursivePackage\.cmake:3 \(find_package\)
+  .*/FindRecursivePackage\.cmake:3 \(find_package\)
+  .*/FindRecursivePackage\.cmake:3 \(find_package\)
+  .*/FindRecursivePackage\.cmake:3 \(find_package\)
+  .*/FindRecursivePackage\.cmake:3 \(find_package\)
+  .*/find_package\.cmake:2 \(find_package\)
+  .*/CMakeLists\.txt:5 \(include\)$

+ 21 - 0
Tests/RunCMake/MaxRecursionDepth/find_package-env-stderr.txt

@@ -0,0 +1,21 @@
+^3
+4
+5
+6
+7
+8
+9
+10
+CMake Error at FindRecursivePackage\.cmake:1 \(message\):
+  Maximum recursion depth of 10 exceeded
+Call Stack \(most recent call first\):
+  FindRecursivePackage\.cmake:3 \(find_package\)
+  FindRecursivePackage\.cmake:3 \(find_package\)
+  FindRecursivePackage\.cmake:3 \(find_package\)
+  FindRecursivePackage\.cmake:3 \(find_package\)
+  FindRecursivePackage\.cmake:3 \(find_package\)
+  FindRecursivePackage\.cmake:3 \(find_package\)
+  FindRecursivePackage\.cmake:3 \(find_package\)
+  FindRecursivePackage\.cmake:3 \(find_package\)
+  find_package\.cmake:2 \(find_package\)
+  CMakeLists\.txt:5 \(include\)$

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/find_package-invalid-env-result.txt

@@ -0,0 +1 @@
+1

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/find_package-invalid-env-script-result.txt

@@ -0,0 +1 @@
+1

+ 7 - 0
Tests/RunCMake/MaxRecursionDepth/find_package-invalid-env-script-stderr.txt

@@ -0,0 +1,7 @@
+[0-9]+
+CMake Error at [^
+]*/Tests/RunCMake/MaxRecursionDepth/FindRecursivePackage.cmake:[0-9]+ \(find_package\):
+  find_package maximum nesting depth of [0-9]+ exceeded.
+Call Stack \(most recent call first\):
+  [^
+]*/Tests/RunCMake/MaxRecursionDepth/FindRecursivePackage.cmake:[0-9]+ \(find_package\)

+ 5 - 0
Tests/RunCMake/MaxRecursionDepth/find_package-invalid-env-stderr.txt

@@ -0,0 +1,5 @@
+[0-9]+
+CMake Error at FindRecursivePackage.cmake:[0-9]+ \(find_package\):
+  find_package maximum nesting depth of [0-9]+ exceeded.
+Call Stack \(most recent call first\):
+  FindRecursivePackage.cmake:[0-9]+ \(find_package\)

+ 5 - 3
Tests/RunCMake/MaxRecursionDepth/find_package-invalid-var-script-stderr.txt

@@ -1,5 +1,7 @@
 [0-9]+
-CMake Error at .*/FindRecursivePackage\.cmake:1 \(message\):
-  Maximum recursion depth of [0-9]+ exceeded
+CMake Error at [^
+]*/Tests/RunCMake/MaxRecursionDepth/FindRecursivePackage.cmake:[0-9]+ \(find_package\):
+  find_package maximum nesting depth of [0-9]+ exceeded.
 Call Stack \(most recent call first\):
-  .*/FindRecursivePackage\.cmake:3 \(find_package\)
+  [^
+]*/Tests/RunCMake/MaxRecursionDepth/FindRecursivePackage.cmake:[0-9]+ \(find_package\)

+ 3 - 3
Tests/RunCMake/MaxRecursionDepth/find_package-invalid-var-stderr.txt

@@ -1,5 +1,5 @@
 [0-9]+
-CMake Error at FindRecursivePackage\.cmake:1 \(message\):
-  Maximum recursion depth of [0-9]+ exceeded
+CMake Error at FindRecursivePackage.cmake:[0-9]+ \(find_package\):
+  find_package maximum nesting depth of [0-9]+ exceeded.
 Call Stack \(most recent call first\):
-  FindRecursivePackage\.cmake:3 \(find_package\)
+  FindRecursivePackage.cmake:[0-9]+ \(find_package\)

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/function-env-result.txt

@@ -0,0 +1 @@
+1

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/function-env-script-result.txt

@@ -0,0 +1 @@
+1

+ 21 - 0
Tests/RunCMake/MaxRecursionDepth/function-env-script-stderr.txt

@@ -0,0 +1,21 @@
+^3
+4
+5
+6
+7
+8
+9
+10
+CMake Error at .*/function\.cmake:2 \(message\):
+  Maximum recursion depth of 10 exceeded
+Call Stack \(most recent call first\):
+  .*/function\.cmake:4 \(recursive\)
+  .*/function\.cmake:4 \(recursive\)
+  .*/function\.cmake:4 \(recursive\)
+  .*/function\.cmake:4 \(recursive\)
+  .*/function\.cmake:4 \(recursive\)
+  .*/function\.cmake:4 \(recursive\)
+  .*/function\.cmake:4 \(recursive\)
+  .*/function\.cmake:4 \(recursive\)
+  .*/function\.cmake:7 \(recursive\)
+  .*/CMakeLists\.txt:5 \(include\)$

+ 21 - 0
Tests/RunCMake/MaxRecursionDepth/function-env-stderr.txt

@@ -0,0 +1,21 @@
+^3
+4
+5
+6
+7
+8
+9
+10
+CMake Error at function\.cmake:2 \(message\):
+  Maximum recursion depth of 10 exceeded
+Call Stack \(most recent call first\):
+  function\.cmake:4 \(recursive\)
+  function\.cmake:4 \(recursive\)
+  function\.cmake:4 \(recursive\)
+  function\.cmake:4 \(recursive\)
+  function\.cmake:4 \(recursive\)
+  function\.cmake:4 \(recursive\)
+  function\.cmake:4 \(recursive\)
+  function\.cmake:4 \(recursive\)
+  function\.cmake:7 \(recursive\)
+  CMakeLists\.txt:5 \(include\)$

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/function-invalid-env-result.txt

@@ -0,0 +1 @@
+1

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/function-invalid-env-script-result.txt

@@ -0,0 +1 @@
+1

+ 5 - 0
Tests/RunCMake/MaxRecursionDepth/function-invalid-env-script-stderr.txt

@@ -0,0 +1,5 @@
+[0-9]+
+CMake Error at .*/function\.cmake:2 \(message\):
+  Maximum recursion depth of [0-9]+ exceeded
+Call Stack \(most recent call first\):
+  .*/function\.cmake:4 \(recursive\)

+ 5 - 0
Tests/RunCMake/MaxRecursionDepth/function-invalid-env-stderr.txt

@@ -0,0 +1,5 @@
+[0-9]+
+CMake Error at function\.cmake:2 \(message\):
+  Maximum recursion depth of [0-9]+ exceeded
+Call Stack \(most recent call first\):
+  function\.cmake:4 \(recursive\)

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/include-env-result.txt

@@ -0,0 +1 @@
+1

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/include-env-script-result.txt

@@ -0,0 +1 @@
+1

+ 21 - 0
Tests/RunCMake/MaxRecursionDepth/include-env-script-stderr.txt

@@ -0,0 +1,21 @@
+^3
+4
+5
+6
+7
+8
+9
+10
+CMake Error at .*/include_recursive\.cmake:1 \(message\):
+  Maximum recursion depth of 10 exceeded
+Call Stack \(most recent call first\):
+  .*/include_recursive\.cmake:3 \(include\)
+  .*/include_recursive\.cmake:3 \(include\)
+  .*/include_recursive\.cmake:3 \(include\)
+  .*/include_recursive\.cmake:3 \(include\)
+  .*/include_recursive\.cmake:3 \(include\)
+  .*/include_recursive\.cmake:3 \(include\)
+  .*/include_recursive\.cmake:3 \(include\)
+  .*/include_recursive\.cmake:3 \(include\)
+  .*/include\.cmake:2 \(include\)
+  .*/CMakeLists\.txt:5 \(include\)$

+ 21 - 0
Tests/RunCMake/MaxRecursionDepth/include-env-stderr.txt

@@ -0,0 +1,21 @@
+^3
+4
+5
+6
+7
+8
+9
+10
+CMake Error at include_recursive\.cmake:1 \(message\):
+  Maximum recursion depth of 10 exceeded
+Call Stack \(most recent call first\):
+  include_recursive\.cmake:3 \(include\)
+  include_recursive\.cmake:3 \(include\)
+  include_recursive\.cmake:3 \(include\)
+  include_recursive\.cmake:3 \(include\)
+  include_recursive\.cmake:3 \(include\)
+  include_recursive\.cmake:3 \(include\)
+  include_recursive\.cmake:3 \(include\)
+  include_recursive\.cmake:3 \(include\)
+  include\.cmake:2 \(include\)
+  CMakeLists\.txt:5 \(include\)$

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/include-invalid-env-result.txt

@@ -0,0 +1 @@
+1

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/include-invalid-env-script-result.txt

@@ -0,0 +1 @@
+1

+ 5 - 0
Tests/RunCMake/MaxRecursionDepth/include-invalid-env-script-stderr.txt

@@ -0,0 +1,5 @@
+[0-9]+
+CMake Error at .*/include_recursive\.cmake:1 \(message\):
+  Maximum recursion depth of [0-9]+ exceeded
+Call Stack \(most recent call first\):
+  .*/include_recursive\.cmake:3 \(include\)

+ 5 - 0
Tests/RunCMake/MaxRecursionDepth/include-invalid-env-stderr.txt

@@ -0,0 +1,5 @@
+[0-9]+
+CMake Error at include_recursive\.cmake:1 \(message\):
+  Maximum recursion depth of [0-9]+ exceeded
+Call Stack \(most recent call first\):
+  include_recursive\.cmake:3 \(include\)

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/macro-env-result.txt

@@ -0,0 +1 @@
+1

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/macro-env-script-result.txt

@@ -0,0 +1 @@
+1

+ 21 - 0
Tests/RunCMake/MaxRecursionDepth/macro-env-script-stderr.txt

@@ -0,0 +1,21 @@
+^3
+4
+5
+6
+7
+8
+9
+10
+CMake Error at .*/macro\.cmake:2 \(message\):
+  Maximum recursion depth of 10 exceeded
+Call Stack \(most recent call first\):
+  .*/macro\.cmake:4 \(recursive\)
+  .*/macro\.cmake:4 \(recursive\)
+  .*/macro\.cmake:4 \(recursive\)
+  .*/macro\.cmake:4 \(recursive\)
+  .*/macro\.cmake:4 \(recursive\)
+  .*/macro\.cmake:4 \(recursive\)
+  .*/macro\.cmake:4 \(recursive\)
+  .*/macro\.cmake:4 \(recursive\)
+  .*/macro\.cmake:7 \(recursive\)
+  .*/CMakeLists\.txt:5 \(include\)$

+ 21 - 0
Tests/RunCMake/MaxRecursionDepth/macro-env-stderr.txt

@@ -0,0 +1,21 @@
+^3
+4
+5
+6
+7
+8
+9
+10
+CMake Error at macro\.cmake:2 \(message\):
+  Maximum recursion depth of 10 exceeded
+Call Stack \(most recent call first\):
+  macro\.cmake:4 \(recursive\)
+  macro\.cmake:4 \(recursive\)
+  macro\.cmake:4 \(recursive\)
+  macro\.cmake:4 \(recursive\)
+  macro\.cmake:4 \(recursive\)
+  macro\.cmake:4 \(recursive\)
+  macro\.cmake:4 \(recursive\)
+  macro\.cmake:4 \(recursive\)
+  macro\.cmake:7 \(recursive\)
+  CMakeLists\.txt:5 \(include\)$

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/macro-invalid-env-result.txt

@@ -0,0 +1 @@
+1

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/macro-invalid-env-script-result.txt

@@ -0,0 +1 @@
+1

+ 5 - 0
Tests/RunCMake/MaxRecursionDepth/macro-invalid-env-script-stderr.txt

@@ -0,0 +1,5 @@
+[0-9]+
+CMake Error at .*/macro\.cmake:2 \(message\):
+  Maximum recursion depth of [0-9]+ exceeded
+Call Stack \(most recent call first\):
+  .*/macro\.cmake:4 \(recursive\)

+ 5 - 0
Tests/RunCMake/MaxRecursionDepth/macro-invalid-env-stderr.txt

@@ -0,0 +1,5 @@
+[0-9]+
+CMake Error at macro\.cmake:2 \(message\):
+  Maximum recursion depth of [0-9]+ exceeded
+Call Stack \(most recent call first\):
+  macro\.cmake:4 \(recursive\)

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/variable_watch-env-result.txt

@@ -0,0 +1 @@
+1

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/variable_watch-env-script-result.txt

@@ -0,0 +1 @@
+1

+ 22 - 0
Tests/RunCMake/MaxRecursionDepth/variable_watch-env-script-stderr.txt

@@ -0,0 +1,22 @@
+^4
+6
+8
+10
+CMake Error at .*/variable_watch\.cmake:[0-9]+ \(update_x\):
+  Maximum recursion depth of 10 exceeded
+Call Stack \(most recent call first\):
+  .*/variable_watch\.cmake:5 \(set\)
+  .*/variable_watch\.cmake:[0-9]+ \(update_x\)
+  .*/variable_watch\.cmake:5 \(set\)
+  .*/variable_watch\.cmake:[0-9]+ \(update_x\)
+  .*/variable_watch\.cmake:5 \(set\)
+  .*/variable_watch\.cmake:[0-9]+ \(update_x\)
+  .*/variable_watch\.cmake:5 \(set\)
+  .*/variable_watch\.cmake:[0-9]+ \(update_x\)
+  .*/variable_watch\.cmake:9 \(set\)
+  .*/CMakeLists\.txt:5 \(include\)
+
+
+CMake Error: Error in cmake code at
+Unknown:0:
+A command failed during the invocation of callback "update_x"\.$

+ 22 - 0
Tests/RunCMake/MaxRecursionDepth/variable_watch-env-stderr.txt

@@ -0,0 +1,22 @@
+^4
+6
+8
+10
+CMake Error at variable_watch\.cmake:[0-9]+ \(update_x\):
+  Maximum recursion depth of 10 exceeded
+Call Stack \(most recent call first\):
+  variable_watch\.cmake:5 \(set\)
+  variable_watch\.cmake:[0-9]+ \(update_x\)
+  variable_watch\.cmake:5 \(set\)
+  variable_watch\.cmake:[0-9]+ \(update_x\)
+  variable_watch\.cmake:5 \(set\)
+  variable_watch\.cmake:[0-9]+ \(update_x\)
+  variable_watch\.cmake:5 \(set\)
+  variable_watch\.cmake:[0-9]+ \(update_x\)
+  variable_watch\.cmake:9 \(set\)
+  CMakeLists\.txt:5 \(include\)
+
+
+CMake Error: Error in cmake code at
+Unknown:0:
+A command failed during the invocation of callback "update_x"\.$

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/variable_watch-invalid-env-result.txt

@@ -0,0 +1 @@
+1

+ 1 - 0
Tests/RunCMake/MaxRecursionDepth/variable_watch-invalid-env-script-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
Tests/RunCMake/MaxRecursionDepth/variable_watch-invalid-env-script-stderr.txt

@@ -0,0 +1,6 @@
+[0-9]+
+CMake Error at .*/variable_watch\.cmake:[0-9]+ \(update_x\):
+  Maximum recursion depth of [0-9]+ exceeded
+Call Stack \(most recent call first\):
+  .*/variable_watch\.cmake:5 \(set\)
+  .*/variable_watch\.cmake:[0-9]+ \(update_x\)

+ 6 - 0
Tests/RunCMake/MaxRecursionDepth/variable_watch-invalid-env-stderr.txt

@@ -0,0 +1,6 @@
+[0-9]+
+CMake Error at variable_watch\.cmake:[0-9]+ \(update_x\):
+  Maximum recursion depth of [0-9]+ exceeded
+Call Stack \(most recent call first\):
+  variable_watch\.cmake:5 \(set\)
+  variable_watch\.cmake:[0-9]+ \(update_x\)