ArgvN.cmake 1.24 KB
Newer Older
1
2
include(${CMAKE_CURRENT_LIST_DIR}/test_utils.cmake)

3
4
5
6
7
8
9
10
11
12
function(test_multi list)
  set(i 0)
  foreach(value IN LISTS ${list})
    math(EXPR j "${i} + 1")
    set(${list}[${i}] "${value}")
    TEST(${list}[${i}] "${ARGV${j}}")
    set(i ${j})
  endforeach()
endfunction()

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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)
36
  test_multi(pref_MULTI1 bar "foo;bar")
37
38
39
  TEST(pref_MULTI2 UNDEFINED)
  TEST(pref_UNPARSED_ARGUMENTS UNDEFINED)
endfunction()
40
41
42
43
44
45
46
47
48
test2("first named" OPT1 SINGLE1 "foo;bar" MULTI1 bar "foo;bar")

function(test3 arg1)
  cmake_parse_arguments(PARSE_ARGV 0
    pref "" "" "")

  test_multi(pref_UNPARSED_ARGUMENTS "foo;bar" dog cat)
endfunction()
test3("foo;bar" dog cat)