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# For now, assume the DebugInfo grammar file is in the current directory.
21# It might migrate to SPIRV-Headers.
22set(DEBUGINFO_GRAMMAR_JSON_FILE "${CMAKE_CURRENT_SOURCE_DIR}/extinst.debuginfo.grammar.json")
23
24# macro() definitions are used in the following because we need to append .inc
25# file paths into some global lists (*_CPP_DEPENDS). And those global lists are
26# later used by set_source_files_properties() calls.
27# function() definitions are not suitable because they create new scopes.
28macro(spvtools_core_tables CONFIG_VERSION)
29  set(GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/spirv.core.grammar.json")
30  set(GRAMMAR_INSTS_INC_FILE "${spirv-tools_BINARY_DIR}/core.insts-${CONFIG_VERSION}.inc")
31  set(GRAMMAR_KINDS_INC_FILE "${spirv-tools_BINARY_DIR}/operand.kinds-${CONFIG_VERSION}.inc")
32  add_custom_command(OUTPUT ${GRAMMAR_INSTS_INC_FILE} ${GRAMMAR_KINDS_INC_FILE}
33    COMMAND ${PYTHON_EXECUTABLE} ${GRAMMAR_PROCESSING_SCRIPT}
34      --spirv-core-grammar=${GRAMMAR_JSON_FILE}
35      --extinst-debuginfo-grammar=${DEBUGINFO_GRAMMAR_JSON_FILE}
36      --core-insts-output=${GRAMMAR_INSTS_INC_FILE}
37      --operand-kinds-output=${GRAMMAR_KINDS_INC_FILE}
38    DEPENDS ${GRAMMAR_PROCESSING_SCRIPT} ${GRAMMAR_JSON_FILE} ${DEBUGINFO_GRAMMAR_JSON_FILE}
39    COMMENT "Generate info tables for SPIR-V v${CONFIG_VERSION} core instructions and operands.")
40  list(APPEND OPCODE_CPP_DEPENDS ${GRAMMAR_INSTS_INC_FILE})
41  list(APPEND OPERAND_CPP_DEPENDS ${GRAMMAR_KINDS_INC_FILE})
42endmacro(spvtools_core_tables)
43
44macro(spvtools_enum_string_mapping CONFIG_VERSION)
45  set(GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/spirv.core.grammar.json")
46  set(GRAMMAR_EXTENSION_ENUM_INC_FILE "${spirv-tools_BINARY_DIR}/extension_enum.inc")
47  set(GRAMMAR_ENUM_STRING_MAPPING_INC_FILE "${spirv-tools_BINARY_DIR}/enum_string_mapping.inc")
48  add_custom_command(OUTPUT ${GRAMMAR_EXTENSION_ENUM_INC_FILE}
49     ${GRAMMAR_ENUM_STRING_MAPPING_INC_FILE}
50    COMMAND ${PYTHON_EXECUTABLE} ${GRAMMAR_PROCESSING_SCRIPT}
51      --spirv-core-grammar=${GRAMMAR_JSON_FILE}
52      --extinst-debuginfo-grammar=${DEBUGINFO_GRAMMAR_JSON_FILE}
53      --extension-enum-output=${GRAMMAR_EXTENSION_ENUM_INC_FILE}
54      --enum-string-mapping-output=${GRAMMAR_ENUM_STRING_MAPPING_INC_FILE}
55    DEPENDS ${GRAMMAR_PROCESSING_SCRIPT} ${GRAMMAR_JSON_FILE} ${DEBUGINFO_GRAMMAR_JSON_FILE}
56    COMMENT "Generate enum-string mapping for SPIR-V v${CONFIG_VERSION}.")
57  list(APPEND EXTENSION_H_DEPENDS ${GRAMMAR_EXTENSION_ENUM_INC_FILE})
58  list(APPEND ENUM_STRING_MAPPING_CPP_DEPENDS ${GRAMMAR_ENUM_STRING_MAPPING_INC_FILE})
59endmacro(spvtools_enum_string_mapping)
60
61macro(spvtools_vimsyntax CONFIG_VERSION CLVERSION)
62  set(GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/spirv.core.grammar.json")
63  set(GLSL_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/extinst.glsl.std.450.grammar.json")
64  set(OPENCL_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/extinst.opencl.std.100.grammar.json")
65  set(VIMSYNTAX_FILE "${spirv-tools_BINARY_DIR}/spvasm.vim")
66  add_custom_command(OUTPUT ${VIMSYNTAX_FILE}
67      COMMAND ${PYTHON_EXECUTABLE} ${VIMSYNTAX_PROCESSING_SCRIPT}
68      --spirv-core-grammar=${GRAMMAR_JSON_FILE}
69      --extinst-debuginfo-grammar=${DEBUGINFO_GRAMMAR_JSON_FILE}
70      --extinst-glsl-grammar=${GLSL_GRAMMAR_JSON_FILE}
71      --extinst-opencl-grammar=${OPENCL_GRAMMAR_JSON_FILE}
72      >${VIMSYNTAX_FILE}
73    DEPENDS ${VIMSYNTAX_PROCESSING_SCRIPT} ${GRAMMAR_JSON_FILE}
74            ${GLSL_GRAMMAR_JSON_FILE} ${OPENCL_GRAMMAR_JSON_FILE} ${DEBUGINFO_GRAMMAR_JSON_FILE}
75    COMMENT "Generate spvasm.vim: Vim syntax file for SPIR-V assembly.")
76endmacro(spvtools_vimsyntax)
77
78macro(spvtools_glsl_tables CONFIG_VERSION)
79  set(CORE_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/spirv.core.grammar.json")
80  set(GLSL_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/extinst.glsl.std.450.grammar.json")
81  set(GRAMMAR_INC_FILE "${spirv-tools_BINARY_DIR}/glsl.std.450.insts.inc")
82  add_custom_command(OUTPUT ${GRAMMAR_INC_FILE}
83    COMMAND ${PYTHON_EXECUTABLE} ${GRAMMAR_PROCESSING_SCRIPT}
84      --extinst-glsl-grammar=${GLSL_GRAMMAR_JSON_FILE}
85      --glsl-insts-output=${GRAMMAR_INC_FILE}
86    DEPENDS ${GRAMMAR_PROCESSING_SCRIPT} ${CORE_GRAMMAR_JSON_FILE} ${GLSL_GRAMMAR_JSON_FILE}
87    COMMENT "Generate info tables for GLSL extended instructions and operands v${CONFIG_VERSION}.")
88  list(APPEND EXTINST_CPP_DEPENDS ${GRAMMAR_INC_FILE})
89endmacro(spvtools_glsl_tables)
90
91macro(spvtools_opencl_tables CONFIG_VERSION)
92  set(CORE_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/spirv.core.grammar.json")
93  set(OPENCL_GRAMMAR_JSON_FILE "${SPIRV_HEADER_INCLUDE_DIR}/spirv/${CONFIG_VERSION}/extinst.opencl.std.100.grammar.json")
94  set(GRAMMAR_INC_FILE "${spirv-tools_BINARY_DIR}/opencl.std.insts.inc")
95  add_custom_command(OUTPUT ${GRAMMAR_INC_FILE}
96    COMMAND ${PYTHON_EXECUTABLE} ${GRAMMAR_PROCESSING_SCRIPT}
97      --extinst-opencl-grammar=${OPENCL_GRAMMAR_JSON_FILE}
98      --opencl-insts-output=${GRAMMAR_INC_FILE}
99    DEPENDS ${GRAMMAR_PROCESSING_SCRIPT} ${CORE_GRAMMAR_JSON_FILE} ${OPENCL_GRAMMAR_JSON_FILE}
100    COMMENT "Generate info tables for OpenCL extended instructions and operands v${CONFIG_VERSION}.")
101  list(APPEND EXTINST_CPP_DEPENDS ${GRAMMAR_INC_FILE})
102endmacro(spvtools_opencl_tables)
103
104macro(spvtools_vendor_tables VENDOR_TABLE)
105  set(INSTS_FILE "${spirv-tools_BINARY_DIR}/${VENDOR_TABLE}.insts.inc")
106  set(GRAMMAR_FILE "${spirv-tools_SOURCE_DIR}/source/extinst.${VENDOR_TABLE}.grammar.json")
107  add_custom_command(OUTPUT ${INSTS_FILE}
108    COMMAND ${PYTHON_EXECUTABLE} ${GRAMMAR_PROCESSING_SCRIPT}
109      --extinst-vendor-grammar=${GRAMMAR_FILE}
110      --vendor-insts-output=${INSTS_FILE}
111    DEPENDS ${GRAMMAR_PROCESSING_SCRIPT} ${GRAMMAR_FILE}
112    COMMENT "Generate extended instruction tables for ${VENDOR_TABLE}.")
113  list(APPEND EXTINST_CPP_DEPENDS ${INSTS_FILE})
114  add_custom_target(spirv-tools-${VENDOR_TABLE} DEPENDS ${INSTS_FILE})
115  set_property(TARGET spirv-tools-${VENDOR_TABLE} PROPERTY FOLDER "SPIRV-Tools build")
116endmacro(spvtools_vendor_tables)
117
118macro(spvtools_extinst_lang_headers NAME GRAMMAR_FILE)
119  set(OUTBASE ${spirv-tools_BINARY_DIR}/${NAME})
120  set(OUT_H ${OUTBASE}.h)
121  add_custom_command(OUTPUT ${OUT_H}
122    COMMAND ${PYTHON_EXECUTABLE} ${LANG_HEADER_PROCESSING_SCRIPT}
123      --extinst-name=${NAME}
124      --extinst-grammar=${GRAMMAR_FILE}
125      --extinst-output-base=${OUTBASE}
126    DEPENDS ${LANG_HEADER_PROCESSING_SCRIPT} ${GRAMMAR_FILE}
127    COMMENT "Generate language specific header for ${NAME}.")
128  list(APPEND EXTINST_CPP_DEPENDS ${OUT_H})
129  add_custom_target(spirv-tools-header-${NAME} DEPENDS ${OUT_H})
130  set_property(TARGET spirv-tools-header-${NAME} PROPERTY FOLDER "SPIRV-Tools build")
131endmacro(spvtools_extinst_lang_headers)
132
133spvtools_core_tables("unified1")
134spvtools_enum_string_mapping("unified1")
135spvtools_opencl_tables("unified1")
136spvtools_glsl_tables("unified1")
137spvtools_vendor_tables("spv-amd-shader-explicit-vertex-parameter")
138spvtools_vendor_tables("spv-amd-shader-trinary-minmax")
139spvtools_vendor_tables("spv-amd-gcn-shader")
140spvtools_vendor_tables("spv-amd-shader-ballot")
141spvtools_vendor_tables("debuginfo")
142spvtools_extinst_lang_headers("DebugInfo" ${DEBUGINFO_GRAMMAR_JSON_FILE})
143
144spvtools_vimsyntax("unified1" "1.0")
145add_custom_target(spirv-tools-vimsyntax DEPENDS ${VIMSYNTAX_FILE})
146set_property(TARGET spirv-tools-vimsyntax PROPERTY FOLDER "SPIRV-Tools utilities")
147
148# Extract the list of known generators from the SPIR-V XML registry file.
149set(GENERATOR_INC_FILE ${spirv-tools_BINARY_DIR}/generators.inc)
150set(SPIRV_XML_REGISTRY_FILE ${SPIRV_HEADER_INCLUDE_DIR}/spirv/spir-v.xml)
151add_custom_command(OUTPUT ${GENERATOR_INC_FILE}
152  COMMAND ${PYTHON_EXECUTABLE} ${XML_REGISTRY_PROCESSING_SCRIPT}
153    --xml=${SPIRV_XML_REGISTRY_FILE}
154    --generator-output=${GENERATOR_INC_FILE}
155  DEPENDS ${XML_REGISTRY_PROCESSING_SCRIPT} ${SPIRV_XML_REGISTRY_FILE}
156  COMMENT "Generate tables based on the SPIR-V XML registry.")
157list(APPEND OPCODE_CPP_DEPENDS ${GENERATOR_INC_FILE})
158
159# The following .cpp files include the above generated .inc files.
160# Add those .inc files as their dependencies.
161#
162# Why using such an awkward way?
163# * If we use add_custom_target() to define a target to generate all .inc files
164#   and let ${SPIRV_TOOLS} depend on it, then we need to run ninja twice every
165#   time the grammar is updated: the first time is for generating those .inc
166#   files, and the second time is for rebuilding .cpp files, when ninja finds
167#   out that .inc files are updated.
168# * If we use add_custom_command() with PRE_BUILD, then the grammar processing
169#   script will always run no matter whether the grammar is updated.
170# * add_dependencies() is used to add *target* dependencies to a target.
171# * The following solution only generates .inc files when the script or the
172#   grammar files is updated, and in a single ninja run.
173set_source_files_properties(
174  ${CMAKE_CURRENT_SOURCE_DIR}/opcode.cpp
175  PROPERTIES OBJECT_DEPENDS "${OPCODE_CPP_DEPENDS}")
176set_source_files_properties(
177  ${CMAKE_CURRENT_SOURCE_DIR}/operand.cpp
178  PROPERTIES OBJECT_DEPENDS "${OPERAND_CPP_DEPENDS}")
179set_source_files_properties(
180  ${CMAKE_CURRENT_SOURCE_DIR}/ext_inst.cpp
181  PROPERTIES OBJECT_DEPENDS "${EXTINST_CPP_DEPENDS}")
182set_source_files_properties(
183  ${CMAKE_CURRENT_SOURCE_DIR}/enum_string_mapping.cpp
184  PROPERTIES OBJECT_DEPENDS "${ENUM_STRING_MAPPING_CPP_DEPENDS}")
185
186set_source_files_properties(
187  ${CMAKE_CURRENT_SOURCE_DIR}/extensions.h
188  PROPERTIES HEADER_FILE_ONLY TRUE)
189set_source_files_properties(
190  ${CMAKE_CURRENT_SOURCE_DIR}/extensions.h
191  PROPERTIES OBJECT_DEPENDS "${EXTENSION_H_DEPENDS}")
192
193set(SPIRV_TOOLS_BUILD_VERSION_INC
194  ${spirv-tools_BINARY_DIR}/build-version.inc)
195set(SPIRV_TOOLS_BUILD_VERSION_INC_GENERATOR
196  ${spirv-tools_SOURCE_DIR}/utils/update_build_version.py)
197set(SPIRV_TOOLS_CHANGES_FILE
198  ${spirv-tools_SOURCE_DIR}/CHANGES)
199add_custom_command(OUTPUT ${SPIRV_TOOLS_BUILD_VERSION_INC}
200   COMMAND ${PYTHON_EXECUTABLE}
201           ${SPIRV_TOOLS_BUILD_VERSION_INC_GENERATOR}
202           ${spirv-tools_SOURCE_DIR} ${SPIRV_TOOLS_BUILD_VERSION_INC}
203   DEPENDS ${SPIRV_TOOLS_BUILD_VERSION_INC_GENERATOR}
204           ${SPIRV_TOOLS_CHANGES_FILE}
205   COMMENT "Update build-version.inc in the SPIRV-Tools build directory (if necessary).")
206# Convenience target for standalone generation of the build-version.inc file.
207# This is not required for any dependence chain.
208add_custom_target(spirv-tools-build-version
209   DEPENDS ${SPIRV_TOOLS_BUILD_VERSION_INC})
210set_property(TARGET spirv-tools-build-version PROPERTY FOLDER "SPIRV-Tools build")
211
212list(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})
213set_source_files_properties(
214  ${CMAKE_CURRENT_SOURCE_DIR}/pch_source.cpp
215  PROPERTIES OBJECT_DEPENDS "${PCH_DEPENDS}")
216
217add_subdirectory(comp)
218add_subdirectory(opt)
219add_subdirectory(reduce)
220add_subdirectory(link)
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/hex_float.h
228  ${CMAKE_CURRENT_SOURCE_DIR}/util/make_unique.h
229  ${CMAKE_CURRENT_SOURCE_DIR}/util/parse_number.h
230  ${CMAKE_CURRENT_SOURCE_DIR}/util/small_vector.h
231  ${CMAKE_CURRENT_SOURCE_DIR}/util/string_utils.h
232  ${CMAKE_CURRENT_SOURCE_DIR}/util/timer.h
233  ${CMAKE_CURRENT_SOURCE_DIR}/assembly_grammar.h
234  ${CMAKE_CURRENT_SOURCE_DIR}/binary.h
235  ${CMAKE_CURRENT_SOURCE_DIR}/cfa.h
236  ${CMAKE_CURRENT_SOURCE_DIR}/diagnostic.h
237  ${CMAKE_CURRENT_SOURCE_DIR}/disassemble.h
238  ${CMAKE_CURRENT_SOURCE_DIR}/enum_set.h
239  ${CMAKE_CURRENT_SOURCE_DIR}/enum_string_mapping.h
240  ${CMAKE_CURRENT_SOURCE_DIR}/ext_inst.h
241  ${CMAKE_CURRENT_SOURCE_DIR}/extensions.h
242  ${CMAKE_CURRENT_SOURCE_DIR}/id_descriptor.h
243  ${CMAKE_CURRENT_SOURCE_DIR}/instruction.h
244  ${CMAKE_CURRENT_SOURCE_DIR}/latest_version_glsl_std_450_header.h
245  ${CMAKE_CURRENT_SOURCE_DIR}/latest_version_opencl_std_header.h
246  ${CMAKE_CURRENT_SOURCE_DIR}/latest_version_spirv_header.h
247  ${CMAKE_CURRENT_SOURCE_DIR}/macro.h
248  ${CMAKE_CURRENT_SOURCE_DIR}/name_mapper.h
249  ${CMAKE_CURRENT_SOURCE_DIR}/opcode.h
250  ${CMAKE_CURRENT_SOURCE_DIR}/operand.h
251  ${CMAKE_CURRENT_SOURCE_DIR}/parsed_operand.h
252  ${CMAKE_CURRENT_SOURCE_DIR}/print.h
253  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_constant.h
254  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_definition.h
255  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_endian.h
256  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_optimizer_options.h
257  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_reducer_options.h
258  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_target_env.h
259  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_validator_options.h
260  ${CMAKE_CURRENT_SOURCE_DIR}/table.h
261  ${CMAKE_CURRENT_SOURCE_DIR}/text.h
262  ${CMAKE_CURRENT_SOURCE_DIR}/text_handler.h
263  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate.h
264
265  ${CMAKE_CURRENT_SOURCE_DIR}/util/bit_vector.cpp
266  ${CMAKE_CURRENT_SOURCE_DIR}/util/parse_number.cpp
267  ${CMAKE_CURRENT_SOURCE_DIR}/util/string_utils.cpp
268  ${CMAKE_CURRENT_SOURCE_DIR}/assembly_grammar.cpp
269  ${CMAKE_CURRENT_SOURCE_DIR}/binary.cpp
270  ${CMAKE_CURRENT_SOURCE_DIR}/diagnostic.cpp
271  ${CMAKE_CURRENT_SOURCE_DIR}/disassemble.cpp
272  ${CMAKE_CURRENT_SOURCE_DIR}/enum_string_mapping.cpp
273  ${CMAKE_CURRENT_SOURCE_DIR}/ext_inst.cpp
274  ${CMAKE_CURRENT_SOURCE_DIR}/extensions.cpp
275  ${CMAKE_CURRENT_SOURCE_DIR}/id_descriptor.cpp
276  ${CMAKE_CURRENT_SOURCE_DIR}/libspirv.cpp
277  ${CMAKE_CURRENT_SOURCE_DIR}/name_mapper.cpp
278  ${CMAKE_CURRENT_SOURCE_DIR}/opcode.cpp
279  ${CMAKE_CURRENT_SOURCE_DIR}/operand.cpp
280  ${CMAKE_CURRENT_SOURCE_DIR}/parsed_operand.cpp
281  ${CMAKE_CURRENT_SOURCE_DIR}/print.cpp
282  ${CMAKE_CURRENT_SOURCE_DIR}/software_version.cpp
283  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_endian.cpp
284  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_optimizer_options.cpp
285  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_reducer_options.cpp
286  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_target_env.cpp
287  ${CMAKE_CURRENT_SOURCE_DIR}/spirv_validator_options.cpp
288  ${CMAKE_CURRENT_SOURCE_DIR}/table.cpp
289  ${CMAKE_CURRENT_SOURCE_DIR}/text.cpp
290  ${CMAKE_CURRENT_SOURCE_DIR}/text_handler.cpp
291  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate.cpp
292  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_adjacency.cpp
293  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_annotation.cpp
294  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_arithmetics.cpp
295  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_atomics.cpp
296  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_barriers.cpp
297  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_bitwise.cpp
298  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_builtins.cpp
299  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_capability.cpp
300  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_cfg.cpp
301  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_composites.cpp
302  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_constants.cpp
303  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_conversion.cpp
304  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_datarules.cpp
305  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_debug.cpp
306  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_decorations.cpp
307  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_derivatives.cpp
308  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_extensions.cpp
309  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_execution_limitations.cpp
310  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_function.cpp
311  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_id.cpp
312  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_image.cpp
313  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_interfaces.cpp
314  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_instruction.cpp
315  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_layout.cpp
316  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_literals.cpp
317  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_logicals.cpp
318  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_memory.cpp
319  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_memory_semantics.cpp
320  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_mode_setting.cpp
321  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_non_uniform.cpp
322  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_primitives.cpp
323  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_scopes.cpp
324  ${CMAKE_CURRENT_SOURCE_DIR}/val/validate_type.cpp
325  ${CMAKE_CURRENT_SOURCE_DIR}/val/decoration.h
326  ${CMAKE_CURRENT_SOURCE_DIR}/val/basic_block.cpp
327  ${CMAKE_CURRENT_SOURCE_DIR}/val/construct.cpp
328  ${CMAKE_CURRENT_SOURCE_DIR}/val/function.cpp
329  ${CMAKE_CURRENT_SOURCE_DIR}/val/instruction.cpp
330  ${CMAKE_CURRENT_SOURCE_DIR}/val/validation_state.cpp)
331
332if (${SPIRV_TIMER_ENABLED})
333  set(SPIRV_SOURCES
334    ${SPIRV_SOURCES}
335    ${CMAKE_CURRENT_SOURCE_DIR}/util/timer.cpp)
336endif()
337
338# The software_version.cpp file includes build-version.inc.
339# Rebuild the software_version.cpp object file if it is older than
340# build-version.inc or whenever build-version.inc itself is out of
341# date.  In the latter case, rebuild build-version.inc first.
342# CMake is not smart enough to detect this dependency automatically.
343# Without this, the dependency detection system for #included files
344# does not kick in on a clean build for the following reason:  The
345# build will fail early because it doesn't know how to build the
346# missing source file build-version.inc. That occurs before the
347# preprocessor is run on software_version.cpp to detect the
348# #include dependency.
349set_source_files_properties(
350  ${CMAKE_CURRENT_SOURCE_DIR}/software_version.cpp
351  PROPERTIES OBJECT_DEPENDS "${SPIRV_TOOLS_BUILD_VERSION_INC}")
352
353spvtools_pch(SPIRV_SOURCES pch_source)
354
355add_library(${SPIRV_TOOLS} ${SPIRV_SOURCES})
356spvtools_default_compile_options(${SPIRV_TOOLS})
357target_include_directories(${SPIRV_TOOLS}
358  PUBLIC ${spirv-tools_SOURCE_DIR}/include
359  PRIVATE ${spirv-tools_BINARY_DIR}
360  PRIVATE ${SPIRV_HEADER_INCLUDE_DIR}
361  )
362set_property(TARGET ${SPIRV_TOOLS} PROPERTY FOLDER "SPIRV-Tools libraries")
363spvtools_check_symbol_exports(${SPIRV_TOOLS})
364
365add_library(${SPIRV_TOOLS}-shared SHARED ${SPIRV_SOURCES})
366spvtools_default_compile_options(${SPIRV_TOOLS}-shared)
367target_include_directories(${SPIRV_TOOLS}-shared
368  PUBLIC ${spirv-tools_SOURCE_DIR}/include
369  PRIVATE ${spirv-tools_BINARY_DIR}
370  PRIVATE ${SPIRV_HEADER_INCLUDE_DIR}
371  )
372set_target_properties(${SPIRV_TOOLS}-shared PROPERTIES CXX_VISIBILITY_PRESET hidden)
373set_property(TARGET ${SPIRV_TOOLS}-shared PROPERTY FOLDER "SPIRV-Tools libraries")
374spvtools_check_symbol_exports(${SPIRV_TOOLS}-shared)
375target_compile_definitions(${SPIRV_TOOLS}-shared
376  PRIVATE SPIRV_TOOLS_IMPLEMENTATION
377  PUBLIC SPIRV_TOOLS_SHAREDLIB
378)
379
380if(ENABLE_SPIRV_TOOLS_INSTALL)
381  install(TARGETS ${SPIRV_TOOLS} ${SPIRV_TOOLS}-shared
382    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
383    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
384    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
385endif(ENABLE_SPIRV_TOOLS_INSTALL)
386
387if(MSVC)
388  # Enable parallel builds across four cores for this lib
389  add_definitions(/MP4)
390endif()
391