• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 The Amber Authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15if (${AMBER_ENABLE_TESTS})
16  if (${AMBER_ENABLE_SHARED_CRT})
17    set(gtest_force_shared_crt ON)
18  endif()
19  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/googletest EXCLUDE_FROM_ALL)
20endif()
21
22if (${AMBER_ENABLE_SPIRV_TOOLS})
23  set(SPIRV-Headers_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/spirv-headers CACHE STRING "")
24  set(SPIRV_SKIP_TESTS ON CACHE BOOL ON)
25  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/spirv-tools EXCLUDE_FROM_ALL)
26endif()
27
28if (${AMBER_ENABLE_SHADERC})
29  set(ENABLE_HLSL ON CACHE BOOL ON)
30  set(BUILD_TESTING FALSE CACHE BOOL ON)
31  set(ENABLE_GLSLANG_BINARIES OFF CACHE BOOL ON)
32  set(ENABLE_SPVREMAPPER OFF CACHE BOOL ON)
33  # Tell Glslang to statically link the C Runtime library.
34  set(LLVM_USE_CRT_DEBUG MTd CACHE STRING "")
35  set(LLVM_USE_CRT_RELEASE MT CACHE STRING "")
36  set(LLVM_USE_CRT_RELWITHDEBINFO MT CACHE STRING "")
37  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/glslang)
38
39  set(SHADERC_THIRD_PARTY_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "")
40  set(SHADERC_SKIP_TESTS ON CACHE BOOL ON)
41  set(SHADERC_ENABLE_WERROR_COMPILE OFF CACHE BOOL "disable werror")
42
43  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/shaderc)
44endif()
45
46if (${AMBER_ENABLE_SAMPLES} AND ${AMBER_ENABLE_LODEPNG})
47  # Lodepng
48  set(LODEPNG_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/lodepng/lodepng.cpp)
49  add_library(lodepng STATIC ${LODEPNG_SOURCES})
50endif()
51
52if (${AMBER_USE_LOCAL_VULKAN})
53  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vulkan-headers)
54
55  # Skip adding the validation layers and the Vulkan loader on Android.
56  if (NOT ANDROID)
57
58    set(BUILD_TESTS FALSE)
59
60    # The vulkan-loader CMake file assumes that directory exists if
61    # Wayland support is to be built.
62    if(NOT EXISTS ${WAYLAND_CLIENT_INCLUDE_DIR})
63      message(STATUS "Amber: Disabling Wayland support in Vulkan-Loader")
64      set(BUILD_WSI_WAYLAND_SUPPORT OFF CACHE BOOL "" FORCE)
65    endif()
66    message(STATUS "Amber: Disabling X11 support in Vulkan-Loader")
67    set(BUILD_WSI_XLIB_SUPPORT OFF CACHE BOOL "" FORCE)
68
69    set(ROBIN_HOOD_HASHING_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/robin-hood-hashing" CACHE STRING "" FORCE)
70    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/robin-hood-hashing)
71    set(SPIRV_HEADERS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/spirv-headers/include" CACHE STRING "" FORCE)
72
73    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vulkan-loader)
74    if (MSVC)
75      option(BUILD_WERROR "Treat compiler warnings as errors" OFF)
76    endif()
77    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vulkan-validationlayers)
78  endif()
79endif()
80
81if (${AMBER_ENABLE_VK_DEBUGGING})
82  set(CPPDAP_JSON_DIR ${CMAKE_CURRENT_SOURCE_DIR}/json)
83  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cppdap)
84endif()
85
86if (${AMBER_ENABLE_SWIFTSHADER})
87  set(SWIFTSHADER_BUILD_EGL FALSE)
88  set(SWIFTSHADER_BUILD_GLESv2 FALSE)
89  set(SWIFTSHADER_BUILD_GLES_CM FALSE)
90  set(SWIFTSHADER_BUILD_VULKAN TRUE)
91  set(SWIFTSHADER_BUILD_SAMPLES FALSE)
92  set(SWIFTSHADER_BUILD_TESTS FALSE)
93  set(SWIFTSHADER_WARNINGS_AS_ERRORS FALSE)
94  set(SWIFTSHADER_LOGGING_LEVEL "Error")
95
96  if (${AMBER_ENABLE_VK_DEBUGGING})
97    set(SWIFTSHADER_ENABLE_VULKAN_DEBUGGER TRUE)
98    set(SWIFTSHADER_BUILD_CPPDAP FALSE) # Already built above
99  endif (${AMBER_ENABLE_VK_DEBUGGING})
100
101  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/swiftshader)
102endif()
103
104if (${AMBER_ENABLE_DXC})
105  set(DXC_EXTERNAL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE STRING "" FORCE)
106  set(DXC_SPIRV_HEADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/spirv-headers" CACHE PATH "" FORCE)
107  set(DXC_SPIRV_TOOLS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/spirv-tools" CACHE PATH "" FORCE)
108
109  set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "")
110  set(LLVM_APPEND_VC_REV ON CACHE BOOL "")
111  set(LLVM_DEFAULT_TARGET_TRIPLE "dxil-ms-dx" CACHE STRING "")
112  set(LLVM_ENABLE_EH ON CACHE BOOL "")
113  set(LLVM_ENABLE_RTTI ON CACHE BOOL "")
114  set(LLVM_BUILD_EXAMPLES OFF CACHE BOOL "")
115  set(LLVM_BUILD_TESTS ON CACHE BOOL "")
116  set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
117  set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
118  set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
119  set(LLVM_INCLUDE_TOOLS ON CACHE BOOL "")
120  set(LLVM_INCLUDE_UTILS OFF CACHE BOOL "")
121  set(LLVM_USE_CRT_DEBUG MTd CACHE STRING "")
122  set(LLVM_USE_CRT_RELEASE MT CACHE STRING "")
123  set(LLVM_USE_CRT_RELWITHDEBINFO MT CACHE STRING "")
124
125  set(LLVM_OPTIMIZED_TABLEGEN OFF CACHE BOOL "")
126  set(LLVM_REQUIRES_EH ON CACHE BOOL "")
127  set(LLVM_REQUIRES_RTTI ON CACHE BOOL "")
128  set(LLVM_TARGETS_TO_BUILD None CACHE STRING "")
129  set(LIBCLANG_BUILD_STATIC ON CACHE BOOL "")
130  set(CLANG_BUILD_EXAMPLES OFF CACHE BOOL "")
131  set(CLANG_CL OFF CACHE BOOL "")
132  set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
133  set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
134  set(CLANG_INCLUDE_TESTS OFF CACHE BOOL "")
135  set(HLSL_INCLUDE_TESTS OFF CACHE BOOL "")
136  set(ENABLE_SPIRV_CODEGEN ON CACHE BOOL "enable spirv codegen")
137  set(SPIRV_BUILD_TESTS OFF CACHE BOOL "Enable dxc spirv tests")
138
139  set(LLVM_BUILD_STATIC ON CACHE BOOL "")
140  set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
141
142  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/dxc EXCLUDE_FROM_ALL)
143
144  if (MSVC)
145    add_custom_target(dxc-binary ALL
146      DEPENDS "${CMAKE_BINARY_DIR}/third_party/dxc/bin/dxcompiler.dll"
147      COMMENT "dxc-binary custom target")
148
149      ADD_CUSTOM_COMMAND(
150        TARGET dxc-binary
151        POST_BUILD
152        COMMAND ${CMAKE_COMMAND}
153        ARGS -E copy ${CMAKE_BINARY_DIR}/third_party/dxc/bin/dxcompiler.dll ${CMAKE_BINARY_DIR}
154      )
155  endif()
156endif()
157
158if (${AMBER_ENABLE_CLSPV})
159  if (NOT DEFINED AMBER_CLSPV_DIR)
160    set(AMBER_CLSPV_DIR "${CMAKE_CURRENT_SOURCE_DIR}/clspv")
161  endif()
162  if (NOT DEFINED AMBER_CLSPV_LLVM_DIR)
163    set(AMBER_CLSPV_LLVM_DIR "${CMAKE_CURRENT_SOURCE_DIR}/clspv-llvm")
164  endif()
165
166  list(APPEND CMAKE_MODULE_PATH ${AMBER_CLSPV_LLVM_DIR}/llvm/cmake/modules/)
167
168  set(CLSPV_LLVM_SOURCE_DIR "${AMBER_CLSPV_LLVM_DIR}/llvm" CACHE STRING "")
169  set(CLSPV_CLANG_SOURCE_DIR "${AMBER_CLSPV_LLVM_DIR}/clang" CACHE STRING "")
170  set(SPIRV_HEADERS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/spirv-headers" CACHE STRING "")
171  set(SPIRV_TOOLS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/spirv-tools" CACHE STRING "")
172  set(LINKER_SUPPORTS_COLOR_DIAGNOSTICS 0 CACHE INTERNAL 0 FORCE)
173
174  set(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN ON CACHE STRING "")
175  set(LLVM_BUILD_STATIC OFF CACHE BOOL "")
176  set(LLVM_INCLUDE_BENCHMARKS OFF CACHE BOOL "")
177  set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
178  set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
179  set(LLVM_INCLUDE_GO_TESTS OFF CACHE BOOL "")
180  set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
181  set(LLVM_INCLUDE_UTILS OFF CACHE BOOL "")
182
183  add_subdirectory(${AMBER_CLSPV_DIR} ${CMAKE_CURRENT_BINARY_DIR}/clspv)
184
185  # TODO(asuonpaa): Using the latest LLVM gives multiple warnings of using deprecated
186  # arguments. Remove this when CLSPV doesn't use them.
187  add_compile_options(clspv, NO_DEPRECATED_FLAGS)
188endif()
189