From cee9015ff8ef30dfc3e5ef3b6e0c6bfd1f11f516 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Sun, 15 Aug 2021 13:34:41 +0100 Subject: [PATCH] Add special build mode for OSS-Fuzz. --- CMakeLists.txt | 1 + cmake/compilerFlags.cmake | 2 +- fuzz/CMakeLists.txt | 14 ++++++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a3102ec..f51cdf33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ option( EXIV2_BUILD_DOC "Add 'doc' target to generate documentatio option( EXIV2_TEAM_EXTRA_WARNINGS "Add more sanity checks using compiler flags" OFF ) option( EXIV2_TEAM_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF ) option( EXIV2_TEAM_USE_SANITIZERS "Enable ASAN and UBSAN when available" OFF ) +option( EXIV2_TEAM_OSS_FUZZ "Build config for OSS-Fuzz" OFF ) option( EXIV2_TEAM_PACKAGING "Additional stuff for generating packages" OFF ) set(EXTRA_COMPILE_FLAGS " ") diff --git a/cmake/compilerFlags.cmake b/cmake/compilerFlags.cmake index e45a5e3f..860385f4 100644 --- a/cmake/compilerFlags.cmake +++ b/cmake/compilerFlags.cmake @@ -70,7 +70,7 @@ if ( MINGW OR UNIX OR MSYS ) # MINGW, Linux, APPLE, CYGWIN # This seems to be causing issues in the Fedora_MinGW GitLab job #add_compile_options(-fasynchronous-unwind-tables) - if( EXIV2_BUILD_FUZZ_TESTS ) + if( EXIV2_BUILD_FUZZ_TESTS AND NOT EXIV2_TEAM_OSS_FUZZ ) if (NOT COMPILER_IS_CLANG) message(FATAL_ERROR "You need to build with Clang for the fuzzers to work. " "Use Clang") diff --git a/fuzz/CMakeLists.txt b/fuzz/CMakeLists.txt index 378b67b1..a58edda9 100644 --- a/fuzz/CMakeLists.txt +++ b/fuzz/CMakeLists.txt @@ -1,10 +1,16 @@ macro(fuzzer name) add_executable(${name} ${name}.cpp) - set_target_properties(${name} - PROPERTIES - COMPILE_FLAGS "-fsanitize=fuzzer" - LINK_FLAGS "-fsanitize=fuzzer") + if(EXIV2_TEAM_OSS_FUZZ) + set_target_properties(${name} + PROPERTIES + LINK_FLAGS "${LIB_FUZZING_ENGINE}") + else() + set_target_properties(${name} + PROPERTIES + COMPILE_FLAGS "-fsanitize=fuzzer" + LINK_FLAGS "-fsanitize=fuzzer") + endif() target_link_libraries(${name} PRIVATE exiv2lib