cJSON/tests/CMakeLists.txt

42 lines
1.4 KiB
CMake
Raw Normal View History

2017-01-16 14:36:11 +01:00
add_library(unity unity/src/unity.c)
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
2017-01-17 01:53:55 +01:00
parse_number
2017-01-17 19:44:38 +01:00
parse_hex4
2017-02-04 02:12:10 +01:00
parse_string
2017-02-06 16:27:59 +01:00
parse_array
2017-02-07 20:24:59 +01:00
parse_object
2017-02-07 20:39:45 +01:00
parse_value
)
2017-01-18 16:18:35 +01:00
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()
foreach(unity_test ${unity_tests})
add_executable("${unity_test}" "${unity_test}.c")
target_link_libraries("${unity_test}" "${CJSON_LIB}" unity)
2017-01-18 16:18:35 +01:00
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()
endforeach()
endif()