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