diff options
author | Craig Scott <craig.scott@crascit.com> | 2024-10-27 11:08:03 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-10-28 13:47:21 (GMT) |
commit | c8567acc326dc72a7f9f8371bd6f4836eeab7c28 (patch) | |
tree | 90c443ded9cdac00b52dea8145364f55414fe904 /Tests | |
parent | fcff1dcb064950f83ef45a41ea236b64fe2ac5e7 (diff) | |
download | CMake-c8567acc326dc72a7f9f8371bd6f4836eeab7c28.zip CMake-c8567acc326dc72a7f9f8371bd6f4836eeab7c28.tar.gz CMake-c8567acc326dc72a7f9f8371bd6f4836eeab7c28.tar.bz2 |
cmake_parse_arguments: Restore capture of value after repeated keyword
When a single-value keyword is repeated, and the first instance is
missing a value, it prevents the value from the second instance from
being stored in a variable. This was a regression introduced by
commit ceeea4e511 (cmake_parse_arguments: Set variable if empty string
given after keyword, 2024-08-18). That change also didn't create a
variable if the keyword was given but without a value. The purpose
of the change was to always define a variable if a keyword was given.
Lastly, that change didn't protect the CMP0174 logic to make it only
apply to the PARSE_ARGV form.
The first two of the above problems are fixed here by tracking the
keywords given instead of checking which keywords were missing
values. The third problem is also fixed here, being tightly coupled
to the same logic as the first two problems.
Fixes: #26397
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/RunCMake/cmake_parse_arguments/CornerCasesArgvN-stderr.txt | 2 | ||||
-rw-r--r-- | Tests/RunCMake/cmake_parse_arguments/CornerCasesArgvN.cmake | 34 |
2 files changed, 32 insertions, 4 deletions
diff --git a/Tests/RunCMake/cmake_parse_arguments/CornerCasesArgvN-stderr.txt b/Tests/RunCMake/cmake_parse_arguments/CornerCasesArgvN-stderr.txt index 1b87306..0815ed3 100644 --- a/Tests/RunCMake/cmake_parse_arguments/CornerCasesArgvN-stderr.txt +++ b/Tests/RunCMake/cmake_parse_arguments/CornerCasesArgvN-stderr.txt @@ -2,7 +2,7 @@ Testing CMP0174 = NEW Testing CMP0174 = OLD Testing CMP0174 = WARN CMake Warning \(dev\) at CornerCasesArgvN\.cmake:[0-9]+ \(cmake_parse_arguments\): - An empty string was given as the value after the P1 keyword\. Policy + The P1 keyword was followed by an empty string or no value at all\. Policy CMP0174 is not set, so cmake_parse_arguments\(\) will unset the arg_P1 variable rather than setting it to an empty string\. Call Stack \(most recent call first\): diff --git a/Tests/RunCMake/cmake_parse_arguments/CornerCasesArgvN.cmake b/Tests/RunCMake/cmake_parse_arguments/CornerCasesArgvN.cmake index 04c0219..487a48f 100644 --- a/Tests/RunCMake/cmake_parse_arguments/CornerCasesArgvN.cmake +++ b/Tests/RunCMake/cmake_parse_arguments/CornerCasesArgvN.cmake @@ -60,7 +60,7 @@ block(SCOPE_FOR POLICIES) cmake_parse_arguments(PARSE_ARGV 0 arg "" "P1;P2" "") TEST(arg_KEYWORDS_MISSING_VALUES "P2") TEST(arg_P1 "") - TEST(arg_P2 "UNDEFINED") + TEST(arg_P2 "") endfunction() test_cmp0174_new_missing(P1 "" P2) @@ -71,28 +71,56 @@ block(SCOPE_FOR POLICIES) TEST(arg_P2 "UNDEFINED") endfunction() test_cmp0174_new_no_missing(P1 "") + + # For repeated keywords, the keyword will be reported as missing a value if + # any one of them is missing a value. + function(test_cmp0174_new_repeated_arg) + cmake_parse_arguments(PARSE_ARGV 0 arg "" "P1;P2" "") + TEST(arg_KEYWORDS_MISSING_VALUES "P1") + TEST(arg_P1 "abc") + TEST(arg_P2 "UNDEFINED") + endfunction() + test_cmp0174_new_repeated_arg(P1 P1 abc) endblock() message(NOTICE "Testing CMP0174 = OLD") block(SCOPE_FOR POLICIES) cmake_policy(SET CMP0174 OLD) function(test_cmp0174_old) - cmake_parse_arguments(PARSE_ARGV 0 arg "" "P1;P2" "") + cmake_parse_arguments(PARSE_ARGV 0 arg "" "P1;P2;P3" "") TEST(arg_KEYWORDS_MISSING_VALUES "P2") TEST(arg_P1 "UNDEFINED") TEST(arg_P2 "UNDEFINED") + TEST(arg_P3 "UNDEFINED") endfunction() test_cmp0174_old(P1 "" P2) + + function(test_cmp0174_old_repeated_arg) + cmake_parse_arguments(PARSE_ARGV 0 arg "" "P1;P2" "") + TEST(arg_KEYWORDS_MISSING_VALUES "P1") + TEST(arg_P1 "abc") + TEST(arg_P2 "UNDEFINED") + endfunction() + test_cmp0174_old_repeated_arg(P1 P1 abc) endblock() message(NOTICE "Testing CMP0174 = WARN") block(SCOPE_FOR POLICIES) cmake_policy(VERSION 3.30) # WARN function(test_cmp0174_warn) - cmake_parse_arguments(PARSE_ARGV 0 arg "" "P1;P2" "") + cmake_parse_arguments(PARSE_ARGV 0 arg "" "P1;P2;P3" "") TEST(arg_KEYWORDS_MISSING_VALUES "P2") TEST(arg_P1 "UNDEFINED") TEST(arg_P2 "UNDEFINED") + TEST(arg_P3 "UNDEFINED") endfunction() test_cmp0174_warn(P1 "" P2) + + function(test_cmp0174_warn_repeated_arg) + cmake_parse_arguments(PARSE_ARGV 0 arg "" "P1;P2" "") + TEST(arg_KEYWORDS_MISSING_VALUES "P1") + TEST(arg_P1 "abc") + TEST(arg_P2 "UNDEFINED") + endfunction() + test_cmp0174_warn_repeated_arg(P1 P1 abc) endblock() |