• 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
71    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vulkan-loader)
72    if (MSVC)
73      option(BUILD_WERROR "Treat compiler warnings as errors" OFF)
74    endif()
75    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vulkan-validationlayers)
76  endif()
77endif()
78
79if (${AMBER_ENABLE_VK_DEBUGGING})
80  set(CPPDAP_JSON_DIR ${CMAKE_CURRENT_SOURCE_DIR}/json)
81  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cppdap)
82endif()
83
84if (${AMBER_ENABLE_SWIFTSHADER})
85  set(SWIFTSHADER_BUILD_EGL FALSE)
86  set(SWIFTSHADER_BUILD_GLESv2 FALSE)
87  set(SWIFTSHADER_BUILD_GLES_CM FALSE)
88  set(SWIFTSHADER_BUILD_VULKAN TRUE)
89  set(SWIFTSHADER_BUILD_SAMPLES FALSE)
90  set(SWIFTSHADER_BUILD_TESTS FALSE)
91  set(SWIFTSHADER_WARNINGS_AS_ERRORS FALSE)
92  set(SWIFTSHADER_LOGGING_LEVEL "Error")
93
94  if (${AMBER_ENABLE_VK_DEBUGGING})
95    set(SWIFTSHADER_ENABLE_VULKAN_DEBUGGER TRUE)
96    set(SWIFTSHADER_BUILD_CPPDAP FALSE) # Already built above
97  endif (${AMBER_ENABLE_VK_DEBUGGING})
98
99  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/swiftshader)
100endif()
101
102if (${AMBER_ENABLE_DXC})
103  set(DXC_EXTERNAL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE STRING "" FORCE)
104  set(DXC_SPIRV_HEADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/spirv-headers" CACHE PATH "" FORCE)
105  set(DXC_SPIRV_TOOLS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/spirv-tools" CACHE PATH "" FORCE)
106
107  set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "")
108  set(LLVM_APPEND_VC_REV ON CACHE BOOL "")
109  set(LLVM_DEFAULT_TARGET_TRIPLE "dxil-ms-dx" CACHE STRING "")
110  set(LLVM_ENABLE_EH ON CACHE BOOL "")
111  set(LLVM_ENABLE_RTTI ON CACHE BOOL "")
112  set(LLVM_BUILD_EXAMPLES OFF CACHE BOOL "")
113  set(LLVM_BUILD_TESTS ON CACHE BOOL "")
114  set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
115  set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
116  set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
117  set(LLVM_INCLUDE_TOOLS ON CACHE BOOL "")
118  set(LLVM_INCLUDE_UTILS OFF CACHE BOOL "")
119  set(LLVM_USE_CRT_DEBUG MTd CACHE STRING "")
120  set(LLVM_USE_CRT_RELEASE MT CACHE STRING "")
121  set(LLVM_USE_CRT_RELWITHDEBINFO MT CACHE STRING "")
122
123  set(LLVM_OPTIMIZED_TABLEGEN OFF CACHE BOOL "")
124  set(LLVM_REQUIRES_EH ON CACHE BOOL "")
125  set(LLVM_REQUIRES_RTTI ON CACHE BOOL "")
126  set(LLVM_TARGETS_TO_BUILD None CACHE STRING "")
127  set(LIBCLANG_BUILD_STATIC ON CACHE BOOL "")
128  set(CLANG_BUILD_EXAMPLES OFF CACHE BOOL "")
129  set(CLANG_CL OFF CACHE BOOL "")
130  set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
131  set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
132  set(CLANG_INCLUDE_TESTS OFF CACHE BOOL "")
133  set(HLSL_INCLUDE_TESTS OFF CACHE BOOL "")
134  set(ENABLE_SPIRV_CODEGEN ON CACHE BOOL "enable spirv codegen")
135  set(SPIRV_BUILD_TESTS OFF CACHE BOOL "Enable dxc spirv tests")
136
137  set(LLVM_BUILD_STATIC ON CACHE BOOL "")
138  set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
139
140  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/dxc EXCLUDE_FROM_ALL)
141
142  if (MSVC)
143    add_custom_target(dxc-binary ALL
144      DEPENDS "${CMAKE_BINARY_DIR}/third_party/dxc/bin/dxcompiler.dll"
145      COMMENT "dxc-binary custom target")
146
147      ADD_CUSTOM_COMMAND(
148        TARGET dxc-binary
149        POST_BUILD
150        COMMAND ${CMAKE_COMMAND}
151        ARGS -E copy ${CMAKE_BINARY_DIR}/third_party/dxc/bin/dxcompiler.dll ${CMAKE_BINARY_DIR}
152      )
153  endif()
154endif()
155
156if (${AMBER_ENABLE_CLSPV})
157  if (NOT DEFINED AMBER_CLSPV_DIR)
158    set(AMBER_CLSPV_DIR "${CMAKE_CURRENT_SOURCE_DIR}/clspv")
159  endif()
160  if (NOT DEFINED AMBER_CLSPV_LLVM_DIR)
161    set(AMBER_CLSPV_LLVM_DIR "${CMAKE_CURRENT_SOURCE_DIR}/clspv-llvm")
162  endif()
163
164  list(APPEND CMAKE_MODULE_PATH ${AMBER_CLSPV_LLVM_DIR}/llvm/cmake/modules/)
165
166  set(CLSPV_LLVM_SOURCE_DIR "${AMBER_CLSPV_LLVM_DIR}/llvm" CACHE STRING "")
167  set(CLSPV_CLANG_SOURCE_DIR "${AMBER_CLSPV_LLVM_DIR}/clang" CACHE STRING "")
168  set(SPIRV_HEADERS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/spirv-headers" CACHE STRING "")
169  set(SPIRV_TOOLS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/spirv-tools" CACHE STRING "")
170  set(LINKER_SUPPORTS_COLOR_DIAGNOSTICS 0 CACHE INTERNAL 0 FORCE)
171
172  set(LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN ON CACHE STRING "")
173  set(LLVM_BUILD_STATIC OFF CACHE BOOL "")
174  set(LLVM_INCLUDE_BENCHMARKS OFF CACHE BOOL "")
175  set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
176  set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
177  set(LLVM_INCLUDE_GO_TESTS OFF CACHE BOOL "")
178  set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
179  set(LLVM_INCLUDE_UTILS OFF CACHE BOOL "")
180
181  add_subdirectory(${AMBER_CLSPV_DIR} ${CMAKE_CURRENT_BINARY_DIR}/clspv)
182
183  # TODO(asuonpaa): Using the latest LLVM gives multiple warnings of using deprecated
184  # arguments. Remove this when CLSPV doesn't use them.
185  add_compile_options(clspv, NO_DEPRECATED_FLAGS)
186endif()
187