• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2019, Paul Dreik
2# License: see LICENSE.rst in the fmt root directory
3
4# settings this links in a main. useful for reproducing,
5# kcov, gdb, afl, valgrind.
6# (note that libFuzzer can also reproduce, just pass it the files)
7option(FMT_FUZZ_LINKMAIN "enables the reproduce mode, instead of libFuzzer" On)
8
9# For oss-fuzz - insert $LIB_FUZZING_ENGINE into the link flags, but only for
10# the fuzz targets, otherwise the cmake configuration step fails.
11set(FMT_FUZZ_LDFLAGS "" CACHE STRING "LDFLAGS for the fuzz targets")
12
13# Find all fuzzers.
14set(SOURCES
15  chrono_duration.cpp
16  named_arg.cpp
17  one_arg.cpp
18  sprintf.cpp
19  two_args.cpp
20)
21
22macro(implement_fuzzer sourcefile)
23  get_filename_component(basename ${sourcefile} NAME_WE)
24  set(name fuzzer_${basename})
25  add_executable(${name} ${sourcefile} fuzzer_common.h)
26  if (FMT_FUZZ_LINKMAIN)
27      target_sources(${name} PRIVATE main.cpp)
28  endif ()
29  target_link_libraries(${name} PRIVATE fmt)
30if (FMT_FUZZ_LDFLAGS)
31  target_link_libraries(${name} PRIVATE ${FMT_FUZZ_LDFLAGS})
32endif ()
33  target_compile_features(${name} PRIVATE cxx_generic_lambdas)
34endmacro ()
35
36foreach (X IN ITEMS ${SOURCES})
37  implement_fuzzer(${X})
38endforeach ()
39