CMakeLists.txt 1.6 KB

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