Add CMAKE_MAXIMUM_RECURSION_DEPTH environment variable

Extend the recursion limit controls added by commit a6982cff0d
(cmMakefile: Impose maximum recursion limit, 2018-12-14,
v3.14.0-rc1~82^2) with an environment variable that is used if the
CMake variable of the same name is not set.
This commit is contained in:
Brad King
2023-03-09 10:17:16 -05:00
parent 395895bda7
commit 89b69bf1ad
49 changed files with 366 additions and 0 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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.

View File

@@ -2865,6 +2865,12 @@ size_t cmMakefile::GetRecursionDepthLimit() const
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;
}

View File

@@ -1,20 +1,42 @@
include(RunCMake)
include(RunCTest)
# 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)

View File

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

View File

@@ -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$

View File

@@ -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\)

View File

@@ -0,0 +1 @@
1

View File

@@ -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\)$

View File

@@ -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\)$

View File

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

View File

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

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1 @@
1

View File

@@ -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\)$

View File

@@ -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\)$

View File

@@ -0,0 +1 @@
1

View File

@@ -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\)

View File

@@ -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\)

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1 @@
1

View File

@@ -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\)$

View File

@@ -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\)$

View File

@@ -0,0 +1 @@
1

View File

@@ -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\)

View File

@@ -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\)

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1 @@
1

View File

@@ -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\)$

View File

@@ -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\)$

View File

@@ -0,0 +1 @@
1

View File

@@ -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\)

View File

@@ -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\)

View File

@@ -0,0 +1 @@
1

View File

@@ -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"\.$

View File

@@ -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"\.$

View File

@@ -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\)

View File

@@ -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\)