Cmake: Add files needed to build with Mir
[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 endif()
23
24 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
25
26 set(SCRIPTS_DIR "${CMAKE_SOURCE_DIR}/scripts")
27
28 # Header file for CMake settings
29 include_directories("${PROJECT_SOURCE_DIR}/include")
30
31 if(NOT WIN32)
32     include(FindPkgConfig)
33 endif()
34
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")
40     if (UNIX)
41         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
42         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
43     endif()
44 endif()
45
46 if(WIN32)
47     # Disable RTTI
48     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
49 endif()
50
51 if(NOT WIN32)
52     if (BUILD_WSI_XCB_SUPPORT)
53         find_package(XCB REQUIRED)
54     endif()
55     set (BUILDTGT_DIR build)
56     set (BINDATA_DIR Bin)
57     set (LIBSOURCE_DIR Lib)
58 else()
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)
61
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)
66         set (BUILDTGT_DIR "")
67         set (BINDATA_DIR "")
68         set (LIBSOURCE_DIR "")
69     elseif (CMAKE_CL_64)
70         set (BUILDTGT_DIR build)
71         set (BINDATA_DIR Bin)
72         set (LIBSOURCE_DIR Lib)
73     else()
74         set (BUILDTGT_DIR build32)
75         set (BINDATA_DIR Bin32)
76         set (LIBSOURCE_DIR Lib32)
77     endif()
78 endif()
79
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)
87
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")
91
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")
94
95
96 if (WIN32)
97     if(CUSTOM_GLSLANG_BIN_ROOT)
98         set(GSLANG_FINAL_BINARY_PATH ${GLSLANG_BINARY_ROOT}/${BUILDTGT_DIR})
99     else()
100         set(GSLANG_FINAL_BINARY_PATH "${EXTERNAL_SOURCE_ROOT}/glslang/${BUILDTGT_DIR}")
101     endif()
102
103     if(DISABLE_BUILD_PATH_DECORATION)
104         set (DEBUG_DECORATION "")
105         set (RELEASE_DECORATION "")
106     else()
107         set (DEBUG_DECORATION "Debug")
108         set (RELEASE_DECORATION "Release")
109     endif()
110
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}" )
117
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}")
123
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}")
127     else()
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}")
130     endif()
131 else()
132     #non windows
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")
141     else()
142         set (GLSLANG_SEARCH_PATH "${EXTERNAL_SOURCE_ROOT}/glslang/${BUILDTGT_DIR}/install/lib" "${CMAKE_SOURCE_DIR}/../x86_64/lib/glslang" )
143     endif()
144
145     if(CUSTOM_SPIRV_TOOLS_BIN_ROOT)
146         set (SPIRV_TOOLS_SEARCH_PATH "${SPIRV_TOOLS_BINARY_ROOT}/source" )
147     else()
148         set (SPIRV_TOOLS_SEARCH_PATH "${EXTERNAL_SOURCE_ROOT}/spirv-tools/${BUILDTGT_DIR}/source" "${CMAKE_SOURCE_DIR}/../x86_64/lib/spirv-tools" )
149     endif()
150 endif()
151
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}")
156
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")
160
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")
167
168 find_library(GLSLANG_LIB NAMES glslang
169              HINTS ${GLSLANG_SEARCH_PATH} )
170
171 find_library(OGLCompiler_LIB NAMES OGLCompiler
172              HINTS ${GLSLANG_SEARCH_PATH} )
173
174 find_library(OSDependent_LIB NAMES OSDependent
175              HINTS ${GLSLANG_SEARCH_PATH} )
176
177 find_library(HLSL_LIB NAMES HLSL
178              HINTS ${GLSLANG_SEARCH_PATH} )
179
180 find_library(SPIRV_LIB NAMES SPIRV
181              HINTS ${GLSLANG_SEARCH_PATH} )
182
183 find_library(SPIRV_REMAPPER_LIB NAMES SPVRemapper
184              HINTS ${GLSLANG_SEARCH_PATH} )
185
186 find_library(SPIRV_TOOLS_LIB NAMES SPIRV-Tools
187              HINTS ${SPIRV_TOOLS_SEARCH_PATH} )
188
189 if (WIN32)
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)
198
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} )
213
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}")
235
236     set (GLSLANG_LIBRARIES glslang OGLCompiler OSDependent HLSL SPIRV SPVRemapper)
237     set (SPIRV_TOOLS_LIBRARIES SPIRV-Tools)
238 else ()
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})
241 endif()
242
243 set (PYTHON_CMD ${PYTHON_EXECUTABLE})
244
245 if(NOT WIN32)
246     include(GNUInstallDirs)
247
248     add_definitions(-DSYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}")
249     add_definitions(-DDATADIR="${CMAKE_INSTALL_FULL_DATADIR}")
250
251     # Make sure /etc is searched by the loader
252     if (NOT (CMAKE_INSTALL_FULL_SYSCONFDIR STREQUAL "/etc"))
253         add_definitions(-DEXTRASYSCONFDIR="/etc")
254     endif()
255
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")
259     endif()
260 endif()
261
262 if(UNIX)
263     install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/vulkan" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
264 endif()
265
266 # loader: Generic VULKAN ICD loader
267 # tests: VULKAN tests
268 if(BUILD_LOADER)
269     add_subdirectory(loader)
270 endif()
271
272 if(BUILD_TESTS)
273     add_subdirectory(tests)
274 endif()
275
276 if(BUILD_LAYERS)
277     add_subdirectory(layers)
278 endif()
279
280 if(BUILD_DEMOS)
281     add_subdirectory(demos)
282 endif()
283
284 if(BUILD_VKJSON)
285     add_subdirectory(libs/vkjson)
286 endif()