Add CHANGES file with high level software history
[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 option(SPIRV_COLOR_TERMINAL "Enable color terminal output" ON)
83 if(${SPIRV_COLOR_TERMINAL})
84   add_definitions(-DSPIRV_COLOR_TERMINAL)
85 endif()
86
87 function(spvtools_default_compile_options TARGET)
88   target_compile_options(${TARGET} PRIVATE ${SPIRV_WARNINGS})
89
90   if (${COMPILER_IS_LIKE_GNU})
91     target_compile_options(${TARGET} PRIVATE
92       -std=c++11 -fno-exceptions -fno-rtti)
93     target_compile_options(${TARGET} PRIVATE
94       -Wall -Wextra -Wno-long-long -Wshadow -Wundef -Wconversion
95       -Wno-sign-conversion)
96     # For good call stacks in profiles, keep the frame pointers.
97     if(NOT "${SPIRV_PERF}" STREQUAL "")
98       target_compile_options(${TARGET} PRIVATE -fno-omit-frame-pointer)
99     endif()
100     if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
101       set(SPIRV_USE_SANITIZER "" CACHE STRING
102         "Use the clang sanitizer [address|memory|thread|...]")
103       if(NOT "${SPIRV_USE_SANITIZER}" STREQUAL "")
104         target_compile_options(${TARGET} PRIVATE
105           -fsanitize=${SPIRV_USE_SANITIZER})
106       endif()
107     else()
108       target_compile_options(${TARGET} PRIVATE
109          -Wno-missing-field-initializers)
110     endif()
111   endif()
112
113   # For MinGW cross compile, statically link to the C++ runtime.
114   # But it still depends on MSVCRT.dll.
115   if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
116     if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
117       set_target_properties(${TARGET} PROPERTIES LINK_FLAGS
118                             -static -static-libgcc -static-libstdc++)
119     endif()
120   endif()
121 endfunction()
122
123 if(NOT COMMAND find_host_package)
124   macro(find_host_package)
125     find_package(${ARGN})
126   endmacro()
127 endif()
128 if(NOT COMMAND find_host_program)
129   macro(find_host_program)
130     find_program(${ARGN})
131   endmacro()
132 endif()
133
134 find_host_package(PythonInterp)
135
136
137 # Defaults to OFF if the user didn't set it.
138 option(SPIRV_SKIP_EXECUTABLES
139        "Skip building the executable and tests along with the library"
140        ${SPIRV_SKIP_EXECUTABLES})
141
142 add_subdirectory(external)
143
144 add_subdirectory(source)
145 add_subdirectory(tools)
146
147 add_subdirectory(test)
148
149 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/spirv-tools/libspirv.h
150   DESTINATION include/spirv-tools/)