CMakeLists.txt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. )
  16. option(ENABLE_VALGRIND OFF "Enable the valgrind memory checker for the tests.")
  17. if (ENABLE_VALGRIND)
  18. find_program(MEMORYCHECK_COMMAND valgrind)
  19. if ("${MEMORYCHECK_COMMAND}" MATCHES "MEMORYCHECK_COMMAND-NOTFOUND")
  20. message(WARNING "Valgrind couldn't be found.")
  21. unset(MEMORYCHECK_COMMAND)
  22. else()
  23. set(MEMORYCHECK_COMMAND_OPTIONS --trace-children=yes --leak-check=full --error-exitcode=1)
  24. endif()
  25. endif()
  26. foreach(unity_test ${unity_tests})
  27. add_executable("${unity_test}" "${unity_test}.c")
  28. target_link_libraries("${unity_test}" "${CJSON_LIB}" unity)
  29. if(MEMORYCHECK_COMMAND)
  30. add_test(NAME "${unity_test}"
  31. COMMAND "${MEMORYCHECK_COMMAND}" ${MEMORYCHECK_COMMAND_OPTIONS} "./${unity_test}")
  32. else()
  33. add_test(NAME "${unity_test}"
  34. COMMAND "./${unity_test}")
  35. endif()
  36. endforeach()
  37. endif()