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