CMakeLists.txt 2.1 KB

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