CMakeLists.txt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. add_library(unity unity/src/unity.c)
  2. if(ENABLE_CJSON_TEST)
  3. #copy test files
  4. file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/inputs")
  5. file(GLOB test_files "inputs/*")
  6. file(COPY ${test_files} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/inputs/")
  7. set(unity_tests
  8. parse_examples
  9. parse_number
  10. parse_hex4
  11. parse_string
  12. parse_array
  13. parse_object
  14. parse_value
  15. print_string
  16. print_number
  17. print_array
  18. print_object
  19. print_value
  20. misc_tests
  21. )
  22. add_library(test-common common.c)
  23. option(ENABLE_VALGRIND OFF "Enable the valgrind memory checker for the tests.")
  24. if (ENABLE_VALGRIND)
  25. find_program(MEMORYCHECK_COMMAND valgrind)
  26. if ("${MEMORYCHECK_COMMAND}" MATCHES "MEMORYCHECK_COMMAND-NOTFOUND")
  27. message(WARNING "Valgrind couldn't be found.")
  28. unset(MEMORYCHECK_COMMAND)
  29. else()
  30. set(MEMORYCHECK_COMMAND_OPTIONS --trace-children=yes --leak-check=full --error-exitcode=1)
  31. endif()
  32. endif()
  33. #"check" target that automatically builds everything and runs the tests
  34. add_custom_target(check
  35. COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
  36. DEPENDS ${unity_tests})
  37. foreach(unity_test ${unity_tests})
  38. add_executable("${unity_test}" "${unity_test}.c")
  39. target_link_libraries("${unity_test}" "${CJSON_LIB}" unity test-common)
  40. if(MEMORYCHECK_COMMAND)
  41. add_test(NAME "${unity_test}"
  42. COMMAND "${MEMORYCHECK_COMMAND}" ${MEMORYCHECK_COMMAND_OPTIONS} "./${unity_test}")
  43. else()
  44. add_test(NAME "${unity_test}"
  45. COMMAND "./${unity_test}")
  46. endif()
  47. endforeach()
  48. endif()