CMakeLists.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. if(ENABLE_CJSON_TEST)
  2. add_library(unity STATIC 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. # Disable -fsanitize=float-divide-by-zero for Unity (GCC bug on x86 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80097)
  20. if (FLAG_SUPPORTED_fsanitizefloatdividebyzero AND (CMAKE_C_COMPILER_ID STREQUAL "GNU"))
  21. if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12")
  22. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize=float-divide-by-zero")
  23. else()
  24. target_compile_options(unity PRIVATE "-fno-sanitize=float-divide-by-zero")
  25. endif()
  26. endif()
  27. # Disable -Wswitch-enum for Unity
  28. if (FLAG_SUPPORTED_Wswitchenum)
  29. if ("${CMAKE_VERSION}" VERSION_LESS "2.8.12")
  30. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch-enum")
  31. else()
  32. target_compile_options(unity PRIVATE "-Wno-switch-enum")
  33. endif()
  34. endif()
  35. #copy test files
  36. file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/inputs")
  37. file(GLOB test_files "inputs/*")
  38. file(COPY ${test_files} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/inputs/")
  39. set(unity_tests
  40. parse_examples
  41. parse_number
  42. parse_hex4
  43. parse_string
  44. parse_array
  45. parse_object
  46. parse_value
  47. print_string
  48. print_number
  49. print_array
  50. print_object
  51. print_value
  52. misc_tests
  53. parse_with_opts
  54. compare_tests
  55. cjson_add
  56. readme_examples
  57. minify_tests
  58. )
  59. option(ENABLE_VALGRIND OFF "Enable the valgrind memory checker for the tests.")
  60. if (ENABLE_VALGRIND)
  61. find_program(MEMORYCHECK_COMMAND valgrind)
  62. if ("${MEMORYCHECK_COMMAND}" MATCHES "MEMORYCHECK_COMMAND-NOTFOUND")
  63. message(WARNING "Valgrind couldn't be found.")
  64. unset(MEMORYCHECK_COMMAND)
  65. else()
  66. set(MEMORYCHECK_COMMAND_OPTIONS --trace-children=yes --leak-check=full --error-exitcode=1 --suppressions=${CMAKE_CURRENT_SOURCE_DIR}/../valgrind.supp)
  67. endif()
  68. endif()
  69. foreach(unity_test ${unity_tests})
  70. add_executable("${unity_test}" "${unity_test}.c")
  71. if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
  72. target_sources(${unity_test} PRIVATE unity_setup.c)
  73. endif()
  74. target_link_libraries("${unity_test}" "${CJSON_LIB}" unity)
  75. if(MEMORYCHECK_COMMAND)
  76. add_test(NAME "${unity_test}"
  77. COMMAND "${MEMORYCHECK_COMMAND}" ${MEMORYCHECK_COMMAND_OPTIONS} "${CMAKE_CURRENT_BINARY_DIR}/${unity_test}")
  78. else()
  79. add_test(NAME "${unity_test}"
  80. COMMAND "./${unity_test}")
  81. endif()
  82. endforeach()
  83. add_dependencies(check ${unity_tests})
  84. if (ENABLE_CJSON_UTILS)
  85. #copy test files
  86. file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/json-patch-tests")
  87. file(GLOB test_files "json-patch-tests/*")
  88. file(COPY ${test_files} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/json-patch-tests/")
  89. set (cjson_utils_tests
  90. json_patch_tests
  91. old_utils_tests
  92. misc_utils_tests)
  93. foreach (cjson_utils_test ${cjson_utils_tests})
  94. add_executable("${cjson_utils_test}" "${cjson_utils_test}.c")
  95. target_link_libraries("${cjson_utils_test}" "${CJSON_LIB}" "${CJSON_UTILS_LIB}" unity)
  96. if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
  97. target_sources(${cjson_utils_test} PRIVATE unity_setup.c)
  98. endif()
  99. if(MEMORYCHECK_COMMAND)
  100. add_test(NAME "${cjson_utils_test}"
  101. COMMAND "${MEMORYCHECK_COMMAND}" ${MEMORYCHECK_COMMAND_OPTIONS} "${CMAKE_CURRENT_BINARY_DIR}/${cjson_utils_test}")
  102. else()
  103. add_test(NAME "${cjson_utils_test}"
  104. COMMAND "./${cjson_utils_test}")
  105. endif()
  106. endforeach()
  107. add_dependencies(check ${cjson_utils_tests})
  108. endif()
  109. endif()