CMakeLists.txt 1.2 KB

123456789101112131415161718192021222324252627282930
  1. # Copyright (c) 2019, Paul Dreik
  2. # License: see LICENSE.rst in the fmt root directory
  3. # Link in the main function. Useful for reproducing, kcov, gdb, afl, valgrind.
  4. # (Note that libFuzzer can also reproduce, just pass it the files.)
  5. option(FMT_FUZZ_LINKMAIN "Enables the reproduce mode, instead of libFuzzer" On)
  6. # For oss-fuzz - insert $LIB_FUZZING_ENGINE into the link flags, but only for
  7. # the fuzz targets, otherwise the CMake configuration step fails.
  8. set(FMT_FUZZ_LDFLAGS "" CACHE STRING "LDFLAGS for the fuzz targets")
  9. # Adds a binary for reproducing, i.e. no fuzzing, just enables replaying data
  10. # through the fuzzers.
  11. function(add_fuzzer source)
  12. get_filename_component(basename ${source} NAME_WE)
  13. set(name ${basename}-fuzzer)
  14. add_executable(${name} ${source} fuzzer-common.h)
  15. if (FMT_FUZZ_LINKMAIN)
  16. target_sources(${name} PRIVATE main.cc)
  17. endif ()
  18. target_link_libraries(${name} PRIVATE fmt)
  19. if (FMT_FUZZ_LDFLAGS)
  20. target_link_libraries(${name} PRIVATE ${FMT_FUZZ_LDFLAGS})
  21. endif ()
  22. target_compile_features(${name} PRIVATE cxx_std_14)
  23. endfunction()
  24. foreach (source chrono-duration.cc chrono-timepoint.cc float.cc named-arg.cc one-arg.cc two-args.cc)
  25. add_fuzzer(${source})
  26. endforeach ()