Mark SPIR-V grammar files as 1.0.
[platform/upstream/SPIRV-Tools.git] / CMakeLists.txt
1 # Copyright (c) 2015-2016 The Khronos Group Inc.
2 #
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:
10 #
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Materials.
13 #
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/
18 #
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.
26
27 cmake_minimum_required(VERSION 2.8.12)
28 project(spirv-tools)
29 enable_testing()
30 set(SPIRV_TOOLS "SPIRV-Tools")
31
32 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
33
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)
40 else()
41   message(FATAL_ERROR "Your platform '${CMAKE_SYSTEM_NAME}' is not supported!")
42 endif()
43
44 if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
45   message(STATUS "No build type selected, default to Debug")
46   set(CMAKE_BUILD_TYPE "Debug")
47 endif()
48
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)
52 endif()
53 if(${COMPILER_IS_LIKE_GNU})
54   set(SPIRV_WARNINGS -Wall -Wextra -Wno-missing-field-initializers)
55
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)
63     else()
64       message(STATUS "Unknown compiler ${CMAKE_CXX_COMPILER_ID}, "
65                      "so SPIRV_WARN_EVERYTHING has no effect")
66     endif()
67   endif()
68
69   if(${SPIRV_WERROR})
70     set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Werror)
71   endif()
72 elseif(MSVC)
73   set(SPIRV_WARNINGS -D_CRT_SECURE_NO_WARNINGS /wd4800)
74
75   if(${SPIRV_WERROR})
76     set(SPIRV_WARNINGS ${SPIRV_WARNINGS} /WX)
77   endif()
78 endif()
79
80 option(SPIRV_COLOR_TERMINAL "Enable color terminal output" ON)
81 if(${SPIRV_COLOR_TERMINAL})
82   add_definitions(-DSPIRV_COLOR_TERMINAL)
83 endif()
84
85 function(spvtools_default_compile_options TARGET)
86   target_compile_options(${TARGET} PRIVATE ${SPIRV_WARNINGS})
87
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
93       -Wno-sign-conversion)
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)
97     endif()
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})
104       endif()
105     else()
106       target_compile_options(${TARGET} PRIVATE
107          -Wno-missing-field-initializers)
108     endif()
109   endif()
110
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++)
117     endif()
118   endif()
119 endfunction()
120
121 if(NOT COMMAND find_host_package)
122   macro(find_host_package)
123     find_package(${ARGN})
124   endmacro()
125 endif()
126 if(NOT COMMAND find_host_program)
127   macro(find_host_program)
128     find_program(${ARGN})
129   endmacro()
130 endif()
131
132 find_host_package(PythonInterp)
133
134 add_custom_target(spirv-tools-build-version
135   ${PYTHON_EXECUTABLE}
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).")
139
140 function(spvtools_tables VERSION)
141   add_custom_target(spirv-tools-build-tables-${VERSION}
142     ${PYTHON_EXECUTABLE}
143     ${CMAKE_CURRENT_SOURCE_DIR}/utils/generate_grammar_tables.py
144     --spirv-core-grammar=${spirv-tools_SOURCE_DIR}/source/spirv-${VERSION}.core.grammar.json
145     --extinst-glsl-grammar=${spirv-tools_SOURCE_DIR}/source/extinst-${VERSION}.glsl.std.450.grammar.json
146     --extinst-opencl-grammar=${spirv-tools_SOURCE_DIR}/source/extinst-${VERSION}.opencl.std.grammar.json
147     --core-insts-output=${spirv-tools_BINARY_DIR}/core.insts-${VERSION}.inc
148     --glsl-insts-output=${spirv-tools_BINARY_DIR}/glsl.std.450.insts-${VERSION}.inc
149     --opencl-insts-output=${spirv-tools_BINARY_DIR}/opencl.std.insts-${VERSION}.inc
150     --operand-kinds-output=${spirv-tools_BINARY_DIR}/operand.kinds-${VERSION}.inc
151     COMMENT "Generate info tables for SPIR-V-${VERSION} instructions and operands.")
152 endfunction(spvtools_tables)
153
154 spvtools_tables("1-0")
155
156 # Defaults to OFF if the user didn't set it.
157 option(SPIRV_SKIP_EXECUTABLES
158        "Skip building the executable and tests along with the library"
159        ${SPIRV_SKIP_EXECUTABLES})
160
161 add_subdirectory(external)
162
163 add_subdirectory(source)
164 add_subdirectory(tools)
165
166 add_subdirectory(test)
167
168 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/libspirv.h
169   DESTINATION include/spirv-tools/)