1# Copyright (c) 2024 Google LLC 2# 3# Use of this source code is governed by a BSD-style license 4# that can be found in the LICENSE file in the root of the source 5# tree. An additional intellectual property rights grant can be found 6# in the file PATENTS. All contributing project authors may 7# be found in the AUTHORS file in the root of the source tree. 8 9# Adds a fuzztest from file TEST_NAME.cc located in the gtest folder. Extra 10# arguments are considered as extra source files. 11 12if(CMAKE_VERSION VERSION_LESS "3.19.0") 13 return() 14endif() 15 16macro(add_webp_fuzztest TEST_NAME) 17 add_executable(${TEST_NAME} ${TEST_NAME}.cc) 18 # FuzzTest bundles GoogleTest so no need to link to gtest libraries. 19 target_link_libraries(${TEST_NAME} PRIVATE fuzz_utils webp ${ARGN}) 20 target_include_directories(${TEST_NAME} PRIVATE ${CMAKE_BINARY_DIR}/src) 21 link_fuzztest(${TEST_NAME}) 22 add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME}) 23 set_property( 24 TEST ${TEST_NAME} 25 PROPERTY ENVIRONMENT "TEST_DATA_DIRS=${CMAKE_CURRENT_SOURCE_DIR}/data/") 26endmacro() 27 28enable_language(CXX) 29set(CMAKE_CXX_STANDARD 17) 30set(CMAKE_CXX_STANDARD_REQUIRED ON) 31 32include(FetchContent) 33 34set(FETCHCONTENT_QUIET FALSE) 35set(fuzztest_SOURCE_DIR ${CMAKE_BINARY_DIR}/_deps/fuzztest-src) 36FetchContent_Declare( 37 fuzztest 38 GIT_REPOSITORY https://github.com/google/fuzztest.git 39 GIT_TAG 078ea0871cc96d3a69bad406577f176a4fa14ae9 40 GIT_PROGRESS TRUE 41 PATCH_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/patch.sh) 42 43FetchContent_MakeAvailable(fuzztest) 44 45fuzztest_setup_fuzzing_flags() 46 47add_library(fuzz_utils fuzz_utils.h fuzz_utils.cc img_alpha.h img_grid.h 48 img_peak.h) 49target_link_libraries(fuzz_utils PUBLIC webpdecoder) 50link_fuzztest(fuzz_utils) 51 52add_webp_fuzztest(advanced_api_fuzzer webpdecode webpdspdecode webputilsdecode) 53add_webp_fuzztest(dec_fuzzer) 54add_webp_fuzztest(enc_dec_fuzzer) 55add_webp_fuzztest(enc_fuzzer imagedec) 56add_webp_fuzztest(huffman_fuzzer webpdecode webpdspdecode webputilsdecode) 57add_webp_fuzztest(imageio_fuzzer imagedec) 58add_webp_fuzztest(simple_api_fuzzer) 59 60if(WEBP_BUILD_LIBWEBPMUX) 61 add_webp_fuzztest(animation_api_fuzzer webpdemux) 62 add_webp_fuzztest(animdecoder_fuzzer imageioutil webpdemux) 63 add_webp_fuzztest(animencoder_fuzzer libwebpmux) 64 add_webp_fuzztest(mux_demux_api_fuzzer libwebpmux webpdemux) 65endif() 66 67if(WEBP_BUILD_WEBPINFO) 68 add_webp_fuzztest(webp_info_fuzzer imageioutil) 69endif() 70