CMakeLists.txt 1.7 KB
Newer Older
M
Max Bruckner 已提交
1
add_library(unity unity/src/unity.c)
2 3 4 5 6 7 8 9 10

if(ENABLE_CJSON_TEST)
    #copy test files
    file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/inputs")
    file(GLOB test_files "inputs/*")
    file(COPY ${test_files} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/inputs/")

    set(unity_tests
        parse_examples
M
Max Bruckner 已提交
11
        parse_number
M
Max Bruckner 已提交
12
        parse_hex4
M
Max Bruckner 已提交
13
        parse_string
M
Max Bruckner 已提交
14
        parse_array
M
Max Bruckner 已提交
15
        parse_object
M
Max Bruckner 已提交
16
        parse_value
M
Max Bruckner 已提交
17
        print_string
M
Max Bruckner 已提交
18
        print_number
M
Max Bruckner 已提交
19
        print_array
M
Max Bruckner 已提交
20
        print_object
M
Max Bruckner 已提交
21
        print_value
22 23
    )

24 25
    add_library(test-common common.c)

M
Max Bruckner 已提交
26 27 28 29 30 31 32 33 34 35 36
    option(ENABLE_VALGRIND OFF "Enable the valgrind memory checker for the tests.")
    if (ENABLE_VALGRIND)
        find_program(MEMORYCHECK_COMMAND valgrind)
        if ("${MEMORYCHECK_COMMAND}" MATCHES "MEMORYCHECK_COMMAND-NOTFOUND")
            message(WARNING "Valgrind couldn't be found.")
            unset(MEMORYCHECK_COMMAND)
        else()
            set(MEMORYCHECK_COMMAND_OPTIONS --trace-children=yes --leak-check=full --error-exitcode=1)
        endif()
    endif()

37 38 39 40 41
    #"check" target that automatically builds everything and runs the tests
    add_custom_target(check 
        COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
        DEPENDS ${unity_tests})

42 43
    foreach(unity_test ${unity_tests})
        add_executable("${unity_test}" "${unity_test}.c")
44
        target_link_libraries("${unity_test}" "${CJSON_LIB}" unity test-common)
M
Max Bruckner 已提交
45 46 47 48 49 50 51
        if(MEMORYCHECK_COMMAND)
            add_test(NAME "${unity_test}"
                COMMAND "${MEMORYCHECK_COMMAND}" ${MEMORYCHECK_COMMAND_OPTIONS} "./${unity_test}")
        else()
            add_test(NAME "${unity_test}"
                COMMAND "./${unity_test}")
        endif()
52 53
    endforeach()
endif()