xref: /freebsd/contrib/libcbor/test/CMakeLists.txt (revision da5432eda807c4b7232d030d5157d5b417ea4f52)
1file(GLOB TESTS "*_test.c")
2
3find_package(CMocka REQUIRED)
4
5message(STATUS "CMocka vars: ${CMOCKA_LIBRARIES} ${CMOCKA_INCLUDE_DIR}")
6
7find_library(MATH_LIBRARY m)
8
9CHECK_INCLUDE_FILE("execinfo.h" HAS_EXECINFO)
10
11foreach (TEST ${TESTS})
12    string(REGEX REPLACE ".*/([^/]+).c" "\\1" NAME ${TEST})
13    message("Adding test ${NAME}")
14    add_executable(${NAME} "${NAME}.c" assertions.c stream_expectations.c test_allocator.c)
15    target_link_libraries(${NAME} ${CMOCKA_LIBRARIES})
16    target_link_libraries(${NAME} cbor)
17    if(MATH_LIBRARY)
18        target_link_libraries(${NAME} ${MATH_LIBRARY})
19    endif()
20    target_include_directories(${NAME} PUBLIC ${CMOCKA_INCLUDE_DIR})
21    # See https://stackoverflow.com/a/10824578/499521
22    ADD_TEST(ctest_build_test_${NAME}
23            "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${NAME})
24    ADD_TEST(ctest_run_${NAME} ${NAME})
25    SET_TESTS_PROPERTIES(ctest_run_${NAME}
26            PROPERTIES DEPENDS ctest_build_test_${NAME})
27    add_dependencies(coverage ${NAME})
28endforeach (TEST)
29
30add_executable(cpp_linkage_test cpp_linkage_test.cpp)
31target_link_libraries(cpp_linkage_test cbor)