1# Copyright (c) 2019 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 15if(SPIRV_BUILD_FUZZER) 16 17 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/protobufs) 18 19 set(PROTOBUF_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/protobufs/spvtoolsfuzz.proto) 20 21 add_custom_command( 22 OUTPUT protobufs/spvtoolsfuzz.pb.cc protobufs/spvtoolsfuzz.pb.h 23 COMMAND protobuf::protoc 24 -I=${CMAKE_CURRENT_SOURCE_DIR}/protobufs 25 --cpp_out=protobufs 26 ${PROTOBUF_SOURCE} 27 DEPENDS ${PROTOBUF_SOURCE} 28 COMMENT "Generate protobuf sources from proto definition file." 29 ) 30 31 set(SPIRV_TOOLS_FUZZ_SOURCES 32 call_graph.h 33 data_descriptor.h 34 equivalence_relation.h 35 fact_manager.h 36 force_render_red.h 37 fuzzer.h 38 fuzzer_context.h 39 fuzzer_pass.h 40 fuzzer_pass_add_access_chains.h 41 fuzzer_pass_add_composite_types.h 42 fuzzer_pass_add_dead_blocks.h 43 fuzzer_pass_add_dead_breaks.h 44 fuzzer_pass_add_dead_continues.h 45 fuzzer_pass_add_equation_instructions.h 46 fuzzer_pass_add_function_calls.h 47 fuzzer_pass_add_global_variables.h 48 fuzzer_pass_add_loads.h 49 fuzzer_pass_add_local_variables.h 50 fuzzer_pass_add_no_contraction_decorations.h 51 fuzzer_pass_add_stores.h 52 fuzzer_pass_add_useful_constructs.h 53 fuzzer_pass_adjust_function_controls.h 54 fuzzer_pass_adjust_loop_controls.h 55 fuzzer_pass_adjust_memory_operands_masks.h 56 fuzzer_pass_adjust_selection_controls.h 57 fuzzer_pass_apply_id_synonyms.h 58 fuzzer_pass_construct_composites.h 59 fuzzer_pass_copy_objects.h 60 fuzzer_pass_donate_modules.h 61 fuzzer_pass_merge_blocks.h 62 fuzzer_pass_obfuscate_constants.h 63 fuzzer_pass_outline_functions.h 64 fuzzer_pass_permute_blocks.h 65 fuzzer_pass_permute_function_parameters.h 66 fuzzer_pass_split_blocks.h 67 fuzzer_pass_swap_commutable_operands.h 68 fuzzer_pass_toggle_access_chain_instruction.h 69 fuzzer_util.h 70 id_use_descriptor.h 71 instruction_descriptor.h 72 instruction_message.h 73 protobufs/spirvfuzz_protobufs.h 74 pseudo_random_generator.h 75 random_generator.h 76 replayer.h 77 shrinker.h 78 transformation.h 79 transformation_access_chain.h 80 transformation_add_constant_boolean.h 81 transformation_add_constant_composite.h 82 transformation_add_constant_null.h 83 transformation_add_constant_scalar.h 84 transformation_add_dead_block.h 85 transformation_add_dead_break.h 86 transformation_add_dead_continue.h 87 transformation_add_function.h 88 transformation_add_global_undef.h 89 transformation_add_global_variable.h 90 transformation_add_local_variable.h 91 transformation_add_no_contraction_decoration.h 92 transformation_add_type_array.h 93 transformation_add_type_boolean.h 94 transformation_add_type_float.h 95 transformation_add_type_function.h 96 transformation_add_type_int.h 97 transformation_add_type_matrix.h 98 transformation_add_type_pointer.h 99 transformation_add_type_struct.h 100 transformation_add_type_vector.h 101 transformation_composite_construct.h 102 transformation_composite_extract.h 103 transformation_compute_data_synonym_fact_closure.h 104 transformation_context.h 105 transformation_copy_object.h 106 transformation_equation_instruction.h 107 transformation_function_call.h 108 transformation_load.h 109 transformation_merge_blocks.h 110 transformation_move_block_down.h 111 transformation_outline_function.h 112 transformation_permute_function_parameters.h 113 transformation_replace_boolean_constant_with_constant_binary.h 114 transformation_replace_constant_with_uniform.h 115 transformation_replace_id_with_synonym.h 116 transformation_set_function_control.h 117 transformation_set_loop_control.h 118 transformation_set_memory_operands_mask.h 119 transformation_set_selection_control.h 120 transformation_split_block.h 121 transformation_store.h 122 transformation_swap_commutable_operands.h 123 transformation_toggle_access_chain_instruction.h 124 transformation_vector_shuffle.h 125 uniform_buffer_element_descriptor.h 126 ${CMAKE_CURRENT_BINARY_DIR}/protobufs/spvtoolsfuzz.pb.h 127 128 call_graph.cpp 129 data_descriptor.cpp 130 fact_manager.cpp 131 force_render_red.cpp 132 fuzzer.cpp 133 fuzzer_context.cpp 134 fuzzer_pass.cpp 135 fuzzer_pass_add_access_chains.cpp 136 fuzzer_pass_add_composite_types.cpp 137 fuzzer_pass_add_dead_blocks.cpp 138 fuzzer_pass_add_dead_breaks.cpp 139 fuzzer_pass_add_dead_continues.cpp 140 fuzzer_pass_add_equation_instructions.cpp 141 fuzzer_pass_add_function_calls.cpp 142 fuzzer_pass_add_global_variables.cpp 143 fuzzer_pass_add_loads.cpp 144 fuzzer_pass_add_local_variables.cpp 145 fuzzer_pass_add_no_contraction_decorations.cpp 146 fuzzer_pass_add_stores.cpp 147 fuzzer_pass_add_useful_constructs.cpp 148 fuzzer_pass_adjust_function_controls.cpp 149 fuzzer_pass_adjust_loop_controls.cpp 150 fuzzer_pass_adjust_memory_operands_masks.cpp 151 fuzzer_pass_adjust_selection_controls.cpp 152 fuzzer_pass_apply_id_synonyms.cpp 153 fuzzer_pass_construct_composites.cpp 154 fuzzer_pass_copy_objects.cpp 155 fuzzer_pass_donate_modules.cpp 156 fuzzer_pass_merge_blocks.cpp 157 fuzzer_pass_obfuscate_constants.cpp 158 fuzzer_pass_outline_functions.cpp 159 fuzzer_pass_permute_blocks.cpp 160 fuzzer_pass_permute_function_parameters.cpp 161 fuzzer_pass_split_blocks.cpp 162 fuzzer_pass_swap_commutable_operands.cpp 163 fuzzer_pass_toggle_access_chain_instruction.cpp 164 fuzzer_util.cpp 165 id_use_descriptor.cpp 166 instruction_descriptor.cpp 167 instruction_message.cpp 168 pseudo_random_generator.cpp 169 random_generator.cpp 170 replayer.cpp 171 shrinker.cpp 172 transformation.cpp 173 transformation_access_chain.cpp 174 transformation_add_constant_boolean.cpp 175 transformation_add_constant_composite.cpp 176 transformation_add_constant_null.cpp 177 transformation_add_constant_scalar.cpp 178 transformation_add_dead_block.cpp 179 transformation_add_dead_break.cpp 180 transformation_add_dead_continue.cpp 181 transformation_add_function.cpp 182 transformation_add_global_undef.cpp 183 transformation_add_global_variable.cpp 184 transformation_add_local_variable.cpp 185 transformation_add_no_contraction_decoration.cpp 186 transformation_add_type_array.cpp 187 transformation_add_type_boolean.cpp 188 transformation_add_type_float.cpp 189 transformation_add_type_function.cpp 190 transformation_add_type_int.cpp 191 transformation_add_type_matrix.cpp 192 transformation_add_type_pointer.cpp 193 transformation_add_type_struct.cpp 194 transformation_add_type_vector.cpp 195 transformation_composite_construct.cpp 196 transformation_composite_extract.cpp 197 transformation_compute_data_synonym_fact_closure.cpp 198 transformation_context.cpp 199 transformation_copy_object.cpp 200 transformation_equation_instruction.cpp 201 transformation_function_call.cpp 202 transformation_load.cpp 203 transformation_merge_blocks.cpp 204 transformation_move_block_down.cpp 205 transformation_outline_function.cpp 206 transformation_permute_function_parameters.cpp 207 transformation_replace_boolean_constant_with_constant_binary.cpp 208 transformation_replace_constant_with_uniform.cpp 209 transformation_replace_id_with_synonym.cpp 210 transformation_set_function_control.cpp 211 transformation_set_loop_control.cpp 212 transformation_set_memory_operands_mask.cpp 213 transformation_set_selection_control.cpp 214 transformation_split_block.cpp 215 transformation_store.cpp 216 transformation_swap_commutable_operands.cpp 217 transformation_toggle_access_chain_instruction.cpp 218 transformation_vector_shuffle.cpp 219 uniform_buffer_element_descriptor.cpp 220 ${CMAKE_CURRENT_BINARY_DIR}/protobufs/spvtoolsfuzz.pb.cc 221 ) 222 223 if(MSVC) 224 # Enable parallel builds across four cores for this lib 225 add_definitions(/MP4) 226 endif() 227 228 spvtools_pch(SPIRV_TOOLS_FUZZ_SOURCES pch_source_fuzz) 229 230 add_library(SPIRV-Tools-fuzz ${SPIRV_TOOLS_FUZZ_SOURCES}) 231 232 spvtools_default_compile_options(SPIRV-Tools-fuzz) 233 target_compile_definitions(SPIRV-Tools-fuzz PUBLIC -DGOOGLE_PROTOBUF_NO_RTTI -DGOOGLE_PROTOBUF_USE_UNALIGNED=0) 234 235 # Compilation of the auto-generated protobuf source file will yield warnings, 236 # which we have no control over and thus wish to ignore. 237 if(${COMPILER_IS_LIKE_GNU}) 238 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/protobufs/spvtoolsfuzz.pb.cc PROPERTIES COMPILE_FLAGS -w) 239 endif() 240 if(MSVC) 241 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/protobufs/spvtoolsfuzz.pb.cc PROPERTIES COMPILE_FLAGS /w) 242 endif() 243 244 target_include_directories(SPIRV-Tools-fuzz 245 PUBLIC 246 $<BUILD_INTERFACE:${spirv-tools_SOURCE_DIR}/include> 247 $<BUILD_INTERFACE:${SPIRV_HEADER_INCLUDE_DIR}> 248 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> 249 PRIVATE ${spirv-tools_BINARY_DIR} 250 PRIVATE ${CMAKE_BINARY_DIR}) 251 252 # The fuzzer reuses a lot of functionality from the SPIRV-Tools library. 253 target_link_libraries(SPIRV-Tools-fuzz 254 PUBLIC ${SPIRV_TOOLS} 255 PUBLIC SPIRV-Tools-opt 256 PUBLIC protobuf::libprotobuf) 257 258 set_property(TARGET SPIRV-Tools-fuzz PROPERTY FOLDER "SPIRV-Tools libraries") 259 spvtools_check_symbol_exports(SPIRV-Tools-fuzz) 260 261 if(ENABLE_SPIRV_TOOLS_INSTALL) 262 install(TARGETS SPIRV-Tools-fuzz EXPORT SPIRV-Tools-fuzzTargets 263 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 264 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 265 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) 266 export(EXPORT SPIRV-Tools-fuzzTargets FILE SPIRV-Tools-fuzzTarget.cmake) 267 268 spvtools_config_package_dir(SPIRV-Tools-fuzz PACKAGE_DIR) 269 install(EXPORT SPIRV-Tools-fuzzTargets FILE SPIRV-Tools-fuzzTarget.cmake 270 DESTINATION ${PACKAGE_DIR}) 271 272 spvtools_generate_config_file(SPIRV-Tools-fuzz) 273 install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-fuzzConfig.cmake DESTINATION ${PACKAGE_DIR}) 274 endif(ENABLE_SPIRV_TOOLS_INSTALL) 275 276endif(SPIRV_BUILD_FUZZER) 277