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