blob: 53e997d14313163f7904dd4ab94ca027d5c00bf2 [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
35# DawnGenerator. We should also use the path utilities in install_if_enabled.
36
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"
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000042)
Dan Sinclair6e581892020-03-02 15:47:43 -050043enable_testing()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000044
Jaswant Panchumarti72b712f2024-06-21 13:16:18 +000045list(INSERT CMAKE_MODULE_PATH 0 "${Dawn_SOURCE_DIR}/src/cmake")
46
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000047set_property(GLOBAL PROPERTY USE_FOLDERS ON)
48
Dan Sinclair6e581892020-03-02 15:47:43 -050049set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
50set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Dan Sinclair6e581892020-03-02 15:47:43 -050051set(CMAKE_DEBUG_POSTFIX "")
dan sinclair2df80912023-11-20 13:22:14 +000052set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Dan Sinclair6e581892020-03-02 15:47:43 -050053
Jaswant Panchumarti72b712f2024-06-21 13:16:18 +000054include(DawnSetIfNotDefined)
55
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000056set(DAWN_BUILD_GEN_DIR "${Dawn_BINARY_DIR}/gen")
57set(DAWN_GENERATOR_DIR "${Dawn_SOURCE_DIR}/generator")
58set(DAWN_SRC_DIR "${Dawn_SOURCE_DIR}/src")
Ben Clayton9fb7a512022-02-04 18:18:18 +000059set(DAWN_INCLUDE_DIR "${Dawn_SOURCE_DIR}/include")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000060set(DAWN_TEMPLATE_DIR "${DAWN_GENERATOR_DIR}/templates")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000061
munozac511ffb2023-09-25 14:01:03 +000062function (install_if_enabled target)
63 if(NOT DAWN_ENABLE_INSTALL)
64 return()
65 endif()
66
67 install(TARGETS ${target}
68 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
69 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
70 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
71 )
72
73 get_target_property(targetHeaders ${target} INTERFACE_SOURCES)
74 if (NOT targetHeaders)
75 return()
76 endif()
77
78 foreach(headerFile ${targetHeaders})
79 # Starting from CMake 3.20 there is the cmake_path command that could simplify this code.
80 # Compute the install subdirectory for the header by stripping out the path to
81 # the include / gen/include directory...
82 string(FIND "${headerFile}" "${DAWN_INCLUDE_DIR}" foundIndex)
83 if (foundIndex EQUAL 0)
84 string(LENGTH "${DAWN_INCLUDE_DIR}/" lengthToRemove)
85 endif()
86 string(FIND "${headerFile}" "${DAWN_BUILD_GEN_DIR}/include/" foundIndex)
87 if (foundIndex EQUAL 0)
88 string(LENGTH "${DAWN_BUILD_GEN_DIR}/include/" lengthToRemove)
89 endif()
90 string(SUBSTRING "${headerFile}" "${lengthToRemove}" -1 headerRelDir)
91
92 # ... then remove everything after the last /
93 string(FIND "${headerRelDir}" "/" foundIndex REVERSE)
94 string(SUBSTRING "${headerRelDir}" 0 ${foundIndex} headerRelDir)
95
96 install(FILES "${headerFile}" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${headerRelDir})
97 endforeach()
98endfunction()
99
Jaswant Panchumarti72b712f2024-06-21 13:16:18 +0000100################################################################################
101# Configuration options
102################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000103# Default values for the backend-enabling options
Peng Huang925b7762023-05-01 16:13:00 +0000104set(ENABLE_D3D11 OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000105set(ENABLE_D3D12 OFF)
106set(ENABLE_METAL OFF)
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000107set(ENABLE_OPENGLES OFF)
108set(ENABLE_DESKTOP_GL OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000109set(ENABLE_VULKAN OFF)
Jaswant Panchumarti5bdf8762024-06-22 11:12:38 +0000110set(ENABLE_SPIRV_VALIDATION OFF)
Corentin Wallez2e22d922022-06-01 09:30:50 +0000111set(USE_WAYLAND OFF)
Corentin Wallezd353ca02020-02-18 02:12:35 +0000112set(USE_X11 OFF)
Stephen Gutekanst55623702023-07-01 11:43:55 +0000113set(USE_WINDOWS_UI OFF)
Ben Claytona6750752022-02-04 18:35:55 +0000114set(BUILD_SAMPLES OFF)
AlexVestin5c3645c2023-10-18 14:08:26 +0000115set(TARGET_MACOS OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000116if (WIN32)
Peng Huang925b7762023-05-01 16:13:00 +0000117 set(ENABLE_D3D11 ON)
Stephen Gutekanst55623702023-07-01 11:43:55 +0000118 set(USE_WINDOWS_UI ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000119 set(ENABLE_D3D12 ON)
Jaswant Panchumarti5bdf8762024-06-22 11:12:38 +0000120 if (NOT WINDOWS_STORE)
121 # Enable Vulkan in win32 compilation only
122 # since UWP only supports d3d
123 set(ENABLE_VULKAN ON)
124 set(ENABLE_SPIRV_VALIDATION ON)
125 endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000126elseif(APPLE)
Jaswant Panchumarti5bdf8762024-06-22 11:12:38 +0000127 set(ENABLE_METAL ON)
128 if(CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "MacOS")
129 set(TARGET_MACOS ON)
130 endif()
Alexander Vestinf2556ab2022-03-25 13:18:46 +0000131elseif(ANDROID)
Jaswant Panchumarti5bdf8762024-06-22 11:12:38 +0000132 set(ENABLE_VULKAN ON)
133 set(ENABLE_OPENGLES ON)
134 # Disable SPIR-V validation on Android because it adds a significant amount
135 # to the binary size, and Tint's output should be well-formed.
136 set(ENABLE_SPIRV_VALIDATION OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000137elseif(UNIX)
Jaswant Panchumarti5bdf8762024-06-22 11:12:38 +0000138 set(ENABLE_OPENGLES ON)
139 set(ENABLE_DESKTOP_GL ON)
140 set(ENABLE_VULKAN ON)
141 set(ENABLE_SPIRV_VALIDATION ON)
142 set(USE_X11 ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000143endif()
144
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000145# GLFW is not supported in UWP
Albin Bernhardssonb8a1b6d2023-07-13 08:51:17 +0000146set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING OFF)
Sonakshi Saxena13446112023-08-23 12:32:14 +0000147
148if ((WIN32 AND NOT WINDOWS_STORE) OR (UNIX AND NOT ANDROID))
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000149 set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING ON)
150endif()
151
152# Current examples are depend on GLFW
153if (DAWN_SUPPORTS_GLFW_FOR_WINDOWING)
Ben Claytona6750752022-02-04 18:35:55 +0000154 set(BUILD_SAMPLES ON)
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000155endif()
156
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000157option(DAWN_ENABLE_ASAN "Enable address sanitizer" OFF)
158option(DAWN_ENABLE_INSTALL "Enable install step for Dawn libraries" OFF)
159option(DAWN_ENABLE_TSAN "Enable thread sanitizer" OFF)
160option(DAWN_ENABLE_MSAN "Enable memory sanitizer" OFF)
161option(DAWN_ENABLE_UBSAN "Enable undefined behaviour sanitizer" OFF)
Ben Clayton96e245e2022-04-08 18:08:36 +0000162
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000163option(DAWN_ENABLE_D3D11 "Enable compilation of the D3D11 backend" ${ENABLE_D3D11})
164option(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12})
165option(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL})
166option(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON)
167option(DAWN_ENABLE_DESKTOP_GL "Enable compilation of the OpenGL backend" ${ENABLE_DESKTOP_GL})
168option(DAWN_ENABLE_OPENGLES "Enable compilation of the OpenGL ES backend" ${ENABLE_OPENGLES})
169option(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backend" ${ENABLE_VULKAN})
Jaswant Panchumarti5bdf8762024-06-22 11:12:38 +0000170option(DAWN_ENABLE_SPIRV_VALIDATION "Enable validation of SPIR-V" ${ENABLE_SPIRV_VALIDATION})
dan sinclair194c1772022-06-21 17:54:03 +0000171
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000172option(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF)
173option(DAWN_USE_WAYLAND "Enable support for Wayland surface" ${USE_WAYLAND})
174option(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11})
175option(DAWN_USE_GLFW "Enable compilation of the GLFW windowing utils" ${DAWN_SUPPORTS_GLFW_FOR_WINDOWING})
176option(DAWN_USE_WINDOWS_UI "Enable support for Windows UI surface" ${USE_WINDOWS_UI})
177option(DAWN_USE_BUILT_DXC "Enable building and using DXC by the D3D12 backend" OFF)
178option(DAWN_DXC_DISABLE_ASSERTS_DEBUG "Disable asserts in DXC in debug builds" OFF)
179option(DAWN_TARGET_MACOS "Manually link Apple core frameworks" ${TARGET_MACOS})
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000180
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000181option(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" ${BUILD_SAMPLES})
182option(DAWN_BUILD_NODE_BINDINGS "Enables building Dawn's NodeJS bindings" OFF)
183option(DAWN_ENABLE_SWIFTSHADER "Enables building Swiftshader as part of the build and Vulkan adapter discovery" OFF)
184option(DAWN_BUILD_BENCHMARKS "Build Dawn benchmarks" OFF)
dan sinclair0c27cf22024-06-11 12:31:38 +0000185option(DAWN_BUILD_PROTOBUF "Build the protobuf dependencies" OFF)
Ben Claytonaffb7a32021-09-28 11:14:42 +0000186
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000187option(DAWN_WERROR "Build with -Werror (or equivalent)" OFF)
188option(DAWN_ENABLE_PIC "Build with Position-Independent-Code enabled" OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000189
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000190option(DAWN_EMIT_COVERAGE "Emit code coverage information" OFF)
Ben Claytonf927bcb2022-12-12 21:21:54 +0000191set_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 +0000192
dan sinclair194c1772022-06-21 17:54:03 +0000193if (DAWN_ENABLE_OPENGLES OR DAWN_ENABLE_DESKTOP_GL)
194 set(TINT_DEFAULT_GLSL ON)
195else()
196 set(TINT_DEFAULT_GLSL OFF)
197endif()
198
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000199option(TINT_ENABLE_INSTALL "Enable install step for Tint libraries" OFF)
200option(TINT_BUILD_CMD_TOOLS "Build the Tint command line tools" ON)
dan sinclair194c1772022-06-21 17:54:03 +0000201
dan sinclair12c428f2024-06-21 01:14:24 +0000202if (NOT DAWN_USE_GLFW AND DAWN_BUILD_SAMPLES)
Erin Melucci38b58e42023-06-14 16:45:33 +0000203 message(SEND_ERROR "Dawn samples require GLFW")
204endif()
205
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000206option(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" ${DAWN_ENABLE_VULKAN})
207option(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON)
208option(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" ${TINT_DEFAULT_GLSL})
209option(TINT_BUILD_GLSL_VALIDATOR "Build the GLSL output validator" ON)
210option(TINT_BUILD_HLSL_WRITER "Build the HLSL output writer" ${DAWN_ENABLE_D3D12})
211option(TINT_BUILD_MSL_WRITER "Build the MSL output writer" ${DAWN_ENABLE_METAL})
212option(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ${DAWN_ENABLE_VULKAN})
213option(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON)
dan sinclair194c1772022-06-21 17:54:03 +0000214
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000215option(TINT_BUILD_SYNTAX_TREE_WRITER "Build the syntax tree writer" OFF)
dan sinclairc22b8b9d2022-11-01 17:02:31 +0000216
Ryan Harrison45788092024-06-19 02:26:57 +0000217if (DAWN_BUILD_PROTOBUF AND TARGET libprotobuf)
218 set(TINT_DEFAULT_BUILD_IR_BINARY ON)
219else()
220 set(TINT_DEFAULT_BUILD_IR_BINARY OFF)
221endif()
Ryan Harrison724dd782024-05-16 16:27:48 +0000222
Ryan Harrison45788092024-06-19 02:26:57 +0000223option(TINT_BUILD_IR_BINARY "Build IR binary format support" ${TINT_DEFAULT_BUILD_IR_BINARY})
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000224option(TINT_BUILD_FUZZERS "Build fuzzers" OFF)
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000225option(TINT_BUILD_IR_FUZZER "Build IR fuzzer" OFF)
226option(TINT_BUILD_BENCHMARKS "Build Tint benchmarks" OFF)
227option(TINT_BUILD_TESTS "Build tests" ON)
228option(TINT_BUILD_AS_OTHER_OS "Override OS detection to force building of *_other.cc files" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000229
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000230option(TINT_BUILD_TINTD "Build the WGSL language server" OFF)
Ben Claytonf9a5b712024-03-13 17:37:33 +0000231
Ben Clayton8fc9b862023-04-19 15:03:19 +0000232set_if_not_defined(TINT_EXTERNAL_BENCHMARK_CORPUS_DIR "" "Directory that holds a corpus of external shaders to benchmark.")
233
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000234option(TINT_ENABLE_BREAK_IN_DEBUGGER "Enable tint::debugger::Break()" OFF)
235option(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF)
236option(TINT_RANDOMIZE_HASHES "Randomize the hash seed value to detect non-deterministic output" OFF)
Corentin Walleze5570872020-10-20 14:26:10 +0000237
dan sinclair194c1772022-06-21 17:54:03 +0000238set_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 +0000239
Ben Clayton30eeac72021-09-24 10:38:18 +0000240set_if_not_defined(DAWN_ABSEIL_DIR "${DAWN_THIRD_PARTY_DIR}/abseil-cpp" "Directory in which to find Abseil")
241set_if_not_defined(DAWN_GLFW_DIR "${DAWN_THIRD_PARTY_DIR}/glfw" "Directory in which to find GLFW")
Ben Clayton30eeac72021-09-24 10:38:18 +0000242set_if_not_defined(DAWN_JINJA2_DIR "${DAWN_THIRD_PARTY_DIR}/jinja2" "Directory in which to find Jinja2")
Arthur Sonzognic5f72f72023-11-29 15:27:40 +0000243set_if_not_defined(DAWN_MARKUPSAFE_DIR "${DAWN_THIRD_PARTY_DIR}/markupsafe" "Directory in which to find MarkupSafe")
Arthur Sonzogni58f8ed22023-11-30 09:30:52 +0000244set_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 +0000245set_if_not_defined(DAWN_SWIFTSHADER_DIR "${DAWN_THIRD_PARTY_DIR}/swiftshader" "Directory in which to find swiftshader")
Ben Claytonfb07fa92023-11-17 18:48:59 +0000246set_if_not_defined(DAWN_PROTOBUF_DIR "${DAWN_THIRD_PARTY_DIR}/protobuf" "Directory in which to find protobuf")
Ryan Harrison25e23b32024-05-27 23:21:05 +0000247set_if_not_defined(DAWN_LPM_DIR "${DAWN_THIRD_PARTY_DIR}/libprotobuf-mutator/src" "Directory in which to find libprotobuf")
dan sinclairc1f6dbd2023-04-11 15:45:18 +0000248
Yuly Novikov143523a2024-05-23 15:59:58 +0000249set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_THIRD_PARTY_DIR}/spirv-tools/src" "Directory in which to find SPIRV-Tools")
250set_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 +0000251set_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 +0000252set_if_not_defined(DAWN_VULKAN_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-headers/src" "Directory in which to find Vulkan-Headers")
253set_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 +0000254
Ben Claytonaffb7a32021-09-28 11:14:42 +0000255# Dependencies for DAWN_BUILD_NODE_BINDINGS
256set_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 +0000257set_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 +0000258set_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 +0000259set_if_not_defined(GO_EXECUTABLE "go" "Golang executable for running the IDL generator")
Ben Claytonaffb7a32021-09-28 11:14:42 +0000260
Jaswant Panchumartidb4c4022024-06-10 09:23:49 +0000261option(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" OFF)
Elie Michel9ae8ed22023-05-12 20:19:41 +0000262
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000263# Much of the backend code is shared among desktop OpenGL and OpenGL ES
264if (${DAWN_ENABLE_DESKTOP_GL} OR ${DAWN_ENABLE_OPENGLES})
265 set(DAWN_ENABLE_OPENGL ON)
266endif()
267
Ben Claytonaffb7a32021-09-28 11:14:42 +0000268if(DAWN_ENABLE_PIC)
269 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
270endif()
271
Jaswant Panchumarti34cca842024-06-25 00:30:37 +0000272# The public config contains only the include paths for the Dawn headers.
273add_library(dawn_public_config INTERFACE)
274target_include_directories(dawn_public_config INTERFACE
275 "${DAWN_INCLUDE_DIR}"
276 "${DAWN_BUILD_GEN_DIR}/include"
277)
278
279# The internal config contains additional path but includes the dawn_public_config include paths
280add_library(dawn_internal_config INTERFACE)
281target_include_directories(dawn_internal_config INTERFACE
282 "${DAWN_SRC_DIR}"
283 "${DAWN_BUILD_GEN_DIR}/src"
284)
285target_link_libraries(dawn_internal_config INTERFACE dawn_public_config)
286
Jaswant Panchumartieb93d8c2024-06-22 10:51:37 +0000287################################################################################
288# Include utility CMake modules
289################################################################################
Jaswant Panchumarti064f5442024-06-22 11:19:03 +0000290include(DawnCompilerChecks)
Jaswant Panchumartieb93d8c2024-06-22 10:51:37 +0000291include(DawnCompilerExtraFlags)
Jaswant Panchumarti61f9bc02024-06-22 10:56:48 +0000292include(DawnCompilerPlatformFlags)
Jaswant Panchumarti34cca842024-06-25 00:30:37 +0000293include(DawnCompilerWarningFlags)
Jaswant Panchumartifa416492024-06-22 11:08:57 +0000294include(DawnInitializeBuildType)
Jaswant Panchumarti85b76752024-06-25 04:24:49 +0000295include(DawnLibrary)
Jaswant Panchumartieb93d8c2024-06-22 10:51:37 +0000296
Peng Huang5c2f1672023-05-01 23:05:42 +0000297message(STATUS "Dawn build D3D11 backend: ${DAWN_ENABLE_D3D11}")
dan sinclair194c1772022-06-21 17:54:03 +0000298message(STATUS "Dawn build D3D12 backend: ${DAWN_ENABLE_D3D12}")
299message(STATUS "Dawn build Metal backend: ${DAWN_ENABLE_METAL}")
300message(STATUS "Dawn build Vulkan backend: ${DAWN_ENABLE_VULKAN}")
301message(STATUS "Dawn build OpenGL backend: ${DAWN_ENABLE_DESKTOP_GL}")
302message(STATUS "Dawn build OpenGL ES backend: ${DAWN_ENABLE_OPENGLES}")
303message(STATUS "Dawn build Null backend: ${DAWN_ENABLE_NULL}")
304
Jaswant Panchumarti5bdf8762024-06-22 11:12:38 +0000305message(STATUS "Dawn enable SPIR-V validation: ${DAWN_ENABLE_SPIRV_VALIDATION}")
306
dan sinclair194c1772022-06-21 17:54:03 +0000307message(STATUS "Dawn build with asserts in all configurations: ${DAWN_ALWAYS_ASSERT}")
308message(STATUS "Dawn build Wayland support: ${DAWN_USE_WAYLAND}")
309message(STATUS "Dawn build X11 support: ${DAWN_USE_X11}")
AlexVestin5c3645c2023-10-18 14:08:26 +0000310message(STATUS "Dawn build GLFW support: ${DAWN_USE_GLFW}")
Stephen Gutekanst55623702023-07-01 11:43:55 +0000311message(STATUS "Dawn build Windows UI support: ${DAWN_USE_WINDOWS_UI}")
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000312message(STATUS "Dawn build and use DXC: ${DAWN_USE_BUILT_DXC}")
Antonio Maioranob4d05de2024-04-16 19:36:58 +0000313message(STATUS "Dawn disable DXC asserts in debug builds: ${DAWN_DXC_DISABLE_ASSERTS_DEBUG}")
dan sinclair194c1772022-06-21 17:54:03 +0000314
315message(STATUS "Dawn build samples: ${DAWN_BUILD_SAMPLES}")
316message(STATUS "Dawn build Node bindings: ${DAWN_BUILD_NODE_BINDINGS}")
317message(STATUS "Dawn build Swiftshader: ${DAWN_ENABLE_SWIFTSHADER}")
Austin Eng6a7bba52023-04-17 18:11:51 +0000318message(STATUS "Dawn build benchmarks: ${DAWN_BUILD_BENCHMARKS}")
dan sinclair194c1772022-06-21 17:54:03 +0000319
320message(STATUS "Dawn build PIC: ${DAWN_ENABLE_PIC}")
321
322message(STATUS "Dawn build with ASAN: ${DAWN_ENABLE_ASAN}")
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000323message(STATUS "Dawn build with TSAN: ${DAWN_ENABLE_TSAN}")
dan sinclair194c1772022-06-21 17:54:03 +0000324message(STATUS "Dawn build with MSAN: ${DAWN_ENABLE_MSAN}")
325message(STATUS "Dawn build with UBSAN: ${DAWN_ENABLE_UBSAN}")
326
Ben Clayton3a3cb362023-08-16 01:05:21 +0000327message(STATUS "Tint build command line executable tools: ${TINT_BUILD_CMD_TOOLS}")
dan sinclair194c1772022-06-21 17:54:03 +0000328message(STATUS "Tint build SPIR-V reader: ${TINT_BUILD_SPV_READER}")
329message(STATUS "Tint build WGSL reader: ${TINT_BUILD_WGSL_READER}")
330message(STATUS "Tint build GLSL writer: ${TINT_BUILD_GLSL_WRITER}")
Ben Claytonf1b8a012023-10-11 17:15:52 +0000331message(STATUS "Tint build GLSL validator: ${TINT_BUILD_GLSL_VALIDATOR}")
dan sinclair194c1772022-06-21 17:54:03 +0000332message(STATUS "Tint build HLSL writer: ${TINT_BUILD_HLSL_WRITER}")
333message(STATUS "Tint build MSL writer: ${TINT_BUILD_MSL_WRITER}")
334message(STATUS "Tint build SPIR-V writer: ${TINT_BUILD_SPV_WRITER}")
335message(STATUS "Tint build WGSL writer: ${TINT_BUILD_WGSL_WRITER}")
dan sinclair0917fbb2023-03-07 18:28:38 +0000336message(STATUS "Tint build Syntax Tree writer: ${TINT_BUILD_SYNTAX_TREE_WRITER}")
dan sinclair194c1772022-06-21 17:54:03 +0000337message(STATUS "Tint build fuzzers: ${TINT_BUILD_FUZZERS}")
dan sinclair12c428f2024-06-21 01:14:24 +0000338message(STATUS "Tint build IR binary: ${TINT_BUILD_IR_BINARY}")
Antonio Maiorano9fb4dc22024-06-18 15:49:36 +0000339message(STATUS "Tint build IR fuzzer: ${TINT_BUILD_IR_FUZZER}")
dan sinclair194c1772022-06-21 17:54:03 +0000340message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}")
341message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}")
342message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}")
Ben Clayton8fc9b862023-04-19 15:03:19 +0000343message(STATUS "Tint external benchmark corpus dir: ${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}")
344
Ryan Harrison88e0d752024-06-14 02:02:10 +0000345set(IS_ASAN ${DAWN_ENABLE_ASAN})
dan sinclair194c1772022-06-21 17:54:03 +0000346
347if (NOT ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS} STREQUAL "")
348 message(STATUS "Using provided LIB_FUZZING_ENGINE options: ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS}")
349endif()
350
Corentin Wallez179e84a2024-03-27 20:20:15 +0000351find_package(Python3 REQUIRED)
Corentin Wallez2f18c9a2024-04-02 08:51:45 +0000352message(STATUS "Dawn: using python at ${Python3_EXECUTABLE}")
dan sinclair194c1772022-06-21 17:54:03 +0000353
Ben Clayton94181522022-11-09 20:55:33 +0000354set(IS_DEBUG_BUILD 0)
355string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
356if ((NOT ${build_type} STREQUAL "RELEASE") AND (NOT ${build_type} STREQUAL "RELWITHDEBINFO"))
357 set(IS_DEBUG_BUILD 1)
358endif()
359
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000360# Compile definitions for the internal config
Ben Clayton94181522022-11-09 20:55:33 +0000361if (DAWN_ALWAYS_ASSERT OR IS_DEBUG_BUILD)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000362 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_ASSERTS")
363endif()
Peng Huang5c2f1672023-05-01 23:05:42 +0000364if (DAWN_ENABLE_D3D11)
365 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D11")
366endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000367if (DAWN_ENABLE_D3D12)
368 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D12")
369endif()
370if (DAWN_ENABLE_METAL)
371 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_METAL")
372endif()
373if (DAWN_ENABLE_NULL)
374 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_NULL")
375endif()
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000376if (DAWN_ENABLE_DESKTOP_GL)
377 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_DESKTOP_GL")
378endif()
379if (DAWN_ENABLE_OPENGLES)
380 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGLES")
381endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000382if (DAWN_ENABLE_OPENGL)
383 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGL")
384endif()
385if (DAWN_ENABLE_VULKAN)
386 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_VULKAN")
387endif()
Corentin Wallez2e22d922022-06-01 09:30:50 +0000388if (DAWN_USE_WAYLAND)
389 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WAYLAND")
390endif()
Corentin Wallezd353ca02020-02-18 02:12:35 +0000391if (DAWN_USE_X11)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000392 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11")
393endif()
Stephen Gutekanst55623702023-07-01 11:43:55 +0000394if (DAWN_USE_WINDOWS_UI)
395 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WINDOWS_UI")
396endif()
Corentin Wallez33466972020-02-24 13:27:28 +0000397if (WIN32)
398 target_compile_definitions(dawn_internal_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN")
399endif()
400
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000401################################################################################
Ryan Harrisone87ac762022-04-06 15:37:27 -0400402# Tint
403################################################################################
404
Alastair Donaldson6a1eb452021-09-02 23:49:25 +0000405set(TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS "" CACHE STRING "Used by OSS-Fuzz to control, via link options, which fuzzing engine should be used")
406
Ben Claytonfb07fa92023-11-17 18:48:59 +0000407set(TINT_ROOT_SOURCE_DIR ${PROJECT_SOURCE_DIR})
Ben Clayton3a3cb362023-08-16 01:05:21 +0000408set(TINT_SPIRV_HEADERS_DIR ${DAWN_SPIRV_HEADERS_DIR})
409set(TINT_SPIRV_TOOLS_DIR ${DAWN_SPIRV_TOOLS_DIR})
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000410
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000411
Ryan Harrisone87ac762022-04-06 15:37:27 -0400412################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000413# Run on all subdirectories
414################################################################################
dan sinclair0c27cf22024-06-11 12:31:38 +0000415if (DAWN_BUILD_PROTOBUF AND EXISTS "${DAWN_PROTOBUF_DIR}/cmake")
Ben Clayton01fa7c82024-01-31 21:07:17 +0000416 if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND WIN32)
417 set(protobuf_HAVE_BUILTIN_ATOMICS 1)
418 endif()
419
Ben Claytonfb07fa92023-11-17 18:48:59 +0000420 # Needs to come before SPIR-V Tools
421 include("third_party/protobuf.cmake")
422endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000423
424add_subdirectory(third_party)
James Price8d9adb02022-05-22 00:41:53 +0000425
426# TODO(crbug.com/tint/455): Tint does not currently build with CMake when
427# BUILD_SHARED_LIBS=1, so always build it as static for now.
428set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS})
429set(BUILD_SHARED_LIBS 0)
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000430add_subdirectory(src/tint)
James Price8d9adb02022-05-22 00:41:53 +0000431set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED})
dan sinclair12c428f2024-06-21 01:14:24 +0000432
433if (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)
434 add_subdirectory(generator)
435 add_subdirectory(src/dawn)
436endif()
Ben Clayton7b778552022-02-04 18:59:15 +0000437
438################################################################################
439# Samples
440################################################################################
dan sinclairb5950522020-03-19 13:03:35 +0000441add_custom_target(tint-lint
442 COMMAND ./tools/lint
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000443 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000444 COMMENT "Running linter"
445 VERBATIM)
446
447add_custom_target(tint-format
448 COMMAND ./tools/format
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000449 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000450 COMMENT "Running formatter"
451 VERBATIM)
Ben Claytonadb10d62020-10-27 21:04:59 +0000452
Ben Clayton78e45302023-01-26 15:57:27 +0000453if (DAWN_EMIT_COVERAGE)
454 add_subdirectory(tools/src/cmd/turbo-cov)
Ben Claytonadb10d62020-10-27 21:04:59 +0000455
Ben Clayton78e45302023-01-26 15:57:27 +0000456 # The tint-generate-coverage target generates a lcov.info file at the project
457 # root, holding the code coverage for all the tint_unitests.
Ben Claytonadb10d62020-10-27 21:04:59 +0000458 # This can be used by tools such as VSCode's Coverage Gutters extension to
459 # visualize code coverage in the editor.
460 get_filename_component(CLANG_BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY)
461 set(PATH_WITH_CLANG "${CLANG_BIN_DIR}:$ENV{PATH}")
462 add_custom_target(tint-generate-coverage
463 COMMAND ${CMAKE_COMMAND} -E env PATH=${PATH_WITH_CLANG} ./tools/tint-generate-coverage $<TARGET_FILE:tint_unittests>
464 DEPENDS tint_unittests
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000465 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
Ben Claytonadb10d62020-10-27 21:04:59 +0000466 COMMENT "Generating tint coverage data"
467 VERBATIM)
468endif()