summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/cmake_parse_arguments/ArgvN.cmake
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2016-09-07 20:47:23 (GMT)
committerBrad King <brad.king@kitware.com>2016-09-08 15:33:46 (GMT)
commitcb299acc27d5f80b2fc801f0f57358ec9f0303d1 (patch)
treedb2426c946edfc3cd760edfc28f66a8bbedf4844 /Tests/RunCMake/cmake_parse_arguments/ArgvN.cmake
parentf506489d1ed222761f9ce752144a458290020e55 (diff)
downloadCMake-cb299acc27d5f80b2fc801f0f57358ec9f0303d1.zip
CMake-cb299acc27d5f80b2fc801f0f57358ec9f0303d1.tar.gz
CMake-cb299acc27d5f80b2fc801f0f57358ec9f0303d1.tar.bz2
cmake_parse_arguments: Add option to read arguments from ARGC/ARGV#
The `ARGC`/`ARGV#` variables in function scope hold the original arguments with no ;-list flattening. Add a way for functions to cleanly parse arguments that may contain `;`. This also avoids extra copying of the arguments. Co-Author: Brad King <brad.king@kitware.com>
Diffstat (limited to 'Tests/RunCMake/cmake_parse_arguments/ArgvN.cmake')
-rw-r--r--Tests/RunCMake/cmake_parse_arguments/ArgvN.cmake30
1 files changed, 30 insertions, 0 deletions
diff --git a/Tests/RunCMake/cmake_parse_arguments/ArgvN.cmake b/Tests/RunCMake/cmake_parse_arguments/ArgvN.cmake
new file mode 100644
index 0000000..61bde03
--- /dev/null
+++ b/Tests/RunCMake/cmake_parse_arguments/ArgvN.cmake
@@ -0,0 +1,30 @@
+include(${CMAKE_CURRENT_LIST_DIR}/test_utils.cmake)
+
+function(test1)
+ cmake_parse_arguments(PARSE_ARGV 0
+ pref "OPT1;OPT2" "SINGLE1;SINGLE2" "MULTI1;MULTI2")
+
+ TEST(pref_OPT1 TRUE)
+ TEST(pref_OPT2 FALSE)
+ TEST(pref_SINGLE1 "foo;bar")
+ TEST(pref_SINGLE2 UNDEFINED)
+ TEST(pref_MULTI1 bar foo bar)
+ TEST(pref_MULTI2 UNDEFINED)
+ TEST(pref_UNPARSED_ARGUMENTS UNDEFINED)
+endfunction()
+test1(OPT1 SINGLE1 "foo;bar" MULTI1 bar foo bar)
+
+function(test2 arg1)
+ cmake_parse_arguments(PARSE_ARGV 1
+ pref "OPT1;OPT2" "SINGLE1;SINGLE2" "MULTI1;MULTI2")
+
+ TEST(arg1 "first named")
+ TEST(pref_OPT1 TRUE)
+ TEST(pref_OPT2 FALSE)
+ TEST(pref_SINGLE1 "foo;bar")
+ TEST(pref_SINGLE2 UNDEFINED)
+ TEST(pref_MULTI1 bar foo bar)
+ TEST(pref_MULTI2 UNDEFINED)
+ TEST(pref_UNPARSED_ARGUMENTS UNDEFINED)
+endfunction()
+test2("first named" OPT1 SINGLE1 "foo;bar" MULTI1 bar foo bar)