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