blob: 9e2909323ac3fc7d9bc7e2a7cf6d64a76bbd5e9a [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
45set_property(GLOBAL PROPERTY USE_FOLDERS ON)
46
Dan Sinclair6e581892020-03-02 15:47:43 -050047set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
48set(CMAKE_POSITION_INDEPENDENT_CODE ON)
dan sinclair05d278e2023-08-30 21:05:31 +000049set(CMAKE_CXX_STANDARD 17)
Dan Sinclair6e581892020-03-02 15:47:43 -050050set(CMAKE_DEBUG_POSTFIX "")
dan sinclair2df80912023-11-20 13:22:14 +000051set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Dan Sinclair6e581892020-03-02 15:47:43 -050052
53if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
54 message(STATUS "No build type selected, default to Debug")
55 set(CMAKE_BUILD_TYPE "Debug")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000056endif()
57
58set(DAWN_BUILD_GEN_DIR "${Dawn_BINARY_DIR}/gen")
59set(DAWN_GENERATOR_DIR "${Dawn_SOURCE_DIR}/generator")
60set(DAWN_SRC_DIR "${Dawn_SOURCE_DIR}/src")
Ben Clayton9fb7a512022-02-04 18:18:18 +000061set(DAWN_INCLUDE_DIR "${Dawn_SOURCE_DIR}/include")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000062set(DAWN_TEMPLATE_DIR "${DAWN_GENERATOR_DIR}/templates")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000063
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000064################################################################################
65# Configuration options
66################################################################################
67
Ben Clayton30eeac72021-09-24 10:38:18 +000068# option_if_not_defined(name description default)
69# Behaves like:
70# option(name description default)
71# If a variable is not already defined with the given name, otherwise the
72# function does nothing.
73# Simplifies customization by projects that use Dawn as a dependency.
74function (option_if_not_defined name description default)
75 if(NOT DEFINED ${name})
76 option(${name} ${description} ${default})
77 endif()
78endfunction()
79
80# set_if_not_defined(name value description)
81# Behaves like:
82# set(${name} ${value} CACHE STRING ${description})
83# If a variable is not already defined with the given name, otherwise the
84# function does nothing.
85# Simplifies customization by projects that use Dawn as a dependency.
86function (set_if_not_defined name value description)
87 if(NOT DEFINED ${name})
88 set(${name} ${value} CACHE STRING ${description})
89 endif()
90endfunction()
91
munozac511ffb2023-09-25 14:01:03 +000092function (install_if_enabled target)
93 if(NOT DAWN_ENABLE_INSTALL)
94 return()
95 endif()
96
97 install(TARGETS ${target}
98 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
99 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
100 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
101 )
102
103 get_target_property(targetHeaders ${target} INTERFACE_SOURCES)
104 if (NOT targetHeaders)
105 return()
106 endif()
107
108 foreach(headerFile ${targetHeaders})
109 # Starting from CMake 3.20 there is the cmake_path command that could simplify this code.
110 # Compute the install subdirectory for the header by stripping out the path to
111 # the include / gen/include directory...
112 string(FIND "${headerFile}" "${DAWN_INCLUDE_DIR}" foundIndex)
113 if (foundIndex EQUAL 0)
114 string(LENGTH "${DAWN_INCLUDE_DIR}/" lengthToRemove)
115 endif()
116 string(FIND "${headerFile}" "${DAWN_BUILD_GEN_DIR}/include/" foundIndex)
117 if (foundIndex EQUAL 0)
118 string(LENGTH "${DAWN_BUILD_GEN_DIR}/include/" lengthToRemove)
119 endif()
120 string(SUBSTRING "${headerFile}" "${lengthToRemove}" -1 headerRelDir)
121
122 # ... then remove everything after the last /
123 string(FIND "${headerRelDir}" "/" foundIndex REVERSE)
124 string(SUBSTRING "${headerRelDir}" 0 ${foundIndex} headerRelDir)
125
126 install(FILES "${headerFile}" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${headerRelDir})
127 endforeach()
128endfunction()
129
130
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000131# Default values for the backend-enabling options
Peng Huang925b7762023-05-01 16:13:00 +0000132set(ENABLE_D3D11 OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000133set(ENABLE_D3D12 OFF)
134set(ENABLE_METAL OFF)
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000135set(ENABLE_OPENGLES OFF)
136set(ENABLE_DESKTOP_GL OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000137set(ENABLE_VULKAN OFF)
Corentin Wallez2e22d922022-06-01 09:30:50 +0000138set(USE_WAYLAND OFF)
Corentin Wallezd353ca02020-02-18 02:12:35 +0000139set(USE_X11 OFF)
Stephen Gutekanst55623702023-07-01 11:43:55 +0000140set(USE_WINDOWS_UI OFF)
Ben Claytona6750752022-02-04 18:35:55 +0000141set(BUILD_SAMPLES OFF)
AlexVestin5c3645c2023-10-18 14:08:26 +0000142set(TARGET_MACOS OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000143if (WIN32)
Peng Huang925b7762023-05-01 16:13:00 +0000144 set(ENABLE_D3D11 ON)
Stephen Gutekanst55623702023-07-01 11:43:55 +0000145 set(USE_WINDOWS_UI ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000146 set(ENABLE_D3D12 ON)
陈俊嘉610de1d2021-06-28 08:19:28 +0000147 if (NOT WINDOWS_STORE)
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000148 # Enable Vulkan in win32 compilation only
149 # since UWP only supports d3d
150 set(ENABLE_VULKAN ON)
151 endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000152elseif(APPLE)
153 set(ENABLE_METAL ON)
AlexVestin5c3645c2023-10-18 14:08:26 +0000154 if(CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "MacOS")
155 set(TARGET_MACOS ON)
156 endif()
Alexander Vestinf2556ab2022-03-25 13:18:46 +0000157elseif(ANDROID)
158 set(ENABLE_VULKAN ON)
159 set(ENABLE_OPENGLES ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000160elseif(UNIX)
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000161 set(ENABLE_OPENGLES ON)
162 set(ENABLE_DESKTOP_GL ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000163 set(ENABLE_VULKAN ON)
Corentin Wallezd353ca02020-02-18 02:12:35 +0000164 set(USE_X11 ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000165endif()
166
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000167# GLFW is not supported in UWP
Albin Bernhardssonb8a1b6d2023-07-13 08:51:17 +0000168set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING OFF)
Sonakshi Saxena13446112023-08-23 12:32:14 +0000169
170if ((WIN32 AND NOT WINDOWS_STORE) OR (UNIX AND NOT ANDROID))
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000171 set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING ON)
172endif()
173
174# Current examples are depend on GLFW
175if (DAWN_SUPPORTS_GLFW_FOR_WINDOWING)
Ben Claytona6750752022-02-04 18:35:55 +0000176 set(BUILD_SAMPLES ON)
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000177endif()
178
Ben Clayton96e245e2022-04-08 18:08:36 +0000179option_if_not_defined(DAWN_ENABLE_ASAN "Enable address sanitizer" OFF)
munozac511ffb2023-09-25 14:01:03 +0000180option_if_not_defined(DAWN_ENABLE_INSTALL "Enable install step for Dawn libraries" OFF)
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000181option_if_not_defined(DAWN_ENABLE_TSAN "Enable thread sanitizer" OFF)
182option_if_not_defined(DAWN_ENABLE_MSAN "Enable memory sanitizer" OFF)
Ben Clayton96e245e2022-04-08 18:08:36 +0000183option_if_not_defined(DAWN_ENABLE_UBSAN "Enable undefined behaviour sanitizer" OFF)
184
Peng Huang5c2f1672023-05-01 23:05:42 +0000185option_if_not_defined(DAWN_ENABLE_D3D11 "Enable compilation of the D3D11 backend" ${ENABLE_D3D11})
Ben Clayton30eeac72021-09-24 10:38:18 +0000186option_if_not_defined(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12})
187option_if_not_defined(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL})
188option_if_not_defined(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON)
189option_if_not_defined(DAWN_ENABLE_DESKTOP_GL "Enable compilation of the OpenGL backend" ${ENABLE_DESKTOP_GL})
190option_if_not_defined(DAWN_ENABLE_OPENGLES "Enable compilation of the OpenGL ES backend" ${ENABLE_OPENGLES})
191option_if_not_defined(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backend" ${ENABLE_VULKAN})
dan sinclair194c1772022-06-21 17:54:03 +0000192
Ben Clayton30eeac72021-09-24 10:38:18 +0000193option_if_not_defined(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF)
Corentin Wallez2e22d922022-06-01 09:30:50 +0000194option_if_not_defined(DAWN_USE_WAYLAND "Enable support for Wayland surface" ${USE_WAYLAND})
Ben Clayton30eeac72021-09-24 10:38:18 +0000195option_if_not_defined(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11})
Erin Melucci38b58e42023-06-14 16:45:33 +0000196option_if_not_defined(DAWN_USE_GLFW "Enable compilation of the GLFW windowing utils" ${DAWN_SUPPORTS_GLFW_FOR_WINDOWING})
Stephen Gutekanst55623702023-07-01 11:43:55 +0000197option_if_not_defined(DAWN_USE_WINDOWS_UI "Enable support for Windows UI surface" ${USE_WINDOWS_UI})
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000198option_if_not_defined(DAWN_USE_BUILT_DXC "Enable building and using DXC by the D3D12 backend" OFF)
AlexVestin5c3645c2023-10-18 14:08:26 +0000199option_if_not_defined(DAWN_TARGET_MACOS "Manually link Apple core frameworks" ${TARGET_MACOS})
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000200
Ben Claytona6750752022-02-04 18:35:55 +0000201option_if_not_defined(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" ${BUILD_SAMPLES})
Ben Claytonaffb7a32021-09-28 11:14:42 +0000202option_if_not_defined(DAWN_BUILD_NODE_BINDINGS "Enables building Dawn's NodeJS bindings" OFF)
Corentin Wallezbe352ea2022-04-11 16:48:43 +0000203option_if_not_defined(DAWN_ENABLE_SWIFTSHADER "Enables building Swiftshader as part of the build and Vulkan adapter discovery" OFF)
Austin Eng6a7bba52023-04-17 18:11:51 +0000204option_if_not_defined(DAWN_BUILD_BENCHMARKS "Build Dawn benchmarks" OFF)
Ben Claytonaffb7a32021-09-28 11:14:42 +0000205
206option_if_not_defined(DAWN_ENABLE_PIC "Build with Position-Independent-Code enabled" OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000207
Ben Claytone38993f2022-12-10 00:15:57 +0000208option_if_not_defined(DAWN_EMIT_COVERAGE "Emit code coverage information" OFF)
Ben Claytonf927bcb2022-12-12 21:21:54 +0000209set_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 +0000210
dan sinclair194c1772022-06-21 17:54:03 +0000211if (DAWN_ENABLE_OPENGLES OR DAWN_ENABLE_DESKTOP_GL)
212 set(TINT_DEFAULT_GLSL ON)
213else()
214 set(TINT_DEFAULT_GLSL OFF)
215endif()
216
munozac511ffb2023-09-25 14:01:03 +0000217option_if_not_defined(TINT_ENABLE_INSTALL "Enable install step for Tint libraries" OFF)
Ben Clayton3a3cb362023-08-16 01:05:21 +0000218option_if_not_defined(TINT_BUILD_CMD_TOOLS "Build the Tint command line tools" ON)
dan sinclair194c1772022-06-21 17:54:03 +0000219
Ben Clayton3a3cb362023-08-16 01:05:21 +0000220if (NOT DAWN_USE_GLFW AND (TINT_BUILD_CMD_TOOLS OR DAWN_BUILD_SAMPLES))
Erin Melucci38b58e42023-06-14 16:45:33 +0000221 message(SEND_ERROR "Dawn samples require GLFW")
222endif()
223
dan sinclair194c1772022-06-21 17:54:03 +0000224option_if_not_defined(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" ${DAWN_ENABLE_VULKAN})
225option_if_not_defined(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON)
226option_if_not_defined(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" ${TINT_DEFAULT_GLSL})
Ben Claytonf1b8a012023-10-11 17:15:52 +0000227option_if_not_defined(TINT_BUILD_GLSL_VALIDATOR "Build the GLSL output validator" ON)
dan sinclair194c1772022-06-21 17:54:03 +0000228option_if_not_defined(TINT_BUILD_HLSL_WRITER "Build the HLSL output writer" ${DAWN_ENABLE_D3D12})
229option_if_not_defined(TINT_BUILD_MSL_WRITER "Build the MSL output writer" ${DAWN_ENABLE_METAL})
230option_if_not_defined(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ${DAWN_ENABLE_VULKAN})
231option_if_not_defined(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON)
232
dan sinclair0917fbb2023-03-07 18:28:38 +0000233option_if_not_defined(TINT_BUILD_SYNTAX_TREE_WRITER "Build the syntax tree writer" OFF)
dan sinclairc22b8b9d2022-11-01 17:02:31 +0000234
dan sinclair194c1772022-06-21 17:54:03 +0000235option_if_not_defined(TINT_BUILD_FUZZERS "Build fuzzers" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000236option_if_not_defined(TINT_BUILD_AST_FUZZER "Build AST fuzzer" OFF)
237option_if_not_defined(TINT_BUILD_REGEX_FUZZER "Build regex fuzzer" OFF)
Austin Eng6a7bba52023-04-17 18:11:51 +0000238option_if_not_defined(TINT_BUILD_BENCHMARKS "Build Tint benchmarks" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000239option_if_not_defined(TINT_BUILD_TESTS "Build tests" ON)
240option_if_not_defined(TINT_BUILD_AS_OTHER_OS "Override OS detection to force building of *_other.cc files" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000241
Ben Claytonf9a5b712024-03-13 17:37:33 +0000242option_if_not_defined(TINT_BUILD_TINTD "Build the WGSL language server" OFF)
Ben Claytonf9a5b712024-03-13 17:37:33 +0000243
Ben Clayton8fc9b862023-04-19 15:03:19 +0000244set_if_not_defined(TINT_EXTERNAL_BENCHMARK_CORPUS_DIR "" "Directory that holds a corpus of external shaders to benchmark.")
245
dan sinclair194c1772022-06-21 17:54:03 +0000246option_if_not_defined(TINT_ENABLE_BREAK_IN_DEBUGGER "Enable tint::debugger::Break()" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000247option_if_not_defined(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF)
Ben Claytonf2b86aa2022-12-13 14:46:02 +0000248option_if_not_defined(TINT_RANDOMIZE_HASHES "Randomize the hash seed value to detect non-deterministic output" OFF)
Corentin Walleze5570872020-10-20 14:26:10 +0000249
Brandon Jonesa04663c2021-09-23 20:36:03 +0000250# Recommended setting for compability with future abseil releases.
251set(ABSL_PROPAGATE_CXX_STD ON)
Brandon Jonesa04663c2021-09-23 20:36:03 +0000252
dan sinclair194c1772022-06-21 17:54:03 +0000253set_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 +0000254set_if_not_defined(DAWN_VULKAN_DEPS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps" "Directory in which to find vulkan-deps")
255
Ben Clayton30eeac72021-09-24 10:38:18 +0000256set_if_not_defined(DAWN_ABSEIL_DIR "${DAWN_THIRD_PARTY_DIR}/abseil-cpp" "Directory in which to find Abseil")
257set_if_not_defined(DAWN_GLFW_DIR "${DAWN_THIRD_PARTY_DIR}/glfw" "Directory in which to find GLFW")
Ben Clayton30eeac72021-09-24 10:38:18 +0000258set_if_not_defined(DAWN_JINJA2_DIR "${DAWN_THIRD_PARTY_DIR}/jinja2" "Directory in which to find Jinja2")
Arthur Sonzognic5f72f72023-11-29 15:27:40 +0000259set_if_not_defined(DAWN_MARKUPSAFE_DIR "${DAWN_THIRD_PARTY_DIR}/markupsafe" "Directory in which to find MarkupSafe")
Arthur Sonzogni58f8ed22023-11-30 09:30:52 +0000260set_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 +0000261set_if_not_defined(DAWN_SWIFTSHADER_DIR "${DAWN_THIRD_PARTY_DIR}/swiftshader" "Directory in which to find swiftshader")
Ben Claytonfb07fa92023-11-17 18:48:59 +0000262set_if_not_defined(DAWN_PROTOBUF_DIR "${DAWN_THIRD_PARTY_DIR}/protobuf" "Directory in which to find protobuf")
dan sinclairc1f6dbd2023-04-11 15:45:18 +0000263
264set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_VULKAN_DEPS_DIR}/spirv-tools/src" "Directory in which to find SPIRV-Tools")
265set_if_not_defined(DAWN_SPIRV_HEADERS_DIR "${DAWN_VULKAN_DEPS_DIR}/spirv-headers/src" "Directory in which to find SPIRV-Headers")
Loko Kung23d09c62022-04-09 00:10:08 +0000266set_if_not_defined(DAWN_VULKAN_HEADERS_DIR "${DAWN_VULKAN_DEPS_DIR}/vulkan-headers/src" "Directory in which to find Vulkan-Headers")
James Price0fe9e442023-09-22 21:51:31 +0000267set_if_not_defined(DAWN_VULKAN_UTILITY_LIBRARIES_DIR "${DAWN_VULKAN_DEPS_DIR}/vulkan-utility-libraries/src" "Directory in which to find Vulkan-Utility-Libraries")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000268
Ben Claytonaffb7a32021-09-28 11:14:42 +0000269# Dependencies for DAWN_BUILD_NODE_BINDINGS
270set_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 +0000271set_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 +0000272set_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 +0000273set_if_not_defined(GO_EXECUTABLE "go" "Golang executable for running the IDL generator")
Ben Claytonaffb7a32021-09-28 11:14:42 +0000274
Elie Michel9ae8ed22023-05-12 20:19:41 +0000275option_if_not_defined(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" OFF)
276
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000277# Much of the backend code is shared among desktop OpenGL and OpenGL ES
278if (${DAWN_ENABLE_DESKTOP_GL} OR ${DAWN_ENABLE_OPENGLES})
279 set(DAWN_ENABLE_OPENGL ON)
280endif()
281
Ben Claytonaffb7a32021-09-28 11:14:42 +0000282if(DAWN_ENABLE_PIC)
283 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
284endif()
285
dan sinclair194c1772022-06-21 17:54:03 +0000286if (${TINT_BUILD_AST_FUZZER})
287 message(STATUS "TINT_BUILD_AST_FUZZER is ON - setting
288 TINT_BUILD_FUZZERS
289 TINT_BUILD_WGSL_READER
290 TINT_BUILD_WGSL_WRITER
291 TINT_BUILD_SPV_WRITER
292 TINT_BUILD_MSL_WRITER
293 TINT_BUILD_GLSL_WRITER
294 TINT_BUILD_HLSL_WRITER to ON")
295 set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE)
296 set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE)
297 set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE)
298 set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE)
299 set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE)
300 set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build GLSL writer" FORCE)
301 set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
302endif()
303
304if (${TINT_BUILD_REGEX_FUZZER})
305 message(STATUS "TINT_BUILD_REGEX_FUZZER is ON - setting
306 TINT_BUILD_FUZZERS
307 TINT_BUILD_WGSL_READER
308 TINT_BUILD_WGSL_WRITER
309 TINT_BUILD_SPV_WRITER
310 TINT_BUILD_MSL_WRITER
311 TINT_BUILD_GLSL_WRITER
312 TINT_BUILD_HLSL_WRITER to ON")
313 set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE)
314 set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE)
315 set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE)
316 set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE)
317 set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE)
318 set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build GLSL writer" FORCE)
319 set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
320endif()
321
Peng Huang5c2f1672023-05-01 23:05:42 +0000322message(STATUS "Dawn build D3D11 backend: ${DAWN_ENABLE_D3D11}")
dan sinclair194c1772022-06-21 17:54:03 +0000323message(STATUS "Dawn build D3D12 backend: ${DAWN_ENABLE_D3D12}")
324message(STATUS "Dawn build Metal backend: ${DAWN_ENABLE_METAL}")
325message(STATUS "Dawn build Vulkan backend: ${DAWN_ENABLE_VULKAN}")
326message(STATUS "Dawn build OpenGL backend: ${DAWN_ENABLE_DESKTOP_GL}")
327message(STATUS "Dawn build OpenGL ES backend: ${DAWN_ENABLE_OPENGLES}")
328message(STATUS "Dawn build Null backend: ${DAWN_ENABLE_NULL}")
329
330message(STATUS "Dawn build with asserts in all configurations: ${DAWN_ALWAYS_ASSERT}")
331message(STATUS "Dawn build Wayland support: ${DAWN_USE_WAYLAND}")
332message(STATUS "Dawn build X11 support: ${DAWN_USE_X11}")
AlexVestin5c3645c2023-10-18 14:08:26 +0000333message(STATUS "Dawn build GLFW support: ${DAWN_USE_GLFW}")
Stephen Gutekanst55623702023-07-01 11:43:55 +0000334message(STATUS "Dawn build Windows UI support: ${DAWN_USE_WINDOWS_UI}")
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000335message(STATUS "Dawn build and use DXC: ${DAWN_USE_BUILT_DXC}")
dan sinclair194c1772022-06-21 17:54:03 +0000336
337message(STATUS "Dawn build samples: ${DAWN_BUILD_SAMPLES}")
338message(STATUS "Dawn build Node bindings: ${DAWN_BUILD_NODE_BINDINGS}")
339message(STATUS "Dawn build Swiftshader: ${DAWN_ENABLE_SWIFTSHADER}")
Austin Eng6a7bba52023-04-17 18:11:51 +0000340message(STATUS "Dawn build benchmarks: ${DAWN_BUILD_BENCHMARKS}")
dan sinclair194c1772022-06-21 17:54:03 +0000341
342message(STATUS "Dawn build PIC: ${DAWN_ENABLE_PIC}")
343
344message(STATUS "Dawn build with ASAN: ${DAWN_ENABLE_ASAN}")
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000345message(STATUS "Dawn build with TSAN: ${DAWN_ENABLE_TSAN}")
dan sinclair194c1772022-06-21 17:54:03 +0000346message(STATUS "Dawn build with MSAN: ${DAWN_ENABLE_MSAN}")
347message(STATUS "Dawn build with UBSAN: ${DAWN_ENABLE_UBSAN}")
348
Ben Clayton3a3cb362023-08-16 01:05:21 +0000349message(STATUS "Tint build command line executable tools: ${TINT_BUILD_CMD_TOOLS}")
dan sinclair194c1772022-06-21 17:54:03 +0000350message(STATUS "Tint build SPIR-V reader: ${TINT_BUILD_SPV_READER}")
351message(STATUS "Tint build WGSL reader: ${TINT_BUILD_WGSL_READER}")
352message(STATUS "Tint build GLSL writer: ${TINT_BUILD_GLSL_WRITER}")
Ben Claytonf1b8a012023-10-11 17:15:52 +0000353message(STATUS "Tint build GLSL validator: ${TINT_BUILD_GLSL_VALIDATOR}")
dan sinclair194c1772022-06-21 17:54:03 +0000354message(STATUS "Tint build HLSL writer: ${TINT_BUILD_HLSL_WRITER}")
355message(STATUS "Tint build MSL writer: ${TINT_BUILD_MSL_WRITER}")
356message(STATUS "Tint build SPIR-V writer: ${TINT_BUILD_SPV_WRITER}")
357message(STATUS "Tint build WGSL writer: ${TINT_BUILD_WGSL_WRITER}")
dan sinclair0917fbb2023-03-07 18:28:38 +0000358message(STATUS "Tint build Syntax Tree writer: ${TINT_BUILD_SYNTAX_TREE_WRITER}")
dan sinclair194c1772022-06-21 17:54:03 +0000359message(STATUS "Tint build fuzzers: ${TINT_BUILD_FUZZERS}")
dan sinclair194c1772022-06-21 17:54:03 +0000360message(STATUS "Tint build AST fuzzer: ${TINT_BUILD_AST_FUZZER}")
361message(STATUS "Tint build regex fuzzer: ${TINT_BUILD_REGEX_FUZZER}")
362message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}")
363message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}")
364message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}")
Ben Clayton8fc9b862023-04-19 15:03:19 +0000365message(STATUS "Tint external benchmark corpus dir: ${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}")
366
dan sinclair194c1772022-06-21 17:54:03 +0000367
368if (NOT ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS} STREQUAL "")
369 message(STATUS "Using provided LIB_FUZZING_ENGINE options: ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS}")
370endif()
371
Corentin Wallez179e84a2024-03-27 20:20:15 +0000372find_package(Python3 REQUIRED)
Corentin Wallez2f18c9a2024-04-02 08:51:45 +0000373message(STATUS "Dawn: using python at ${Python3_EXECUTABLE}")
dan sinclair194c1772022-06-21 17:54:03 +0000374
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000375################################################################################
Ben Clayton96e245e2022-04-08 18:08:36 +0000376# common_compile_options - sets compiler and linker options common for dawn and
377# tint on the given target
378################################################################################
379function(common_compile_options TARGET)
380 if (COMPILER_IS_LIKE_GNU)
381 target_compile_options(${TARGET} PRIVATE
382 -fno-exceptions
383 -fno-rtti
dan sinclaircf2456b2023-01-07 23:09:14 +0000384
385 -Wno-deprecated-builtins
dan sinclair07c32cb2023-01-09 15:10:33 +0000386 -Wno-unknown-warning-option
Antonio Maioranoe4d64ed2024-03-04 21:15:03 +0000387 -Wno-switch-default
Ben Clayton96e245e2022-04-08 18:08:36 +0000388 )
389
Antonio Maiorano39357642024-03-27 18:23:32 +0000390 set(SANITIZER_OPTIONS "")
Ben Clayton96e245e2022-04-08 18:08:36 +0000391 if (${DAWN_ENABLE_MSAN})
Antonio Maiorano39357642024-03-27 18:23:32 +0000392 list(APPEND SANITIZER_OPTIONS "-fsanitize=memory")
393 endif()
394 if (${DAWN_ENABLE_ASAN})
395 list(APPEND SANITIZER_OPTIONS "-fsanitize=address")
396 endif()
397 if (${DAWN_ENABLE_TSAN})
398 list(APPEND SANITIZER_OPTIONS "-fsanitize=thread")
399 endif()
400 if (${DAWN_ENABLE_UBSAN})
401 list(APPEND SANITIZER_OPTIONS "-fsanitize=undefined" "-fsanitize=float-divide-by-zero")
402 endif()
403 if (SANITIZER_OPTIONS)
404 target_compile_options(${TARGET} PUBLIC ${SANITIZER_OPTIONS})
405 target_link_options(${TARGET} PUBLIC ${SANITIZER_OPTIONS})
Ben Clayton96e245e2022-04-08 18:08:36 +0000406 endif()
407 endif(COMPILER_IS_LIKE_GNU)
Setoc6927202022-09-14 16:41:07 +0000408
409 if(MSVC)
410 target_compile_options(${TARGET} PUBLIC /utf-8)
411 endif()
Ben Claytone38993f2022-12-10 00:15:57 +0000412
413 if (DAWN_EMIT_COVERAGE)
Ben Clayton54264d32023-01-10 21:55:43 +0000414 target_compile_definitions(${TARGET} PRIVATE "DAWN_EMIT_COVERAGE")
Ben Claytone38993f2022-12-10 00:15:57 +0000415 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
416 target_compile_options(${TARGET} PRIVATE "--coverage")
417 target_link_options(${TARGET} PRIVATE "gcov")
Ben Clayton78e45302023-01-26 15:57:27 +0000418 elseif(COMPILER_IS_CLANG OR COMPILER_IS_CLANG_CL)
Ben Claytone38993f2022-12-10 00:15:57 +0000419 target_compile_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping")
420 target_link_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping")
421 else()
422 message(FATAL_ERROR "Coverage generation not supported for the ${CMAKE_CXX_COMPILER_ID} toolchain")
423 endif()
424 endif(DAWN_EMIT_COVERAGE)
Ben Clayton96e245e2022-04-08 18:08:36 +0000425endfunction()
426
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000427if (${DAWN_ENABLE_TSAN})
428 add_compile_options(-stdlib=libc++)
429 add_link_options(-stdlib=libc++)
430endif()
431
Ben Clayton96e245e2022-04-08 18:08:36 +0000432################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000433# Dawn's public and internal "configs"
434################################################################################
435
Ben Clayton94181522022-11-09 20:55:33 +0000436set(IS_DEBUG_BUILD 0)
437string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
438if ((NOT ${build_type} STREQUAL "RELEASE") AND (NOT ${build_type} STREQUAL "RELWITHDEBINFO"))
439 set(IS_DEBUG_BUILD 1)
440endif()
441
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000442# The public config contains only the include paths for the Dawn headers.
443add_library(dawn_public_config INTERFACE)
444target_include_directories(dawn_public_config INTERFACE
Ben Clayton9fb7a512022-02-04 18:18:18 +0000445 "${DAWN_INCLUDE_DIR}"
446 "${DAWN_BUILD_GEN_DIR}/include"
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000447)
448
449# The internal config conatins additional path but includes the dawn_public_config include paths
450add_library(dawn_internal_config INTERFACE)
451target_include_directories(dawn_internal_config INTERFACE
452 "${DAWN_SRC_DIR}"
453 "${DAWN_BUILD_GEN_DIR}/src"
454)
455target_link_libraries(dawn_internal_config INTERFACE dawn_public_config)
456
457# Compile definitions for the internal config
Ben Clayton94181522022-11-09 20:55:33 +0000458if (DAWN_ALWAYS_ASSERT OR IS_DEBUG_BUILD)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000459 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_ASSERTS")
460endif()
Peng Huang5c2f1672023-05-01 23:05:42 +0000461if (DAWN_ENABLE_D3D11)
462 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D11")
463endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000464if (DAWN_ENABLE_D3D12)
465 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D12")
466endif()
467if (DAWN_ENABLE_METAL)
468 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_METAL")
469endif()
470if (DAWN_ENABLE_NULL)
471 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_NULL")
472endif()
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000473if (DAWN_ENABLE_DESKTOP_GL)
474 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_DESKTOP_GL")
475endif()
476if (DAWN_ENABLE_OPENGLES)
477 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGLES")
478endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000479if (DAWN_ENABLE_OPENGL)
480 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGL")
481endif()
482if (DAWN_ENABLE_VULKAN)
483 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_VULKAN")
484endif()
Corentin Wallez2e22d922022-06-01 09:30:50 +0000485if (DAWN_USE_WAYLAND)
486 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WAYLAND")
487endif()
Corentin Wallezd353ca02020-02-18 02:12:35 +0000488if (DAWN_USE_X11)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000489 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11")
490endif()
Stephen Gutekanst55623702023-07-01 11:43:55 +0000491if (DAWN_USE_WINDOWS_UI)
492 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WINDOWS_UI")
493endif()
Corentin Wallez33466972020-02-24 13:27:28 +0000494if (WIN32)
495 target_compile_definitions(dawn_internal_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN")
496endif()
497
dan sinclair05d278e2023-08-30 21:05:31 +0000498set(CMAKE_CXX_STANDARD "17")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000499
500################################################################################
Ryan Harrisone87ac762022-04-06 15:37:27 -0400501# Tint
502################################################################################
503
Alastair Donaldson6a1eb452021-09-02 23:49:25 +0000504set(TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS "" CACHE STRING "Used by OSS-Fuzz to control, via link options, which fuzzing engine should be used")
505
Ben Claytonfb07fa92023-11-17 18:48:59 +0000506set(TINT_ROOT_SOURCE_DIR ${PROJECT_SOURCE_DIR})
Ben Clayton3a3cb362023-08-16 01:05:21 +0000507set(TINT_SPIRV_HEADERS_DIR ${DAWN_SPIRV_HEADERS_DIR})
508set(TINT_SPIRV_TOOLS_DIR ${DAWN_SPIRV_TOOLS_DIR})
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000509
Antonio Maioranod6009722021-03-17 13:32:54 +0000510# CMake < 3.15 sets /W3 in CMAKE_CXX_FLAGS. Remove it if it's there.
511# See https://gitlab.kitware.com/cmake/cmake/-/issues/18317
512if (MSVC)
Vasyl Teliman0b3611b2021-06-24 18:10:46 +0000513 if (CMAKE_CXX_FLAGS MATCHES "/W3")
514 string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
515 endif()
Antonio Maioranod6009722021-03-17 13:32:54 +0000516endif()
517
Ryan Harrison563d3e92020-04-28 19:27:38 +0000518if (${TINT_CHECK_CHROMIUM_STYLE})
519 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -add-plugin -Xclang find-bad-constructs")
520endif()
521
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000522if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC"))
523 set(COMPILER_IS_CLANG_CL TRUE)
524endif()
525
Ben Clayton78e45302023-01-26 15:57:27 +0000526if((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000527 ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND
528 (NOT COMPILER_IS_CLANG_CL)))
Ben Clayton78e45302023-01-26 15:57:27 +0000529 set(COMPILER_IS_CLANG TRUE)
530endif()
531
Ben Clayton7d956612023-10-03 10:14:55 +0000532if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
533 set(COMPILER_IS_GNU TRUE)
534endif()
535
Ben Clayton78e45302023-01-26 15:57:27 +0000536if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR COMPILER_IS_CLANG)
Dan Sinclair6e581892020-03-02 15:47:43 -0500537 set(COMPILER_IS_LIKE_GNU TRUE)
538endif()
539
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000540# Enable msbuild multiprocessor builds
541if (MSVC AND NOT COMPILER_IS_CLANG_CL)
542 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
543endif()
544
Ryan Harrisone87ac762022-04-06 15:37:27 -0400545################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000546# Run on all subdirectories
547################################################################################
Austin Eng01f13352023-11-30 19:52:59 +0000548if (EXISTS "${DAWN_PROTOBUF_DIR}/cmake")
Ben Clayton01fa7c82024-01-31 21:07:17 +0000549 if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND WIN32)
550 set(protobuf_HAVE_BUILTIN_ATOMICS 1)
551 endif()
552
Ben Claytonfb07fa92023-11-17 18:48:59 +0000553 # Needs to come before SPIR-V Tools
554 include("third_party/protobuf.cmake")
555endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000556
557add_subdirectory(third_party)
James Price8d9adb02022-05-22 00:41:53 +0000558
559# TODO(crbug.com/tint/455): Tint does not currently build with CMake when
560# BUILD_SHARED_LIBS=1, so always build it as static for now.
561set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS})
562set(BUILD_SHARED_LIBS 0)
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000563add_subdirectory(src/tint)
James Price8d9adb02022-05-22 00:41:53 +0000564set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED})
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000565add_subdirectory(generator)
566add_subdirectory(src/dawn)
Ben Clayton7b778552022-02-04 18:59:15 +0000567
568################################################################################
569# Samples
570################################################################################
dan sinclairb5950522020-03-19 13:03:35 +0000571add_custom_target(tint-lint
572 COMMAND ./tools/lint
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000573 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000574 COMMENT "Running linter"
575 VERBATIM)
576
577add_custom_target(tint-format
578 COMMAND ./tools/format
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000579 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000580 COMMENT "Running formatter"
581 VERBATIM)
Ben Claytonadb10d62020-10-27 21:04:59 +0000582
Ben Clayton78e45302023-01-26 15:57:27 +0000583if (DAWN_EMIT_COVERAGE)
584 add_subdirectory(tools/src/cmd/turbo-cov)
Ben Claytonadb10d62020-10-27 21:04:59 +0000585
Ben Clayton78e45302023-01-26 15:57:27 +0000586 # The tint-generate-coverage target generates a lcov.info file at the project
587 # root, holding the code coverage for all the tint_unitests.
Ben Claytonadb10d62020-10-27 21:04:59 +0000588 # This can be used by tools such as VSCode's Coverage Gutters extension to
589 # visualize code coverage in the editor.
590 get_filename_component(CLANG_BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY)
591 set(PATH_WITH_CLANG "${CLANG_BIN_DIR}:$ENV{PATH}")
592 add_custom_target(tint-generate-coverage
593 COMMAND ${CMAKE_COMMAND} -E env PATH=${PATH_WITH_CLANG} ./tools/tint-generate-coverage $<TARGET_FILE:tint_unittests>
594 DEPENDS tint_unittests
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000595 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
Ben Claytonadb10d62020-10-27 21:04:59 +0000596 COMMENT "Generating tint coverage data"
597 VERBATIM)
598endif()