CMakeLists.txt 1.86 KB
Newer Older
Ben Boeckel's avatar
Ben Boeckel committed
1 2 3 4 5 6 7 8 9
cmake_minimum_required(VERSION 2.8)

project(ArgumentExpansion)

function (argument_tester expected expected_len)
    list(LENGTH ARGN argn_len)
    list(LENGTH ${expected} expected_received_len)

    if (NOT ${expected_received_len} EQUAL ${expected_len})
10
        message(STATUS "Unexpected: Expanding expected values isn't working")
11
    endif ()
Ben Boeckel's avatar
Ben Boeckel committed
12 13 14 15 16 17 18

    if (${argn_len} EQUAL ${expected_len})
        set(i 0)
        while (i LESS ${argn_len})
            list(GET ARGN ${i} argn_value)
            list(GET ${expected} ${i} expected_value)

19
            if (NOT "${argn_value}" STREQUAL "${expected_value}")
20
                message(STATUS "Unexpected: Argument ${i} doesn't match")
Ben Boeckel's avatar
Ben Boeckel committed
21 22
                message(STATUS "    Expected: ${expected_value}")
                message(STATUS "    Received: ${argn_value}")
23
            endif ()
Ben Boeckel's avatar
Ben Boeckel committed
24 25

            math(EXPR i "${i} + 1")
26 27
        endwhile ()
    else ()
28
        message(STATUS "Unexpected: Lengths of arguments don't match")
Ben Boeckel's avatar
Ben Boeckel committed
29 30
        message(STATUS "    Expected: ${expected_len}")
        message(STATUS "    Received: ${argn_len}")
31 32
    endif ()
endfunction ()
Ben Boeckel's avatar
Ben Boeckel committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

set(empty_test)
message(STATUS "Test: Empty arguments")
argument_tester(empty_test 0 ${empty_test})

set(single_arg_test
    "single arg")
message(STATUS "Test: Single argument")
argument_tester(single_arg_test 1 ${single_arg_test})

set(multiple_arg_test
    "first arg"
    "second arg")
message(STATUS "Test: Multiple arguments")
argument_tester(multiple_arg_test 2 ${multiple_arg_test})

set(nested_list_arg_test
    "${multiple_arg_test}"
    "first arg"
    "second arg")
53 54
message(STATUS "Test: Nested list argument flattens")
argument_tester(nested_list_arg_test 4 ${nested_list_arg_test})
Ben Boeckel's avatar
Ben Boeckel committed
55 56 57

set(semicolon_arg_test
    "pre\;post")
58 59 60
set(semicolon_arg_test_flat "pre;post")
message(STATUS "Test: Semicolon argument flattens")
argument_tester(semicolon_arg_test_flat 2 ${semicolon_arg_test})