1file(GLOB TESTS "*_test.c") 2 3if(NOT CBOR_CUSTOM_ALLOC) 4 # Memory allocation test requires custom allocator support to instrument it. 5 list(REMOVE_ITEM TESTS ${CMAKE_CURRENT_SOURCE_DIR}/memory_allocation_test.c) 6endif(NOT CBOR_CUSTOM_ALLOC) 7 8find_package(CMocka REQUIRED) 9 10message(STATUS "CMocka vars: ${CMOCKA_LIBRARIES} ${CMOCKA_INCLUDE_DIR}") 11 12foreach (TEST ${TESTS}) 13 string(REGEX REPLACE ".*/([^/]+).c" "\\1" NAME ${TEST}) 14 message("Adding test ${NAME}") 15 add_executable(${NAME} "${NAME}.c" assertions.c stream_expectations.c) 16 target_link_libraries(${NAME} ${CMOCKA_LIBRARIES}) 17 target_link_libraries(${NAME} cbor) 18 target_include_directories(${NAME} PUBLIC ${CMOCKA_INCLUDE_DIR}) 19 # See https://stackoverflow.com/a/10824578/499521 20 ADD_TEST(ctest_build_test_${NAME} 21 "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${NAME}) 22 ADD_TEST(ctest_run_${NAME} ${NAME}) 23 SET_TESTS_PROPERTIES(ctest_run_${NAME} 24 PROPERTIES DEPENDS ctest_build_test_${NAME}) 25 add_dependencies(coverage ${NAME}) 26endforeach (TEST) 27 28add_executable(cpp_linkage_test cpp_linkage_test.cpp) 29target_link_libraries(cpp_linkage_test cbor)