110ff414cSEd Mastefile(GLOB TESTS "*_test.c") 210ff414cSEd Maste 310ff414cSEd Mastefind_package(CMocka REQUIRED) 410ff414cSEd Maste 510ff414cSEd Mastemessage(STATUS "CMocka vars: ${CMOCKA_LIBRARIES} ${CMOCKA_INCLUDE_DIR}") 610ff414cSEd Maste 7*5d3e7166SEd Mastefind_library(MATH_LIBRARY m) 8*5d3e7166SEd Maste 9*5d3e7166SEd MasteCHECK_INCLUDE_FILE("execinfo.h" HAS_EXECINFO) 10*5d3e7166SEd Maste 1110ff414cSEd Masteforeach (TEST ${TESTS}) 1210ff414cSEd Maste string(REGEX REPLACE ".*/([^/]+).c" "\\1" NAME ${TEST}) 1310ff414cSEd Maste message("Adding test ${NAME}") 14*5d3e7166SEd Maste add_executable(${NAME} "${NAME}.c" assertions.c stream_expectations.c test_allocator.c) 1510ff414cSEd Maste target_link_libraries(${NAME} ${CMOCKA_LIBRARIES}) 1610ff414cSEd Maste target_link_libraries(${NAME} cbor) 17*5d3e7166SEd Maste if(MATH_LIBRARY) 18*5d3e7166SEd Maste target_link_libraries(${NAME} ${MATH_LIBRARY}) 19*5d3e7166SEd Maste endif() 2010ff414cSEd Maste target_include_directories(${NAME} PUBLIC ${CMOCKA_INCLUDE_DIR}) 2110ff414cSEd Maste # See https://stackoverflow.com/a/10824578/499521 2210ff414cSEd Maste ADD_TEST(ctest_build_test_${NAME} 2310ff414cSEd Maste "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${NAME}) 2410ff414cSEd Maste ADD_TEST(ctest_run_${NAME} ${NAME}) 2510ff414cSEd Maste SET_TESTS_PROPERTIES(ctest_run_${NAME} 2610ff414cSEd Maste PROPERTIES DEPENDS ctest_build_test_${NAME}) 2710ff414cSEd Maste add_dependencies(coverage ${NAME}) 2810ff414cSEd Masteendforeach (TEST) 2910ff414cSEd Maste 3010ff414cSEd Masteadd_executable(cpp_linkage_test cpp_linkage_test.cpp) 3110ff414cSEd Mastetarget_link_libraries(cpp_linkage_test cbor)