CMakeLists.txt 1.6 KB

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