• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2015-2016 The Khronos Group Inc.
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
15set(GRAMMAR_PROCESSING_SCRIPT "${spirv-tools_SOURCE_DIR}/utils/generate_grammar_tables.py")
16set(VIMSYNTAX_PROCESSING_SCRIPT "${spirv-tools_SOURCE_DIR}/utils/generate_vim_syntax.py")
17set(XML_REGISTRY_PROCESSING_SCRIPT "${spirv-tools_SOURCE_DIR}/utils/generate_registry_tables.py")
18set(LANG_HEADER_PROCESSING_SCRIPT "${spirv-tools_SOURCE_DIR}/utils/generate_language_headers.py")
19
20# Pull in grammar files that have migrated to SPIRV-Headers
21set(DEBUGINFO_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/unified1/extinst.debuginfo.grammar.json")
22set(CLDEBUGINFO100_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json")
23set(VKDEBUGINFO100_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/unified1/extinst.nonsemantic.shader.debuginfo.100.grammar.json")
24
25# macro() definitions are used in the following because we need to append .inc
26# file paths into some global lists (*_CPP_DEPENDS). And those global lists are
27# later used by set_source_files_properties() calls.
28# function() definitions are not suitable because they create new scopes.
29macro(spvtools_core_tables CONFIG_VERSION)
30  set(GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/spirv.core.grammar.json")
31  set(GRAMMAR_INSTS_INC_FILE "${spirv-tools_BINARY_DIR}/core.insts-${CONFIG_VERSION}.inc")
32  set(GRAMMAR_KINDS_INC_FILE "${spirv-tools_BINARY_DIR}/operand.kinds-${CONFIG_VERSION}.inc")
33  add_custom_command(OUTPUT ${GRAMMAR_INSTS_INC_FILE} ${GRAMMAR_KINDS_INC_FILE}
34    COMMAND ${PYTHON_EXECUTABLE} ${GRAMMAR_PROCESSING_SCRIPT}
35      --spirv-core-grammar=${GRAMMAR_JSON_FILE}
36      --extinst-debuginfo-grammar=${DEBUGINFO_GRAMMAR_JSON_FILE}
37      --extinst-cldebuginfo100-grammar=${CLDEBUGINFO100_GRAMMAR_JSON_FILE}
38      --core-insts-output=${GRAMMAR_INSTS_INC_FILE}
39      --operand-kinds-output=${GRAMMAR_KINDS_INC_FILE}
40      --output-language=c++
41    DEPENDS ${GRAMMAR_PROCESSING_SCRIPT}
42            ${GRAMMAR_JSON_FILE}
43            ${DEBUGINFO_GRAMMAR_JSON_FILE}
44            ${CLDEBUGINFO100_GRAMMAR_JSON_FILE}
45    COMMENT "Generate info tables for SPIR-V v${CONFIG_VERSION} core instructions and operands.")
46  list(APPEND OPCODE_CPP_DEPENDS ${GRAMMAR_INSTS_INC_FILE})
47  list(APPEND OPERAND_CPP_DEPENDS ${GRAMMAR_KINDS_INC_FILE})
48endmacro(spvtools_core_tables)
49
50macro(spvtools_enum_string_mapping CONFIG_VERSION)
51  set(GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/spirv.core.grammar.json")
52  set(GRAMMAR_EXTENSION_ENUM_INC_FILE "${spirv-tools_BINARY_DIR}/extension_enum.inc")
53  set(GRAMMAR_ENUM_STRING_MAPPING_INC_FILE "${spirv-tools_BINARY_DIR}/enum_string_mapping.inc")
54  add_custom_command(OUTPUT ${GRAMMAR_EXTENSION_ENUM_INC_FILE}
55     ${GRAMMAR_ENUM_STRING_MAPPING_INC_FILE}
56    COMMAND ${PYTHON_EXECUTABLE} ${GRAMMAR_PROCESSING_SCRIPT}
57      --spirv-core-grammar=${GRAMMAR_JSON_FILE}
58      --extinst-debuginfo-grammar=${DEBUGINFO_GRAMMAR_JSON_FILE}
59      --extinst-cldebuginfo100-grammar=${CLDEBUGINFO100_GRAMMAR_JSON_FILE}
60      --extension-enum-output=${GRAMMAR_EXTENSION_ENUM_INC_FILE}
61      --enum-string-mapping-output=${GRAMMAR_ENUM_STRING_MAPPING_INC_FILE}
62      --output-language=c++
63    DEPENDS ${GRAMMAR_PROCESSING_SCRIPT}
64            ${GRAMMAR_JSON_FILE}
65            ${DEBUGINFO_GRAMMAR_JSON_FILE}
66            ${CLDEBUGINFO100_GRAMMAR_JSON_FILE}
67    COMMENT "Generate enum-string mapping for SPIR-V v${CONFIG_VERSION}.")
68  list(APPEND EXTENSION_H_DEPENDS ${GRAMMAR_EXTENSION_ENUM_INC_FILE})
69  list(APPEND ENUM_STRING_MAPPING_CPP_DEPENDS ${GRAMMAR_ENUM_STRING_MAPPING_INC_FILE})
70endmacro(spvtools_enum_string_mapping)
71
72macro(spvtools_vimsyntax CONFIG_VERSION CLVERSION)
73  set(GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/spirv.core.grammar.json")
74  set(GLSL_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/extinst.glsl.std.450.grammar.json")
75  set(OPENCL_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/extinst.opencl.std.100.grammar.json")
76  set(VIMSYNTAX_FILE "${spirv-tools_BINARY_DIR}/spvasm.vim")
77  add_custom_command(OUTPUT ${VIMSYNTAX_FILE}
78      COMMAND ${PYTHON_EXECUTABLE} ${VIMSYNTAX_PROCESSING_SCRIPT}
79      --spirv-core-grammar=${GRAMMAR_JSON_FILE}
80      --extinst-debuginfo-grammar=${DEBUGINFO_GRAMMAR_JSON_FILE}
81      --extinst-glsl-grammar=${GLSL_GRAMMAR_JSON_FILE}
82      --extinst-opencl-grammar=${OPENCL_GRAMMAR_JSON_FILE}
83      >${VIMSYNTAX_FILE}
84    DEPENDS ${VIMSYNTAX_PROCESSING_SCRIPT} ${GRAMMAR_JSON_FILE}
85            ${GLSL_GRAMMAR_JSON_FILE} ${OPENCL_GRAMMAR_JSON_FILE} ${DEBUGINFO_GRAMMAR_JSON_FILE}
86    COMMENT "Generate spvasm.vim: Vim syntax file for SPIR-V assembly.")
87endmacro(spvtools_vimsyntax)
88
89macro(spvtools_glsl_tables CONFIG_VERSION)
90  set(CORE_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/spirv.core.grammar.json")
91  set(GLSL_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/extinst.glsl.std.450.grammar.json")
92  set(GRAMMAR_INC_FILE "${spirv-tools_BINARY_DIR}/glsl.std.450.insts.inc")
93  add_custom_command(OUTPUT ${GRAMMAR_INC_FILE}
94    COMMAND ${PYTHON_EXECUTABLE} ${GRAMMAR_PROCESSING_SCRIPT}
95      --extinst-glsl-grammar=${GLSL_GRAMMAR_JSON_FILE}
96      --glsl-insts-output=${GRAMMAR_INC_FILE}
97      --output-language=c++
98    DEPENDS ${GRAMMAR_PROCESSING_SCRIPT} ${CORE_GRAMMAR_JSON_FILE} ${GLSL_GRAMMAR_JSON_FILE}
99    COMMENT "Generate info tables for GLSL extended instructions and operands v${CONFIG_VERSION}.")
100  list(APPEND EXTINST_CPP_DEPENDS ${GRAMMAR_INC_FILE})
101endmacro(spvtools_glsl_tables)
102
103macro(spvtools_opencl_tables CONFIG_VERSION)
104  set(CORE_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/spirv.core.grammar.json")
105  set(OPENCL_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/extinst.opencl.std.100.grammar.json")
106  set(GRAMMAR_INC_FILE "${spirv-tools_BINARY_DIR}/opencl.std.insts.inc")
107  add_custom_command(OUTPUT ${GRAMMAR_INC_FILE}
108    COMMAND ${PYTHON_EXECUTABLE} ${GRAMMAR_PROCESSING_SCRIPT}
109      --extinst-opencl-grammar=${OPENCL_GRAMMAR_JSON_FILE}
110      --opencl-insts-output=${GRAMMAR_INC_FILE}
111    DEPENDS ${GRAMMAR_PROCESSING_SCRIPT} ${CORE_GRAMMAR_JSON_FILE} ${OPENCL_GRAMMAR_JSON_FILE}
112    COMMENT "Generate info tables for OpenCL extended instructions and operands v${CONFIG_VERSION}.")
113  list(APPEND EXTINST_CPP_DEPENDS ${GRAMMAR_INC_FILE})
114endmacro(spvtools_opencl_tables)
115
116macro(spvtools_vendor_tables VENDOR_TABLE SHORT_NAME OPERAND_KIND_PREFIX)
117  set(INSTS_FILE "${spirv-tools_BINARY_DIR}/${VENDOR_TABLE}.insts.inc")
118  set(GRAMMAR_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/unified1/extinst.${VENDOR_TABLE}.grammar.json")
119  if(NOT EXISTS ${GRAMMAR_FILE})
120    set(GRAMMAR_FILE "${spirv-tools_SOURCE_DIR}/source/extinst.${VENDOR_TABLE}.grammar.json")
121  endif()
122  add_custom_command(OUTPUT ${INSTS_FILE}
123    COMMAND ${PYTHON_EXECUTABLE} ${GRAMMAR_PROCESSING_SCRIPT}
124      --extinst-vendor-grammar=${GRAMMAR_FILE}
125      --vendor-insts-output=${INSTS_FILE}
126      --vendor-operand-kind-prefix=${OPERAND_KIND_PREFIX}
127    DEPENDS ${GRAMMAR_PROCESSING_SCRIPT} ${GRAMMAR_FILE}
128    COMMENT "Generate extended instruction tables for ${VENDOR_TABLE}.")
129  add_custom_target(spv-tools-${SHORT_NAME} DEPENDS ${INSTS_FILE})
130  set_property(TARGET spv-tools-${SHORT_NAME} PROPERTY FOLDER "SPIRV-Tools build")
131  list(APPEND EXTINST_CPP_DEPENDS spv-tools-${SHORT_NAME})
132endmacro(spvtools_vendor_tables)
133
134macro(spvtools_extinst_lang_headers NAME GRAMMAR_FILE)
135  set(OUT_H ${spirv-tools_BINARY_DIR}/${NAME}.h)
136  add_custom_command(OUTPUT ${OUT_H}
137    COMMAND ${PYTHON_EXECUTABLE} ${LANG_HEADER_PROCESSING_SCRIPT}
138      --extinst-grammar=${GRAMMAR_FILE}
139      --extinst-output-path=${OUT_H}
140    DEPENDS ${LANG_HEADER_PROCESSING_SCRIPT} ${GRAMMAR_FILE}
141    COMMENT "Generate language specific header for ${NAME}.")
142  add_custom_target(spirv-tools-header-${NAME} DEPENDS ${OUT_H})
143  set_property(TARGET spirv-tools-header-${NAME} PROPERTY FOLDER "SPIRV-Tools build")
144  list(APPEND EXTINST_CPP_DEPENDS spirv-tools-header-${NAME})
145endmacro(spvtools_extinst_lang_headers)
146
147spvtools_core_tables("unified1")
148spvtools_enum_string_mapping("unified1")
149spvtools_opencl_tables("unified1")
150spvtools_glsl_tables("unified1")
151spvtools_vendor_tables("spv-amd-shader-explicit-vertex-parameter" "spv-amd-sevp" "")
152spvtools_vendor_tables("spv-amd-shader-trinary-minmax" "spv-amd-stm" "")
153spvtools_vendor_tables("spv-amd-gcn-shader" "spv-amd-gs" "")
154spvtools_vendor_tables("spv-amd-shader-ballot" "spv-amd-sb" "")
155spvtools_vendor_tables("debuginfo" "debuginfo" "")
156spvtools_vendor_tables("opencl.debuginfo.100" "cldi100" "CLDEBUG100_")
157spvtools_vendor_tables("nonsemantic.shader.debuginfo.100" "shdi100" "SHDEBUG100_")
158spvtools_vendor_tables("nonsemantic.clspvreflection" "clspvreflection" "")
159spvtools_extinst_lang_headers("DebugInfo" ${DEBUGINFO_GRAMMAR_JSON_FILE})
160spvtools_extinst_lang_headers("OpenCLDebugInfo100" ${CLDEBUGINFO100_GRAMMAR_JSON_FILE})
161spvtools_extinst_lang_headers("NonSemanticShaderDebugInfo100" ${VKDEBUGINFO100_GRAMMAR_JSON_FILE})
162
163spvtools_vimsyntax("unified1" "1.0")
164add_custom_target(spirv-tools-vimsyntax DEPENDS ${VIMSYNTAX_FILE})
165set_property(TARGET spirv-tools-vimsyntax PROPERTY FOLDER "SPIRV-Tools utilities")
166
167# Extract the list of known generators from the SPIR-V XML registry file.
168set(GENERATOR_INC_FILE ${spirv-tools_BINARY_DIR}/generators.inc)
169set(SPIRV_XML_REGISTRY_FILE ${SPIRV_HEADER_INCLUDE_DIR}/spirv/spir-v.xml)
170add_custom_command(OUTPUT ${GENERATOR_INC_FILE}
171  COMMAND ${PYTHON_EXECUTABLE} ${XML_REGISTRY_PROCESSING_SCRIPT}
172    --xml=${SPIRV_XML_REGISTRY_FILE}
173    --generator-output=${GENERATOR_INC_FILE}
174  DEPENDS ${XML_REGISTRY_PROCESSING_SCRIPT} ${SPIRV_XML_REGISTRY_FILE}
175  COMMENT "Generate tables based on the SPIR-V XML registry.")
176list(APPEND OPCODE_CPP_DEPENDS ${GENERATOR_INC_FILE})
177
178# The following .cpp files include the above generated .inc files.
179# Add those .inc files as their dependencies.
180#
181# We need to wrap the .inc files with a custom target to avoid problems when
182# multiple targets depend on the same custom command.
183add_custom_target(core_tables
184  DEPENDS ${OPCODE_CPP_DEPENDS} ${OPERAND_CPP_DEPENDS})
185add_custom_target(enum_string_mapping
186  DEPENDS ${EXTENSION_H_DEPENDS} ${ENUM_STRING_MAPPING_CPP_DEPENDS})
187add_custom_target(extinst_tables
188  DEPENDS ${EXTINST_CPP_DEPENDS})
189
190set_source_files_properties(
191  ${CMAKE_CURRENT_SOURCE_DIR}/extensions.h
192  PROPERTIES HEADER_FILE_ONLY TRUE)
193
194set(SPIRV_TOOLS_BUILD_VERSION_INC
195  ${spirv-tools_BINARY_DIR}/build-version.inc)
196set(SPIRV_TOOLS_BUILD_VERSION_INC_GENERATOR
197  ${spirv-tools_SOURCE_DIR}/utils/update_build_version.py)
198add_custom_command(OUTPUT ${SPIRV_TOOLS_BUILD_VERSION_INC}
199   COMMAND ${PYTHON_EXECUTABLE}
200           ${SPIRV_TOOLS_BUILD_VERSION_INC_GENERATOR}
201           ${spirv-tools_SOURCE_DIR} ${SPIRV_TOOLS_BUILD_VERSION_INC}
202   DEPENDS ${SPIRV_TOOLS_BUILD_VERSION_INC_GENERATOR}
203   COMMENT "Update build-version.inc in the SPIRV-Tools build directory (if necessary).")
204# Convenience target for standalone generation of the build-version.inc file.
205# This is not required for any dependence chain.
206add_custom_target(spirv-tools-build-version
207   DEPENDS ${SPIRV_TOOLS_BUILD_VERSION_INC})
208set_property(TARGET spirv-tools-build-version PROPERTY FOLDER "SPIRV-Tools build")
209
210list(APPEND PCH_DEPENDS ${ENUM_STRING_MAPPING_CPP_DEPENDS} ${OPCODE_CPP_DEPENDS} ${OPERAND_CPP_DEPENDS} ${EXTENSION_H_DEPENDS} ${EXTINST_CPP_DEPENDS} ${SPIRV_TOOLS_BUILD_VERSION_INC})
211set_source_files_properties(
212  ${CMAKE_CURRENT_SOURCE_DIR}/pch_source.cpp
213  PROPERTIES OBJECT_DEPENDS "${PCH_DEPENDS}")
214
215add_subdirectory(opt)
216add_subdirectory(reduce)
217add_subdirectory(fuzz)
218add_subdirectory(link)
219add_subdirectory(lint)
220add_subdirectory(diff)
221
222set(SPIRV_SOURCES
223  ${spirv-tools_SOURCE_DIR}/include/spirv-tools/libspirv.h
224
225  ${CMAKE_CURRENT_SOURCE_DIR}/util/bitutils.h
226  ${CMAKE_CURRENT_SOURCE_DIR}/util/bit_vector.h
227  ${CMAKE_CURRENT_SOURCE_DIR}/util/hash_combine.h
228  ${CMAKE_CURRENT_SOURCE_DIR}/util/hex_float.h
229  ${CMAKE_CURRENT_SOURCE_DIR}/util/make_unique.h
230  ${CMAKE_CURRENT_SOURCE_DIR}/util/parse_number.h
231  ${CMAKE_CURRENT_SOURCE_DIR}/util/small_vector.h
232  ${CMAKE_CURRENT_SOURCE_DIR}/util/string_utils.h
233  ${CMAKE_CURRENT_SOURCE_DIR}/util/timer.h
234  ${CMAKE_CURRENT_SOURCE_DIR}/assembly_grammar.h
235  ${CMAKE_CURRENT_SOURCE_DIR}/binary.h
236  ${CMAKE_CURRENT_SOURCE_DIR}/cfa.h
237  ${CMAKE_CURRENT_SOURCE_DIR}/common_debug_info.h
238  ${CMAKE_CURRENT_SOURCE_DIR}/diagnostic.h
239  ${CMAKE_CURRENT_SOURCE_DIR}/disassemble.h
240  ${CMAKE_CURRENT_SOURCE_DIR}/enum_set.h
241  ${CMAKE_CURRENT_SOURCE_DIR}/enum_string_mapping.h
242  ${CMAKE_CURRENT_SOURCE_DIR}/ext_inst.h
243  ${CMAKE_CURRENT_SOURCE_DIR}/extensions.h
244  ${CMAKE_CURRENT_SOURCE_DIR}/instruction.h
245  ${CMAKE_CURRENT_SOURCE_DIR}/latest_version_glsl_std_450_header.h
246  ${CMAKE_CURRENT_SOURCE_DIR}/latest_version_opencl_std_header.h
247  ${CMAKE_CURRENT_SOURCE_DIR}/latest_version_spirv_header.h
248  ${CMAKE_CURRENT_SOURCE_DIR}/macro.h
249  ${CMAKE_CURRENT_SOURCE_DIR}/name_mapper.h
250  ${CMAKE_CURRENT_SOURCE_DIR}/opcode.h
251  ${CMAKE_CURRENT_SOURCE_DIR}/operand.h
252  ${CMAKE_CURRENT_SOURCE_DIR}/parsed_operand.h
253  ${CMAKE_CURRENT_SOURCE_DIR}/print.h
254  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_constant.h
255  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_definition.h
256  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_endian.h
257  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_fuzzer_options.h
258  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_optimizer_options.h
259  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_reducer_options.h
260  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_target_env.h
261  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_validator_options.h
262  ${CMAKE_CURRENT_SOURCE_DIR}/table.h
263  ${CMAKE_CURRENT_SOURCE_DIR}/text.h
264  ${CMAKE_CURRENT_SOURCE_DIR}/text_handler.h
265  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate.h
266
267  ${CMAKE_CURRENT_SOURCE_DIR}/util/bit_vector.cpp
268  ${CMAKE_CURRENT_SOURCE_DIR}/util/parse_number.cpp
269  ${CMAKE_CURRENT_SOURCE_DIR}/util/string_utils.cpp
270  ${CMAKE_CURRENT_SOURCE_DIR}/assembly_grammar.cpp
271  ${CMAKE_CURRENT_SOURCE_DIR}/binary.cpp
272  ${CMAKE_CURRENT_SOURCE_DIR}/diagnostic.cpp
273  ${CMAKE_CURRENT_SOURCE_DIR}/disassemble.cpp
274  ${CMAKE_CURRENT_SOURCE_DIR}/enum_string_mapping.cpp
275  ${CMAKE_CURRENT_SOURCE_DIR}/ext_inst.cpp
276  ${CMAKE_CURRENT_SOURCE_DIR}/extensions.cpp
277  ${CMAKE_CURRENT_SOURCE_DIR}/libspirv.cpp
278  ${CMAKE_CURRENT_SOURCE_DIR}/name_mapper.cpp
279  ${CMAKE_CURRENT_SOURCE_DIR}/opcode.cpp
280  ${CMAKE_CURRENT_SOURCE_DIR}/operand.cpp
281  ${CMAKE_CURRENT_SOURCE_DIR}/parsed_operand.cpp
282  ${CMAKE_CURRENT_SOURCE_DIR}/print.cpp
283  ${CMAKE_CURRENT_SOURCE_DIR}/software_version.cpp
284  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_endian.cpp
285  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_fuzzer_options.cpp
286  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_optimizer_options.cpp
287  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_reducer_options.cpp
288  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_target_env.cpp
289  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_validator_options.cpp
290  ${CMAKE_CURRENT_SOURCE_DIR}/table.cpp
291  ${CMAKE_CURRENT_SOURCE_DIR}/text.cpp
292  ${CMAKE_CURRENT_SOURCE_DIR}/text_handler.cpp
293  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate.cpp
294  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_adjacency.cpp
295  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_annotation.cpp
296  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_arithmetics.cpp
297  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_atomics.cpp
298  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_barriers.cpp
299  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_bitwise.cpp
300  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_builtins.cpp
301  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_capability.cpp
302  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_cfg.cpp
303  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_composites.cpp
304  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_constants.cpp
305  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_conversion.cpp
306  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_debug.cpp
307  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_decorations.cpp
308  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_derivatives.cpp
309  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_extensions.cpp
310  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_execution_limitations.cpp
311  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_function.cpp
312  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_id.cpp
313  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_image.cpp
314  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_interfaces.cpp
315  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_instruction.cpp
316  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_layout.cpp
317  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_literals.cpp
318  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_logicals.cpp
319  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_memory.cpp
320  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_memory_semantics.cpp
321  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_mesh_shading.cpp
322  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_misc.cpp
323  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_mode_setting.cpp
324  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_non_uniform.cpp
325  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_primitives.cpp
326  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_ray_query.cpp
327  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_ray_tracing.cpp
328  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_ray_tracing_reorder.cpp
329  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_scopes.cpp
330  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_small_type_uses.cpp
331  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_type.cpp
332  ${CMAKE_CURRENT_SOURCE_DIR}/val/decoration.h
333  ${CMAKE_CURRENT_SOURCE_DIR}/val/basic_block.cpp
334  ${CMAKE_CURRENT_SOURCE_DIR}/val/construct.cpp
335  ${CMAKE_CURRENT_SOURCE_DIR}/val/function.cpp
336  ${CMAKE_CURRENT_SOURCE_DIR}/val/instruction.cpp
337  ${CMAKE_CURRENT_SOURCE_DIR}/val/validation_state.cpp)
338
339if (${SPIRV_TIMER_ENABLED})
340  set(SPIRV_SOURCES
341    ${SPIRV_SOURCES}
342    ${CMAKE_CURRENT_SOURCE_DIR}/util/timer.cpp)
343endif()
344
345# The software_version.cpp file includes build-version.inc.
346# Rebuild the software_version.cpp object file if it is older than
347# build-version.inc or whenever build-version.inc itself is out of
348# date.  In the latter case, rebuild build-version.inc first.
349# CMake is not smart enough to detect this dependency automatically.
350# Without this, the dependency detection system for #included files
351# does not kick in on a clean build for the following reason:  The
352# build will fail early because it doesn't know how to build the
353# missing source file build-version.inc. That occurs before the
354# preprocessor is run on software_version.cpp to detect the
355# #include dependency.
356set_source_files_properties(
357  ${CMAKE_CURRENT_SOURCE_DIR}/software_version.cpp
358  PROPERTIES OBJECT_DEPENDS "${SPIRV_TOOLS_BUILD_VERSION_INC}")
359
360spvtools_pch(SPIRV_SOURCES pch_source)
361
362# spirv_tools_default_target_options() sets the target options that are common
363# for all ${SPIRV_TOOLS} targets.
364function(spirv_tools_default_target_options target)
365  spvtools_default_compile_options(${target})
366  target_include_directories(${target}
367    PUBLIC
368      $<BUILD_INTERFACE:${spirv-tools_SOURCE_DIR}/include>
369      $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
370    PRIVATE ${spirv-tools_BINARY_DIR}
371    PRIVATE ${SPIRV_HEADER_INCLUDE_DIR}
372  )
373  set_property(TARGET ${target} PROPERTY FOLDER "SPIRV-Tools libraries")
374  spvtools_check_symbol_exports(${target})
375  add_dependencies(${target} spirv-tools-build-version core_tables enum_string_mapping extinst_tables)
376endfunction()
377
378# Always build ${SPIRV_TOOLS}-shared. This is expected distro packages, and
379# unlike the other SPIRV_TOOLS target, defaults to hidden symbol visibility.
380add_library(${SPIRV_TOOLS}-shared SHARED ${SPIRV_SOURCES})
381spirv_tools_default_target_options(${SPIRV_TOOLS}-shared)
382set_target_properties(${SPIRV_TOOLS}-shared PROPERTIES CXX_VISIBILITY_PRESET hidden)
383target_compile_definitions(${SPIRV_TOOLS}-shared
384  PRIVATE SPIRV_TOOLS_IMPLEMENTATION
385  PUBLIC SPIRV_TOOLS_SHAREDLIB
386)
387
388if(SPIRV_TOOLS_BUILD_STATIC)
389  add_library(${SPIRV_TOOLS}-static STATIC ${SPIRV_SOURCES})
390  spirv_tools_default_target_options(${SPIRV_TOOLS}-static)
391  # The static target does not have the '-static' suffix.
392  set_target_properties(${SPIRV_TOOLS}-static PROPERTIES OUTPUT_NAME "${SPIRV_TOOLS}")
393
394  # Create the "${SPIRV_TOOLS}" target as an alias to either "${SPIRV_TOOLS}-static"
395  # or "${SPIRV_TOOLS}-shared" depending on the value of BUILD_SHARED_LIBS.
396  if(BUILD_SHARED_LIBS)
397    add_library(${SPIRV_TOOLS} ALIAS ${SPIRV_TOOLS}-shared)
398  else()
399    add_library(${SPIRV_TOOLS} ALIAS ${SPIRV_TOOLS}-static)
400  endif()
401
402  set(SPIRV_TOOLS_TARGETS ${SPIRV_TOOLS}-static ${SPIRV_TOOLS}-shared)
403else()
404  add_library(${SPIRV_TOOLS} ${SPIRV_TOOLS_LIBRARY_TYPE} ${SPIRV_SOURCES})
405  spirv_tools_default_target_options(${SPIRV_TOOLS})
406  set(SPIRV_TOOLS_TARGETS ${SPIRV_TOOLS} ${SPIRV_TOOLS}-shared)
407endif()
408
409if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
410  find_library(LIBRT rt)
411  if(LIBRT)
412    foreach(target ${SPIRV_TOOLS_TARGETS})
413      target_link_libraries(${target} rt)
414    endforeach()
415  endif()
416endif()
417
418if (ANDROID)
419    foreach(target ${SPIRV_TOOLS_TARGETS})
420        target_link_libraries(${target} PRIVATE android log)
421    endforeach()
422endif()
423
424if(ENABLE_SPIRV_TOOLS_INSTALL)
425  install(TARGETS ${SPIRV_TOOLS_TARGETS} EXPORT ${SPIRV_TOOLS}Targets)
426  export(EXPORT ${SPIRV_TOOLS}Targets FILE ${SPIRV_TOOLS}Target.cmake)
427
428  spvtools_config_package_dir(${SPIRV_TOOLS} PACKAGE_DIR)
429  install(EXPORT ${SPIRV_TOOLS}Targets FILE ${SPIRV_TOOLS}Target.cmake DESTINATION ${PACKAGE_DIR})
430
431  # Special config file for root library compared to other libs.
432  file(WRITE ${CMAKE_BINARY_DIR}/${SPIRV_TOOLS}Config.cmake
433    "include(\${CMAKE_CURRENT_LIST_DIR}/${SPIRV_TOOLS}Target.cmake)\n"
434    "if(TARGET ${SPIRV_TOOLS})\n"
435    "    set(${SPIRV_TOOLS}_LIBRARIES ${SPIRV_TOOLS})\n"
436    "    get_target_property(${SPIRV_TOOLS}_INCLUDE_DIRS ${SPIRV_TOOLS} INTERFACE_INCLUDE_DIRECTORIES)\n"
437    "endif()\n")
438  install(FILES ${CMAKE_BINARY_DIR}/${SPIRV_TOOLS}Config.cmake DESTINATION ${PACKAGE_DIR})
439endif(ENABLE_SPIRV_TOOLS_INSTALL)
440
441if(MSVC AND (NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")))
442  # Enable parallel builds across four cores for this lib
443  add_definitions(/MP4)
444endif()
445