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