forked from KhronosGroup/SPIRV-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
250 lines (228 loc) · 10.7 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# Copyright (c) 2015-2016 The Khronos Group Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and/or associated documentation files (the
# "Materials"), to deal in the Materials without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Materials, and to
# permit persons to whom the Materials are furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Materials.
#
# MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
# KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
# SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
# https://www.khronos.org/registry/
#
# THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
cmake_minimum_required(VERSION 2.8)
project(spirv-tools)
set(SPIRV_TOOLS "SPIRV-Tools")
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
add_definitions(-DSPIRV_LINUX)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
add_definitions(-DSPIRV_WINDOWS)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
add_definitions(-DSPIRV_MAC)
else()
message(FATAL_ERROR "Your platform '${CMAKE_SYSTEM_NAME}' is not supported!")
endif()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
message(STATUS "No build type selected, default to Debug")
set(CMAKE_BUILD_TYPE "Debug")
endif()
option(SPIRV_WERROR "Enable error on warning" ON)
if(UNIX)
set(SPIRV_WARNINGS -Wall -Wextra -Wno-missing-field-initializers)
option(SPIRV_WARN_EVERYTHING "Enable -Weverything" ${SPIRV_WARN_EVERYTHING})
if(${SPIRV_WARN_EVERYTHING})
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(SPIRV_WARNINGS ${SPIRV_WARNINGS}
-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Wpedantic -pedantic-errors)
else()
message(STATUS "Unknown compiler ${CMAKE_CXX_COMPILER_ID}, "
"so SPIRV_WARN_EVERYTHING has no effect")
endif()
endif()
if(${SPIRV_WERROR})
set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Werror)
endif()
elseif(WIN32)
set(SPIRV_WARNINGS -D_CRT_SECURE_NO_WARNINGS /wd4800)
if(${SPIRV_WERROR})
set(SPIRV_WARNINGS ${SPIRV_WARNINGS} /WX)
endif()
endif()
option(SPIRV_COLOR_TERMINAL "Enable color terminal output" ON)
if(${SPIRV_COLOR_TERMINAL})
add_definitions(-DSPIRV_COLOR_TERMINAL)
endif()
function(default_compile_options TARGET)
target_compile_options(${TARGET} PRIVATE ${SPIRV_WARNINGS})
if (UNIX)
target_compile_options(${TARGET} PRIVATE
-std=c++11 -fno-exceptions -fno-rtti)
# For good call stacks in profiles, keep the frame pointers.
if(NOT "${SPIRV_PERF}" STREQUAL "")
target_compile_options(${TARGET} PRIVATE -fno-omit-frame-pointer)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(SPIRV_USE_SANITIZER "" CACHE STRING
"Use the clang sanitizer [address|memory|thread|...]")
if(NOT "${SPIRV_USE_SANITIZER}" STREQUAL "")
target_compile_options(${TARGET} PRIVATE
-fsanitize=${SPIRV_USE_SANITIZER})
endif()
endif()
endif()
endfunction()
set(SPIRV_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/include/libspirv/libspirv.h
${CMAKE_CURRENT_SOURCE_DIR}/include/util/bitutils.h
${CMAKE_CURRENT_SOURCE_DIR}/include/util/hex_float.h
${CMAKE_CURRENT_SOURCE_DIR}/source/assembly_grammar.h
${CMAKE_CURRENT_SOURCE_DIR}/source/binary.h
${CMAKE_CURRENT_SOURCE_DIR}/source/diagnostic.h
${CMAKE_CURRENT_SOURCE_DIR}/source/ext_inst.h
${CMAKE_CURRENT_SOURCE_DIR}/source/instruction.h
${CMAKE_CURRENT_SOURCE_DIR}/source/opcode.h
${CMAKE_CURRENT_SOURCE_DIR}/source/operand.h
${CMAKE_CURRENT_SOURCE_DIR}/source/print.h
${CMAKE_CURRENT_SOURCE_DIR}/source/spirv_constant.h
${CMAKE_CURRENT_SOURCE_DIR}/source/spirv_definition.h
${CMAKE_CURRENT_SOURCE_DIR}/source/spirv_endian.h
${CMAKE_CURRENT_SOURCE_DIR}/source/table.h
${CMAKE_CURRENT_SOURCE_DIR}/source/text.h
${CMAKE_CURRENT_SOURCE_DIR}/source/text_handler.h
${CMAKE_CURRENT_SOURCE_DIR}/source/validate.h
${CMAKE_CURRENT_SOURCE_DIR}/source/validate_types.h
${CMAKE_CURRENT_SOURCE_DIR}/source/assembly_grammar.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/binary.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/disassemble.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/diagnostic.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/ext_inst.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/opcode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/operand.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/print.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/spirv_endian.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/table.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/text.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/text_handler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/validate.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/validate_types.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source/validate_id.cpp)
add_library(${SPIRV_TOOLS} ${SPIRV_SOURCES})
default_compile_options(${SPIRV_TOOLS})
target_include_directories(${SPIRV_TOOLS} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/external/include)
# Defaults to OFF if the user didn't set it.
option(SPIRV_SKIP_EXECUTABLES
"Skip building the executable and tests along with the library"
${SPIRV_SKIP_EXECUTABLES})
set(SPIRV_INSTALL_TARGETS ${SPIRV_TOOLS})
if (NOT ${SPIRV_SKIP_EXECUTABLES})
list(APPEND SPIRV_INSTALL_TARGETS spirv-as spirv-dis spirv-val)
add_executable(spirv-as ${CMAKE_CURRENT_SOURCE_DIR}/tools/as/as.cpp)
default_compile_options(spirv-as)
target_link_libraries(spirv-as PRIVATE ${SPIRV_TOOLS})
add_executable(spirv-dis ${CMAKE_CURRENT_SOURCE_DIR}/tools/dis/dis.cpp)
default_compile_options(spirv-dis)
target_link_libraries(spirv-dis PRIVATE ${SPIRV_TOOLS})
add_executable(spirv-val ${CMAKE_CURRENT_SOURCE_DIR}/tools/val/val.cpp)
default_compile_options(spirv-val)
target_link_libraries(spirv-val PRIVATE ${SPIRV_TOOLS})
set(GMOCK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest/googlemock)
if(EXISTS ${GMOCK_DIR})
if(WIN32)
option(gtest_force_shared_crt
"Use shared (DLL) run-time lib even when Google Test is built as static lib."
ON)
endif()
add_subdirectory(${GMOCK_DIR})
endif()
if (TARGET gmock)
message(STATUS "Found Google Mock, building tests.")
set(TEST_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/test/TestFixture.h
${CMAKE_CURRENT_SOURCE_DIR}/test/UnitSPIRV.h
${CMAKE_CURRENT_SOURCE_DIR}/test/AssemblyContext.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/AssemblyFormat.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/BinaryDestroy.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/BinaryEndianness.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/BinaryHeaderGet.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/BinaryParse.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/BinaryToText.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/BinaryToText.Literal.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/Comment.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/DiagnosticPrint.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/DiagnosticStream.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/ExtInstGLSLstd450.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/ExtInst.OpenCL.std.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/FixWord.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/GeneratorMagicNumber.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/HexFloat.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/ImmediateInt.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/LibspirvMacros.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/NamedId.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/OpcodeMake.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/OpcodeRequiresCapabilities.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/OpcodeSplit.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/OpcodeTableGet.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/OperandCapabilities.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/Operand.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/OperandPattern.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextAdvance.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextDestroy.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextLiteral.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextStartsNewInst.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Annotation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Barrier.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Constant.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.ControlFlow.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Debug.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.DeviceSideEnqueue.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Extension.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Function.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Group.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Image.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Literal.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Memory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Miscellaneous.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.ModeSetting.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.TypeDeclaration.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/TextWordGet.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/UnitSPIRV.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/ValidateFixtures.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/Validate.Layout.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/Validate.SSA.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/ValidateID.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp)
add_executable(UnitSPIRV ${TEST_SOURCES})
default_compile_options(UnitSPIRV)
target_include_directories(UnitSPIRV PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${gmock_SOURCE_DIR}/include ${gtest_SOURCE_DIR}/include)
target_link_libraries(UnitSPIRV PRIVATE ${SPIRV_TOOLS} gmock)
else()
message(STATUS "Did not find googletest, tests will not be built."
"To enable tests place googletest in '<spirv-dir>/external/googletest'.")
endif()
endif()
install(TARGETS ${SPIRV_INSTALL_TARGETS}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/libspirv/libspirv.h
DESTINATION include/libspirv/)