diff options
author | Brad King <brad.king@kitware.com> | 2021-05-03 13:59:27 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-05-03 13:59:35 (GMT) |
commit | 4df3f5300a13827336ca5329b53834cf0fb63a7d (patch) | |
tree | 89b2489244747aac917921dbb79eecf30bc09f60 /Tests/RunCMake | |
parent | ec6ba9a3b80a6653d157bb25faa758fa418305c9 (diff) | |
parent | 46896d98bb8ed8a1068da70220581f8bbc3847fc (diff) | |
download | CMake-4df3f5300a13827336ca5329b53834cf0fb63a7d.zip CMake-4df3f5300a13827336ca5329b53834cf0fb63a7d.tar.gz CMake-4df3f5300a13827336ca5329b53834cf0fb63a7d.tar.bz2 |
Merge topic 'foreach-loop-variable'
46896d98bb foreach(): loop variables are only available in the loop scope
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Ben Boeckel <ben.boeckel@kitware.com>
Acked-by: Michael Hirsch <michael@scivision.dev>
Merge-request: !6044
Diffstat (limited to 'Tests/RunCMake')
-rw-r--r-- | Tests/RunCMake/foreach/RunCMakeTest.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/foreach/foreach-var-scope-CMP0124-NEW.cmake | 51 | ||||
-rw-r--r-- | Tests/RunCMake/foreach/foreach-var-scope-CMP0124-OLD.cmake | 53 |
3 files changed, 106 insertions, 0 deletions
diff --git a/Tests/RunCMake/foreach/RunCMakeTest.cmake b/Tests/RunCMake/foreach/RunCMakeTest.cmake index d3f7c23..15ca477 100644 --- a/Tests/RunCMake/foreach/RunCMakeTest.cmake +++ b/Tests/RunCMake/foreach/RunCMakeTest.cmake @@ -20,3 +20,5 @@ run_cmake(foreach-RANGE-non-int-test-3-2) run_cmake(foreach-RANGE-non-int-test-3-3) run_cmake(foreach-RANGE-invalid-test) run_cmake(foreach-RANGE-out-of-range-test) +run_cmake(foreach-var-scope-CMP0124-OLD) +run_cmake(foreach-var-scope-CMP0124-NEW) diff --git a/Tests/RunCMake/foreach/foreach-var-scope-CMP0124-NEW.cmake b/Tests/RunCMake/foreach/foreach-var-scope-CMP0124-NEW.cmake new file mode 100644 index 0000000..7e2eee0 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-var-scope-CMP0124-NEW.cmake @@ -0,0 +1,51 @@ + +cmake_policy(SET CMP0124 NEW) + +foreach(VAR a b c) +endforeach() +if (DEFINED VAR) + message(SEND_ERROR "Variable 'VAR' unexpectedly defined.") +endif() + +set(LIST1 a b c) +set(LIST2 x y z) +foreach(VAR1_1 VAR1_2 IN ZIP_LISTS LIST1 LIST2) +endforeach() +if (DEFINED VAR1_1 OR DEFINED VAR1_2) + message(SEND_ERROR "Variables 'VAR1_1' or 'VAR1_2' unexpectedly defined.") +endif() + + +set (VAR2 OLD) +foreach(VAR2 a b c) +endforeach() +if (NOT DEFINED VAR2 OR NOT VAR2 STREQUAL "OLD") + message(SEND_ERROR "Variable 'VAR2' not defined or wrong value.") +endif() + +set (VAR2_2 OLD) +foreach(VAR2_1 VAR2_2 IN ZIP_LISTS LIST1 LIST2) +endforeach() +if (DEFINED VAR2_1 OR NOT DEFINED VAR2_2) + message(SEND_ERROR "Variable 'VAR2_1' unexpectedly defined or variable 'VAR2_2' not defined.") +endif() + + +set (VAR3 OLD CACHE STRING "") +foreach(VAR3 a b c) +endforeach() +# check that only cache variable is defined +set(OLD_VALUE "${VAR3}") +unset(VAR3 CACHE) +if (DEFINED VAR3 OR NOT OLD_VALUE STREQUAL "OLD") + message(SEND_ERROR "Variable 'VAR3' wrongly defined or wrong value.") +endif() + +set (VAR3_2 OLD CACHE STRING "") +foreach(VAR3_1 VAR3_2 IN ZIP_LISTS LIST1 LIST2) +endforeach() +set(OLD_VALUE "${VAR3_2}") +unset(VAR3_2 CACHE) +if (DEFINED VAR3_1 OR DEFINED VAR3_2 OR NOT OLD_VALUE STREQUAL "OLD") + message(SEND_ERROR "Variable 'VAR3_1' unexpectedly defined or variable 'VAR2_2' wrongly defined or wrong value.") +endif() diff --git a/Tests/RunCMake/foreach/foreach-var-scope-CMP0124-OLD.cmake b/Tests/RunCMake/foreach/foreach-var-scope-CMP0124-OLD.cmake new file mode 100644 index 0000000..f955982 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-var-scope-CMP0124-OLD.cmake @@ -0,0 +1,53 @@ + +cmake_policy(SET CMP0124 OLD) + +foreach(VAR a b c) +endforeach() +if (NOT DEFINED VAR OR NOT VAR STREQUAL "") + message(SEND_ERROR "Variable 'VAR' not defined or wrong value.") +endif() + +set(LIST1 a b c) +set(LIST2 x y z) +foreach(VAR1_1 VAR1_2 IN ZIP_LISTS LIST1 LIST2) +endforeach() +if (NOT DEFINED VAR1_1 OR NOT VAR1_1 STREQUAL "" + OR NOT DEFINED VAR1_2 OR NOT VAR1_2 STREQUAL "") + message(SEND_ERROR "Variables 'VAR1_1' or 'VAR1_2' not defined or wrong value.") +endif() + + +set (VAR2 OLD) +foreach(VAR2 a b c) +endforeach() +if (NOT DEFINED VAR2 OR NOT VAR2 STREQUAL "OLD") + message(SEND_ERROR "Variable 'VAR2' not defined or wrong value.") +endif() + +set (VAR2_2 OLD) +foreach(VAR2_1 VAR2_2 IN ZIP_LISTS LIST1 LIST2) +endforeach() +if (NOT DEFINED VAR2_1 OR NOT VAR2_1 STREQUAL "" + OR NOT DEFINED VAR2_2 OR NOT VAR2_2 STREQUAL "OLD") + message(SEND_ERROR "Variables 'VAR2_1' or 'VAR2_2' not defined or wrong value.") +endif() + + +set (VAR3 OLD CACHE STRING "") +foreach(VAR3 a b c) +endforeach() +# a normal variable is defined, holding cache variable value +unset(VAR3 CACHE) +if (NOT DEFINED VAR3 OR NOT VAR3 STREQUAL "OLD") + message(SEND_ERROR "Variable 'VAR3' not defined or wrong value.") +endif() + +set (VAR3_2 OLD CACHE STRING "") +foreach(VAR3_1 VAR3_2 IN ZIP_LISTS LIST1 LIST2) +endforeach() +# a normal variable is defined, holding cache variable value +unset(VAR3_2 CACHE) +if (NOT DEFINED VAR3_1 OR NOT VAR3_1 STREQUAL "" + OR NOT DEFINED VAR3_2 OR NOT VAR3_2 STREQUAL "OLD") + message(SEND_ERROR "Variables 'VAR3_1' or 'VAR3_2' not defined or wrong value.") +endif() |