CMakeLists.txt 2.2 KB

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