CMakeLists.txt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # ArduinoJson - https://arduinojson.org
  2. # Copyright © 2014-2022, Benoit BLANCHON
  3. # MIT License
  4. if(MSVC)
  5. add_compile_options(-D_CRT_SECURE_NO_WARNINGS)
  6. endif()
  7. add_executable(msgpack_reproducer
  8. msgpack_fuzzer.cpp
  9. reproducer.cpp
  10. )
  11. target_link_libraries(msgpack_reproducer
  12. ArduinoJson
  13. )
  14. add_executable(json_reproducer
  15. json_fuzzer.cpp
  16. reproducer.cpp
  17. )
  18. target_link_libraries(json_reproducer
  19. ArduinoJson
  20. )
  21. macro(add_fuzzer name)
  22. set(FUZZER "${name}_fuzzer")
  23. set(CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_corpus")
  24. set(SEED_CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_seed_corpus")
  25. add_executable("${FUZZER}"
  26. "${name}_fuzzer.cpp"
  27. )
  28. target_link_libraries("${FUZZER}"
  29. ArduinoJson
  30. )
  31. set_target_properties("${FUZZER}"
  32. PROPERTIES
  33. COMPILE_FLAGS
  34. "-fprofile-instr-generate -fcoverage-mapping -fsanitize=fuzzer -fno-sanitize-recover=all"
  35. LINK_FLAGS
  36. "-fprofile-instr-generate -fcoverage-mapping -fsanitize=fuzzer -fno-sanitize-recover=all"
  37. )
  38. add_test(
  39. NAME
  40. "${FUZZER}"
  41. COMMAND
  42. "${FUZZER}" "${CORPUS_DIR}" "${SEED_CORPUS_DIR}" -max_total_time=5 -timeout=1
  43. )
  44. set_tests_properties("${FUZZER}"
  45. PROPERTIES
  46. LABELS "Fuzzing"
  47. )
  48. endmacro()
  49. if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6)
  50. add_fuzzer(json)
  51. add_fuzzer(msgpack)
  52. endif()