CMakeLists.txt 1.7 KB

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