]> git.proxmox.com Git - ceph.git/blob - ceph/src/fmt/test/fuzzing/CMakeLists.txt
import quincy beta 17.1.0
[ceph.git] / ceph / src / fmt / test / fuzzing / CMakeLists.txt
1 # Copyright (c) 2019, Paul Dreik
2 # License: see LICENSE.rst in the fmt root directory
3
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)
7
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")
11
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)
20 endif ()
21 target_link_libraries(${name} PRIVATE fmt)
22 if (FMT_FUZZ_LDFLAGS)
23 target_link_libraries(${name} PRIVATE ${FMT_FUZZ_LDFLAGS})
24 endif ()
25 target_compile_features(${name} PRIVATE cxx_generic_lambdas)
26 endfunction()
27
28 foreach (source chrono-duration.cc float.cc named-arg.cc one-arg.cc two-args.cc)
29 add_fuzzer(${source})
30 endforeach ()