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. |
dan sinclair | 12c428f | 2024-06-21 01:14:24 +0000 | [diff] [blame] | 34 | if (DAWN_FETCH_DEPENDENCIES) |
Elie Michel | 9ae8ed2 | 2023-05-12 20:19:41 +0000 | [diff] [blame] | 35 | set(EXTRA_FETCH_ARGS) |
Lokbondo Kung | 868a467 | 2024-10-25 20:17:03 +0000 | [diff] [blame] | 36 | if (NOT TARGET gmock AND (DAWN_BUILD_TESTS OR TINT_BUILD_TESTS)) |
Elie Michel | 9ae8ed2 | 2023-05-12 20:19:41 +0000 | [diff] [blame] | 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 | |
Loko Kung | 90fdaa8 | 2024-07-24 00:59:58 +0000 | [diff] [blame] | 50 | ################################################################################ |
| 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 | |
| 57 | if (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") |
| 71 | endif() |
| 72 | |
Lokbondo Kung | 868a467 | 2024-10-25 20:17:03 +0000 | [diff] [blame] | 73 | if ((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 Ninomiya | 8456387 | 2024-11-01 23:04:25 +0000 | [diff] [blame] | 79 | |
| 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 Kung | 868a467 | 2024-10-25 20:17:03 +0000 | [diff] [blame] | 86 | add_subdirectory(${DAWN_GOOGLETEST_DIR} "${CMAKE_CURRENT_BINARY_DIR}/googletest" EXCLUDE_FROM_ALL) |
| 87 | endif() |
| 88 | |
Loko Kung | 90fdaa8 | 2024-07-24 00:59:58 +0000 | [diff] [blame] | 89 | ################################################################################ |
| 90 | # End of Emscripten enabled third party directories |
| 91 | ################################################################################ |
| 92 | if (${DAWN_ENABLE_EMSCRIPTEN}) |
| 93 | return() |
| 94 | endif() |
| 95 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 96 | if (NOT TARGET SPIRV-Headers) |
Corentin Wallez | 42450c6 | 2020-04-10 17:04:31 +0000 | [diff] [blame] | 97 | set(SPIRV_HEADERS_SKIP_EXAMPLES ON CACHE BOOL "" FORCE) |
| 98 | set(SPIRV_HEADERS_SKIP_INSTALL ON CACHE BOOL "" FORCE) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 99 | |
| 100 | message(STATUS "Dawn: using SPIRV-Headers at ${DAWN_SPIRV_HEADERS_DIR}") |
Aleksi Sapon | 9a10674 | 2021-09-28 16:48:01 +0000 | [diff] [blame] | 101 | add_subdirectory(${DAWN_SPIRV_HEADERS_DIR} "${CMAKE_CURRENT_BINARY_DIR}/spirv-headers") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 102 | endif() |
| 103 | |
Jaswant Panchumarti | 4660e72 | 2024-06-21 13:26:45 +0000 | [diff] [blame] | 104 | if (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 Panchumarti | 22e7815 | 2024-06-21 15:44:23 +0000 | [diff] [blame] | 110 | set(SPIRV_SKIP_TESTS ON CACHE BOOL "Controls whether SPIR-V tests are run" FORCE) |
Corentin Wallez | 42450c6 | 2020-04-10 17:04:31 +0000 | [diff] [blame] | 111 | set(SPIRV_SKIP_EXECUTABLES ON CACHE BOOL "" FORCE) |
| 112 | set(SKIP_SPIRV_TOOLS_INSTALL ON CACHE BOOL "" FORCE) |
Jaswant Panchumarti | 22e7815 | 2024-06-21 15:44:23 +0000 | [diff] [blame] | 113 | set(SPIRV_WERROR OFF CACHE BOOL OFF FORCE) |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 114 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 115 | message(STATUS "Dawn: using SPIRV-Tools at ${DAWN_SPIRV_TOOLS_DIR}") |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 116 | 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] | 117 | endif() |
| 118 | |
dan sinclair | 12c428f | 2024-06-21 01:14:24 +0000 | [diff] [blame] | 119 | 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] | 120 | set(SKIP_GLSLANG_INSTALL ON CACHE BOOL "" FORCE) |
Corentin Wallez | 2f18c9a | 2024-04-02 08:51:45 +0000 | [diff] [blame] | 121 | set(ENABLE_OPT OFF CACHE BOOL "" FORCE) |
dan sinclair | 12c428f | 2024-06-21 01:14:24 +0000 | [diff] [blame] | 122 | message(STATUS "Dawn: using GLSLang at ${DAWN_GLSLANG_DIR}") |
Jaswant Panchumarti | b415b2e5 | 2024-06-28 13:21:16 +0000 | [diff] [blame] | 123 | # 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 sinclair | 12c428f | 2024-06-21 01:14:24 +0000 | [diff] [blame] | 127 | add_subdirectory("${DAWN_GLSLANG_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/glslang" EXCLUDE_FROM_ALL) |
Jaswant Panchumarti | b415b2e5 | 2024-06-28 13:21:16 +0000 | [diff] [blame] | 128 | set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED}) |
Corentin Wallez | f9f1c4b | 2022-05-16 09:11:21 +0000 | [diff] [blame] | 129 | endif() |
| 130 | |
Erin Melucci | 38b58e4 | 2023-06-14 16:45:33 +0000 | [diff] [blame] | 131 | if (NOT TARGET glfw AND DAWN_USE_GLFW) |
Ben Clayton | 0ecd67a | 2021-09-23 20:13:53 +0000 | [diff] [blame] | 132 | 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 Wallez | 978bc12 | 2023-05-15 13:01:16 +0000 | [diff] [blame] | 135 | set(GLFW_BUILD_X11 ${DAWN_USE_X11} CACHE BOOL "" FORCE) |
| 136 | set(GLFW_BUILD_WAYLAND ${DAWN_USE_WAYLAND} CACHE BOOL "" FORCE) |
Jaswant Panchumarti | 05e8417 | 2024-06-28 13:40:34 +0000 | [diff] [blame] | 137 | set(GLFW_INSTALL OFF CACHE BOOL "" FORCE) |
Ben Clayton | 0ecd67a | 2021-09-23 20:13:53 +0000 | [diff] [blame] | 138 | |
| 139 | message(STATUS "Dawn: using GLFW at ${DAWN_GLFW_DIR}") |
Aleksi Sapon | 9a10674 | 2021-09-28 16:48:01 +0000 | [diff] [blame] | 140 | add_subdirectory(${DAWN_GLFW_DIR} "${CMAKE_CURRENT_BINARY_DIR}/glfw") |
Ben Clayton | 0ecd67a | 2021-09-23 20:13:53 +0000 | [diff] [blame] | 141 | endif() |
| 142 | |
dan sinclair | 0c27cf2 | 2024-06-11 12:31:38 +0000 | [diff] [blame] | 143 | if (DAWN_BUILD_PROTOBUF AND NOT TARGET libprotobuf-mutator) |
Ryan Harrison | 25e23b3 | 2024-05-27 23:21:05 +0000 | [diff] [blame] | 144 | message(STATUS "Dawn: using LPM at ${DAWN_LPM_DIR}") |
| 145 | include("libprotobuf-mutator/BUILD.cmake") |
| 146 | endif() |
| 147 | |
dan sinclair | 12c428f | 2024-06-21 01:14:24 +0000 | [diff] [blame] | 148 | if (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 Kung | c96ef43 | 2022-04-02 03:02:40 +0000 | [diff] [blame] | 153 | endif() |
| 154 | |
Jaswant Panchumarti | 3998f70 | 2024-06-22 10:33:03 +0000 | [diff] [blame] | 155 | if (NOT TARGET Vulkan-Headers AND DAWN_ENABLE_VULKAN) |
| 156 | message(STATUS "Dawn: using Vulkan-Headers at ${DAWN_VULKAN_HEADERS_DIR}") |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 157 | |
Jaswant Panchumarti | 3998f70 | 2024-06-22 10:33:03 +0000 | [diff] [blame] | 158 | set(VULKAN_HEADERS_ENABLE_MODULE OFF) |
| 159 | add_subdirectory(${DAWN_VULKAN_HEADERS_DIR} "${CMAKE_CURRENT_BINARY_DIR}/vulkan-headers") |
dan sinclair | 12c428f | 2024-06-21 01:14:24 +0000 | [diff] [blame] | 160 | endif() |
| 161 | |
Jaswant Panchumarti | 0a3b1b9 | 2024-06-27 12:34:13 +0000 | [diff] [blame] | 162 | if (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") |
| 165 | endif() |
| 166 | |
dan sinclair | 12c428f | 2024-06-21 01:14:24 +0000 | [diff] [blame] | 167 | if (DAWN_ENABLE_SWIFTSHADER AND NOT TARGET vk_swiftshader) |
Corentin Wallez | be352ea | 2022-04-11 16:48:43 +0000 | [diff] [blame] | 168 | 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") |
| 173 | endif() |
| 174 | |
dan sinclair | 12c428f | 2024-06-21 01:14:24 +0000 | [diff] [blame] | 175 | if (TINT_BUILD_BENCHMARKS OR DAWN_BUILD_BENCHMARKS) |
Corentin Wallez | f9f1c4b | 2022-05-16 09:11:21 +0000 | [diff] [blame] | 176 | set(BENCHMARK_ENABLE_TESTING FALSE CACHE BOOL FALSE FORCE) |
Austin Eng | 6a7bba5 | 2023-04-17 18:11:51 +0000 | [diff] [blame] | 177 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/google_benchmark/src EXCLUDE_FROM_ALL) |
Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 178 | endif() |
| 179 | |
Antonio Maiorano | c5c7480 | 2024-08-08 14:45:08 +0000 | [diff] [blame] | 180 | # Populates 'targets' with list of all targets under 'dir' |
| 181 | # Use 'get_all_targets_recursive' instead of this macro |
| 182 | macro(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}) |
| 189 | endmacro() |
| 190 | function(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) |
| 194 | endfunction() |
| 195 | |
Antonio Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 196 | function(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 Panchumarti | 0a3b1b9 | 2024-06-27 12:34:13 +0000 | [diff] [blame] | 205 | # 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 Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 210 | |
| 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 Maiorano | 3935764 | 2024-03-27 18:23:32 +0000 | [diff] [blame] | 227 | 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 Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 235 | # 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 Maiorano | e14e427 | 2024-05-07 19:40:19 +0000 | [diff] [blame] | 242 | set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "" FORCE) |
Antonio Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 243 | |
Antonio Maiorano | 76d8219 | 2024-01-25 17:45:32 +0000 | [diff] [blame] | 244 | if (NOT WIN32) |
| 245 | set(DIRECTX_HEADER_INCLUDE_DIR "${DAWN_THIRD_PARTY_DIR}/dxheaders/include") |
| 246 | endif() |
Antonio Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 247 | |
| 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 Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 253 | # 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 Maiorano | c5c7480 | 2024-08-08 14:45:08 +0000 | [diff] [blame] | 271 | 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 Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 294 | # 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 Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 312 | if (WIN32) |
Antonio Maiorano | 08c4d0a | 2024-03-19 15:09:08 +0000 | [diff] [blame] | 313 | 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 Maiorano | 01c4a65 | 2024-03-13 19:38:13 +0000 | [diff] [blame] | 318 | 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 Maiorano | 08c4d0a | 2024-03-19 15:09:08 +0000 | [diff] [blame] | 322 | message(STATUS "Found WINDOWSSDKDIR environment variable: ${WIN10_SDK_PATH}") |
Antonio Maiorano | 01c4a65 | 2024-03-13 19:38:13 +0000 | [diff] [blame] | 323 | 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 Maiorano | 08c4d0a | 2024-03-19 15:09:08 +0000 | [diff] [blame] | 330 | 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] | 331 | endif() |
| 332 | |
Antonio Maiorano | 08c4d0a | 2024-03-19 15:09:08 +0000 | [diff] [blame] | 333 | message(STATUS "Finding Windows SDK version") |
Antonio Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 334 | if (CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION) |
| 335 | set (WIN10_SDK_VERSION ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}) |
Antonio Maiorano | 08c4d0a | 2024-03-19 15:09:08 +0000 | [diff] [blame] | 336 | 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] | 337 | 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 Maiorano | 08c4d0a | 2024-03-19 15:09:08 +0000 | [diff] [blame] | 343 | list(POP_BACK sdk_dirs WIN10_SDK_VERSION) |
Antonio Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 344 | endif() |
| 345 | unset(sdk_dirs) |
Antonio Maiorano | 08c4d0a | 2024-03-19 15:09:08 +0000 | [diff] [blame] | 346 | 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] | 347 | 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() |
| 358 | endfunction() |
| 359 | |
| 360 | if (DAWN_USE_BUILT_DXC) |
| 361 | AddSubdirectoryDXC() |
| 362 | endif() |
Ben Clayton | f9a5b71 | 2024-03-13 17:37:33 +0000 | [diff] [blame] | 363 | |
| 364 | if (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) |
| 368 | endif() |