build: update spirv and glslang revisions
[platform/upstream/Vulkan-Tools.git] / CMakeLists.txt
1 # The name of our project is "VULKAN". CMakeLists files in this project can
2 # refer to the root source directory of the project as ${VULKAN_SOURCE_DIR} and
3 # to the root binary directory of the project as ${VULKAN_BINARY_DIR}.
4 cmake_minimum_required(VERSION 2.8.11)
5 project (VULKAN)
6 # set (CMAKE_VERBOSE_MAKEFILE 1)
7
8 # The MAJOR number of the version we're building, used in naming
9 # vulkan-<major>.dll (and other files).
10 set(MAJOR "1")
11
12 find_package(PythonInterp 3 REQUIRED)
13
14 if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
15     add_definitions(-DVK_USE_PLATFORM_WIN32_KHR -DWIN32_LEAN_AND_MEAN)
16     set(DisplayServer Win32)
17 elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
18     add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR)
19     set(DisplayServer Android)
20 elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
21     #   Note: Supported configurations are XCB, XCB + Xlib, Wayland.  
22     #         MIR is stubbed and untested 
23     option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON)
24     option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON)
25     option(BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" OFF)
26     option(BUILD_WSI_MIR_SUPPORT "Build Mir WSI support" OFF)
27
28     if (BUILD_WSI_XCB_SUPPORT)
29         add_definitions(-DVK_USE_PLATFORM_XCB_KHR)
30         set(DisplayServer Xcb)
31     endif()
32
33     if (BUILD_WSI_XLIB_SUPPORT)
34         add_definitions(-DVK_USE_PLATFORM_XLIB_KHR)
35         set(DisplayServer Xlib)
36     endif()
37
38     if (BUILD_WSI_WAYLAND_SUPPORT)
39         add_definitions(-DVK_USE_PLATFORM_WAYLAND_KHR)
40         set(DisplayServer Wayland)
41     endif()
42
43     if (BUILD_WSI_MIR_SUPPORT)
44         add_definitions(-DVK_USE_PLATFORM_MIR_KHR)
45         set(DisplayServer Mir)
46     endif()
47 else()
48     message(FATAL_ERROR "Unsupported Platform!")
49 endif()
50
51 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
52
53 # Header file for CMake settings
54 include_directories("${PROJECT_SOURCE_DIR}/include")
55
56 if(NOT WIN32)
57     include(FindPkgConfig)
58 endif()
59
60 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
61     set(COMMON_COMPILE_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
62     set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -fno-strict-aliasing -fno-builtin-memcmp")
63     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 ${COMMON_COMPILE_FLAGS}")
64     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_COMPILE_FLAGS} -std=c++11 -fno-rtti")
65     if (UNIX)
66         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
67         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
68     endif()
69 endif()
70
71 if(WIN32)
72     # Disable RTTI
73     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
74 endif()
75
76 if(NOT WIN32)
77     find_package(XCB REQUIRED)
78     set (BUILDTGT_DIR build)
79     set (BINDATA_DIR Bin)
80     set (LIBSOURCE_DIR Lib)
81 else()
82     option(DISABLE_BUILD_PATH_DECORATION "Disable the decoration of the gslang and SPIRV-Tools build path with MSVC build type info" OFF)
83     option(DISABLE_BUILDTGT_DIR_DECORATION "Disable the decoration of the gslang and SPIRV-Tools build path with target info" OFF)
84
85     # For Windows, since 32-bit and 64-bit items can co-exist, we build each in its own build directory.
86     # 32-bit target data goes in build32, and 64-bit target data goes into build.  So, include/link the
87     # appropriate data at build time.
88     if (DISABLE_BUILDTGT_DIR_DECORATION)
89         set (BUILDTGT_DIR "")
90         set (BINDATA_DIR "")
91         set (LIBSOURCE_DIR "")
92     elseif (CMAKE_CL_64)
93         set (BUILDTGT_DIR build)
94         set (BINDATA_DIR Bin)
95         set (LIBSOURCE_DIR Lib)
96     else()
97         set (BUILDTGT_DIR build32)
98         set (BINDATA_DIR Bin32)
99         set (LIBSOURCE_DIR Lib32)
100     endif()
101 endif()
102
103 option(BUILD_LOADER "Build loader" ON)
104 option(BUILD_TESTS "Build tests" ON)
105 option(BUILD_LAYERS "Build layers" ON)
106 option(BUILD_DEMOS "Build demos" ON)
107 option(BUILD_VKJSON "Build vkjson" ON)
108 option(CUSTOM_GLSLANG_BIN_ROOT "Use the user defined GLSLANG_BINARY_ROOT" OFF)
109 option(CUSTOM_SPIRV_TOOLS_BIN_ROOT "Use the user defined SPIRV_TOOLS_BINARY_ROOT" OFF)
110
111 #Choose natural default paths for glslang and SPIRV-Tools binaries to support custom definition by the user on the CMake command line or in the GUI
112 set(GLSLANG_BINARY_ROOT "${CMAKE_BINARY_DIR}/../glslang" CACHE STRING "User defined path to the glslang binaries for this project")
113 set(SPIRV_TOOLS_BINARY_ROOT "${CMAKE_BINARY_DIR}/../SPIRV-Tools" CACHE STRING "User defined path to the SPIRV-Tools binaries for this project")
114
115 # Define a variable for a default root location to the gslang, SPIRV-Tools and other external sources and cache it to allow the user to customize it as needed
116 set(EXTERNAL_SOURCE_ROOT "${CMAKE_SOURCE_DIR}/external" CACHE STRING "Root path to external sources such as glslang and SPIRV-Tools")
117
118
119 if (WIN32)
120     if(CUSTOM_GLSLANG_BIN_ROOT)
121         set(GSLANG_FINAL_BINARY_PATH ${GLSLANG_BINARY_ROOT}/${BUILDTGT_DIR})
122     else()
123         set(GSLANG_FINAL_BINARY_PATH "${EXTERNAL_SOURCE_ROOT}/glslang/${BUILDTGT_DIR}")
124     endif()
125
126     if(DISABLE_BUILD_PATH_DECORATION)
127         set (DEBUG_DECORATION "")
128         set (RELEASE_DECORATION "")
129     else()
130         set (DEBUG_DECORATION "Debug")
131         set (RELEASE_DECORATION "Release")
132     endif()
133
134     # Take some steps to set up a variable pointing to the final glslang binaries given the variety of input options
135     set (GLSLANG_SEARCH_PATH "${GSLANG_FINAL_BINARY_PATH}/glslang/${RELEASE_DECORATION}"
136                              "${GSLANG_FINAL_BINARY_PATH}/glslang/OSDependent/Windows/${RELEASE_DECORATION}"
137                              "${GSLANG_FINAL_BINARY_PATH}/hlsl/${RELEASE_DECORATION}"
138                              "${GSLANG_FINAL_BINARY_PATH}/OGLCompilersDLL/${RELEASE_DECORATION}"
139                              "${GSLANG_FINAL_BINARY_PATH}/SPIRV/${RELEASE_DECORATION}" )
140
141     set (GLSLANG_DEBUG_SEARCH_PATH "${GSLANG_FINAL_BINARY_PATH}/glslang/${DEBUG_DECORATION}"
142                                    "${GSLANG_FINAL_BINARY_PATH}/glslang/OSDependent/Windows/${DEBUG_DECORATION}"
143                                    "${GSLANG_FINAL_BINARY_PATH}/hlsl/${DEBUG_DECORATION}"
144                                    "${GSLANG_FINAL_BINARY_PATH}/OGLCompilersDLL/${DEBUG_DECORATION}"
145                                    "${GSLANG_FINAL_BINARY_PATH}/SPIRV/${DEBUG_DECORATION}")
146
147     if(CUSTOM_SPIRV_TOOLS_BIN_ROOT)
148         set (SPIRV_TOOLS_SEARCH_PATH "${SPIRV_TOOLS_BINARY_ROOT}/${BUILDTGT_DIR}/source/${RELEASE_DECORATION}")
149         set (SPIRV_TOOLS_DEBUG_SEARCH_PATH "${SPIRV_TOOLS_BINARY_ROOT}/${BUILDTGT_DIR}/source/${DEBUG_DECORATION}")
150     else()
151         set (SPIRV_TOOLS_SEARCH_PATH "${EXTERNAL_SOURCE_ROOT}/spirv-tools/${BUILDTGT_DIR}/source/${RELEASE_DECORATION}")
152         set (SPIRV_TOOLS_DEBUG_SEARCH_PATH "${EXTERNAL_SOURCE_ROOT}/spirv-tools/${BUILDTGT_DIR}/source/${DEBUG_DECORATION}")
153     endif()
154 else()
155     #non windows
156     if(CUSTOM_GLSLANG_BIN_ROOT)
157         set (GLSLANG_SEARCH_PATH "${GLSLANG_BINARY_ROOT}/install/lib"
158                                  "${GLSLANG_BINARY_ROOT}/glslang"
159                                  "${GLSLANG_BINARY_ROOT}/glslang/OSDependent/Unix"
160                                  "${GLSLANG_BINARY_ROOT}/OGLCompilersDLL"
161                                  "${GLSLANG_BINARY_ROOT}/SPIRV"
162                                  "${GLSLANG_BINARY_ROOT}/hlsl"
163                                  "${GLSLANG_BINARY_ROOT}/StandAlone")
164     else()
165         set (GLSLANG_SEARCH_PATH "${EXTERNAL_SOURCE_ROOT}/glslang/${BUILDTGT_DIR}/install/lib" "${CMAKE_SOURCE_DIR}/../x86_64/lib/glslang" )
166     endif()
167
168     if(CUSTOM_SPIRV_TOOLS_BIN_ROOT)
169         set (SPIRV_TOOLS_SEARCH_PATH "${SPIRV_TOOLS_BINARY_ROOT}/source" )
170     else()
171         set (SPIRV_TOOLS_SEARCH_PATH "${EXTERNAL_SOURCE_ROOT}/spirv-tools/${BUILDTGT_DIR}/source" "${CMAKE_SOURCE_DIR}/../x86_64/lib/spirv-tools" )
172     endif()
173 endif()
174
175 find_program(GLSLANG_VALIDATOR NAMES glslangValidator
176              HINTS "${CMAKE_SOURCE_DIR}/external/glslang/${BUILDTGT_DIR}/install/bin"
177                    "${GLSLANG_BINARY_ROOT}/StandAlone"
178                    "${PROJECT_SOURCE_DIR}/external/${BINDATA_DIR}")
179
180 find_path(GLSLANG_SPIRV_INCLUDE_DIR SPIRV/spirv.hpp HINTS "${EXTERNAL_SOURCE_ROOT}/glslang"
181                                                     "${CMAKE_SOURCE_DIR}/../glslang"
182                                               DOC "Path to SPIRV/spirv.hpp")
183
184 find_path(SPIRV_TOOLS_INCLUDE_DIR spirv-tools/libspirv.h HINTS "${EXTERNAL_SOURCE_ROOT}/spirv-tools/include"
185                                                    "${EXTERNAL_SOURCE_ROOT}/SPIRV-Tools/include"
186                                                    "${CMAKE_SOURCE_DIR}/../spirv-tools/include"
187                                                    "${CMAKE_SOURCE_DIR}/../SPIRV-Tools/include"
188                                                    "${EXTERNAL_SOURCE_ROOT}/source/spirv-tools/external/include"
189                                              DOC "Path to spirv-tools/libspirv.h")
190
191 find_library(GLSLANG_LIB NAMES glslang
192              HINTS ${GLSLANG_SEARCH_PATH} )
193
194 find_library(OGLCompiler_LIB NAMES OGLCompiler
195              HINTS ${GLSLANG_SEARCH_PATH} )
196
197 find_library(OSDependent_LIB NAMES OSDependent
198              HINTS ${GLSLANG_SEARCH_PATH} )
199
200 find_library(HLSL_LIB NAMES HLSL
201              HINTS ${GLSLANG_SEARCH_PATH} )
202
203 find_library(SPIRV_LIB NAMES SPIRV
204              HINTS ${GLSLANG_SEARCH_PATH} )
205
206 find_library(SPIRV_REMAPPER_LIB NAMES SPVRemapper
207              HINTS ${GLSLANG_SEARCH_PATH} )
208
209 find_library(SPIRV_TOOLS_LIB NAMES SPIRV-Tools
210              HINTS ${SPIRV_TOOLS_SEARCH_PATH} )
211
212 if (WIN32)
213     add_library(glslang     STATIC IMPORTED)
214     add_library(OGLCompiler STATIC IMPORTED)
215     add_library(OSDependent STATIC IMPORTED)
216     add_library(HLSL        STATIC IMPORTED)
217     add_library(SPIRV       STATIC IMPORTED)
218     add_library(SPVRemapper       STATIC IMPORTED)
219     add_library(Loader      STATIC IMPORTED)
220     add_library(SPIRV-Tools STATIC IMPORTED)
221
222     find_library(GLSLANG_DLIB NAMES glslangd
223                  HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
224     find_library(OGLCompiler_DLIB NAMES OGLCompilerd
225                  HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
226     find_library(OSDependent_DLIB NAMES OSDependentd
227                  HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
228     find_library(HLSL_DLIB NAMES HLSLd
229                  HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
230     find_library(SPIRV_DLIB NAMES SPIRVd
231                  HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
232     find_library(SPIRV_REMAPPER_DLIB NAMES SPVRemapperd
233                  HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
234     find_library(SPIRV_TOOLS_DLIB NAMES SPIRV-Tools
235                  HINTS ${SPIRV_TOOLS_DEBUG_SEARCH_PATH} )
236
237     set_target_properties(glslang PROPERTIES
238                          IMPORTED_LOCATION       "${GLSLANG_LIB}"
239                          IMPORTED_LOCATION_DEBUG "${GLSLANG_DLIB}")
240     set_target_properties(OGLCompiler PROPERTIES
241                          IMPORTED_LOCATION       "${OGLCompiler_LIB}"
242                          IMPORTED_LOCATION_DEBUG "${OGLCompiler_DLIB}")
243     set_target_properties(OSDependent PROPERTIES
244                          IMPORTED_LOCATION       "${OSDependent_LIB}"
245                          IMPORTED_LOCATION_DEBUG "${OSDependent_DLIB}")
246     set_target_properties(HLSL PROPERTIES
247                          IMPORTED_LOCATION       "${HLSL_LIB}"
248                          IMPORTED_LOCATION_DEBUG "${HLSL_DLIB}")
249     set_target_properties(SPIRV PROPERTIES
250                          IMPORTED_LOCATION       "${SPIRV_LIB}"
251                          IMPORTED_LOCATION_DEBUG "${SPIRV_DLIB}")
252     set_target_properties(SPVRemapper PROPERTIES
253                          IMPORTED_LOCATION       "${SPIRV_REMAPPER_LIB}"
254                          IMPORTED_LOCATION_DEBUG "${SPIRV_REMAPPER_DLIB}")
255     set_target_properties(SPIRV-Tools PROPERTIES
256                          IMPORTED_LOCATION       "${SPIRV_TOOLS_LIB}"
257                          IMPORTED_LOCATION_DEBUG "${SPIRV_TOOLS_DLIB}")
258
259     set (GLSLANG_LIBRARIES glslang OGLCompiler OSDependent HLSL SPIRV SPVRemapper)
260     set (SPIRV_TOOLS_LIBRARIES SPIRV-Tools)
261 else ()
262     set (GLSLANG_LIBRARIES ${GLSLANG_LIB} ${OGLCompiler_LIB} ${OSDependent_LIB} ${HLSL_LIB} ${SPIRV_LIB} ${SPIRV_REMAPPER_LIB})
263     set (SPIRV_TOOLS_LIBRARIES ${SPIRV_TOOLS_LIB})
264 endif()
265
266 set (PYTHON_CMD ${PYTHON_EXECUTABLE})
267
268 if(NOT WIN32)
269     include(GNUInstallDirs)
270     add_definitions(-DSYSCONFDIR="${CMAKE_INSTALL_SYSCONFDIR}")
271     add_definitions(-DDATADIR="${CMAKE_INSTALL_DATADIR}")
272     if (CMAKE_INSTALL_PREFIX STREQUAL "/usr/local")
273     elseif (CMAKE_INSTALL_PREFIX STREQUAL "")
274     else()
275         add_definitions(-DLOCALPREFIX="${CMAKE_INSTALL_PREFIX}")
276     endif()
277 endif()
278
279 # loader: Generic VULKAN ICD loader
280 # tests: VULKAN tests
281 if(BUILD_LOADER)
282     add_subdirectory(loader)
283 endif()
284
285 if(BUILD_TESTS)
286     add_subdirectory(tests)
287 endif()
288
289 if(BUILD_LAYERS)
290     add_subdirectory(layers)
291 endif()
292
293 if(BUILD_DEMOS)
294     add_subdirectory(demos)
295 endif()
296
297 if(BUILD_VKJSON)
298     add_subdirectory(libs/vkjson)
299 endif()