cmake: Remove building and setup of glslang
[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
6 # This must come before the project command.
7 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "Minimum OS X deployment version")
8
9 project (VULKAN)
10 # set (CMAKE_VERBOSE_MAKEFILE 1)
11
12 # The API_NAME allows renaming builds to avoid conflicts with installed SDKs
13 # The MAJOR number of the version we're building, used in naming
14 # <api-name>-<major>.dll (and other files).
15 set(API_NAME "Vulkan" CACHE STRING "API name to use when building")
16 set(MAJOR "1")
17 string(TOLOWER ${API_NAME} API_LOWERCASE)
18
19 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
20 find_package(PythonInterp 3 REQUIRED)
21
22 # If CMAKE 3.7+, use FindVulkan
23 if (NOT CMAKE_VERSION VERSION_LESS 3.7.0)
24     message(STATUS "Using find_package to locate Vulkan")
25     find_package(Vulkan)
26 endif()
27
28 option(USE_CCACHE "Use ccache" OFF)
29 if (USE_CCACHE)
30     find_program(CCACHE_FOUND ccache)
31     if(CCACHE_FOUND)
32         set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
33         set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
34     endif(CCACHE_FOUND)
35 endif()
36
37 if(APPLE)
38     # CMake versions 3 or later need CMAKE_MACOSX_RPATH defined.
39     # This avoids the CMP0042 policy message.
40     set(CMAKE_MACOSX_RPATH 1)
41     # The "install" target for MacOS fixes up bundles in place.
42     set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
43 endif()
44
45 # Enable cmake folders
46 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
47 set(LVL_TARGET_FOLDER lvl_cmake_targets)
48
49 if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
50     set(FALLBACK_CONFIG_DIRS "/etc/xdg" CACHE STRING
51         "Search path to use when XDG_CONFIG_DIRS is unset or empty or the current process is SUID/SGID. Default is freedesktop compliant.")
52     set(FALLBACK_DATA_DIRS "/usr/local/share:/usr/share" CACHE STRING
53         "Search path to use when XDG_DATA_DIRS is unset or empty or the current process is SUID/SGID. Default is freedesktop compliant.")
54 endif()
55
56 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
57     include(FindPkgConfig)
58     option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON)
59     option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON)
60     option(BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" ON)
61     option(BUILD_WSI_MIR_SUPPORT "Build Mir WSI support" OFF)
62     set(DEMOS_WSI_SELECTION "XCB" CACHE STRING "Select WSI target for demos (XCB, XLIB, WAYLAND, MIR, DISPLAY)")
63
64     if (BUILD_WSI_XCB_SUPPORT)
65         find_package(XCB REQUIRED)
66     endif()
67
68     if (BUILD_WSI_XLIB_SUPPORT)
69         find_package(X11 REQUIRED)
70     endif()
71
72     if (BUILD_WSI_WAYLAND_SUPPORT)
73         find_package(Wayland REQUIRED)
74         include_directories(${WAYLAND_CLIENT_INCLUDE_DIR})
75     endif()
76
77     if (BUILD_WSI_MIR_SUPPORT)
78         find_package(Mir REQUIRED)
79     endif()
80
81 endif()
82
83 set(SCRIPTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/scripts")
84
85 # Header file for CMake settings
86 include_directories("${PROJECT_SOURCE_DIR}/include")
87
88 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
89     set(COMMON_COMPILE_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
90     set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -fno-strict-aliasing -fno-builtin-memcmp")
91
92     # For GCC version 7.1 or greater, we need to disable the implicit fallthrough warning since
93     # there's no consistent way to satisfy all compilers until they all accept the C++17 standard
94     if (CMAKE_COMPILER_IS_GNUCC AND NOT (CMAKE_CXX_COMPILER_VERSION LESS 7.1))
95         set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -Wimplicit-fallthrough=0")
96     endif()
97
98     if (APPLE)
99         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_COMPILE_FLAGS}")
100     else()
101         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 ${COMMON_COMPILE_FLAGS}")
102     endif()
103     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_COMPILE_FLAGS} -std=c++11 -fno-rtti")
104     if (UNIX)
105         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
106         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
107     endif()
108 endif()
109
110 if(WIN32)
111     # Treat warnings as errors
112     add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/WX>")
113     # Disable RTTI
114     add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/GR->")
115     # Warn about nested declarations
116     add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/w34456>")
117     # Warn about potentially uninitialized variables
118     add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/w34701>")
119     add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/w34703>")
120     # Warn about different indirection types.
121     add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/w34057>")
122     # Warn about signed/unsigned mismatch.
123     add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/w34245>")
124 endif()
125
126 if(NOT WIN32)
127     set (BUILDTGT_DIR build)
128     set (BINDATA_DIR Bin)
129     set (LIBSOURCE_DIR Lib)
130 else()
131     # is WIN32
132     option(DISABLE_BUILD_PATH_DECORATION "Disable the decoration of the gslang and SPIRV-Tools build path with MSVC build type info" OFF)
133     option(DISABLE_BUILDTGT_DIR_DECORATION "Disable the decoration of the gslang and SPIRV-Tools build path with target info" OFF)
134     option(ENABLE_WIN10_ONECORE "Link the loader with OneCore umbrella libraries" OFF)
135
136     # For Windows, since 32-bit and 64-bit items can co-exist, we build each in its own build directory.
137     # 32-bit target data goes in build32, and 64-bit target data goes into build.  So, include/link the
138     # appropriate data at build time.
139     if (DISABLE_BUILDTGT_DIR_DECORATION)
140         set (BUILDTGT_DIR "")
141         set (BINDATA_DIR "")
142         set (LIBSOURCE_DIR "")
143     elseif (CMAKE_CL_64)
144         set (BUILDTGT_DIR build)
145         set (BINDATA_DIR Bin)
146         set (LIBSOURCE_DIR Lib)
147     else()
148         set (BUILDTGT_DIR build32)
149         set (BINDATA_DIR Bin32)
150         set (LIBSOURCE_DIR Lib32)
151     endif()
152 endif()
153
154 option(BUILD_DEMOS "Build demos" ON)
155 option(BUILD_ICD "Build icd" ON)
156
157 find_program(GLSLANG_VALIDATOR NAMES glslangValidator
158              HINTS "${EXTERNAL_SOURCE_ROOT}/glslang/${BUILDTGT_DIR}/install/bin"
159                    "${GLSLANG_BINARY_ROOT}/StandAlone"
160                    "${PROJECT_SOURCE_DIR}/external/${BINDATA_DIR}")
161
162 find_library(Vulkan_LIBRARY NAMES vulkan-1 vulkan
163              HINTS ${VK_SDK_PATH} )
164
165
166 set (PYTHON_CMD ${PYTHON_EXECUTABLE})
167
168 # Move to icd dir 
169 # Define macro used for building vkxml generated files
170 macro(run_vk_xml_generate dependency output)
171     add_custom_command(OUTPUT ${output}
172     COMMAND ${PYTHON_CMD} ${SCRIPTS_DIR}/lvl_genvk.py -registry ${SCRIPTS_DIR}/vk.xml ${output}
173     DEPENDS ${SCRIPTS_DIR}/vk.xml ${SCRIPTS_DIR}/generator.py ${SCRIPTS_DIR}/${dependency} ${SCRIPTS_DIR}/lvl_genvk.py ${SCRIPTS_DIR}/reg.py
174     )
175 endmacro()
176
177 if(UNIX)
178     if(INSTALL_LVL_FILES)
179         install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/vulkan" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
180     endif()
181
182     # uninstall target
183     configure_file(
184         "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
185         "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
186         IMMEDIATE @ONLY)
187
188     add_custom_target(uninstall
189         COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
190 endif()
191
192 add_definitions(-DAPI_NAME="${API_NAME}")
193
194 if(BUILD_DEMOS)
195     add_subdirectory(demos)
196 endif()
197 if(BUILD_ICD)
198     add_subdirectory(icd)
199 endif()