blob: b6fc27371e7efe8bcd247311c7818ef661df3722 [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
Erin Meluccid1e92bb2024-03-27 15:43:05 +000028# As per https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md
29cmake_minimum_required(VERSION 3.13)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000030
Erin Meluccid1e92bb2024-03-27 15:43:05 +000031# - Since we are past CMake 3.12 we can add CONFIGURE_DEPENDS to DawnGenerator to rerun CMake
Corentin Walleza3014cc2024-03-27 13:53:14 +000032# in case any of the generator files changes. We should also remove the CACHE "" FORCE stuff to
Erin Meluccid1e92bb2024-03-27 15:43:05 +000033# override options in third_party dependencies.
Corentin Walleza3014cc2024-03-27 13:53:14 +000034# - When upgrading to CMake 3.20 we can take advantage of the GENERATED property being global in
Jaswant Panchumarti5a26bdd2024-07-04 14:13:55 +000035# DawnGenerator. We should also use the path utilities in dawn_install_target.
Corentin Walleza3014cc2024-03-27 13:53:14 +000036
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000037project(
38 Dawn
39 DESCRIPTION "Dawn, a WebGPU implementation"
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000040 LANGUAGES C CXX
Erin Meluccid1e92bb2024-03-27 15:43:05 +000041 HOMEPAGE_URL "https://dawn.googlesource.com/dawn"
Jaswant Panchumarti5a26bdd2024-07-04 14:13:55 +000042 VERSION 0.0.0
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000043)
Dan Sinclair6e581892020-03-02 15:47:43 -050044enable_testing()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000045
Jaswant Panchumarti72b712f2024-06-21 13:16:18 +000046list(INSERT CMAKE_MODULE_PATH 0 "${Dawn_SOURCE_DIR}/src/cmake")
47
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000048set_property(GLOBAL PROPERTY USE_FOLDERS ON)
49
Dan Sinclair6e581892020-03-02 15:47:43 -050050set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
51set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Dan Sinclair6e581892020-03-02 15:47:43 -050052set(CMAKE_DEBUG_POSTFIX "")
dan sinclair2df80912023-11-20 13:22:14 +000053set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Dan Sinclair6e581892020-03-02 15:47:43 -050054
Jaswant Panchumarti72b712f2024-06-21 13:16:18 +000055include(DawnSetIfNotDefined)
56
Jaswant Panchumartie9cc8e42024-07-02 16:26:36 +000057set(DAWN_BUILD_GEN_DIR "${Dawn_BINARY_DIR}/gen" CACHE PATH "Directory that contains generated source files")
58set(DAWN_GENERATOR_DIR "${Dawn_SOURCE_DIR}/generator" CACHE PATH "Directory that contains scripts to generate sources and headers")
59set(DAWN_SRC_DIR "${Dawn_SOURCE_DIR}/src" CACHE PATH "Directory that contains source files for dawn")
60set(DAWN_INCLUDE_DIR "${Dawn_SOURCE_DIR}/include" CACHE PATH "Directory that contains public headers for dawn")
61set(DAWN_TEMPLATE_DIR "${DAWN_GENERATOR_DIR}/templates" CACHE PATH "Directory that contains templates for generators")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000062
Jaswant Panchumarti72b712f2024-06-21 13:16:18 +000063################################################################################
64# Configuration options
65################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000066# Default values for the backend-enabling options
Peng Huang925b7762023-05-01 16:13:00 +000067set(ENABLE_D3D11 OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000068set(ENABLE_D3D12 OFF)
69set(ENABLE_METAL OFF)
Loko Kung90fdaa82024-07-24 00:59:58 +000070set(ENABLE_NULL ON)
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +000071set(ENABLE_OPENGLES OFF)
72set(ENABLE_DESKTOP_GL OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000073set(ENABLE_VULKAN OFF)
Loko Kung90fdaa82024-07-24 00:59:58 +000074set(ENABLE_EMSCRIPTEN OFF)
Jaswant Panchumarti5bdf8762024-06-22 11:12:38 +000075set(ENABLE_SPIRV_VALIDATION OFF)
Corentin Wallez2e22d922022-06-01 09:30:50 +000076set(USE_WAYLAND OFF)
Corentin Wallezd353ca02020-02-18 02:12:35 +000077set(USE_X11 OFF)
Stephen Gutekanst55623702023-07-01 11:43:55 +000078set(USE_WINDOWS_UI OFF)
Ben Claytona6750752022-02-04 18:35:55 +000079set(BUILD_SAMPLES OFF)
AlexVestin5c3645c2023-10-18 14:08:26 +000080set(TARGET_MACOS OFF)
Loko Kung90fdaa82024-07-24 00:59:58 +000081if (CMAKE_SYSTEM_NAME MATCHES "Emscripten")
82 # Only the samples are supported for Emscripten at the moment.
83 # TODO(crbug.com/42240181): Make dawn_end2end_tests work too.
84 set(ENABLE_EMSCRIPTEN ON)
85 set(BUILD_SAMPLES ON)
86 set(ENABLE_NULL OFF)
87elseif (WIN32)
88 set(ENABLE_D3D11 ON)
89 set(USE_WINDOWS_UI ON)
90 set(ENABLE_D3D12 ON)
Jaswant Panchumarti5bdf8762024-06-22 11:12:38 +000091 if (NOT WINDOWS_STORE)
92 # Enable Vulkan in win32 compilation only
93 # since UWP only supports d3d
94 set(ENABLE_VULKAN ON)
95 set(ENABLE_SPIRV_VALIDATION ON)
96 endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000097elseif(APPLE)
Jaswant Panchumarti5bdf8762024-06-22 11:12:38 +000098 set(ENABLE_METAL ON)
99 if(CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "MacOS")
100 set(TARGET_MACOS ON)
101 endif()
Alexander Vestinf2556ab2022-03-25 13:18:46 +0000102elseif(ANDROID)
Jaswant Panchumarti5bdf8762024-06-22 11:12:38 +0000103 set(ENABLE_VULKAN ON)
104 set(ENABLE_OPENGLES ON)
105 # Disable SPIR-V validation on Android because it adds a significant amount
106 # to the binary size, and Tint's output should be well-formed.
107 set(ENABLE_SPIRV_VALIDATION OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000108elseif(UNIX)
Jaswant Panchumarti5bdf8762024-06-22 11:12:38 +0000109 set(ENABLE_OPENGLES ON)
110 set(ENABLE_DESKTOP_GL ON)
111 set(ENABLE_VULKAN ON)
112 set(ENABLE_SPIRV_VALIDATION ON)
113 set(USE_X11 ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000114endif()
115
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000116# GLFW is not supported in UWP
Albin Bernhardssonb8a1b6d2023-07-13 08:51:17 +0000117set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING OFF)
Loko Kung90fdaa82024-07-24 00:59:58 +0000118if (NOT ENABLE_EMSCRIPTEN AND ((WIN32 AND NOT WINDOWS_STORE) OR (UNIX AND NOT ANDROID)))
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000119 set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING ON)
120endif()
121
122# Current examples are depend on GLFW
123if (DAWN_SUPPORTS_GLFW_FOR_WINDOWING)
Ben Claytona6750752022-02-04 18:35:55 +0000124 set(BUILD_SAMPLES ON)
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000125endif()
126
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000127option(DAWN_ENABLE_ASAN "Enable address sanitizer" OFF)
128option(DAWN_ENABLE_INSTALL "Enable install step for Dawn libraries" OFF)
129option(DAWN_ENABLE_TSAN "Enable thread sanitizer" OFF)
130option(DAWN_ENABLE_MSAN "Enable memory sanitizer" OFF)
131option(DAWN_ENABLE_UBSAN "Enable undefined behaviour sanitizer" OFF)
Ben Clayton96e245e2022-04-08 18:08:36 +0000132
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000133option(DAWN_ENABLE_D3D11 "Enable compilation of the D3D11 backend" ${ENABLE_D3D11})
134option(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12})
135option(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL})
Loko Kung90fdaa82024-07-24 00:59:58 +0000136option(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ${ENABLE_NULL})
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000137option(DAWN_ENABLE_DESKTOP_GL "Enable compilation of the OpenGL backend" ${ENABLE_DESKTOP_GL})
138option(DAWN_ENABLE_OPENGLES "Enable compilation of the OpenGL ES backend" ${ENABLE_OPENGLES})
139option(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backend" ${ENABLE_VULKAN})
Jaswant Panchumarti5bdf8762024-06-22 11:12:38 +0000140option(DAWN_ENABLE_SPIRV_VALIDATION "Enable validation of SPIR-V" ${ENABLE_SPIRV_VALIDATION})
dan sinclair194c1772022-06-21 17:54:03 +0000141
Loko Kung90fdaa82024-07-24 00:59:58 +0000142# Optional path to Emscripten toolchain to allow for building WASM.
143option(DAWN_EMSCRIPTEN_TOOLCHAIN "Directory in which to find Emscripten toolchain" "")
144set(DAWN_ENABLE_EMSCRIPTEN OFF)
145if (NOT ${DAWN_EMSCRIPTEN_TOOLCHAIN} STREQUAL "" AND ENABLE_EMSCRIPTEN)
146 set(DAWN_ENABLE_EMSCRIPTEN ON)
147endif()
148
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000149option(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF)
150option(DAWN_USE_WAYLAND "Enable support for Wayland surface" ${USE_WAYLAND})
151option(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11})
152option(DAWN_USE_GLFW "Enable compilation of the GLFW windowing utils" ${DAWN_SUPPORTS_GLFW_FOR_WINDOWING})
153option(DAWN_USE_WINDOWS_UI "Enable support for Windows UI surface" ${USE_WINDOWS_UI})
154option(DAWN_USE_BUILT_DXC "Enable building and using DXC by the D3D12 backend" OFF)
Antonio Maioranoc5c74802024-08-08 14:45:08 +0000155option(DAWN_DXC_ENABLE_ASSERTS_IN_NDEBUG "Enable DXC asserts in non-debug builds" ON)
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000156option(DAWN_TARGET_MACOS "Manually link Apple core frameworks" ${TARGET_MACOS})
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000157
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000158option(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" ${BUILD_SAMPLES})
159option(DAWN_BUILD_NODE_BINDINGS "Enables building Dawn's NodeJS bindings" OFF)
160option(DAWN_ENABLE_SWIFTSHADER "Enables building Swiftshader as part of the build and Vulkan adapter discovery" OFF)
161option(DAWN_BUILD_BENCHMARKS "Build Dawn benchmarks" OFF)
dan sinclair0c27cf22024-06-11 12:31:38 +0000162option(DAWN_BUILD_PROTOBUF "Build the protobuf dependencies" OFF)
Ben Claytonaffb7a32021-09-28 11:14:42 +0000163
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000164option(DAWN_WERROR "Build with -Werror (or equivalent)" OFF)
165option(DAWN_ENABLE_PIC "Build with Position-Independent-Code enabled" OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000166
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000167option(DAWN_EMIT_COVERAGE "Emit code coverage information" OFF)
Ben Claytonf927bcb2022-12-12 21:21:54 +0000168set_if_not_defined(LLVM_SOURCE_DIR "${Dawn_LLVM_SOURCE_DIR}" "Directory to an LLVM source checkout. Required to build turbo-cov")
Ben Claytone38993f2022-12-10 00:15:57 +0000169
dan sinclair194c1772022-06-21 17:54:03 +0000170if (DAWN_ENABLE_OPENGLES OR DAWN_ENABLE_DESKTOP_GL)
171 set(TINT_DEFAULT_GLSL ON)
172else()
173 set(TINT_DEFAULT_GLSL OFF)
174endif()
175
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000176option(TINT_ENABLE_INSTALL "Enable install step for Tint libraries" OFF)
177option(TINT_BUILD_CMD_TOOLS "Build the Tint command line tools" ON)
dan sinclair194c1772022-06-21 17:54:03 +0000178
Loko Kung90fdaa82024-07-24 00:59:58 +0000179if (DAWN_BUILD_SAMPLES)
180 if (NOT DAWN_USE_GLFW AND NOT DAWN_ENABLE_EMSCRIPTEN)
181 message(SEND_ERROR "Dawn samples require GLFW or Emscripten")
182 endif()
Erin Melucci38b58e42023-06-14 16:45:33 +0000183endif()
184
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000185option(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" ${DAWN_ENABLE_VULKAN})
186option(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON)
187option(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" ${TINT_DEFAULT_GLSL})
188option(TINT_BUILD_GLSL_VALIDATOR "Build the GLSL output validator" ON)
189option(TINT_BUILD_HLSL_WRITER "Build the HLSL output writer" ${DAWN_ENABLE_D3D12})
190option(TINT_BUILD_MSL_WRITER "Build the MSL output writer" ${DAWN_ENABLE_METAL})
191option(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ${DAWN_ENABLE_VULKAN})
192option(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON)
dan sinclair194c1772022-06-21 17:54:03 +0000193
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000194option(TINT_BUILD_SYNTAX_TREE_WRITER "Build the syntax tree writer" OFF)
dan sinclairc22b8b9d2022-11-01 17:02:31 +0000195
Ryan Harrison45788092024-06-19 02:26:57 +0000196if (DAWN_BUILD_PROTOBUF AND TARGET libprotobuf)
197 set(TINT_DEFAULT_BUILD_IR_BINARY ON)
198else()
199 set(TINT_DEFAULT_BUILD_IR_BINARY OFF)
200endif()
Ryan Harrison724dd782024-05-16 16:27:48 +0000201
Ryan Harrison45788092024-06-19 02:26:57 +0000202option(TINT_BUILD_IR_BINARY "Build IR binary format support" ${TINT_DEFAULT_BUILD_IR_BINARY})
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000203option(TINT_BUILD_FUZZERS "Build fuzzers" OFF)
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000204option(TINT_BUILD_IR_FUZZER "Build IR fuzzer" OFF)
205option(TINT_BUILD_BENCHMARKS "Build Tint benchmarks" OFF)
206option(TINT_BUILD_TESTS "Build tests" ON)
207option(TINT_BUILD_AS_OTHER_OS "Override OS detection to force building of *_other.cc files" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000208
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000209option(TINT_BUILD_TINTD "Build the WGSL language server" OFF)
Ben Claytonf9a5b712024-03-13 17:37:33 +0000210
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000211option(TINT_ENABLE_BREAK_IN_DEBUGGER "Enable tint::debugger::Break()" OFF)
212option(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF)
213option(TINT_RANDOMIZE_HASHES "Randomize the hash seed value to detect non-deterministic output" OFF)
Corentin Walleze5570872020-10-20 14:26:10 +0000214
dan sinclair194c1772022-06-21 17:54:03 +0000215set_if_not_defined(DAWN_THIRD_PARTY_DIR "${Dawn_SOURCE_DIR}/third_party" "Directory in which to find third-party dependencies.")
dan sinclairc1f6dbd2023-04-11 15:45:18 +0000216
Ben Clayton30eeac72021-09-24 10:38:18 +0000217set_if_not_defined(DAWN_ABSEIL_DIR "${DAWN_THIRD_PARTY_DIR}/abseil-cpp" "Directory in which to find Abseil")
218set_if_not_defined(DAWN_GLFW_DIR "${DAWN_THIRD_PARTY_DIR}/glfw" "Directory in which to find GLFW")
Ben Clayton30eeac72021-09-24 10:38:18 +0000219set_if_not_defined(DAWN_JINJA2_DIR "${DAWN_THIRD_PARTY_DIR}/jinja2" "Directory in which to find Jinja2")
Arthur Sonzognic5f72f72023-11-29 15:27:40 +0000220set_if_not_defined(DAWN_MARKUPSAFE_DIR "${DAWN_THIRD_PARTY_DIR}/markupsafe" "Directory in which to find MarkupSafe")
Arthur Sonzogni58f8ed22023-11-30 09:30:52 +0000221set_if_not_defined(DAWN_KHRONOS_DIR "${DAWN_THIRD_PARTY_DIR}/khronos" "Directory in which to find Khronos GL headers")
Corentin Wallezbe352ea2022-04-11 16:48:43 +0000222set_if_not_defined(DAWN_SWIFTSHADER_DIR "${DAWN_THIRD_PARTY_DIR}/swiftshader" "Directory in which to find swiftshader")
Ben Claytonfb07fa92023-11-17 18:48:59 +0000223set_if_not_defined(DAWN_PROTOBUF_DIR "${DAWN_THIRD_PARTY_DIR}/protobuf" "Directory in which to find protobuf")
Ryan Harrison25e23b32024-05-27 23:21:05 +0000224set_if_not_defined(DAWN_LPM_DIR "${DAWN_THIRD_PARTY_DIR}/libprotobuf-mutator/src" "Directory in which to find libprotobuf")
Loko Kung90fdaa82024-07-24 00:59:58 +0000225set_if_not_defined(DAWN_EMDAWNWEBGPU_DIR "${DAWN_THIRD_PARTY_DIR}/emdawnwebgpu" "Directory in which to find Dawn specific Emscripten bindings")
dan sinclairc1f6dbd2023-04-11 15:45:18 +0000226
Yuly Novikov143523a2024-05-23 15:59:58 +0000227set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_THIRD_PARTY_DIR}/spirv-tools/src" "Directory in which to find SPIRV-Tools")
228set_if_not_defined(DAWN_SPIRV_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/spirv-headers/src" "Directory in which to find SPIRV-Headers")
dan sinclair12c428f2024-06-21 01:14:24 +0000229set_if_not_defined(DAWN_GLSLANG_DIR "${DAWN_THIRD_PARTY_DIR}/glslang/src" "Directory in which to find GLSLang")
Yuly Novikov143523a2024-05-23 15:59:58 +0000230set_if_not_defined(DAWN_VULKAN_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-headers/src" "Directory in which to find Vulkan-Headers")
231set_if_not_defined(DAWN_VULKAN_UTILITY_LIBRARIES_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-utility-libraries/src" "Directory in which to find Vulkan-Utility-Libraries")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000232
Ben Claytonaffb7a32021-09-28 11:14:42 +0000233# Dependencies for DAWN_BUILD_NODE_BINDINGS
234set_if_not_defined(NODE_ADDON_API_DIR "${DAWN_THIRD_PARTY_DIR}/node-addon-api" "Directory in which to find node-addon-api")
Ben Clayton72e3ba62021-09-30 18:04:01 +0000235set_if_not_defined(NODE_API_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/node-api-headers" "Directory in which to find node-api-headers")
Ben Claytonaffb7a32021-09-28 11:14:42 +0000236set_if_not_defined(WEBGPU_IDL_PATH "${DAWN_THIRD_PARTY_DIR}/gpuweb/webgpu.idl" "Path to the webgpu.idl definition file")
Austin Eng4948c812021-10-15 14:28:32 +0000237set_if_not_defined(GO_EXECUTABLE "go" "Golang executable for running the IDL generator")
Ben Claytonaffb7a32021-09-28 11:14:42 +0000238
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000239option(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" OFF)
Elie Michel9ae8ed22023-05-12 20:19:41 +0000240
Jaswant Panchumarti5a26bdd2024-07-04 14:13:55 +0000241option(DAWN_BUILD_MONOLITHIC_LIBRARY "Bundle all dawn components into a single shared library." ON)
242
Loko Kung90fdaa82024-07-24 00:59:58 +0000243# Optional path to Emscripten toolchain to allow for building WASM.
244set_if_not_defined(DAWN_EMSCRIPTEN_TOOLCHAIN "" "Directory in which to find Emscripten toolchain")
245set(DAWN_ENABLE_EMSCRIPTEN OFF)
246if (NOT ${DAWN_EMSCRIPTEN_TOOLCHAIN} STREQUAL "" AND ENABLE_EMSCRIPTEN)
247 set(DAWN_ENABLE_EMSCRIPTEN ON)
248endif()
249
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000250# Much of the backend code is shared among desktop OpenGL and OpenGL ES
251if (${DAWN_ENABLE_DESKTOP_GL} OR ${DAWN_ENABLE_OPENGLES})
252 set(DAWN_ENABLE_OPENGL ON)
253endif()
254
Ben Claytonaffb7a32021-09-28 11:14:42 +0000255if(DAWN_ENABLE_PIC)
256 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
257endif()
258
Jaswant Panchumarti5a26bdd2024-07-04 14:13:55 +0000259# Defines `CMAKE_INSTALL_*DIR` variables
260include(GNUInstallDirs)
Jaswant Panchumarti34cca842024-06-25 00:30:37 +0000261# The public config contains only the include paths for the Dawn headers.
262add_library(dawn_public_config INTERFACE)
263target_include_directories(dawn_public_config INTERFACE
Jaswant Panchumarti5a26bdd2024-07-04 14:13:55 +0000264 "$<BUILD_INTERFACE:${DAWN_INCLUDE_DIR}>"
265 "$<BUILD_INTERFACE:${DAWN_BUILD_GEN_DIR}/include>"
266 "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
Jaswant Panchumarti34cca842024-06-25 00:30:37 +0000267)
268
269# The internal config contains additional path but includes the dawn_public_config include paths
270add_library(dawn_internal_config INTERFACE)
271target_include_directories(dawn_internal_config INTERFACE
dan sinclaird90557b2024-08-28 16:15:03 +0000272 "${PROJECT_SOURCE_DIR}"
Jaswant Panchumarti34cca842024-06-25 00:30:37 +0000273 "${DAWN_SRC_DIR}"
274 "${DAWN_BUILD_GEN_DIR}/src"
275)
276target_link_libraries(dawn_internal_config INTERFACE dawn_public_config)
277
Jaswant Panchumartieb93d8c2024-06-22 10:51:37 +0000278################################################################################
279# Include utility CMake modules
280################################################################################
Jaswant Panchumarti064f5442024-06-22 11:19:03 +0000281include(DawnCompilerChecks)
Jaswant Panchumartieb93d8c2024-06-22 10:51:37 +0000282include(DawnCompilerExtraFlags)
Jaswant Panchumarti61f9bc02024-06-22 10:56:48 +0000283include(DawnCompilerPlatformFlags)
Jaswant Panchumarti34cca842024-06-25 00:30:37 +0000284include(DawnCompilerWarningFlags)
Jaswant Panchumartifa416492024-06-22 11:08:57 +0000285include(DawnInitializeBuildType)
Jaswant Panchumarti85b76752024-06-25 04:24:49 +0000286include(DawnLibrary)
Jaswant Panchumartieb93d8c2024-06-22 10:51:37 +0000287
Peng Huang5c2f1672023-05-01 23:05:42 +0000288message(STATUS "Dawn build D3D11 backend: ${DAWN_ENABLE_D3D11}")
dan sinclair194c1772022-06-21 17:54:03 +0000289message(STATUS "Dawn build D3D12 backend: ${DAWN_ENABLE_D3D12}")
290message(STATUS "Dawn build Metal backend: ${DAWN_ENABLE_METAL}")
291message(STATUS "Dawn build Vulkan backend: ${DAWN_ENABLE_VULKAN}")
292message(STATUS "Dawn build OpenGL backend: ${DAWN_ENABLE_DESKTOP_GL}")
293message(STATUS "Dawn build OpenGL ES backend: ${DAWN_ENABLE_OPENGLES}")
Loko Kung7df368a2024-08-08 20:59:02 +0000294message(STATUS "Dawn build Emscripten: ${DAWN_ENABLE_EMSCRIPTEN}")
dan sinclair194c1772022-06-21 17:54:03 +0000295message(STATUS "Dawn build Null backend: ${DAWN_ENABLE_NULL}")
296
Jaswant Panchumarti5bdf8762024-06-22 11:12:38 +0000297message(STATUS "Dawn enable SPIR-V validation: ${DAWN_ENABLE_SPIRV_VALIDATION}")
298
dan sinclair194c1772022-06-21 17:54:03 +0000299message(STATUS "Dawn build with asserts in all configurations: ${DAWN_ALWAYS_ASSERT}")
300message(STATUS "Dawn build Wayland support: ${DAWN_USE_WAYLAND}")
301message(STATUS "Dawn build X11 support: ${DAWN_USE_X11}")
AlexVestin5c3645c2023-10-18 14:08:26 +0000302message(STATUS "Dawn build GLFW support: ${DAWN_USE_GLFW}")
Stephen Gutekanst55623702023-07-01 11:43:55 +0000303message(STATUS "Dawn build Windows UI support: ${DAWN_USE_WINDOWS_UI}")
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000304message(STATUS "Dawn build and use DXC: ${DAWN_USE_BUILT_DXC}")
Antonio Maioranoc5c74802024-08-08 14:45:08 +0000305message(STATUS "Dawn enable DXC asserts in non-debug builds: ${DAWN_DXC_ENABLE_ASSERTS_IN_NDEBUG}")
dan sinclair194c1772022-06-21 17:54:03 +0000306
307message(STATUS "Dawn build samples: ${DAWN_BUILD_SAMPLES}")
308message(STATUS "Dawn build Node bindings: ${DAWN_BUILD_NODE_BINDINGS}")
309message(STATUS "Dawn build Swiftshader: ${DAWN_ENABLE_SWIFTSHADER}")
Austin Eng6a7bba52023-04-17 18:11:51 +0000310message(STATUS "Dawn build benchmarks: ${DAWN_BUILD_BENCHMARKS}")
dan sinclair194c1772022-06-21 17:54:03 +0000311
312message(STATUS "Dawn build PIC: ${DAWN_ENABLE_PIC}")
313
314message(STATUS "Dawn build with ASAN: ${DAWN_ENABLE_ASAN}")
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000315message(STATUS "Dawn build with TSAN: ${DAWN_ENABLE_TSAN}")
dan sinclair194c1772022-06-21 17:54:03 +0000316message(STATUS "Dawn build with MSAN: ${DAWN_ENABLE_MSAN}")
317message(STATUS "Dawn build with UBSAN: ${DAWN_ENABLE_UBSAN}")
318
Loko Kung90fdaa82024-07-24 00:59:58 +0000319# We don't build Tint when building with Emscripten so silence these messages.
320if (NOT ${DAWN_ENABLE_EMSCRIPTEN})
Ben Clayton3a3cb362023-08-16 01:05:21 +0000321message(STATUS "Tint build command line executable tools: ${TINT_BUILD_CMD_TOOLS}")
dan sinclair194c1772022-06-21 17:54:03 +0000322message(STATUS "Tint build SPIR-V reader: ${TINT_BUILD_SPV_READER}")
323message(STATUS "Tint build WGSL reader: ${TINT_BUILD_WGSL_READER}")
324message(STATUS "Tint build GLSL writer: ${TINT_BUILD_GLSL_WRITER}")
Ben Claytonf1b8a012023-10-11 17:15:52 +0000325message(STATUS "Tint build GLSL validator: ${TINT_BUILD_GLSL_VALIDATOR}")
dan sinclair194c1772022-06-21 17:54:03 +0000326message(STATUS "Tint build HLSL writer: ${TINT_BUILD_HLSL_WRITER}")
327message(STATUS "Tint build MSL writer: ${TINT_BUILD_MSL_WRITER}")
328message(STATUS "Tint build SPIR-V writer: ${TINT_BUILD_SPV_WRITER}")
329message(STATUS "Tint build WGSL writer: ${TINT_BUILD_WGSL_WRITER}")
dan sinclair0917fbb2023-03-07 18:28:38 +0000330message(STATUS "Tint build Syntax Tree writer: ${TINT_BUILD_SYNTAX_TREE_WRITER}")
dan sinclair194c1772022-06-21 17:54:03 +0000331message(STATUS "Tint build fuzzers: ${TINT_BUILD_FUZZERS}")
dan sinclair12c428f2024-06-21 01:14:24 +0000332message(STATUS "Tint build IR binary: ${TINT_BUILD_IR_BINARY}")
Antonio Maiorano9fb4dc22024-06-18 15:49:36 +0000333message(STATUS "Tint build IR fuzzer: ${TINT_BUILD_IR_FUZZER}")
dan sinclair194c1772022-06-21 17:54:03 +0000334message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}")
335message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}")
336message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}")
Loko Kung90fdaa82024-07-24 00:59:58 +0000337endif()
Ben Clayton8fc9b862023-04-19 15:03:19 +0000338
Ryan Harrison88e0d752024-06-14 02:02:10 +0000339set(IS_ASAN ${DAWN_ENABLE_ASAN})
dan sinclair194c1772022-06-21 17:54:03 +0000340
341if (NOT ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS} STREQUAL "")
342 message(STATUS "Using provided LIB_FUZZING_ENGINE options: ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS}")
343endif()
344
Corentin Wallez179e84a2024-03-27 20:20:15 +0000345find_package(Python3 REQUIRED)
Corentin Wallez2f18c9a2024-04-02 08:51:45 +0000346message(STATUS "Dawn: using python at ${Python3_EXECUTABLE}")
dan sinclair194c1772022-06-21 17:54:03 +0000347
Ben Clayton94181522022-11-09 20:55:33 +0000348set(IS_DEBUG_BUILD 0)
349string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
350if ((NOT ${build_type} STREQUAL "RELEASE") AND (NOT ${build_type} STREQUAL "RELWITHDEBINFO"))
351 set(IS_DEBUG_BUILD 1)
352endif()
353
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000354# Compile definitions for the internal config
Ben Clayton94181522022-11-09 20:55:33 +0000355if (DAWN_ALWAYS_ASSERT OR IS_DEBUG_BUILD)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000356 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_ASSERTS")
357endif()
Peng Huang5c2f1672023-05-01 23:05:42 +0000358if (DAWN_ENABLE_D3D11)
359 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D11")
360endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000361if (DAWN_ENABLE_D3D12)
362 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D12")
363endif()
364if (DAWN_ENABLE_METAL)
365 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_METAL")
366endif()
367if (DAWN_ENABLE_NULL)
368 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_NULL")
369endif()
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000370if (DAWN_ENABLE_DESKTOP_GL)
371 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_DESKTOP_GL")
372endif()
373if (DAWN_ENABLE_OPENGLES)
374 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGLES")
375endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000376if (DAWN_ENABLE_OPENGL)
377 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGL")
378endif()
379if (DAWN_ENABLE_VULKAN)
380 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_VULKAN")
381endif()
Corentin Wallez2e22d922022-06-01 09:30:50 +0000382if (DAWN_USE_WAYLAND)
383 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WAYLAND")
384endif()
Corentin Wallezd353ca02020-02-18 02:12:35 +0000385if (DAWN_USE_X11)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000386 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11")
387endif()
Stephen Gutekanst55623702023-07-01 11:43:55 +0000388if (DAWN_USE_WINDOWS_UI)
389 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WINDOWS_UI")
390endif()
Corentin Wallez33466972020-02-24 13:27:28 +0000391if (WIN32)
392 target_compile_definitions(dawn_internal_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN")
393endif()
394
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000395################################################################################
Ryan Harrisone87ac762022-04-06 15:37:27 -0400396# Tint
397################################################################################
398
Alastair Donaldson6a1eb452021-09-02 23:49:25 +0000399set(TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS "" CACHE STRING "Used by OSS-Fuzz to control, via link options, which fuzzing engine should be used")
400
Ben Claytonfb07fa92023-11-17 18:48:59 +0000401set(TINT_ROOT_SOURCE_DIR ${PROJECT_SOURCE_DIR})
Ben Clayton3a3cb362023-08-16 01:05:21 +0000402set(TINT_SPIRV_HEADERS_DIR ${DAWN_SPIRV_HEADERS_DIR})
403set(TINT_SPIRV_TOOLS_DIR ${DAWN_SPIRV_TOOLS_DIR})
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000404
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000405
Ryan Harrisone87ac762022-04-06 15:37:27 -0400406################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000407# Run on all subdirectories
408################################################################################
dan sinclair0c27cf22024-06-11 12:31:38 +0000409if (DAWN_BUILD_PROTOBUF AND EXISTS "${DAWN_PROTOBUF_DIR}/cmake")
Ben Clayton01fa7c82024-01-31 21:07:17 +0000410 if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND WIN32)
411 set(protobuf_HAVE_BUILTIN_ATOMICS 1)
412 endif()
413
Ben Claytonfb07fa92023-11-17 18:48:59 +0000414 # Needs to come before SPIR-V Tools
415 include("third_party/protobuf.cmake")
416endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000417
418add_subdirectory(third_party)
James Price8d9adb02022-05-22 00:41:53 +0000419
420# TODO(crbug.com/tint/455): Tint does not currently build with CMake when
421# BUILD_SHARED_LIBS=1, so always build it as static for now.
422set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS})
423set(BUILD_SHARED_LIBS 0)
dan sinclaird90557b2024-08-28 16:15:03 +0000424
425add_subdirectory(src/utils)
426
Loko Kung90fdaa82024-07-24 00:59:58 +0000427# Only build Tint when we are not building under Emscripten.
428if (NOT ${DAWN_ENABLE_EMSCRIPTEN})
429 add_subdirectory(src/tint)
430endif()
James Price8d9adb02022-05-22 00:41:53 +0000431set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED})
dan sinclair12c428f2024-06-21 01:14:24 +0000432
Loko Kung90fdaa82024-07-24 00:59:58 +0000433if (DAWN_ENABLE_D3D11 OR DAWN_ENABLE_D3D12 OR DAWN_ENABLE_METAL OR DAWN_ENABLE_NULL OR DAWN_ENABLE_DESKTOP_GL OR DAWN_ENABLE_OPENGLES OR DAWN_ENABLE_VULKAN OR DAWN_ENABLE_EMSCRIPTEN)
dan sinclair12c428f2024-06-21 01:14:24 +0000434 add_subdirectory(generator)
Loko Kung90fdaa82024-07-24 00:59:58 +0000435 # Note that we must add Emscripten directory first to ensure the correct
436 # headers will be exported upwards.
437 add_subdirectory(src/emdawnwebgpu)
dan sinclair12c428f2024-06-21 01:14:24 +0000438 add_subdirectory(src/dawn)
439endif()
Ben Clayton7b778552022-02-04 18:59:15 +0000440
441################################################################################
442# Samples
443################################################################################
dan sinclairb5950522020-03-19 13:03:35 +0000444add_custom_target(tint-lint
445 COMMAND ./tools/lint
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000446 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000447 COMMENT "Running linter"
448 VERBATIM)
449
450add_custom_target(tint-format
451 COMMAND ./tools/format
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000452 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000453 COMMENT "Running formatter"
454 VERBATIM)
Ben Claytonadb10d62020-10-27 21:04:59 +0000455
Ben Clayton78e45302023-01-26 15:57:27 +0000456if (DAWN_EMIT_COVERAGE)
457 add_subdirectory(tools/src/cmd/turbo-cov)
Ben Claytonadb10d62020-10-27 21:04:59 +0000458
Ben Clayton78e45302023-01-26 15:57:27 +0000459 # The tint-generate-coverage target generates a lcov.info file at the project
460 # root, holding the code coverage for all the tint_unitests.
Ben Claytonadb10d62020-10-27 21:04:59 +0000461 # This can be used by tools such as VSCode's Coverage Gutters extension to
462 # visualize code coverage in the editor.
463 get_filename_component(CLANG_BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY)
464 set(PATH_WITH_CLANG "${CLANG_BIN_DIR}:$ENV{PATH}")
465 add_custom_target(tint-generate-coverage
466 COMMAND ${CMAKE_COMMAND} -E env PATH=${PATH_WITH_CLANG} ./tools/tint-generate-coverage $<TARGET_FILE:tint_unittests>
467 DEPENDS tint_unittests
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000468 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
Ben Claytonadb10d62020-10-27 21:04:59 +0000469 COMMENT "Generating tint coverage data"
470 VERBATIM)
471endif()
Jaswant Panchumarti5a26bdd2024-07-04 14:13:55 +0000472
473if (DAWN_BUILD_MONOLITHIC_LIBRARY AND DAWN_ENABLE_INSTALL)
474 # This series of functions add the necessary information so that other CMake projects
475 # can use Dawn, be it from a build directory, a local install or when packaged.
476 install(EXPORT DawnTargets
477 FILE DawnTargets.cmake
478 NAMESPACE dawn::
479 DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Dawn")
480 export(EXPORT DawnTargets
481 FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/DawnTargets.cmake"
482 NAMESPACE dawn::
483 )
484 # Create a ConfigVersion.cmake file:
485 include(CMakePackageConfigHelpers)
486 write_basic_package_version_file(
487 "${CMAKE_CURRENT_BINARY_DIR}/DawnConfigVersion.cmake"
488 COMPATIBILITY AnyNewerVersion)
489 # Configure config file
490 configure_package_config_file("${CMAKE_CURRENT_LIST_DIR}/src/cmake/DawnConfig.cmake.in"
491 "${CMAKE_CURRENT_BINARY_DIR}/DawnConfig.cmake"
492 INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Dawn"
493 )
494 # Install the fully generated config and configVersion files
495 install(FILES
496 "${CMAKE_CURRENT_BINARY_DIR}/DawnConfig.cmake"
497 "${CMAKE_CURRENT_BINARY_DIR}/DawnConfigVersion.cmake"
498 DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Dawn"
499 )
500endif ()