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)
6 # set (CMAKE_VERBOSE_MAKEFILE 1)
8 # The MAJOR number of the version we're building, used in naming
9 # vulkan-<major>.dll (and other files).
12 find_package(PythonInterp 3 REQUIRED)
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 # TODO: Basic support is present for Xlib but is untested.
22 # Mir support is stubbed in but unimplemented 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)
28 if (BUILD_WSI_XCB_SUPPORT)
29 add_definitions(-DVK_USE_PLATFORM_XCB_KHR)
30 set(DisplayServer Xcb)
33 if (BUILD_WSI_XLIB_SUPPORT)
34 add_definitions(-DVK_USE_PLATFORM_XLIB_KHR)
35 set(DisplayServer Xlib)
38 if (BUILD_WSI_WAYLAND_SUPPORT)
39 add_definitions(-DVK_USE_PLATFORM_WAYLAND_KHR)
40 set(DisplayServer Wayland)
43 if (BUILD_WSI_MIR_SUPPORT)
44 add_definitions(-DVK_USE_PLATFORM_MIR_KHR)
45 set(DisplayServer Mir)
48 message(FATAL_ERROR "Unsupported Platform!")
51 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
53 # Header file for CMake settings
54 include_directories("${PROJECT_SOURCE_DIR}/include")
57 include(FindPkgConfig)
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")
66 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
67 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
73 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
77 find_package(XCB REQUIRED)
78 set (BUILDTGT_DIR build)
80 set (LIBSOURCE_DIR Lib)
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)
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)
91 set (LIBSOURCE_DIR "")
93 set (BUILDTGT_DIR build)
95 set (LIBSOURCE_DIR Lib)
97 set (BUILDTGT_DIR build32)
98 set (BINDATA_DIR Bin32)
99 set (LIBSOURCE_DIR Lib32)
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)
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")
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")
120 if(CUSTOM_GLSLANG_BIN_ROOT)
121 set(GSLANG_FINAL_BINARY_PATH ${GLSLANG_BINARY_ROOT}/${BUILDTGT_DIR})
123 set(GSLANG_FINAL_BINARY_PATH "${EXTERNAL_SOURCE_ROOT}/glslang/${BUILDTGT_DIR}")
126 if(DISABLE_BUILD_PATH_DECORATION)
127 set (DEBUG_DECORATION "")
128 set (RELEASE_DECORATION "")
130 set (DEBUG_DECORATION "Debug")
131 set (RELEASE_DECORATION "Release")
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}" )
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}")
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}")
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}")
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")
165 set (GLSLANG_SEARCH_PATH "${EXTERNAL_SOURCE_ROOT}/glslang/${BUILDTGT_DIR}/install/lib" "${CMAKE_SOURCE_DIR}/../x86_64/lib/glslang" )
168 if(CUSTOM_SPIRV_TOOLS_BIN_ROOT)
169 set (SPIRV_TOOLS_SEARCH_PATH "${SPIRV_TOOLS_BINARY_ROOT}/source" )
171 set (SPIRV_TOOLS_SEARCH_PATH "${EXTERNAL_SOURCE_ROOT}/spirv-tools/${BUILDTGT_DIR}/source" "${CMAKE_SOURCE_DIR}/../x86_64/lib/spirv-tools" )
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}")
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")
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")
191 find_library(GLSLANG_LIB NAMES glslang
192 HINTS ${GLSLANG_SEARCH_PATH} )
194 find_library(OGLCompiler_LIB NAMES OGLCompiler
195 HINTS ${GLSLANG_SEARCH_PATH} )
197 find_library(OSDependent_LIB NAMES OSDependent
198 HINTS ${GLSLANG_SEARCH_PATH} )
200 find_library(HLSL_LIB NAMES HLSL
201 HINTS ${GLSLANG_SEARCH_PATH} )
203 find_library(SPIRV_LIB NAMES SPIRV
204 HINTS ${GLSLANG_SEARCH_PATH} )
206 find_library(SPIRV_TOOLS_LIB NAMES SPIRV-Tools
207 HINTS ${SPIRV_TOOLS_SEARCH_PATH} )
210 add_library(glslang STATIC IMPORTED)
211 add_library(OGLCompiler STATIC IMPORTED)
212 add_library(OSDependent STATIC IMPORTED)
213 add_library(HLSL STATIC IMPORTED)
214 add_library(SPIRV STATIC IMPORTED)
215 add_library(Loader STATIC IMPORTED)
216 add_library(SPIRV-Tools STATIC IMPORTED)
218 find_library(GLSLANG_DLIB NAMES glslangd
219 HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
220 find_library(OGLCompiler_DLIB NAMES OGLCompilerd
221 HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
222 find_library(OSDependent_DLIB NAMES OSDependentd
223 HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
224 find_library(HLSL_DLIB NAMES HLSLd
225 HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
226 find_library(SPIRV_DLIB NAMES SPIRVd
227 HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
228 find_library(SPIRV_TOOLS_DLIB NAMES SPIRV-Tools
229 HINTS ${SPIRV_TOOLS_DEBUG_SEARCH_PATH} )
231 set_target_properties(glslang PROPERTIES
232 IMPORTED_LOCATION "${GLSLANG_LIB}"
233 IMPORTED_LOCATION_DEBUG "${GLSLANG_DLIB}")
234 set_target_properties(OGLCompiler PROPERTIES
235 IMPORTED_LOCATION "${OGLCompiler_LIB}"
236 IMPORTED_LOCATION_DEBUG "${OGLCompiler_DLIB}")
237 set_target_properties(OSDependent PROPERTIES
238 IMPORTED_LOCATION "${OSDependent_LIB}"
239 IMPORTED_LOCATION_DEBUG "${OSDependent_DLIB}")
240 set_target_properties(HLSL PROPERTIES
241 IMPORTED_LOCATION "${HLSL_LIB}"
242 IMPORTED_LOCATION_DEBUG "${HLSL_DLIB}")
243 set_target_properties(SPIRV PROPERTIES
244 IMPORTED_LOCATION "${SPIRV_LIB}"
245 IMPORTED_LOCATION_DEBUG "${SPIRV_DLIB}")
246 set_target_properties(SPIRV-Tools PROPERTIES
247 IMPORTED_LOCATION "${SPIRV_TOOLS_LIB}"
248 IMPORTED_LOCATION_DEBUG "${SPIRV_TOOLS_DLIB}")
250 set (GLSLANG_LIBRARIES glslang OGLCompiler OSDependent HLSL SPIRV)
251 set (SPIRV_TOOLS_LIBRARIES SPIRV-Tools)
253 set (GLSLANG_LIBRARIES ${GLSLANG_LIB} ${OGLCompiler_LIB} ${OSDependent_LIB} ${HLSL_LIB} ${SPIRV_LIB})
254 set (SPIRV_TOOLS_LIBRARIES ${SPIRV_TOOLS_LIB})
257 set (PYTHON_CMD ${PYTHON_EXECUTABLE})
260 include(GNUInstallDirs)
261 add_definitions(-DSYSCONFDIR="${CMAKE_INSTALL_SYSCONFDIR}")
262 add_definitions(-DDATADIR="${CMAKE_INSTALL_DATADIR}")
263 if (CMAKE_INSTALL_PREFIX STREQUAL "/usr/local")
264 elseif (CMAKE_INSTALL_PREFIX STREQUAL "")
266 add_definitions(-DLOCALPREFIX="${CMAKE_INSTALL_PREFIX}")
270 # loader: Generic VULKAN ICD loader
271 # tests: VULKAN tests
273 add_subdirectory(loader)
277 add_subdirectory(tests)
281 add_subdirectory(layers)
285 add_subdirectory(demos)
289 add_subdirectory(libs/vkjson)