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