CMakeLists.txt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. )
  20. add_library(test-common common.c)
  21. option(ENABLE_VALGRIND OFF "Enable the valgrind memory checker for the tests.")
  22. if (ENABLE_VALGRIND)
  23. find_program(MEMORYCHECK_COMMAND valgrind)
  24. if ("${MEMORYCHECK_COMMAND}" MATCHES "MEMORYCHECK_COMMAND-NOTFOUND")
  25. message(WARNING "Valgrind couldn't be found.")
  26. unset(MEMORYCHECK_COMMAND)
  27. else()
  28. set(MEMORYCHECK_COMMAND_OPTIONS --trace-children=yes --leak-check=full --error-exitcode=1)
  29. endif()
  30. endif()
  31. #"check" target that automatically builds everything and runs the tests
  32. add_custom_target(check
  33. COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
  34. DEPENDS ${unity_tests})
  35. foreach(unity_test ${unity_tests})
  36. add_executable("${unity_test}" "${unity_test}.c")
  37. target_link_libraries("${unity_test}" "${CJSON_LIB}" unity test-common)
  38. if(MEMORYCHECK_COMMAND)
  39. add_test(NAME "${unity_test}"
  40. COMMAND "${MEMORYCHECK_COMMAND}" ${MEMORYCHECK_COMMAND_OPTIONS} "./${unity_test}")
  41. else()
  42. add_test(NAME "${unity_test}"
  43. COMMAND "./${unity_test}")
  44. endif()
  45. endforeach()
  46. endif()