Add a default virtual dtor to Pass and check for missing virtual dtors
[platform/upstream/SPIRV-Tools.git] / CMakeLists.txt
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
15 cmake_minimum_required(VERSION 2.8.12)
16 if (POLICY CMP0054)
17   # Avoid dereferencing variables or interpret keywords that have been
18   # quoted or bracketed.
19   # https://cmake.org/cmake/help/v3.1/policy/CMP0054.html
20   cmake_policy(SET CMP0054 NEW)
21 endif()
22
23 project(spirv-tools)
24 enable_testing()
25 set(SPIRV_TOOLS "SPIRV-Tools")
26
27 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
28
29 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
30   add_definitions(-DSPIRV_LINUX)
31 elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
32   add_definitions(-DSPIRV_WINDOWS)
33 elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN")
34   add_definitions(-DSPIRV_WINDOWS)
35 elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
36   add_definitions(-DSPIRV_MAC)
37 elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
38   add_definitions(-DSPIRV_ANDROID)
39 else()
40   message(FATAL_ERROR "Your platform '${CMAKE_SYSTEM_NAME}' is not supported!")
41 endif()
42
43 if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
44   message(STATUS "No build type selected, default to Debug")
45   set(CMAKE_BUILD_TYPE "Debug")
46 endif()
47
48 option(SPIRV_WERROR "Enable error on warning" ON)
49 if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
50   set(COMPILER_IS_LIKE_GNU TRUE)
51 endif()
52 if(${COMPILER_IS_LIKE_GNU})
53   set(SPIRV_WARNINGS -Wall -Wextra -Wnon-virtual-dtor -Wno-missing-field-initializers)
54
55   option(SPIRV_WARN_EVERYTHING "Enable -Weverything" ${SPIRV_WARN_EVERYTHING})
56   if(${SPIRV_WARN_EVERYTHING})
57     if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
58       set(SPIRV_WARNINGS ${SPIRV_WARNINGS}
59         -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded)
60     elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
61       set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Wpedantic -pedantic-errors)
62     else()
63       message(STATUS "Unknown compiler ${CMAKE_CXX_COMPILER_ID}, "
64                      "so SPIRV_WARN_EVERYTHING has no effect")
65     endif()
66   endif()
67
68   if(${SPIRV_WERROR})
69     set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Werror)
70   endif()
71 elseif(MSVC)
72   set(SPIRV_WARNINGS -D_CRT_SECURE_NO_WARNINGS /wd4800)
73
74   if(${SPIRV_WERROR})
75     set(SPIRV_WARNINGS ${SPIRV_WARNINGS} /WX)
76   endif()
77 endif()
78
79 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/source)
80
81 option(SPIRV_COLOR_TERMINAL "Enable color terminal output" ON)
82 if(${SPIRV_COLOR_TERMINAL})
83   add_definitions(-DSPIRV_COLOR_TERMINAL)
84 endif()
85
86 option(SPIRV_LOG_DEBUG "Enable excessive debug output" OFF)
87 if(${SPIRV_LOG_DEBUG})
88   add_definitions(-DSPIRV_LOG_DEBUG)
89 endif()
90
91 function(spvtools_default_compile_options TARGET)
92   target_compile_options(${TARGET} PRIVATE ${SPIRV_WARNINGS})
93
94   if (${COMPILER_IS_LIKE_GNU})
95     target_compile_options(${TARGET} PRIVATE
96       -std=c++11 -fno-exceptions -fno-rtti)
97     target_compile_options(${TARGET} PRIVATE
98       -Wall -Wextra -Wno-long-long -Wshadow -Wundef -Wconversion
99       -Wno-sign-conversion)
100     # For good call stacks in profiles, keep the frame pointers.
101     if(NOT "${SPIRV_PERF}" STREQUAL "")
102       target_compile_options(${TARGET} PRIVATE -fno-omit-frame-pointer)
103     endif()
104     if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
105       set(SPIRV_USE_SANITIZER "" CACHE STRING
106         "Use the clang sanitizer [address|memory|thread|...]")
107       if(NOT "${SPIRV_USE_SANITIZER}" STREQUAL "")
108         target_compile_options(${TARGET} PRIVATE
109           -fsanitize=${SPIRV_USE_SANITIZER})
110       endif()
111     else()
112       target_compile_options(${TARGET} PRIVATE
113          -Wno-missing-field-initializers)
114     endif()
115   endif()
116
117   # For MinGW cross compile, statically link to the C++ runtime.
118   # But it still depends on MSVCRT.dll.
119   if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
120     if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
121       set_target_properties(${TARGET} PROPERTIES
122         LINK_FLAGS -static -static-libgcc -static-libstdc++)
123     endif()
124   endif()
125 endfunction()
126
127 if(NOT COMMAND find_host_package)
128   macro(find_host_package)
129     find_package(${ARGN})
130   endmacro()
131 endif()
132 if(NOT COMMAND find_host_program)
133   macro(find_host_program)
134     find_program(${ARGN})
135   endmacro()
136 endif()
137
138 find_host_package(PythonInterp)
139
140
141 # Defaults to OFF if the user didn't set it.
142 option(SPIRV_SKIP_EXECUTABLES
143   "Skip building the executable and tests along with the library"
144   ${SPIRV_SKIP_EXECUTABLES})
145 option(SPIRV_SKIP_TESTS
146   "Skip building tests along with the library" ${SPIRV_SKIP_TESTS})
147 if ("${SPIRV_SKIP_EXECUTABLES}")
148   set(SPIRV_SKIP_TESTS ON)
149 endif()
150
151 add_subdirectory(external)
152
153 add_subdirectory(source)
154 add_subdirectory(tools)
155
156 add_subdirectory(test)
157 add_subdirectory(examples)
158
159 install(
160   FILES
161     ${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/libspirv.h
162     ${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/libspirv.hpp
163     ${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/optimizer.hpp
164   DESTINATION
165     include/spirv-tools/)
166
167 add_test(NAME spirv-tools-copyrights
168          COMMAND ${PYTHON_EXECUTABLE} utils/check_copyright.py
169          WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})