Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 1 | # Copyright 2022 The Dawn & Tint Authors |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 2 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | # Redistribution and use in source and binary forms, with or without |
| 4 | # modification, are permitted provided that the following conditions are met: |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 5 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 6 | # 1. Redistributions of source code must retain the above copyright notice, this |
| 7 | # list of conditions and the following disclaimer. |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 8 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 9 | # 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 Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 27 | |
Aleksi Sapon | 9a10674 | 2021-09-28 16:48:01 +0000 | [diff] [blame] | 28 | # Don't build testing in third_party dependencies |
| 29 | set(BUILD_TESTING OFF) |
| 30 | |
Elie Michel | 9ae8ed2 | 2023-05-12 20:19:41 +0000 | [diff] [blame] | 31 | # 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. |
| 34 | if (${DAWN_FETCH_DEPENDENCIES}) |
Elie Michel | 9ae8ed2 | 2023-05-12 20:19:41 +0000 | [diff] [blame] | 35 | set(EXTRA_FETCH_ARGS) |
| 36 | if (NOT TARGET gmock AND ${TINT_BUILD_TESTS}) |
| 37 | list(APPEND EXTRA_FETCH_ARGS --use-test-deps) |
| 38 | endif() |
| 39 | |
| 40 | message(STATUS "Running fetch_dawn_dependencies:") |
| 41 | execute_process( |
| 42 | COMMAND |
Corentin Wallez | 299ad59 | 2024-03-28 20:21:11 +0000 | [diff] [blame] | 43 | ${Python3_EXECUTABLE} |
Elie Michel | 9ae8ed2 | 2023-05-12 20:19:41 +0000 | [diff] [blame] | 44 | "${PROJECT_SOURCE_DIR}/tools/fetch_dawn_dependencies.py" |
| 45 | --directory ${PROJECT_SOURCE_DIR} |
| 46 | ${EXTRA_FETCH_ARGS} |
| 47 | ) |
| 48 | endif () |
| 49 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 50 | if (NOT TARGET SPIRV-Headers) |
Corentin Wallez | 42450c6 | 2020-04-10 17:04:31 +0000 | [diff] [blame] | 51 | set(SPIRV_HEADERS_SKIP_EXAMPLES ON CACHE BOOL "" FORCE) |
| 52 | set(SPIRV_HEADERS_SKIP_INSTALL ON CACHE BOOL "" FORCE) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 53 | |
| 54 | message(STATUS "Dawn: using SPIRV-Headers at ${DAWN_SPIRV_HEADERS_DIR}") |
Aleksi Sapon | 9a10674 | 2021-09-28 16:48:01 +0000 | [diff] [blame] | 55 | add_subdirectory(${DAWN_SPIRV_HEADERS_DIR} "${CMAKE_CURRENT_BINARY_DIR}/spirv-headers") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 56 | endif() |
| 57 | |
| 58 | if (NOT TARGET SPIRV-Tools) |
Corentin Wallez | 42450c6 | 2020-04-10 17:04:31 +0000 | [diff] [blame] | 59 | set(SPIRV_SKIP_TESTS ON CACHE BOOL "" FORCE) |
| 60 | set(SPIRV_SKIP_EXECUTABLES ON CACHE BOOL "" FORCE) |
| 61 | set(SKIP_SPIRV_TOOLS_INSTALL ON CACHE BOOL "" FORCE) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 62 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 63 | if(${TINT_BUILD_SPV_READER} OR ${TINT_BUILD_SPV_WRITER}) |
Corentin Wallez | f9f1c4b | 2022-05-16 09:11:21 +0000 | [diff] [blame] | 64 | set(SPIRV_SKIP_TESTS ON CACHE BOOL "Controls whether SPIR-V tests are run" FORCE) |
| 65 | set(SPIRV_WERROR OFF CACHE BOOL OFF FORCE) |
| 66 | if (${TINT_BUILD_SPIRV_TOOLS_FUZZER}) |
| 67 | set(SPIRV_BUILD_FUZZER ON CACHE BOOL "Controls whether spirv-fuzz is built" FORCE) |
| 68 | endif() |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 69 | endif() |
| 70 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 71 | message(STATUS "Dawn: using SPIRV-Tools at ${DAWN_SPIRV_TOOLS_DIR}") |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 72 | add_subdirectory(${DAWN_SPIRV_TOOLS_DIR} "${CMAKE_CURRENT_BINARY_DIR}/spirv-tools" EXCLUDE_FROM_ALL) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 73 | endif() |
| 74 | |
Antonio Maiorano | 4759145 | 2023-10-19 16:09:04 +0000 | [diff] [blame] | 75 | if(NOT TARGET glslang AND (${TINT_BUILD_GLSL_WRITER} OR ${TINT_BUILD_GLSL_VALIDATOR}) AND ${TINT_BUILD_CMD_TOOLS}) |
Corentin Wallez | f9f1c4b | 2022-05-16 09:11:21 +0000 | [diff] [blame] | 76 | set(SKIP_GLSLANG_INSTALL ON CACHE BOOL "" FORCE) |
Corentin Wallez | 2f18c9a | 2024-04-02 08:51:45 +0000 | [diff] [blame] | 77 | set(ENABLE_OPT OFF CACHE BOOL "" FORCE) |
Corentin Wallez | f9f1c4b | 2022-05-16 09:11:21 +0000 | [diff] [blame] | 78 | add_subdirectory("${DAWN_THIRD_PARTY_DIR}/vulkan-deps/glslang/src" "${CMAKE_CURRENT_BINARY_DIR}/glslang" EXCLUDE_FROM_ALL) |
| 79 | endif() |
| 80 | |
Erin Melucci | 38b58e4 | 2023-06-14 16:45:33 +0000 | [diff] [blame] | 81 | if (NOT TARGET glfw AND DAWN_USE_GLFW) |
Ben Clayton | 0ecd67a | 2021-09-23 20:13:53 +0000 | [diff] [blame] | 82 | set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) |
| 83 | set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) |
| 84 | set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) |
Corentin Wallez | 978bc12 | 2023-05-15 13:01:16 +0000 | [diff] [blame] | 85 | set(GLFW_BUILD_X11 ${DAWN_USE_X11} CACHE BOOL "" FORCE) |
| 86 | set(GLFW_BUILD_WAYLAND ${DAWN_USE_WAYLAND} CACHE BOOL "" FORCE) |
Ben Clayton | 0ecd67a | 2021-09-23 20:13:53 +0000 | [diff] [blame] | 87 | |
| 88 | message(STATUS "Dawn: using GLFW at ${DAWN_GLFW_DIR}") |
Aleksi Sapon | 9a10674 | 2021-09-28 16:48:01 +0000 | [diff] [blame] | 89 | add_subdirectory(${DAWN_GLFW_DIR} "${CMAKE_CURRENT_BINARY_DIR}/glfw") |
Ben Clayton | 0ecd67a | 2021-09-23 20:13:53 +0000 | [diff] [blame] | 90 | endif() |
| 91 | |
Brandon Jones | a04663c | 2021-09-23 20:36:03 +0000 | [diff] [blame] | 92 | if (NOT TARGET libabsl) |
| 93 | message(STATUS "Dawn: using Abseil at ${DAWN_ABSEIL_DIR}") |
dan sinclair | cf2456b | 2023-01-07 23:09:14 +0000 | [diff] [blame] | 94 | if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") OR |
| 95 | ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")) |
| 96 | add_compile_options( |
| 97 | -Wno-array-parameter |
| 98 | -Wno-deprecated-builtins |
| 99 | -Wno-unknown-warning-option |
| 100 | ) |
| 101 | endif() |
| 102 | |
Aleksi Sapon | 9a10674 | 2021-09-28 16:48:01 +0000 | [diff] [blame] | 103 | add_subdirectory(${DAWN_ABSEIL_DIR} "${CMAKE_CURRENT_BINARY_DIR}/abseil") |
Brandon Jones | a04663c | 2021-09-23 20:36:03 +0000 | [diff] [blame] | 104 | endif() |
| 105 | |
Loko Kung | c96ef43 | 2022-04-02 03:02:40 +0000 | [diff] [blame] | 106 | if (NOT TARGET Vulkan-Headers) |
| 107 | message(STATUS "Dawn: using Vulkan-Headers at ${DAWN_VULKAN_HEADERS_DIR}") |
| 108 | add_subdirectory(${DAWN_VULKAN_HEADERS_DIR} "${CMAKE_CURRENT_BINARY_DIR}/vulkan-headers") |
| 109 | endif() |
| 110 | |
Corentin Wallez | 215b537 | 2020-02-15 00:39:13 +0000 | [diff] [blame] | 111 | # Header-only library for khrplatform.h |
| 112 | add_library(dawn_khronos_platform INTERFACE) |
Antonio Maiorano | 83bdc7f | 2023-08-21 15:29:35 +0000 | [diff] [blame] | 113 | target_sources(dawn_khronos_platform INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/khronos/EGL-Registry/api/KHR/khrplatform.h") |
| 114 | target_include_directories(dawn_khronos_platform INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/khronos/EGL-Registry/api") |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 115 | |
| 116 | # Header-only library for Vulkan headers |
| 117 | add_library(dawn_vulkan_headers INTERFACE) |
| 118 | target_sources(dawn_vulkan_headers INTERFACE |
| 119 | "${CMAKE_CURRENT_SOURCE_DIR}/khronos/vulkan/vk_icd.h" |
| 120 | "${CMAKE_CURRENT_SOURCE_DIR}/khronos/vulkan/vk_layer.h" |
| 121 | "${CMAKE_CURRENT_SOURCE_DIR}/khronos/vulkan/vk_platform.h" |
| 122 | "${CMAKE_CURRENT_SOURCE_DIR}/khronos/vulkan/vk_sdk_platform.h" |
| 123 | "${CMAKE_CURRENT_SOURCE_DIR}/khronos/vulkan/vulkan.h" |
| 124 | "${CMAKE_CURRENT_SOURCE_DIR}/khronos/vulkan/vulkan_core.h" |
| 125 | ) |
| 126 | target_include_directories(dawn_vulkan_headers INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/khronos") |
| 127 | |
Corentin Wallez | f9f1c4b | 2022-05-16 09:11:21 +0000 | [diff] [blame] | 128 | if (NOT TARGET vk_swiftshader AND ${DAWN_ENABLE_SWIFTSHADER}) |
Corentin Wallez | be352ea | 2022-04-11 16:48:43 +0000 | [diff] [blame] | 129 | set(SWIFTSHADER_BUILD_TESTS OFF CACHE BOOL "" FORCE) |
| 130 | set(SWIFTSHADER_BUILD_BENCHMARKS OFF CACHE BOOL "" FORCE) |
| 131 | |
| 132 | message(STATUS "Dawn: using Swiftshader at ${DAWN_SWIFTSHADER_DIR}") |
| 133 | add_subdirectory(${DAWN_SWIFTSHADER_DIR} "${CMAKE_CURRENT_BINARY_DIR}/swiftshader") |
| 134 | endif() |
| 135 | |
Austin Eng | 6a7bba5 | 2023-04-17 18:11:51 +0000 | [diff] [blame] | 136 | if (${TINT_BUILD_BENCHMARKS} OR ${DAWN_BUILD_BENCHMARKS}) |
Corentin Wallez | f9f1c4b | 2022-05-16 09:11:21 +0000 | [diff] [blame] | 137 | set(BENCHMARK_ENABLE_TESTING FALSE CACHE BOOL FALSE FORCE) |
Austin Eng | 6a7bba5 | 2023-04-17 18:11:51 +0000 | [diff] [blame] | 138 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/google_benchmark/src EXCLUDE_FROM_ALL) |
Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 139 | endif() |
| 140 | |
Corentin Wallez | f9f1c4b | 2022-05-16 09:11:21 +0000 | [diff] [blame] | 141 | if (NOT TARGET gmock AND ${TINT_BUILD_TESTS}) |
| 142 | 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) |
| 143 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/googletest EXCLUDE_FROM_ALL) |
David Neto | 5b46d71 | 2020-06-26 22:29:27 +0000 | [diff] [blame] | 144 | endif() |
Antonio Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 145 | |
| 146 | function(AddSubdirectoryDXC) |
| 147 | # We use a CMake function so that all these (non-cache) variables are scoped |
| 148 | # only to this function. |
| 149 | set(HLSL_OPTIONAL_PROJS_IN_DEFAULT OFF) |
| 150 | set(HLSL_ENABLE_ANALYZE OFF) |
| 151 | set(HLSL_OFFICIAL_BUILD OFF) |
| 152 | set(HLSL_ENABLE_FIXED_VER OFF) |
| 153 | set(HLSL_BUILD_DXILCONV OFF) |
| 154 | set(HLSL_INCLUDE_TESTS OFF) |
| 155 | |
| 156 | set(ENABLE_SPIRV_CODEGEN OFF) |
| 157 | set(SPIRV_BUILD_TESTS OFF) |
| 158 | |
| 159 | set(LLVM_BUILD_RUNTIME ON) |
| 160 | set(LLVM_BUILD_EXAMPLES OFF) |
| 161 | set(LLVM_BUILD_TESTS OFF) |
| 162 | set(LLVM_INCLUDE_TESTS OFF) |
| 163 | set(LLVM_INCLUDE_DOCS OFF) |
| 164 | set(LLVM_INCLUDE_EXAMPLES OFF) |
| 165 | set(LLVM_OPTIMIZED_TABLEGEN OFF) |
| 166 | set(LLVM_APPEND_VC_REV OFF) |
| 167 | # Enable exception handling (requires RTTI) |
| 168 | set(LLVM_ENABLE_RTTI ON) |
| 169 | set(LLVM_ENABLE_EH ON) |
| 170 | set(CLANG_CL OFF) |
| 171 | |
Antonio Maiorano | 3935764 | 2024-03-27 18:23:32 +0000 | [diff] [blame] | 172 | if (DAWN_ENABLE_ASAN AND DAWN_ENABLE_UBSAN) |
| 173 | set(LLVM_USE_SANITIZER "Address;Undefined") |
| 174 | elseif(DAWN_ENABLE_ASAN) |
| 175 | set(LLVM_USE_SANITIZER "Address") |
| 176 | elseif(DAWN_ENABLE_UBSAN) |
| 177 | set(LLVM_USE_SANITIZER "Undefined") |
| 178 | endif() |
| 179 | |
Antonio Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 180 | # Cache variables -- these are *not* scoped to this function |
| 181 | set(LLVM_TARGETS_TO_BUILD "None" CACHE STRING "" FORCE) |
| 182 | set(LLVM_DEFAULT_TARGET_TRIPLE "dxil-ms-dx" CACHE STRING "" FORCE) |
| 183 | set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "" FORCE) |
| 184 | set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "" FORCE) |
| 185 | set(CLANG_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) |
| 186 | set(CLANG_INCLUDE_TESTS OFF CACHE BOOL "" FORCE) |
| 187 | |
Antonio Maiorano | 76d8219 | 2024-01-25 17:45:32 +0000 | [diff] [blame] | 188 | if (NOT WIN32) |
| 189 | set(DIRECTX_HEADER_INCLUDE_DIR "${DAWN_THIRD_PARTY_DIR}/dxheaders/include") |
| 190 | endif() |
Antonio Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 191 | |
| 192 | # Disable HCT.cmake looking for and using clang-format. This is used to compare generated files |
| 193 | # against the copy that is committed to the repo, but fails because the DXC .clangformat file is |
| 194 | # not visible from our build dir. We don't need this validation, so just disable it. |
| 195 | set(CLANG_FORMAT_EXE "" CACHE STRING "" FORCE) |
| 196 | |
Antonio Maiorano | b4d05de | 2024-04-16 19:36:58 +0000 | [diff] [blame] | 197 | if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT DAWN_DXC_DISABLE_ASSERTS_DEBUG) |
| 198 | set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "" FORCE) |
| 199 | else() |
| 200 | set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "" FORCE) |
| 201 | endif() |
Antonio Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 202 | |
| 203 | # Override RPATH so that it points to current dir (exe path). This allows both executable and |
| 204 | # shared library to be in the same location, which we set below. Note that DXC places places |
| 205 | # executables in a bin directory, and shared libraries in a lib directory. |
| 206 | if (APPLE) |
| 207 | set(CMAKE_INSTALL_NAME_DIR "@rpath") |
| 208 | set(CMAKE_INSTALL_RPATH "@executable_path") |
| 209 | else() |
| 210 | set(CMAKE_INSTALL_RPATH "\$ORIGIN") |
| 211 | endif() |
| 212 | |
| 213 | message(STATUS "\nAdding DXC to build:\n") |
| 214 | add_subdirectory(dxc |
| 215 | # Disable all targets by default, and enable only the dxc and dxcompiler targets (below) |
| 216 | EXCLUDE_FROM_ALL |
| 217 | ) |
| 218 | set_target_properties(dxc PROPERTIES EXCLUDE_FROM_ALL FALSE) |
| 219 | set_target_properties(dxcompiler PROPERTIES EXCLUDE_FROM_ALL FALSE) |
| 220 | |
| 221 | # Override output dir for both targets so that they end up in the same place |
| 222 | # as the rest of our binaries. Otherwise, DXC wants its outputs in bin and lib dirs. |
| 223 | get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) |
| 224 | if (isMultiConfig) |
| 225 | set_target_properties(dxc dxcompiler PROPERTIES |
| 226 | "RUNTIME_OUTPUT_DIRECTORY_DEBUG" "${CMAKE_BINARY_DIR}/$<CONFIG>" |
| 227 | "RUNTIME_OUTPUT_DIRECTORY_RELEASE" "${CMAKE_BINARY_DIR}/$<CONFIG>" |
| 228 | "LIBRARY_OUTPUT_DIRECTORY_DEBUG" "${CMAKE_BINARY_DIR}/$<CONFIG>" |
| 229 | "LIBRARY_OUTPUT_DIRECTORY_RELEASE" "${CMAKE_BINARY_DIR}/$<CONFIG>" |
| 230 | ) |
| 231 | else() |
| 232 | set_target_properties(dxc dxcompiler PROPERTIES |
| 233 | "RUNTIME_OUTPUT_DIRECTORY" "${CMAKE_BINARY_DIR}" |
| 234 | "LIBRARY_OUTPUT_DIRECTORY" "${CMAKE_BINARY_DIR}" |
| 235 | ) |
| 236 | endif() |
| 237 | |
| 238 | # Create a target that copies dxil.dll from the platform SDK |
Antonio Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 239 | if (WIN32) |
Antonio Maiorano | 08c4d0a | 2024-03-19 15:09:08 +0000 | [diff] [blame] | 240 | message(STATUS "Finding Windows SDK Directory") |
| 241 | |
| 242 | message(STATUS "Display environment variables:") |
| 243 | execute_process(COMMAND ${CMAKE_COMMAND} -E environment COMMAND_ECHO STDOUT) |
| 244 | |
Antonio Maiorano | 01c4a65 | 2024-03-13 19:38:13 +0000 | [diff] [blame] | 245 | if(DEFINED ENV{WINDOWSSDKDIR}) |
| 246 | # If WINDOWSSDKDIR env var is defined, use its value. This is defined, for example, when |
| 247 | # using a Visual Studio command prompt. |
| 248 | set(WIN10_SDK_PATH "$ENV{WINDOWSSDKDIR}") |
Antonio Maiorano | 08c4d0a | 2024-03-19 15:09:08 +0000 | [diff] [blame] | 249 | message(STATUS "Found WINDOWSSDKDIR environment variable: ${WIN10_SDK_PATH}") |
Antonio Maiorano | 01c4a65 | 2024-03-13 19:38:13 +0000 | [diff] [blame] | 250 | else() |
| 251 | # There's no easy way to get the Windows SDK path in CMake; however, conveniently, DXC |
| 252 | # contains a FindD3D12.cmake file that returns WIN10_SDK_PATH and WIN10_SDK_VERSION, |
| 253 | # so let's use that. |
| 254 | # TODO(crbug.com/tint/2106): Get the Win10 SDK path and version ourselves until |
| 255 | # dxc/cmake/modules/FindD3D12.cmake supports non-VS generators. |
| 256 | get_filename_component(WIN10_SDK_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" ABSOLUTE CACHE) |
Antonio Maiorano | 08c4d0a | 2024-03-19 15:09:08 +0000 | [diff] [blame] | 257 | message(STATUS "WINDOWSSDKDIR environment variable is not defined, retrieving from registry: ${WIN10_SDK_PATH}") |
Antonio Maiorano | 01c4a65 | 2024-03-13 19:38:13 +0000 | [diff] [blame] | 258 | endif() |
| 259 | |
Antonio Maiorano | 08c4d0a | 2024-03-19 15:09:08 +0000 | [diff] [blame] | 260 | message(STATUS "Finding Windows SDK version") |
Antonio Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 261 | if (CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION) |
| 262 | set (WIN10_SDK_VERSION ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}) |
Antonio Maiorano | 08c4d0a | 2024-03-19 15:09:08 +0000 | [diff] [blame] | 263 | message(STATUS "Found Windows SDK version from CMake variable 'CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION': ${WIN10_SDK_VERSION}") |
Antonio Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 264 | else() |
| 265 | # CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION may not be defined if, for example, |
| 266 | # the Ninja generator is used instead of Visual Studio. Attempt to retrieve the |
| 267 | # most recent SDK version from the list of paths under "${WIN10_SDK_PATH}/Include/". |
| 268 | file(GLOB sdk_dirs RELATIVE "${WIN10_SDK_PATH}/Include/" "${WIN10_SDK_PATH}/Include/10.*") |
| 269 | if (sdk_dirs) |
Antonio Maiorano | 08c4d0a | 2024-03-19 15:09:08 +0000 | [diff] [blame] | 270 | list(POP_BACK sdk_dirs WIN10_SDK_VERSION) |
Antonio Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 271 | endif() |
| 272 | unset(sdk_dirs) |
Antonio Maiorano | 08c4d0a | 2024-03-19 15:09:08 +0000 | [diff] [blame] | 273 | 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 Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 274 | endif() |
| 275 | |
| 276 | set(DXIL_DLL_PATH "${WIN10_SDK_PATH}/bin/${WIN10_SDK_VERSION}/x64/dxil.dll") |
| 277 | add_custom_target(copy_dxil_dll) |
| 278 | add_custom_command( |
| 279 | TARGET copy_dxil_dll |
| 280 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DXIL_DLL_PATH} $<TARGET_FILE_DIR:dxcompiler> |
| 281 | COMMENT "Copying ${DXIL_DLL_PATH} to $<TARGET_FILE_DIR:dxcompiler>") |
| 282 | # Make dxc target depend on copy_dxil_dll |
| 283 | add_dependencies(dxc copy_dxil_dll) |
| 284 | endif() |
| 285 | endfunction() |
| 286 | |
| 287 | if (DAWN_USE_BUILT_DXC) |
| 288 | AddSubdirectoryDXC() |
| 289 | endif() |
Ben Clayton | f9a5b71 | 2024-03-13 17:37:33 +0000 | [diff] [blame] | 290 | |
| 291 | if (TINT_BUILD_TINTD) |
| 292 | set(LANGSVR_JSON_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/jsoncpp") |
| 293 | add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/jsoncpp" EXCLUDE_FROM_ALL) |
| 294 | add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/langsvr" EXCLUDE_FROM_ALL) |
| 295 | endif() |