CMakeLists.txt 1.9 KB

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