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 API_NAME allows renaming builds to avoid conflicts with installed SDKs
9 # The MAJOR number of the version we're building, used in naming
10 # <api-name>-<major>.dll (and other files).
11 set(API_NAME "Vulkan" CACHE STRING "API name to use when building")
13 string(TOLOWER ${API_NAME} API_LOWERCASE)
15 find_package(PythonInterp 3 REQUIRED)
17 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
18 option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON)
19 option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON)
20 option(BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" OFF)
21 option(BUILD_WSI_MIR_SUPPORT "Build Mir WSI support" OFF)
24 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
26 set(SCRIPTS_DIR "${CMAKE_SOURCE_DIR}/scripts")
28 # Header file for CMake settings
29 include_directories("${PROJECT_SOURCE_DIR}/include")
32 include(FindPkgConfig)
35 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
36 set(COMMON_COMPILE_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
37 set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -fno-strict-aliasing -fno-builtin-memcmp")
38 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 ${COMMON_COMPILE_FLAGS}")
39 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_COMPILE_FLAGS} -std=c++11 -fno-rtti")
41 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
42 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
48 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
52 if (BUILD_WSI_XCB_SUPPORT)
53 find_package(XCB REQUIRED)
55 set (BUILDTGT_DIR build)
57 set (LIBSOURCE_DIR Lib)
59 option(DISABLE_BUILD_PATH_DECORATION "Disable the decoration of the gslang and SPIRV-Tools build path with MSVC build type info" OFF)
60 option(DISABLE_BUILDTGT_DIR_DECORATION "Disable the decoration of the gslang and SPIRV-Tools build path with target info" OFF)
62 # For Windows, since 32-bit and 64-bit items can co-exist, we build each in its own build directory.
63 # 32-bit target data goes in build32, and 64-bit target data goes into build. So, include/link the
64 # appropriate data at build time.
65 if (DISABLE_BUILDTGT_DIR_DECORATION)
68 set (LIBSOURCE_DIR "")
70 set (BUILDTGT_DIR build)
72 set (LIBSOURCE_DIR Lib)
74 set (BUILDTGT_DIR build32)
75 set (BINDATA_DIR Bin32)
76 set (LIBSOURCE_DIR Lib32)
80 option(BUILD_LOADER "Build loader" ON)
81 option(BUILD_TESTS "Build tests" ON)
82 option(BUILD_LAYERS "Build layers" ON)
83 option(BUILD_DEMOS "Build demos" ON)
84 option(BUILD_VKJSON "Build vkjson" ON)
85 option(CUSTOM_GLSLANG_BIN_ROOT "Use the user defined GLSLANG_BINARY_ROOT" OFF)
86 option(CUSTOM_SPIRV_TOOLS_BIN_ROOT "Use the user defined SPIRV_TOOLS_BINARY_ROOT" OFF)
88 #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
89 set(GLSLANG_BINARY_ROOT "${CMAKE_BINARY_DIR}/../glslang" CACHE STRING "User defined path to the glslang binaries for this project")
90 set(SPIRV_TOOLS_BINARY_ROOT "${CMAKE_BINARY_DIR}/../SPIRV-Tools" CACHE STRING "User defined path to the SPIRV-Tools binaries for this project")
92 # 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
93 set(EXTERNAL_SOURCE_ROOT "${CMAKE_SOURCE_DIR}/external" CACHE STRING "Root path to external sources such as glslang and SPIRV-Tools")
97 if(CUSTOM_GLSLANG_BIN_ROOT)
98 set(GSLANG_FINAL_BINARY_PATH ${GLSLANG_BINARY_ROOT}/${BUILDTGT_DIR})
100 set(GSLANG_FINAL_BINARY_PATH "${EXTERNAL_SOURCE_ROOT}/glslang/${BUILDTGT_DIR}")
103 if(DISABLE_BUILD_PATH_DECORATION)
104 set (DEBUG_DECORATION "")
105 set (RELEASE_DECORATION "")
107 set (DEBUG_DECORATION "Debug")
108 set (RELEASE_DECORATION "Release")
111 # Take some steps to set up a variable pointing to the final glslang binaries given the variety of input options
112 set (GLSLANG_SEARCH_PATH "${GSLANG_FINAL_BINARY_PATH}/glslang/${RELEASE_DECORATION}"
113 "${GSLANG_FINAL_BINARY_PATH}/glslang/OSDependent/Windows/${RELEASE_DECORATION}"
114 "${GSLANG_FINAL_BINARY_PATH}/hlsl/${RELEASE_DECORATION}"
115 "${GSLANG_FINAL_BINARY_PATH}/OGLCompilersDLL/${RELEASE_DECORATION}"
116 "${GSLANG_FINAL_BINARY_PATH}/SPIRV/${RELEASE_DECORATION}" )
118 set (GLSLANG_DEBUG_SEARCH_PATH "${GSLANG_FINAL_BINARY_PATH}/glslang/${DEBUG_DECORATION}"
119 "${GSLANG_FINAL_BINARY_PATH}/glslang/OSDependent/Windows/${DEBUG_DECORATION}"
120 "${GSLANG_FINAL_BINARY_PATH}/hlsl/${DEBUG_DECORATION}"
121 "${GSLANG_FINAL_BINARY_PATH}/OGLCompilersDLL/${DEBUG_DECORATION}"
122 "${GSLANG_FINAL_BINARY_PATH}/SPIRV/${DEBUG_DECORATION}")
124 if(CUSTOM_SPIRV_TOOLS_BIN_ROOT)
125 set (SPIRV_TOOLS_SEARCH_PATH "${SPIRV_TOOLS_BINARY_ROOT}/${BUILDTGT_DIR}/source/${RELEASE_DECORATION}")
126 set (SPIRV_TOOLS_DEBUG_SEARCH_PATH "${SPIRV_TOOLS_BINARY_ROOT}/${BUILDTGT_DIR}/source/${DEBUG_DECORATION}")
128 set (SPIRV_TOOLS_SEARCH_PATH "${EXTERNAL_SOURCE_ROOT}/spirv-tools/${BUILDTGT_DIR}/source/${RELEASE_DECORATION}")
129 set (SPIRV_TOOLS_DEBUG_SEARCH_PATH "${EXTERNAL_SOURCE_ROOT}/spirv-tools/${BUILDTGT_DIR}/source/${DEBUG_DECORATION}")
133 if(CUSTOM_GLSLANG_BIN_ROOT)
134 set (GLSLANG_SEARCH_PATH "${GLSLANG_BINARY_ROOT}/install/lib"
135 "${GLSLANG_BINARY_ROOT}/glslang"
136 "${GLSLANG_BINARY_ROOT}/glslang/OSDependent/Unix"
137 "${GLSLANG_BINARY_ROOT}/OGLCompilersDLL"
138 "${GLSLANG_BINARY_ROOT}/SPIRV"
139 "${GLSLANG_BINARY_ROOT}/hlsl"
140 "${GLSLANG_BINARY_ROOT}/StandAlone")
142 set (GLSLANG_SEARCH_PATH "${EXTERNAL_SOURCE_ROOT}/glslang/${BUILDTGT_DIR}/install/lib" "${CMAKE_SOURCE_DIR}/../x86_64/lib/glslang" )
145 if(CUSTOM_SPIRV_TOOLS_BIN_ROOT)
146 set (SPIRV_TOOLS_SEARCH_PATH "${SPIRV_TOOLS_BINARY_ROOT}/source" )
148 set (SPIRV_TOOLS_SEARCH_PATH "${EXTERNAL_SOURCE_ROOT}/spirv-tools/${BUILDTGT_DIR}/source" "${CMAKE_SOURCE_DIR}/../x86_64/lib/spirv-tools" )
152 find_program(GLSLANG_VALIDATOR NAMES glslangValidator
153 HINTS "${CMAKE_SOURCE_DIR}/external/glslang/${BUILDTGT_DIR}/install/bin"
154 "${GLSLANG_BINARY_ROOT}/StandAlone"
155 "${PROJECT_SOURCE_DIR}/external/${BINDATA_DIR}")
157 find_path(GLSLANG_SPIRV_INCLUDE_DIR SPIRV/spirv.hpp HINTS "${EXTERNAL_SOURCE_ROOT}/glslang"
158 "${CMAKE_SOURCE_DIR}/../glslang"
159 DOC "Path to SPIRV/spirv.hpp")
161 find_path(SPIRV_TOOLS_INCLUDE_DIR spirv-tools/libspirv.h HINTS "${EXTERNAL_SOURCE_ROOT}/spirv-tools/include"
162 "${EXTERNAL_SOURCE_ROOT}/SPIRV-Tools/include"
163 "${CMAKE_SOURCE_DIR}/../spirv-tools/include"
164 "${CMAKE_SOURCE_DIR}/../SPIRV-Tools/include"
165 "${EXTERNAL_SOURCE_ROOT}/source/spirv-tools/external/include"
166 DOC "Path to spirv-tools/libspirv.h")
168 find_library(GLSLANG_LIB NAMES glslang
169 HINTS ${GLSLANG_SEARCH_PATH} )
171 find_library(OGLCompiler_LIB NAMES OGLCompiler
172 HINTS ${GLSLANG_SEARCH_PATH} )
174 find_library(OSDependent_LIB NAMES OSDependent
175 HINTS ${GLSLANG_SEARCH_PATH} )
177 find_library(HLSL_LIB NAMES HLSL
178 HINTS ${GLSLANG_SEARCH_PATH} )
180 find_library(SPIRV_LIB NAMES SPIRV
181 HINTS ${GLSLANG_SEARCH_PATH} )
183 find_library(SPIRV_REMAPPER_LIB NAMES SPVRemapper
184 HINTS ${GLSLANG_SEARCH_PATH} )
186 find_library(SPIRV_TOOLS_LIB NAMES SPIRV-Tools
187 HINTS ${SPIRV_TOOLS_SEARCH_PATH} )
190 add_library(glslang STATIC IMPORTED)
191 add_library(OGLCompiler STATIC IMPORTED)
192 add_library(OSDependent STATIC IMPORTED)
193 add_library(HLSL STATIC IMPORTED)
194 add_library(SPIRV STATIC IMPORTED)
195 add_library(SPVRemapper STATIC IMPORTED)
196 add_library(Loader STATIC IMPORTED)
197 add_library(SPIRV-Tools STATIC IMPORTED)
199 find_library(GLSLANG_DLIB NAMES glslangd
200 HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
201 find_library(OGLCompiler_DLIB NAMES OGLCompilerd
202 HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
203 find_library(OSDependent_DLIB NAMES OSDependentd
204 HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
205 find_library(HLSL_DLIB NAMES HLSLd
206 HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
207 find_library(SPIRV_DLIB NAMES SPIRVd
208 HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
209 find_library(SPIRV_REMAPPER_DLIB NAMES SPVRemapperd
210 HINTS ${GLSLANG_DEBUG_SEARCH_PATH} )
211 find_library(SPIRV_TOOLS_DLIB NAMES SPIRV-Tools
212 HINTS ${SPIRV_TOOLS_DEBUG_SEARCH_PATH} )
214 set_target_properties(glslang PROPERTIES
215 IMPORTED_LOCATION "${GLSLANG_LIB}"
216 IMPORTED_LOCATION_DEBUG "${GLSLANG_DLIB}")
217 set_target_properties(OGLCompiler PROPERTIES
218 IMPORTED_LOCATION "${OGLCompiler_LIB}"
219 IMPORTED_LOCATION_DEBUG "${OGLCompiler_DLIB}")
220 set_target_properties(OSDependent PROPERTIES
221 IMPORTED_LOCATION "${OSDependent_LIB}"
222 IMPORTED_LOCATION_DEBUG "${OSDependent_DLIB}")
223 set_target_properties(HLSL PROPERTIES
224 IMPORTED_LOCATION "${HLSL_LIB}"
225 IMPORTED_LOCATION_DEBUG "${HLSL_DLIB}")
226 set_target_properties(SPIRV PROPERTIES
227 IMPORTED_LOCATION "${SPIRV_LIB}"
228 IMPORTED_LOCATION_DEBUG "${SPIRV_DLIB}")
229 set_target_properties(SPVRemapper PROPERTIES
230 IMPORTED_LOCATION "${SPIRV_REMAPPER_LIB}"
231 IMPORTED_LOCATION_DEBUG "${SPIRV_REMAPPER_DLIB}")
232 set_target_properties(SPIRV-Tools PROPERTIES
233 IMPORTED_LOCATION "${SPIRV_TOOLS_LIB}"
234 IMPORTED_LOCATION_DEBUG "${SPIRV_TOOLS_DLIB}")
236 set (GLSLANG_LIBRARIES glslang OGLCompiler OSDependent HLSL SPIRV SPVRemapper)
237 set (SPIRV_TOOLS_LIBRARIES SPIRV-Tools)
239 set (GLSLANG_LIBRARIES ${GLSLANG_LIB} ${OGLCompiler_LIB} ${OSDependent_LIB} ${HLSL_LIB} ${SPIRV_LIB} ${SPIRV_REMAPPER_LIB})
240 set (SPIRV_TOOLS_LIBRARIES ${SPIRV_TOOLS_LIB})
243 set (PYTHON_CMD ${PYTHON_EXECUTABLE})
246 include(GNUInstallDirs)
248 add_definitions(-DSYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}")
249 add_definitions(-DDATADIR="${CMAKE_INSTALL_FULL_DATADIR}")
251 # Make sure /etc is searched by the loader
252 if (NOT (CMAKE_INSTALL_FULL_SYSCONFDIR STREQUAL "/etc"))
253 add_definitions(-DEXTRASYSCONFDIR="/etc")
256 # Make sure /usr/share is searched by the loader
257 if (NOT (CMAKE_INSTALL_FULL_DATADIR STREQUAL "/usr/share"))
258 add_definitions(-DEXTRADATADIR="/usr/share")
263 install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/vulkan" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
266 # loader: Generic VULKAN ICD loader
267 # tests: VULKAN tests
269 add_subdirectory(loader)
273 add_subdirectory(tests)
277 add_subdirectory(layers)
281 add_subdirectory(demos)
285 add_subdirectory(libs/vkjson)