CMakeLists.txt 1.9 KB

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