Split validate_types file into multiple classes
[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 elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
41   add_definitions(-DSPIRV_ANDROID)
42 else()
43   message(FATAL_ERROR "Your platform '${CMAKE_SYSTEM_NAME}' is not supported!")
44 endif()
45
46 if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
47   message(STATUS "No build type selected, default to Debug")
48   set(CMAKE_BUILD_TYPE "Debug")
49 endif()
50
51 option(SPIRV_WERROR "Enable error on warning" ON)
52 if((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang"))
53   set(COMPILER_IS_LIKE_GNU TRUE)
54 endif()
55 if(${COMPILER_IS_LIKE_GNU})
56   set(SPIRV_WARNINGS -Wall -Wextra -Wno-missing-field-initializers)
57
58   option(SPIRV_WARN_EVERYTHING "Enable -Weverything" ${SPIRV_WARN_EVERYTHING})
59   if(${SPIRV_WARN_EVERYTHING})
60     if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
61       set(SPIRV_WARNINGS ${SPIRV_WARNINGS}
62         -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded)
63     elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
64       set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Wpedantic -pedantic-errors)
65     else()
66       message(STATUS "Unknown compiler ${CMAKE_CXX_COMPILER_ID}, "
67                      "so SPIRV_WARN_EVERYTHING has no effect")
68     endif()
69   endif()
70
71   if(${SPIRV_WERROR})
72     set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Werror)
73   endif()
74 elseif(MSVC)
75   set(SPIRV_WARNINGS -D_CRT_SECURE_NO_WARNINGS /wd4800)
76
77   if(${SPIRV_WERROR})
78     set(SPIRV_WARNINGS ${SPIRV_WARNINGS} /WX)
79   endif()
80 endif()
81
82 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/source)
83
84 option(SPIRV_COLOR_TERMINAL "Enable color terminal output" ON)
85 if(${SPIRV_COLOR_TERMINAL})
86   add_definitions(-DSPIRV_COLOR_TERMINAL)
87 endif()
88
89 function(spvtools_default_compile_options TARGET)
90   target_compile_options(${TARGET} PRIVATE ${SPIRV_WARNINGS})
91
92   if (${COMPILER_IS_LIKE_GNU})
93     target_compile_options(${TARGET} PRIVATE
94       -std=c++11 -fno-exceptions -fno-rtti)
95     target_compile_options(${TARGET} PRIVATE
96       -Wall -Wextra -Wno-long-long -Wshadow -Wundef -Wconversion
97       -Wno-sign-conversion)
98     # For good call stacks in profiles, keep the frame pointers.
99     if(NOT "${SPIRV_PERF}" STREQUAL "")
100       target_compile_options(${TARGET} PRIVATE -fno-omit-frame-pointer)
101     endif()
102     if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
103       set(SPIRV_USE_SANITIZER "" CACHE STRING
104         "Use the clang sanitizer [address|memory|thread|...]")
105       if(NOT "${SPIRV_USE_SANITIZER}" STREQUAL "")
106         target_compile_options(${TARGET} PRIVATE
107           -fsanitize=${SPIRV_USE_SANITIZER})
108       endif()
109     else()
110       target_compile_options(${TARGET} PRIVATE
111          -Wno-missing-field-initializers)
112     endif()
113   endif()
114
115   # For MinGW cross compile, statically link to the C++ runtime.
116   # But it still depends on MSVCRT.dll.
117   if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
118     if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
119       set_target_properties(${TARGET} PROPERTIES LINK_FLAGS
120                             -static -static-libgcc -static-libstdc++)
121     endif()
122   endif()
123 endfunction()
124
125 if(NOT COMMAND find_host_package)
126   macro(find_host_package)
127     find_package(${ARGN})
128   endmacro()
129 endif()
130 if(NOT COMMAND find_host_program)
131   macro(find_host_program)
132     find_program(${ARGN})
133   endmacro()
134 endif()
135
136 find_host_package(PythonInterp)
137
138
139 # Defaults to OFF if the user didn't set it.
140 option(SPIRV_SKIP_EXECUTABLES
141        "Skip building the executable and tests along with the library"
142        ${SPIRV_SKIP_EXECUTABLES})
143
144 add_subdirectory(external)
145
146 add_subdirectory(source)
147 add_subdirectory(tools)
148
149 add_subdirectory(test)
150
151 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/libspirv.h
152   DESTINATION include/spirv-tools/)