1 # Copyright (c) 2015-2016 The Khronos Group Inc.
3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and/or associated documentation files (the
5 # "Materials"), to deal in the Materials without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish,
7 # distribute, sublicense, and/or sell copies of the Materials, and to
8 # permit persons to whom the Materials are furnished to do so, subject to
9 # the following conditions:
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Materials.
14 # MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
15 # KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
16 # SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
17 # https://www.khronos.org/registry/
19 # THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 # MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
27 cmake_minimum_required(VERSION 2.8.12)
30 set(SPIRV_TOOLS "SPIRV-Tools")
32 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
34 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
35 add_definitions(-DSPIRV_LINUX)
36 elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
37 add_definitions(-DSPIRV_WINDOWS)
38 elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
39 add_definitions(-DSPIRV_MAC)
41 message(FATAL_ERROR "Your platform '${CMAKE_SYSTEM_NAME}' is not supported!")
44 if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
45 message(STATUS "No build type selected, default to Debug")
46 set(CMAKE_BUILD_TYPE "Debug")
49 option(SPIRV_WERROR "Enable error on warning" ON)
50 if((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang"))
51 set(COMPILER_IS_LIKE_GNU TRUE)
53 if(${COMPILER_IS_LIKE_GNU})
54 set(SPIRV_WARNINGS -Wall -Wextra -Wno-missing-field-initializers)
56 option(SPIRV_WARN_EVERYTHING "Enable -Weverything" ${SPIRV_WARN_EVERYTHING})
57 if(${SPIRV_WARN_EVERYTHING})
58 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
59 set(SPIRV_WARNINGS ${SPIRV_WARNINGS}
60 -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded)
61 elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
62 set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Wpedantic -pedantic-errors)
64 message(STATUS "Unknown compiler ${CMAKE_CXX_COMPILER_ID}, "
65 "so SPIRV_WARN_EVERYTHING has no effect")
70 set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Werror)
73 set(SPIRV_WARNINGS -D_CRT_SECURE_NO_WARNINGS /wd4800)
76 set(SPIRV_WARNINGS ${SPIRV_WARNINGS} /WX)
80 option(SPIRV_COLOR_TERMINAL "Enable color terminal output" ON)
81 if(${SPIRV_COLOR_TERMINAL})
82 add_definitions(-DSPIRV_COLOR_TERMINAL)
85 function(spvtools_default_compile_options TARGET)
86 target_compile_options(${TARGET} PRIVATE ${SPIRV_WARNINGS})
88 if (${COMPILER_IS_LIKE_GNU})
89 target_compile_options(${TARGET} PRIVATE
90 -std=c++11 -fno-exceptions -fno-rtti)
91 target_compile_options(${TARGET} PRIVATE
92 -Wall -Wextra -Wno-long-long -Wshadow -Wundef -Wconversion
94 # For good call stacks in profiles, keep the frame pointers.
95 if(NOT "${SPIRV_PERF}" STREQUAL "")
96 target_compile_options(${TARGET} PRIVATE -fno-omit-frame-pointer)
98 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
99 set(SPIRV_USE_SANITIZER "" CACHE STRING
100 "Use the clang sanitizer [address|memory|thread|...]")
101 if(NOT "${SPIRV_USE_SANITIZER}" STREQUAL "")
102 target_compile_options(${TARGET} PRIVATE
103 -fsanitize=${SPIRV_USE_SANITIZER})
106 target_compile_options(${TARGET} PRIVATE
107 -Wno-missing-field-initializers)
111 # For MinGW cross compile, statically link to the C++ runtime.
112 # But it still depends on MSVCRT.dll.
113 if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
114 if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
115 set_target_properties(${TARGET} PROPERTIES LINK_FLAGS
116 -static -static-libgcc -static-libstdc++)
121 if(NOT COMMAND find_host_package)
122 macro(find_host_package)
123 find_package(${ARGN})
126 if(NOT COMMAND find_host_program)
127 macro(find_host_program)
128 find_program(${ARGN})
132 find_host_package(PythonInterp)
134 add_custom_target(spirv-tools-build-version
136 ${CMAKE_CURRENT_SOURCE_DIR}/utils/update_build_version.py
137 ${spirv-tools_SOURCE_DIR}
138 COMMENT "Update build-version.inc in the Spirv-tools build directory (if necessary).")
140 add_custom_target(spirv-tools-build-tables
142 ${CMAKE_CURRENT_SOURCE_DIR}/utils/generate_grammar_tables.py
143 --spirv-core-grammar=${spirv-tools_SOURCE_DIR}/source/spirv.core.grammar.json
144 --extinst-glsl-grammar=${spirv-tools_SOURCE_DIR}/source/extinst.glsl.std.450.grammar.json
145 --extinst-opencl-grammar=${spirv-tools_SOURCE_DIR}/source/extinst.opencl.std.grammar.json
146 --core-insts-output=${spirv-tools_BINARY_DIR}/core.insts.inc
147 --glsl-insts-output=${spirv-tools_BINARY_DIR}/glsl.std.450.insts.inc
148 --opencl-insts-output=${spirv-tools_BINARY_DIR}/opencl.std.insts.inc
149 --operand-kinds-output=${spirv-tools_BINARY_DIR}/operand.kinds.inc
150 COMMENT "Generate info tables for SPIR-V instructions and operands.")
152 # Defaults to OFF if the user didn't set it.
153 option(SPIRV_SKIP_EXECUTABLES
154 "Skip building the executable and tests along with the library"
155 ${SPIRV_SKIP_EXECUTABLES})
157 add_subdirectory(external)
159 add_subdirectory(source)
160 add_subdirectory(tools)
162 add_subdirectory(test)
164 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/libspirv.h
165 DESTINATION include/spirv-tools/)