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