blob: 1ffa3d8fdd36061698800bef74f58ac270d10c47 [file] [log] [blame]
Ryan Harrisone87ac762022-04-06 15:37:27 -04001# Copyright 2022 The Dawn & Tint Authors
Corentin Wallez7fe6efb2020-02-05 17:16:05 +00002#
Austin Engcc2516a2023-10-17 20:57:54 +00003# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions are met:
Corentin Wallez7fe6efb2020-02-05 17:16:05 +00005#
Austin Engcc2516a2023-10-17 20:57:54 +00006# 1. Redistributions of source code must retain the above copyright notice, this
7# list of conditions and the following disclaimer.
Corentin Wallez7fe6efb2020-02-05 17:16:05 +00008#
Austin Engcc2516a2023-10-17 20:57:54 +00009# 2. Redistributions in binary form must reproduce the above copyright notice,
10# this list of conditions and the following disclaimer in the documentation
11# and/or other materials provided with the distribution.
12#
13# 3. Neither the name of the copyright holder nor the names of its
14# contributors may be used to endorse or promote products derived from
15# this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000027
Aleksi Sapon9a106742021-09-28 16:48:01 +000028# Don't build testing in third_party dependencies
29set(BUILD_TESTING OFF)
30
Elie Michel9ae8ed22023-05-12 20:19:41 +000031# fetch_dawn_dependencies.py is an alternative to using depot_tools
32# It is particularly interesting when building dawn as a subdirectory in
33# a parent project that does not want to use depot_tools.
dan sinclair12c428f2024-06-21 01:14:24 +000034if (DAWN_FETCH_DEPENDENCIES)
Elie Michel9ae8ed22023-05-12 20:19:41 +000035 set(EXTRA_FETCH_ARGS)
Lokbondo Kung868a4672024-10-25 20:17:03 +000036 if (NOT TARGET gmock AND (DAWN_BUILD_TESTS OR TINT_BUILD_TESTS))
Elie Michel9ae8ed22023-05-12 20:19:41 +000037 list(APPEND EXTRA_FETCH_ARGS --use-test-deps)
38 endif()
39
40 message(STATUS "Running fetch_dawn_dependencies:")
41 execute_process(
42 COMMAND
Corentin Wallez299ad592024-03-28 20:21:11 +000043 ${Python3_EXECUTABLE}
Elie Michel9ae8ed22023-05-12 20:19:41 +000044 "${PROJECT_SOURCE_DIR}/tools/fetch_dawn_dependencies.py"
45 --directory ${PROJECT_SOURCE_DIR}
46 ${EXTRA_FETCH_ARGS}
47 )
48endif ()
49
Loko Kung90fdaa82024-07-24 00:59:58 +000050################################################################################
51# Start of Emscripten enabled third party directories
52# To minimize the number of third party targets to make when building with
53# Emscripten to the minimal set, only subdirectories added within the Start
54# and End of the Emscripten block are enabled .
55################################################################################
56
57if (NOT TARGET absl::strings)
58 # Recommended setting for compability with future abseil releases.
59 set(ABSL_PROPAGATE_CXX_STD ON CACHE BOOL "" FORCE)
60 message(STATUS "Dawn: using Abseil at ${DAWN_ABSEIL_DIR}")
61 if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") OR
62 ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang"))
63 add_compile_options(
64 -Wno-array-parameter
65 -Wno-deprecated-builtins
66 -Wno-unknown-warning-option
67 )
68 endif()
69
70 add_subdirectory(${DAWN_ABSEIL_DIR} "${CMAKE_CURRENT_BINARY_DIR}/abseil")
71endif()
72
Lokbondo Kung868a4672024-10-25 20:17:03 +000073if ((DAWN_BUILD_TESTS OR TINT_BUILD_TESTS) AND NOT TARGET gmock)
74 set(gtest_force_shared_crt ON CACHE BOOL "Controls whether a shared run-time library should be used even when Google Test is built as static library" FORCE)
75 if (${DAWN_ENABLE_EMSCRIPTEN})
76 # For Emscripten builds, we need to disable pthreads.
77 set(gtest_disable_pthreads ON)
78 endif()
Kai Ninomiya84563872024-11-01 23:04:25 +000079
80 # We don't use exceptions, so we don't need gtest to handle them. Emscripten
81 # builds in particular, with JSPI enabled, crash without this enabled.
82 # There doesn't seem to be an option to tell the gtest build files to do
83 # this, so we set it globally. (This seems to be the intended usage.)
84 add_definitions(-DGTEST_HAS_EXCEPTIONS=0)
85
Lokbondo Kung868a4672024-10-25 20:17:03 +000086 add_subdirectory(${DAWN_GOOGLETEST_DIR} "${CMAKE_CURRENT_BINARY_DIR}/googletest" EXCLUDE_FROM_ALL)
87endif()
88
Loko Kung90fdaa82024-07-24 00:59:58 +000089################################################################################
90# End of Emscripten enabled third party directories
91################################################################################
92if (${DAWN_ENABLE_EMSCRIPTEN})
93 return()
94endif()
95
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000096if (NOT TARGET SPIRV-Headers)
Corentin Wallez42450c62020-04-10 17:04:31 +000097 set(SPIRV_HEADERS_SKIP_EXAMPLES ON CACHE BOOL "" FORCE)
98 set(SPIRV_HEADERS_SKIP_INSTALL ON CACHE BOOL "" FORCE)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000099
100 message(STATUS "Dawn: using SPIRV-Headers at ${DAWN_SPIRV_HEADERS_DIR}")
Aleksi Sapon9a106742021-09-28 16:48:01 +0000101 add_subdirectory(${DAWN_SPIRV_HEADERS_DIR} "${CMAKE_CURRENT_BINARY_DIR}/spirv-headers")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000102endif()
103
Jaswant Panchumarti4660e722024-06-21 13:26:45 +0000104if (NOT TARGET SPIRV-Tools AND
105 (((DAWN_ENABLE_OPENGL OR DAWN_ENABLE_VULKAN)
106 AND DAWN_ENABLE_SPIRV_VALIDATION)
107 OR TINT_BUILD_SPV_READER
108 OR TINT_BUILD_SPV_WRITER
109 OR DAWN_USE_BUILT_DXC))
Jaswant Panchumarti22e78152024-06-21 15:44:23 +0000110 set(SPIRV_SKIP_TESTS ON CACHE BOOL "Controls whether SPIR-V tests are run" FORCE)
Corentin Wallez42450c62020-04-10 17:04:31 +0000111 set(SPIRV_SKIP_EXECUTABLES ON CACHE BOOL "" FORCE)
112 set(SKIP_SPIRV_TOOLS_INSTALL ON CACHE BOOL "" FORCE)
Jaswant Panchumarti22e78152024-06-21 15:44:23 +0000113 set(SPIRV_WERROR OFF CACHE BOOL OFF FORCE)
Ryan Harrisone87ac762022-04-06 15:37:27 -0400114
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000115 message(STATUS "Dawn: using SPIRV-Tools at ${DAWN_SPIRV_TOOLS_DIR}")
Ryan Harrisone87ac762022-04-06 15:37:27 -0400116 add_subdirectory(${DAWN_SPIRV_TOOLS_DIR} "${CMAKE_CURRENT_BINARY_DIR}/spirv-tools" EXCLUDE_FROM_ALL)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000117endif()
118
dan sinclair12c428f2024-06-21 01:14:24 +0000119if(NOT TARGET glslang AND (TINT_BUILD_GLSL_WRITER OR TINT_BUILD_GLSL_VALIDATOR) AND TINT_BUILD_CMD_TOOLS)
Corentin Wallezf9f1c4b2022-05-16 09:11:21 +0000120 set(SKIP_GLSLANG_INSTALL ON CACHE BOOL "" FORCE)
Corentin Wallez2f18c9a2024-04-02 08:51:45 +0000121 set(ENABLE_OPT OFF CACHE BOOL "" FORCE)
dan sinclair12c428f2024-06-21 01:14:24 +0000122 message(STATUS "Dawn: using GLSLang at ${DAWN_GLSLANG_DIR}")
Jaswant Panchumartib415b2e52024-06-28 13:21:16 +0000123 # https://github.com/KhronosGroup/glslang/issues/2283
124 # glslang does not export symbols properly when BUILD_SHARED_LIBS=1, so always build it as static for now.
125 set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS})
126 set(BUILD_SHARED_LIBS 0)
dan sinclair12c428f2024-06-21 01:14:24 +0000127 add_subdirectory("${DAWN_GLSLANG_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/glslang" EXCLUDE_FROM_ALL)
Jaswant Panchumartib415b2e52024-06-28 13:21:16 +0000128 set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED})
Corentin Wallezf9f1c4b2022-05-16 09:11:21 +0000129endif()
130
Erin Melucci38b58e42023-06-14 16:45:33 +0000131if (NOT TARGET glfw AND DAWN_USE_GLFW)
Ben Clayton0ecd67a2021-09-23 20:13:53 +0000132 set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
133 set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
134 set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
Corentin Wallez978bc122023-05-15 13:01:16 +0000135 set(GLFW_BUILD_X11 ${DAWN_USE_X11} CACHE BOOL "" FORCE)
136 set(GLFW_BUILD_WAYLAND ${DAWN_USE_WAYLAND} CACHE BOOL "" FORCE)
Jaswant Panchumarti05e84172024-06-28 13:40:34 +0000137 set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
Ben Clayton0ecd67a2021-09-23 20:13:53 +0000138
139 message(STATUS "Dawn: using GLFW at ${DAWN_GLFW_DIR}")
Aleksi Sapon9a106742021-09-28 16:48:01 +0000140 add_subdirectory(${DAWN_GLFW_DIR} "${CMAKE_CURRENT_BINARY_DIR}/glfw")
Ben Clayton0ecd67a2021-09-23 20:13:53 +0000141endif()
142
dan sinclair0c27cf22024-06-11 12:31:38 +0000143if (DAWN_BUILD_PROTOBUF AND NOT TARGET libprotobuf-mutator)
Ryan Harrison25e23b32024-05-27 23:21:05 +0000144 message(STATUS "Dawn: using LPM at ${DAWN_LPM_DIR}")
145 include("libprotobuf-mutator/BUILD.cmake")
146endif()
147
dan sinclair12c428f2024-06-21 01:14:24 +0000148if (DAWN_ENABLE_DESKTOP_GL OR DAWN_ENABLE_OPENGLES)
149 # Header-only library for khrplatform.h
150 add_library(dawn_khronos_platform INTERFACE)
151 target_sources(dawn_khronos_platform INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/khronos/EGL-Registry/api/KHR/khrplatform.h")
152 target_include_directories(dawn_khronos_platform INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/khronos/EGL-Registry/api")
Loko Kungc96ef432022-04-02 03:02:40 +0000153endif()
154
Jaswant Panchumarti3998f702024-06-22 10:33:03 +0000155if (NOT TARGET Vulkan-Headers AND DAWN_ENABLE_VULKAN)
156 message(STATUS "Dawn: using Vulkan-Headers at ${DAWN_VULKAN_HEADERS_DIR}")
Ryan Harrisone87ac762022-04-06 15:37:27 -0400157
Jaswant Panchumarti3998f702024-06-22 10:33:03 +0000158 set(VULKAN_HEADERS_ENABLE_MODULE OFF)
159 add_subdirectory(${DAWN_VULKAN_HEADERS_DIR} "${CMAKE_CURRENT_BINARY_DIR}/vulkan-headers")
dan sinclair12c428f2024-06-21 01:14:24 +0000160endif()
161
Jaswant Panchumarti0a3b1b92024-06-27 12:34:13 +0000162if (NOT TARGET VulkanUtilityHeaders AND DAWN_ENABLE_VULKAN)
163 message(STATUS "Dawn: using VulkanUtilityLibraries at ${DAWN_VULKAN_UTILITY_LIBRARIES_DIR}")
164 add_subdirectory(${DAWN_VULKAN_UTILITY_LIBRARIES_DIR} "${CMAKE_CURRENT_BINARY_DIR}/vulkan-utility-libraries")
165endif()
166
dan sinclair12c428f2024-06-21 01:14:24 +0000167if (DAWN_ENABLE_SWIFTSHADER AND NOT TARGET vk_swiftshader)
Corentin Wallezbe352ea2022-04-11 16:48:43 +0000168 set(SWIFTSHADER_BUILD_TESTS OFF CACHE BOOL "" FORCE)
169 set(SWIFTSHADER_BUILD_BENCHMARKS OFF CACHE BOOL "" FORCE)
170
171 message(STATUS "Dawn: using Swiftshader at ${DAWN_SWIFTSHADER_DIR}")
172 add_subdirectory(${DAWN_SWIFTSHADER_DIR} "${CMAKE_CURRENT_BINARY_DIR}/swiftshader")
173endif()
174
dan sinclair12c428f2024-06-21 01:14:24 +0000175if (TINT_BUILD_BENCHMARKS OR DAWN_BUILD_BENCHMARKS)
Corentin Wallezf9f1c4b2022-05-16 09:11:21 +0000176 set(BENCHMARK_ENABLE_TESTING FALSE CACHE BOOL FALSE FORCE)
Austin Eng6a7bba52023-04-17 18:11:51 +0000177 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/google_benchmark/src EXCLUDE_FROM_ALL)
Ben Claytonbe2362b2022-01-18 18:58:16 +0000178endif()
179
Antonio Maioranoc5c74802024-08-08 14:45:08 +0000180# Populates 'targets' with list of all targets under 'dir'
181# Use 'get_all_targets_recursive' instead of this macro
182macro(do_get_all_targets_recursive targets dir)
183 get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
184 foreach(subdir ${subdirectories})
185 do_get_all_targets_recursive(${targets} ${subdir})
186 endforeach()
187 get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
188 list(APPEND ${targets} ${current_targets})
189endmacro()
190function(get_all_targets_recursive targets dir)
191 set(targets_out)
192 do_get_all_targets_recursive(targets_out ${dir})
193 set(${targets} ${targets_out} PARENT_SCOPE)
194endfunction()
195
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000196function(AddSubdirectoryDXC)
197 # We use a CMake function so that all these (non-cache) variables are scoped
198 # only to this function.
199 set(HLSL_OPTIONAL_PROJS_IN_DEFAULT OFF)
200 set(HLSL_ENABLE_ANALYZE OFF)
201 set(HLSL_OFFICIAL_BUILD OFF)
202 set(HLSL_ENABLE_FIXED_VER OFF)
203 set(HLSL_BUILD_DXILCONV OFF)
204 set(HLSL_INCLUDE_TESTS OFF)
Jaswant Panchumarti0a3b1b92024-06-27 12:34:13 +0000205 # When bundling up dawn, the object files of dxc must be binary compatible with rest of dawn.
206 # The default value of `OFF` adds a macro `_ITERATOR_DEBUG_LEVEL=0`.
207 # This is a problem in `Debug` builds of dawn because all of dawn's objects get compiled
208 # with `_ITERATOR_DEBUG_LEVEL=2`
209 set(HLSL_ENABLE_DEBUG_ITERATORS ON)
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000210
211 set(ENABLE_SPIRV_CODEGEN OFF)
212 set(SPIRV_BUILD_TESTS OFF)
213
214 set(LLVM_BUILD_RUNTIME ON)
215 set(LLVM_BUILD_EXAMPLES OFF)
216 set(LLVM_BUILD_TESTS OFF)
217 set(LLVM_INCLUDE_TESTS OFF)
218 set(LLVM_INCLUDE_DOCS OFF)
219 set(LLVM_INCLUDE_EXAMPLES OFF)
220 set(LLVM_OPTIMIZED_TABLEGEN OFF)
221 set(LLVM_APPEND_VC_REV OFF)
222 # Enable exception handling (requires RTTI)
223 set(LLVM_ENABLE_RTTI ON)
224 set(LLVM_ENABLE_EH ON)
225 set(CLANG_CL OFF)
226
Antonio Maiorano39357642024-03-27 18:23:32 +0000227 if (DAWN_ENABLE_ASAN AND DAWN_ENABLE_UBSAN)
228 set(LLVM_USE_SANITIZER "Address;Undefined")
229 elseif(DAWN_ENABLE_ASAN)
230 set(LLVM_USE_SANITIZER "Address")
231 elseif(DAWN_ENABLE_UBSAN)
232 set(LLVM_USE_SANITIZER "Undefined")
233 endif()
234
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000235 # Cache variables -- these are *not* scoped to this function
236 set(LLVM_TARGETS_TO_BUILD "None" CACHE STRING "" FORCE)
237 set(LLVM_DEFAULT_TARGET_TRIPLE "dxil-ms-dx" CACHE STRING "" FORCE)
238 set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "" FORCE)
239 set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "" FORCE)
240 set(CLANG_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
241 set(CLANG_INCLUDE_TESTS OFF CACHE BOOL "" FORCE)
Antonio Maioranoe14e4272024-05-07 19:40:19 +0000242 set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "" FORCE)
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000243
Antonio Maiorano76d82192024-01-25 17:45:32 +0000244 if (NOT WIN32)
245 set(DIRECTX_HEADER_INCLUDE_DIR "${DAWN_THIRD_PARTY_DIR}/dxheaders/include")
246 endif()
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000247
248 # Disable HCT.cmake looking for and using clang-format. This is used to compare generated files
249 # against the copy that is committed to the repo, but fails because the DXC .clangformat file is
250 # not visible from our build dir. We don't need this validation, so just disable it.
251 set(CLANG_FORMAT_EXE "" CACHE STRING "" FORCE)
252
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000253 # Override RPATH so that it points to current dir (exe path). This allows both executable and
254 # shared library to be in the same location, which we set below. Note that DXC places places
255 # executables in a bin directory, and shared libraries in a lib directory.
256 if (APPLE)
257 set(CMAKE_INSTALL_NAME_DIR "@rpath")
258 set(CMAKE_INSTALL_RPATH "@executable_path")
259 else()
260 set(CMAKE_INSTALL_RPATH "\$ORIGIN")
261 endif()
262
263 message(STATUS "\nAdding DXC to build:\n")
264 add_subdirectory(dxc
265 # Disable all targets by default, and enable only the dxc and dxcompiler targets (below)
266 EXCLUDE_FROM_ALL
267 )
268 set_target_properties(dxc PROPERTIES EXCLUDE_FROM_ALL FALSE)
269 set_target_properties(dxcompiler PROPERTIES EXCLUDE_FROM_ALL FALSE)
270
Antonio Maioranoc5c74802024-08-08 14:45:08 +0000271 if ((NOT IS_DEBUG_BUILD) AND DAWN_DXC_ENABLE_ASSERTS_IN_NDEBUG)
272 # NOTE: Don't set LLVM_ENABLE_ASSERTIONS because it modifies CMAKE_CXX_FLAGS_* by removing NDEBUG
273 # from it; but this is a global CMake flag that affects all targets, including the non-DXC ones.
274 # Instead, we add '-UNDEBUG', which will come after the default '-DNDEBUG' that comes from
275 # CMAKE_CXX_FLAGS_*, and rely on the fact that compilers will undefine NDEBUG if it comes last
276 # on the compile command line. This was tested on Clang, GCC, and MSVC.
277 # Also note that MSVC will warn about both being defined, which is why DXC/LLVM
278 # removes NDEBUG from CMAKE_CXX_FLAGS_*, but we can live with the warnings.
279 # TODO(crbug.com/358169277): Once we move the 'dxc' directory one level deeper,
280 # use add_definitions instead of getting all targets and setting properties on them.
281 get_all_targets_recursive(ALL_TARGETS ${CMAKE_CURRENT_SOURCE_DIR}/dxc)
282 foreach(t IN LISTS ALL_TARGETS)
283 set_property(TARGET ${t} APPEND PROPERTY COMPILE_OPTIONS "-UNDEBUG")
284 if (NOT MSVC)
285 set_property(TARGET ${t} APPEND PROPERTY COMPILE_DEFINITIONS "_DEBUG")
286 endif()
287 # Reduce binary size by dropping assertion strings
288 set_property(TARGET ${t} APPEND PROPERTY COMPILE_DEFINITIONS "LLVM_ASSERTIONS_NO_STRINGS")
289 # Always trap on asserts for consistent crash logging
290 set_property(TARGET ${t} APPEND PROPERTY COMPILE_DEFINITIONS "LLVM_ASSERTIONS_TRAP")
291 endforeach()
292 endif()
293
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000294 # Override output dir for both targets so that they end up in the same place
295 # as the rest of our binaries. Otherwise, DXC wants its outputs in bin and lib dirs.
296 get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
297 if (isMultiConfig)
298 set_target_properties(dxc dxcompiler PROPERTIES
299 "RUNTIME_OUTPUT_DIRECTORY_DEBUG" "${CMAKE_BINARY_DIR}/$<CONFIG>"
300 "RUNTIME_OUTPUT_DIRECTORY_RELEASE" "${CMAKE_BINARY_DIR}/$<CONFIG>"
301 "LIBRARY_OUTPUT_DIRECTORY_DEBUG" "${CMAKE_BINARY_DIR}/$<CONFIG>"
302 "LIBRARY_OUTPUT_DIRECTORY_RELEASE" "${CMAKE_BINARY_DIR}/$<CONFIG>"
303 )
304 else()
305 set_target_properties(dxc dxcompiler PROPERTIES
306 "RUNTIME_OUTPUT_DIRECTORY" "${CMAKE_BINARY_DIR}"
307 "LIBRARY_OUTPUT_DIRECTORY" "${CMAKE_BINARY_DIR}"
308 )
309 endif()
310
311 # Create a target that copies dxil.dll from the platform SDK
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000312 if (WIN32)
Antonio Maiorano08c4d0a2024-03-19 15:09:08 +0000313 message(STATUS "Finding Windows SDK Directory")
314
315 message(STATUS "Display environment variables:")
316 execute_process(COMMAND ${CMAKE_COMMAND} -E environment COMMAND_ECHO STDOUT)
317
Antonio Maiorano01c4a652024-03-13 19:38:13 +0000318 if(DEFINED ENV{WINDOWSSDKDIR})
319 # If WINDOWSSDKDIR env var is defined, use its value. This is defined, for example, when
320 # using a Visual Studio command prompt.
321 set(WIN10_SDK_PATH "$ENV{WINDOWSSDKDIR}")
Antonio Maiorano08c4d0a2024-03-19 15:09:08 +0000322 message(STATUS "Found WINDOWSSDKDIR environment variable: ${WIN10_SDK_PATH}")
Antonio Maiorano01c4a652024-03-13 19:38:13 +0000323 else()
324 # There's no easy way to get the Windows SDK path in CMake; however, conveniently, DXC
325 # contains a FindD3D12.cmake file that returns WIN10_SDK_PATH and WIN10_SDK_VERSION,
326 # so let's use that.
327 # TODO(crbug.com/tint/2106): Get the Win10 SDK path and version ourselves until
328 # dxc/cmake/modules/FindD3D12.cmake supports non-VS generators.
329 get_filename_component(WIN10_SDK_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" ABSOLUTE CACHE)
Antonio Maiorano08c4d0a2024-03-19 15:09:08 +0000330 message(STATUS "WINDOWSSDKDIR environment variable is not defined, retrieving from registry: ${WIN10_SDK_PATH}")
Antonio Maiorano01c4a652024-03-13 19:38:13 +0000331 endif()
332
Antonio Maiorano08c4d0a2024-03-19 15:09:08 +0000333 message(STATUS "Finding Windows SDK version")
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000334 if (CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION)
335 set (WIN10_SDK_VERSION ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION})
Antonio Maiorano08c4d0a2024-03-19 15:09:08 +0000336 message(STATUS "Found Windows SDK version from CMake variable 'CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION': ${WIN10_SDK_VERSION}")
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000337 else()
338 # CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION may not be defined if, for example,
339 # the Ninja generator is used instead of Visual Studio. Attempt to retrieve the
340 # most recent SDK version from the list of paths under "${WIN10_SDK_PATH}/Include/".
341 file(GLOB sdk_dirs RELATIVE "${WIN10_SDK_PATH}/Include/" "${WIN10_SDK_PATH}/Include/10.*")
342 if (sdk_dirs)
Antonio Maiorano08c4d0a2024-03-19 15:09:08 +0000343 list(POP_BACK sdk_dirs WIN10_SDK_VERSION)
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000344 endif()
345 unset(sdk_dirs)
Antonio Maiorano08c4d0a2024-03-19 15:09:08 +0000346 message(STATUS "Windows SDK version not found from CMake variable 'CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION', attempted to find from SDK path: ${WIN10_SDK_VERSION}")
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000347 endif()
348
349 set(DXIL_DLL_PATH "${WIN10_SDK_PATH}/bin/${WIN10_SDK_VERSION}/x64/dxil.dll")
350 add_custom_target(copy_dxil_dll)
351 add_custom_command(
352 TARGET copy_dxil_dll
353 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DXIL_DLL_PATH} $<TARGET_FILE_DIR:dxcompiler>
354 COMMENT "Copying ${DXIL_DLL_PATH} to $<TARGET_FILE_DIR:dxcompiler>")
355 # Make dxc target depend on copy_dxil_dll
356 add_dependencies(dxc copy_dxil_dll)
357 endif()
358endfunction()
359
360if (DAWN_USE_BUILT_DXC)
361 AddSubdirectoryDXC()
362endif()
Ben Claytonf9a5b712024-03-13 17:37:33 +0000363
364if (TINT_BUILD_TINTD)
365 set(LANGSVR_JSON_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/jsoncpp")
366 add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/jsoncpp" EXCLUDE_FROM_ALL)
367 add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/langsvr" EXCLUDE_FROM_ALL)
368endif()