Debian Codegraph @

test/fuzzers/CMakeLists.txt

raw
1 # Copyright (c) 2021 Google LLC
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 function(add_spvtools_libfuzzer_target)
16 set(one_value_args TARGET)
17 set(multi_value_args SRCS LIBS)
18 cmake_parse_arguments(
19 ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN})
20
21 add_executable(${ARG_TARGET} ${ARG_SRCS})
22 spvtools_default_compile_options(${ARG_TARGET})
23 target_link_libraries(${ARG_TARGET} PRIVATE ${ARG_LIBS})
24 target_include_directories(${ARG_TARGET} PRIVATE
25 ${spirv-tools_SOURCE_DIR}
26 ${spirv-tools_BINARY_DIR}
27 )
28 set_property(TARGET ${ARG_TARGET} PROPERTY FOLDER "SPIRV-Tools libFuzzer targets")
29 if(NOT ${SPIRV_LIB_FUZZING_ENGINE_LINK_OPTIONS} STREQUAL "")
30 # This is set when the fuzzers are being built by OSS-Fuzz. In this case the
31 # variable provides the necessary linker flags, and OSS-Fuzz will take care
32 # of passing suitable compiler flags.
33 target_link_options(${ARG_TARGET} PRIVATE ${SPIRV_LIB_FUZZING_ENGINE_LINK_OPTIONS})
34 else()
35 # When the fuzzers are being built outside of OSS-Fuzz, standard libFuzzer
36 # arguments to enable fuzzing are used.
37 target_compile_options(${ARG_TARGET} PRIVATE "-fsanitize=fuzzer")
38 target_link_options(${ARG_TARGET} PRIVATE "-fsanitize=fuzzer")
39 endif()
40 endfunction()
41
42 if (${SPIRV_BUILD_LIBFUZZER_TARGETS})
43 if(NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
44 message(FATAL_ERROR "The libFuzzer targets are only supported with the Clang compiler. Compiler '${CMAKE_CXX_COMPILER_ID}' is not supported!")
45 endif()
46 add_spvtools_libfuzzer_target(TARGET spvtools_as_fuzzer SRCS spvtools_as_fuzzer.cpp random_generator.cpp LIBS ${SPIRV_TOOLS_FULL_VISIBILITY})
47 add_spvtools_libfuzzer_target(TARGET spvtools_binary_parser_fuzzer SRCS spvtools_binary_parser_fuzzer.cpp random_generator.cpp LIBS ${SPIRV_TOOLS_FULL_VISIBILITY})
48 add_spvtools_libfuzzer_target(TARGET spvtools_dis_fuzzer SRCS spvtools_dis_fuzzer.cpp random_generator.cpp LIBS ${SPIRV_TOOLS_FULL_VISIBILITY})
49 add_spvtools_libfuzzer_target(TARGET spvtools_opt_legalization_fuzzer SRCS spvtools_opt_legalization_fuzzer.cpp spvtools_opt_fuzzer_common.cpp random_generator.cpp LIBS SPIRV-Tools-opt ${SPIRV_TOOLS_FULL_VISIBILITY})
50 add_spvtools_libfuzzer_target(TARGET spvtools_opt_performance_fuzzer SRCS spvtools_opt_performance_fuzzer.cpp spvtools_opt_fuzzer_common.cpp random_generator.cpp LIBS SPIRV-Tools-opt ${SPIRV_TOOLS_FULL_VISIBILITY})
51 add_spvtools_libfuzzer_target(TARGET spvtools_opt_size_fuzzer SRCS spvtools_opt_size_fuzzer.cpp spvtools_opt_fuzzer_common.cpp random_generator.cpp LIBS SPIRV-Tools-opt ${SPIRV_TOOLS_FULL_VISIBILITY})
52 add_spvtools_libfuzzer_target(TARGET spvtools_val_fuzzer SRCS spvtools_val_fuzzer.cpp random_generator.cpp LIBS ${SPIRV_TOOLS_FULL_VISIBILITY})
53 if (${SPIRV_BUILD_FUZZER})
54 add_spvtools_libfuzzer_target(TARGET spvtools_fuzz_fuzzer SRCS spvtools_fuzz_fuzzer.cpp random_generator.cpp LIBS SPIRV-Tools-fuzz ${SPIRV_TOOLS_FULL_VISIBILITY})
55 endif()
56 endif()