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