blob: 5420136b0ce41a56a7218edadacb3d8fc3ccb445 [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#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Dan Sinclair6e581892020-03-02 15:47:43 -050015cmake_minimum_required(VERSION 3.10.2)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000016
dan sinclairfb5a4922022-04-19 22:25:45 +000017# When upgrading to CMake 3.11 we can remove DAWN_PLACEHOLDER_FILE because source-less add_library
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000018# becomes available.
19# When upgrading to CMake 3.12 we should add CONFIGURE_DEPENDS to DawnGenerator to rerun CMake in
Corentin Wallez42450c62020-04-10 17:04:31 +000020# case any of the generator files changes. We should also remove the CACHE "" FORCE stuff to
dan sinclair1877c272020-10-20 19:46:21 +000021# override options in third_party dependencies. We can also add the HOMEPAGE_URL
22# entry to the project `HOMEPAGE_URL "https://dawn.googlesource.com/dawn"`
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000023
24project(
25 Dawn
26 DESCRIPTION "Dawn, a WebGPU implementation"
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000027 LANGUAGES C CXX
28)
Dan Sinclair6e581892020-03-02 15:47:43 -050029enable_testing()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000030
31set_property(GLOBAL PROPERTY USE_FOLDERS ON)
32
Dan Sinclair6e581892020-03-02 15:47:43 -050033set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
34set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Ben Clayton7b0686a2022-01-06 09:23:11 +000035set(CMAKE_CXX_STANDARD 17)
Dan Sinclair6e581892020-03-02 15:47:43 -050036set(CMAKE_DEBUG_POSTFIX "")
37
38if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
39 message(STATUS "No build type selected, default to Debug")
40 set(CMAKE_BUILD_TYPE "Debug")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000041endif()
42
43set(DAWN_BUILD_GEN_DIR "${Dawn_BINARY_DIR}/gen")
44set(DAWN_GENERATOR_DIR "${Dawn_SOURCE_DIR}/generator")
45set(DAWN_SRC_DIR "${Dawn_SOURCE_DIR}/src")
Ben Clayton9fb7a512022-02-04 18:18:18 +000046set(DAWN_INCLUDE_DIR "${Dawn_SOURCE_DIR}/include")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000047set(DAWN_TEMPLATE_DIR "${DAWN_GENERATOR_DIR}/templates")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000048
dan sinclairfb5a4922022-04-19 22:25:45 +000049set(DAWN_PLACEHOLDER_FILE "${DAWN_SRC_DIR}/Placeholder.cpp")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000050
51################################################################################
52# Configuration options
53################################################################################
54
Ben Clayton30eeac72021-09-24 10:38:18 +000055# option_if_not_defined(name description default)
56# Behaves like:
57# option(name description default)
58# If a variable is not already defined with the given name, otherwise the
59# function does nothing.
60# Simplifies customization by projects that use Dawn as a dependency.
61function (option_if_not_defined name description default)
62 if(NOT DEFINED ${name})
63 option(${name} ${description} ${default})
64 endif()
65endfunction()
66
67# set_if_not_defined(name value description)
68# Behaves like:
69# set(${name} ${value} CACHE STRING ${description})
70# If a variable is not already defined with the given name, otherwise the
71# function does nothing.
72# Simplifies customization by projects that use Dawn as a dependency.
73function (set_if_not_defined name value description)
74 if(NOT DEFINED ${name})
75 set(${name} ${value} CACHE STRING ${description})
76 endif()
77endfunction()
78
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000079# Default values for the backend-enabling options
Peng Huang925b7762023-05-01 16:13:00 +000080set(ENABLE_D3D11 OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000081set(ENABLE_D3D12 OFF)
82set(ENABLE_METAL OFF)
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +000083set(ENABLE_OPENGLES OFF)
84set(ENABLE_DESKTOP_GL OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000085set(ENABLE_VULKAN OFF)
Corentin Wallez2e22d922022-06-01 09:30:50 +000086set(USE_WAYLAND OFF)
Corentin Wallezd353ca02020-02-18 02:12:35 +000087set(USE_X11 OFF)
Stephen Gutekanst55623702023-07-01 11:43:55 +000088set(USE_WINDOWS_UI OFF)
Ben Claytona6750752022-02-04 18:35:55 +000089set(BUILD_SAMPLES OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000090if (WIN32)
Peng Huang925b7762023-05-01 16:13:00 +000091 set(ENABLE_D3D11 ON)
Stephen Gutekanst55623702023-07-01 11:43:55 +000092 set(USE_WINDOWS_UI ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000093 set(ENABLE_D3D12 ON)
陈俊嘉610de1d2021-06-28 08:19:28 +000094 if (NOT WINDOWS_STORE)
陈俊嘉b2bc57a2021-06-24 07:00:16 +000095 # Enable Vulkan in win32 compilation only
96 # since UWP only supports d3d
97 set(ENABLE_VULKAN ON)
98 endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000099elseif(APPLE)
100 set(ENABLE_METAL ON)
Alexander Vestinf2556ab2022-03-25 13:18:46 +0000101elseif(ANDROID)
102 set(ENABLE_VULKAN ON)
103 set(ENABLE_OPENGLES ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000104elseif(UNIX)
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000105 set(ENABLE_OPENGLES ON)
106 set(ENABLE_DESKTOP_GL ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000107 set(ENABLE_VULKAN ON)
Corentin Wallezd353ca02020-02-18 02:12:35 +0000108 set(USE_X11 ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000109endif()
110
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000111# GLFW is not supported in UWP
Albin Bernhardssonb8a1b6d2023-07-13 08:51:17 +0000112set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING OFF)
Ryan Harrisone87ac762022-04-06 15:37:27 -0400113if ((WIN32 AND NOT WINDOWS_STORE) OR UNIX AND NOT ANDROID)
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000114 set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING ON)
115endif()
116
117# Current examples are depend on GLFW
118if (DAWN_SUPPORTS_GLFW_FOR_WINDOWING)
Ben Claytona6750752022-02-04 18:35:55 +0000119 set(BUILD_SAMPLES ON)
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000120endif()
121
Ben Clayton96e245e2022-04-08 18:08:36 +0000122option_if_not_defined(DAWN_ENABLE_ASAN "Enable address sanitizer" OFF)
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000123option_if_not_defined(DAWN_ENABLE_TSAN "Enable thread sanitizer" OFF)
124option_if_not_defined(DAWN_ENABLE_MSAN "Enable memory sanitizer" OFF)
Ben Clayton96e245e2022-04-08 18:08:36 +0000125option_if_not_defined(DAWN_ENABLE_UBSAN "Enable undefined behaviour sanitizer" OFF)
126
Peng Huang5c2f1672023-05-01 23:05:42 +0000127option_if_not_defined(DAWN_ENABLE_D3D11 "Enable compilation of the D3D11 backend" ${ENABLE_D3D11})
Ben Clayton30eeac72021-09-24 10:38:18 +0000128option_if_not_defined(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12})
129option_if_not_defined(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL})
130option_if_not_defined(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON)
131option_if_not_defined(DAWN_ENABLE_DESKTOP_GL "Enable compilation of the OpenGL backend" ${ENABLE_DESKTOP_GL})
132option_if_not_defined(DAWN_ENABLE_OPENGLES "Enable compilation of the OpenGL ES backend" ${ENABLE_OPENGLES})
133option_if_not_defined(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backend" ${ENABLE_VULKAN})
dan sinclair194c1772022-06-21 17:54:03 +0000134
Ben Clayton30eeac72021-09-24 10:38:18 +0000135option_if_not_defined(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF)
Corentin Wallez2e22d922022-06-01 09:30:50 +0000136option_if_not_defined(DAWN_USE_WAYLAND "Enable support for Wayland surface" ${USE_WAYLAND})
Ben Clayton30eeac72021-09-24 10:38:18 +0000137option_if_not_defined(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11})
Erin Melucci38b58e42023-06-14 16:45:33 +0000138option_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 +0000139option_if_not_defined(DAWN_USE_WINDOWS_UI "Enable support for Windows UI surface" ${USE_WINDOWS_UI})
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000140
Ben Claytona6750752022-02-04 18:35:55 +0000141option_if_not_defined(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" ${BUILD_SAMPLES})
Ben Claytonaffb7a32021-09-28 11:14:42 +0000142option_if_not_defined(DAWN_BUILD_NODE_BINDINGS "Enables building Dawn's NodeJS bindings" OFF)
Corentin Wallezbe352ea2022-04-11 16:48:43 +0000143option_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 +0000144option_if_not_defined(DAWN_BUILD_BENCHMARKS "Build Dawn benchmarks" OFF)
Ben Claytonaffb7a32021-09-28 11:14:42 +0000145
146option_if_not_defined(DAWN_ENABLE_PIC "Build with Position-Independent-Code enabled" OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000147
Ben Claytone38993f2022-12-10 00:15:57 +0000148option_if_not_defined(DAWN_EMIT_COVERAGE "Emit code coverage information" OFF)
Ben Claytonf927bcb2022-12-12 21:21:54 +0000149set_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 +0000150
dan sinclair194c1772022-06-21 17:54:03 +0000151if (DAWN_ENABLE_OPENGLES OR DAWN_ENABLE_DESKTOP_GL)
152 set(TINT_DEFAULT_GLSL ON)
153else()
154 set(TINT_DEFAULT_GLSL OFF)
155endif()
156
157option_if_not_defined(TINT_BUILD_SAMPLES "Build samples" ${DAWN_BUILD_SAMPLES})
158option_if_not_defined(TINT_BUILD_DOCS "Build documentation" ON)
159option_if_not_defined(TINT_DOCS_WARN_AS_ERROR "When building documentation, treat warnings as errors" OFF)
160
Erin Melucci38b58e42023-06-14 16:45:33 +0000161if (NOT DAWN_USE_GLFW AND (TINT_BUILD_SAMPLES OR DAWN_BUILD_SAMPLES))
162 message(SEND_ERROR "Dawn samples require GLFW")
163endif()
164
dan sinclair194c1772022-06-21 17:54:03 +0000165option_if_not_defined(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" ${DAWN_ENABLE_VULKAN})
166option_if_not_defined(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON)
167option_if_not_defined(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" ${TINT_DEFAULT_GLSL})
168option_if_not_defined(TINT_BUILD_HLSL_WRITER "Build the HLSL output writer" ${DAWN_ENABLE_D3D12})
169option_if_not_defined(TINT_BUILD_MSL_WRITER "Build the MSL output writer" ${DAWN_ENABLE_METAL})
170option_if_not_defined(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ${DAWN_ENABLE_VULKAN})
171option_if_not_defined(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON)
172
dan sinclair0917fbb2023-03-07 18:28:38 +0000173option_if_not_defined(TINT_BUILD_SYNTAX_TREE_WRITER "Build the syntax tree writer" OFF)
dan sinclair92612612022-11-01 18:15:50 +0000174option_if_not_defined(TINT_BUILD_IR "Build the IR" ON)
dan sinclairc22b8b9d2022-11-01 17:02:31 +0000175
dan sinclair194c1772022-06-21 17:54:03 +0000176option_if_not_defined(TINT_BUILD_FUZZERS "Build fuzzers" OFF)
177option_if_not_defined(TINT_BUILD_SPIRV_TOOLS_FUZZER "Build SPIRV-Tools fuzzer" OFF)
178option_if_not_defined(TINT_BUILD_AST_FUZZER "Build AST fuzzer" OFF)
179option_if_not_defined(TINT_BUILD_REGEX_FUZZER "Build regex fuzzer" OFF)
Austin Eng6a7bba52023-04-17 18:11:51 +0000180option_if_not_defined(TINT_BUILD_BENCHMARKS "Build Tint benchmarks" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000181option_if_not_defined(TINT_BUILD_TESTS "Build tests" ON)
182option_if_not_defined(TINT_BUILD_AS_OTHER_OS "Override OS detection to force building of *_other.cc files" OFF)
183option_if_not_defined(TINT_BUILD_REMOTE_COMPILE "Build the remote-compile tool for validating shaders on a remote machine" OFF)
184
Ben Clayton8fc9b862023-04-19 15:03:19 +0000185set_if_not_defined(TINT_EXTERNAL_BENCHMARK_CORPUS_DIR "" "Directory that holds a corpus of external shaders to benchmark.")
186
dan sinclair194c1772022-06-21 17:54:03 +0000187option_if_not_defined(TINT_ENABLE_BREAK_IN_DEBUGGER "Enable tint::debugger::Break()" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000188option_if_not_defined(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF)
Ben Claytonf2b86aa2022-12-13 14:46:02 +0000189option_if_not_defined(TINT_RANDOMIZE_HASHES "Randomize the hash seed value to detect non-deterministic output" OFF)
Corentin Walleze5570872020-10-20 14:26:10 +0000190
Brandon Jonesa04663c2021-09-23 20:36:03 +0000191# Recommended setting for compability with future abseil releases.
192set(ABSL_PROPAGATE_CXX_STD ON)
Brandon Jonesa04663c2021-09-23 20:36:03 +0000193
dan sinclair194c1772022-06-21 17:54:03 +0000194set_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 +0000195set_if_not_defined(DAWN_VULKAN_DEPS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps" "Directory in which to find vulkan-deps")
196
Ben Clayton30eeac72021-09-24 10:38:18 +0000197set_if_not_defined(DAWN_ABSEIL_DIR "${DAWN_THIRD_PARTY_DIR}/abseil-cpp" "Directory in which to find Abseil")
198set_if_not_defined(DAWN_GLFW_DIR "${DAWN_THIRD_PARTY_DIR}/glfw" "Directory in which to find GLFW")
Ben Clayton30eeac72021-09-24 10:38:18 +0000199set_if_not_defined(DAWN_JINJA2_DIR "${DAWN_THIRD_PARTY_DIR}/jinja2" "Directory in which to find Jinja2")
dan sinclair6b67a902023-04-07 07:52:36 +0000200set_if_not_defined(DAWN_MARKUPSAFE_DIR "${DAWN_THIRD_PARTY_DIR}/markupsafe" "Directory in which to find MarkupSafe")
Stephen White94349492022-06-29 15:29:41 +0000201set_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 +0000202set_if_not_defined(DAWN_SWIFTSHADER_DIR "${DAWN_THIRD_PARTY_DIR}/swiftshader" "Directory in which to find swiftshader")
dan sinclairc1f6dbd2023-04-11 15:45:18 +0000203
204set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_VULKAN_DEPS_DIR}/spirv-tools/src" "Directory in which to find SPIRV-Tools")
205set_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 +0000206set_if_not_defined(DAWN_VULKAN_HEADERS_DIR "${DAWN_VULKAN_DEPS_DIR}/vulkan-headers/src" "Directory in which to find Vulkan-Headers")
Loko Kung83a5d522022-04-13 19:14:46 +0000207set_if_not_defined(DAWN_VULKAN_TOOLS_DIR "${DAWN_VULKAN_DEPS_DIR}/vulkan-tools/src" "Directory in which to find Vulkan-Tools")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000208
Ben Claytonaffb7a32021-09-28 11:14:42 +0000209# Dependencies for DAWN_BUILD_NODE_BINDINGS
210set_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 +0000211set_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 +0000212set_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 +0000213set_if_not_defined(GO_EXECUTABLE "go" "Golang executable for running the IDL generator")
Ben Claytonaffb7a32021-09-28 11:14:42 +0000214
Elie Michel9ae8ed22023-05-12 20:19:41 +0000215option_if_not_defined(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" OFF)
216
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000217# Much of the backend code is shared among desktop OpenGL and OpenGL ES
218if (${DAWN_ENABLE_DESKTOP_GL} OR ${DAWN_ENABLE_OPENGLES})
219 set(DAWN_ENABLE_OPENGL ON)
220endif()
221
Ben Claytonaffb7a32021-09-28 11:14:42 +0000222if(DAWN_ENABLE_PIC)
223 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
224endif()
225
dan sinclair194c1772022-06-21 17:54:03 +0000226if (${TINT_BUILD_SPIRV_TOOLS_FUZZER})
227 message(STATUS "TINT_BUILD_SPIRV_TOOLS_FUZZER is ON - setting
228 TINT_BUILD_FUZZERS
229 TINT_BUILD_SPV_READER
230 TINT_BUILD_SPV_WRITER
231 TINT_BUILD_WGSL_READER
232 TINT_BUILD_WGSL_WRITER
233 TINT_BUILD_GLSL_WRITER
234 TINT_BUILD_HLSL_WRITER
235 TINT_BUILD_MSL_WRITER to ON")
236 set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE)
237 set(TINT_BUILD_SPV_READER ON CACHE BOOL "Build SPIR-V reader" FORCE)
238 set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE)
239 set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE)
240 set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE)
241 set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
242 set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
243 set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE)
244endif()
245
246if (${TINT_BUILD_AST_FUZZER})
247 message(STATUS "TINT_BUILD_AST_FUZZER is ON - setting
248 TINT_BUILD_FUZZERS
249 TINT_BUILD_WGSL_READER
250 TINT_BUILD_WGSL_WRITER
251 TINT_BUILD_SPV_WRITER
252 TINT_BUILD_MSL_WRITER
253 TINT_BUILD_GLSL_WRITER
254 TINT_BUILD_HLSL_WRITER to ON")
255 set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE)
256 set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE)
257 set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE)
258 set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE)
259 set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE)
260 set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build GLSL writer" FORCE)
261 set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
262endif()
263
264if (${TINT_BUILD_REGEX_FUZZER})
265 message(STATUS "TINT_BUILD_REGEX_FUZZER is ON - setting
266 TINT_BUILD_FUZZERS
267 TINT_BUILD_WGSL_READER
268 TINT_BUILD_WGSL_WRITER
269 TINT_BUILD_SPV_WRITER
270 TINT_BUILD_MSL_WRITER
271 TINT_BUILD_GLSL_WRITER
272 TINT_BUILD_HLSL_WRITER to ON")
273 set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE)
274 set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE)
275 set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE)
276 set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE)
277 set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE)
278 set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build GLSL writer" FORCE)
279 set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
280endif()
281
Peng Huang5c2f1672023-05-01 23:05:42 +0000282message(STATUS "Dawn build D3D11 backend: ${DAWN_ENABLE_D3D11}")
dan sinclair194c1772022-06-21 17:54:03 +0000283message(STATUS "Dawn build D3D12 backend: ${DAWN_ENABLE_D3D12}")
284message(STATUS "Dawn build Metal backend: ${DAWN_ENABLE_METAL}")
285message(STATUS "Dawn build Vulkan backend: ${DAWN_ENABLE_VULKAN}")
286message(STATUS "Dawn build OpenGL backend: ${DAWN_ENABLE_DESKTOP_GL}")
287message(STATUS "Dawn build OpenGL ES backend: ${DAWN_ENABLE_OPENGLES}")
288message(STATUS "Dawn build Null backend: ${DAWN_ENABLE_NULL}")
289
290message(STATUS "Dawn build with asserts in all configurations: ${DAWN_ALWAYS_ASSERT}")
291message(STATUS "Dawn build Wayland support: ${DAWN_USE_WAYLAND}")
292message(STATUS "Dawn build X11 support: ${DAWN_USE_X11}")
Stephen Gutekanst55623702023-07-01 11:43:55 +0000293message(STATUS "Dawn build Windows UI support: ${DAWN_USE_WINDOWS_UI}")
dan sinclair194c1772022-06-21 17:54:03 +0000294
295message(STATUS "Dawn build samples: ${DAWN_BUILD_SAMPLES}")
296message(STATUS "Dawn build Node bindings: ${DAWN_BUILD_NODE_BINDINGS}")
297message(STATUS "Dawn build Swiftshader: ${DAWN_ENABLE_SWIFTSHADER}")
Austin Eng6a7bba52023-04-17 18:11:51 +0000298message(STATUS "Dawn build benchmarks: ${DAWN_BUILD_BENCHMARKS}")
dan sinclair194c1772022-06-21 17:54:03 +0000299
300message(STATUS "Dawn build PIC: ${DAWN_ENABLE_PIC}")
301
302message(STATUS "Dawn build with ASAN: ${DAWN_ENABLE_ASAN}")
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000303message(STATUS "Dawn build with TSAN: ${DAWN_ENABLE_TSAN}")
dan sinclair194c1772022-06-21 17:54:03 +0000304message(STATUS "Dawn build with MSAN: ${DAWN_ENABLE_MSAN}")
305message(STATUS "Dawn build with UBSAN: ${DAWN_ENABLE_UBSAN}")
306
307message(STATUS "Tint build samples: ${TINT_BUILD_SAMPLES}")
308message(STATUS "Tint build docs: ${TINT_BUILD_DOCS}")
309message(STATUS "Tint build docs with warn as error: ${TINT_DOCS_WARN_AS_ERROR}")
310message(STATUS "Tint build SPIR-V reader: ${TINT_BUILD_SPV_READER}")
311message(STATUS "Tint build WGSL reader: ${TINT_BUILD_WGSL_READER}")
312message(STATUS "Tint build GLSL writer: ${TINT_BUILD_GLSL_WRITER}")
313message(STATUS "Tint build HLSL writer: ${TINT_BUILD_HLSL_WRITER}")
314message(STATUS "Tint build MSL writer: ${TINT_BUILD_MSL_WRITER}")
315message(STATUS "Tint build SPIR-V writer: ${TINT_BUILD_SPV_WRITER}")
316message(STATUS "Tint build WGSL writer: ${TINT_BUILD_WGSL_WRITER}")
dan sinclair0917fbb2023-03-07 18:28:38 +0000317message(STATUS "Tint build Syntax Tree writer: ${TINT_BUILD_SYNTAX_TREE_WRITER}")
dan sinclair92612612022-11-01 18:15:50 +0000318message(STATUS "Tint build IR: ${TINT_BUILD_IR}")
dan sinclair194c1772022-06-21 17:54:03 +0000319message(STATUS "Tint build fuzzers: ${TINT_BUILD_FUZZERS}")
320message(STATUS "Tint build SPIRV-Tools fuzzer: ${TINT_BUILD_SPIRV_TOOLS_FUZZER}")
321message(STATUS "Tint build AST fuzzer: ${TINT_BUILD_AST_FUZZER}")
322message(STATUS "Tint build regex fuzzer: ${TINT_BUILD_REGEX_FUZZER}")
323message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}")
324message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}")
325message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}")
326message(STATUS "Tint build remote-compile tool: ${TINT_BUILD_REMOTE_COMPILE}")
Ben Clayton8fc9b862023-04-19 15:03:19 +0000327message(STATUS "Tint external benchmark corpus dir: ${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}")
328
dan sinclair194c1772022-06-21 17:54:03 +0000329
330if (NOT ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS} STREQUAL "")
331 message(STATUS "Using provided LIB_FUZZING_ENGINE options: ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS}")
332endif()
333
334message(STATUS "Using python3")
335find_package(PythonInterp 3 REQUIRED)
336
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000337################################################################################
Ben Clayton96e245e2022-04-08 18:08:36 +0000338# common_compile_options - sets compiler and linker options common for dawn and
339# tint on the given target
340################################################################################
341function(common_compile_options TARGET)
342 if (COMPILER_IS_LIKE_GNU)
343 target_compile_options(${TARGET} PRIVATE
344 -fno-exceptions
345 -fno-rtti
dan sinclaircf2456b2023-01-07 23:09:14 +0000346
347 -Wno-deprecated-builtins
dan sinclair07c32cb2023-01-09 15:10:33 +0000348 -Wno-unknown-warning-option
Ben Clayton96e245e2022-04-08 18:08:36 +0000349 )
350
351 if (${DAWN_ENABLE_MSAN})
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000352 target_compile_options(${TARGET} PUBLIC -fsanitize=memory)
353 target_link_options(${TARGET} PUBLIC -fsanitize=memory)
Ben Clayton96e245e2022-04-08 18:08:36 +0000354 elseif (${DAWN_ENABLE_ASAN})
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000355 target_compile_options(${TARGET} PUBLIC -fsanitize=address)
356 target_link_options(${TARGET} PUBLIC -fsanitize=address)
357 elseif (${DAWN_ENABLE_TSAN})
358 target_compile_options(${TARGET} PUBLIC -fsanitize=thread)
359 target_link_options(${TARGET} PUBLIC -fsanitize=thread)
Ben Clayton96e245e2022-04-08 18:08:36 +0000360 elseif (${DAWN_ENABLE_UBSAN})
Antonio Maioranodeb2ec92023-03-24 18:44:02 +0000361 target_compile_options(${TARGET} PUBLIC -fsanitize=undefined -fsanitize=float-divide-by-zero)
362 target_link_options(${TARGET} PUBLIC -fsanitize=undefined -fsanitize=float-divide-by-zero)
Ben Clayton96e245e2022-04-08 18:08:36 +0000363 endif()
364 endif(COMPILER_IS_LIKE_GNU)
Setoc6927202022-09-14 16:41:07 +0000365
366 if(MSVC)
367 target_compile_options(${TARGET} PUBLIC /utf-8)
368 endif()
Ben Claytone38993f2022-12-10 00:15:57 +0000369
370 if (DAWN_EMIT_COVERAGE)
Ben Clayton54264d32023-01-10 21:55:43 +0000371 target_compile_definitions(${TARGET} PRIVATE "DAWN_EMIT_COVERAGE")
Ben Claytone38993f2022-12-10 00:15:57 +0000372 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
373 target_compile_options(${TARGET} PRIVATE "--coverage")
374 target_link_options(${TARGET} PRIVATE "gcov")
Ben Clayton78e45302023-01-26 15:57:27 +0000375 elseif(COMPILER_IS_CLANG OR COMPILER_IS_CLANG_CL)
Ben Claytone38993f2022-12-10 00:15:57 +0000376 target_compile_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping")
377 target_link_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping")
378 else()
379 message(FATAL_ERROR "Coverage generation not supported for the ${CMAKE_CXX_COMPILER_ID} toolchain")
380 endif()
381 endif(DAWN_EMIT_COVERAGE)
Ben Clayton96e245e2022-04-08 18:08:36 +0000382endfunction()
383
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000384if (${DAWN_ENABLE_TSAN})
385 add_compile_options(-stdlib=libc++)
386 add_link_options(-stdlib=libc++)
387endif()
388
Ben Clayton96e245e2022-04-08 18:08:36 +0000389################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000390# Dawn's public and internal "configs"
391################################################################################
392
Ben Clayton94181522022-11-09 20:55:33 +0000393set(IS_DEBUG_BUILD 0)
394string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
395if ((NOT ${build_type} STREQUAL "RELEASE") AND (NOT ${build_type} STREQUAL "RELWITHDEBINFO"))
396 set(IS_DEBUG_BUILD 1)
397endif()
398
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000399# The public config contains only the include paths for the Dawn headers.
400add_library(dawn_public_config INTERFACE)
401target_include_directories(dawn_public_config INTERFACE
Ben Clayton9fb7a512022-02-04 18:18:18 +0000402 "${DAWN_INCLUDE_DIR}"
403 "${DAWN_BUILD_GEN_DIR}/include"
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000404)
405
406# The internal config conatins additional path but includes the dawn_public_config include paths
407add_library(dawn_internal_config INTERFACE)
408target_include_directories(dawn_internal_config INTERFACE
409 "${DAWN_SRC_DIR}"
410 "${DAWN_BUILD_GEN_DIR}/src"
411)
412target_link_libraries(dawn_internal_config INTERFACE dawn_public_config)
413
414# Compile definitions for the internal config
Ben Clayton94181522022-11-09 20:55:33 +0000415if (DAWN_ALWAYS_ASSERT OR IS_DEBUG_BUILD)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000416 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_ASSERTS")
417endif()
Peng Huang5c2f1672023-05-01 23:05:42 +0000418if (DAWN_ENABLE_D3D11)
419 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D11")
420endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000421if (DAWN_ENABLE_D3D12)
422 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D12")
423endif()
424if (DAWN_ENABLE_METAL)
425 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_METAL")
426endif()
427if (DAWN_ENABLE_NULL)
428 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_NULL")
429endif()
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000430if (DAWN_ENABLE_DESKTOP_GL)
431 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_DESKTOP_GL")
432endif()
433if (DAWN_ENABLE_OPENGLES)
434 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGLES")
435endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000436if (DAWN_ENABLE_OPENGL)
437 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGL")
438endif()
439if (DAWN_ENABLE_VULKAN)
440 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_VULKAN")
441endif()
Corentin Wallez2e22d922022-06-01 09:30:50 +0000442if (DAWN_USE_WAYLAND)
443 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WAYLAND")
444endif()
Corentin Wallezd353ca02020-02-18 02:12:35 +0000445if (DAWN_USE_X11)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000446 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11")
447endif()
Stephen Gutekanst55623702023-07-01 11:43:55 +0000448if (DAWN_USE_WINDOWS_UI)
449 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WINDOWS_UI")
450endif()
Corentin Wallez33466972020-02-24 13:27:28 +0000451if (WIN32)
452 target_compile_definitions(dawn_internal_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN")
453endif()
454
Corentin Wallez7c8bc942022-01-05 09:26:46 +0000455set(CMAKE_CXX_STANDARD "17")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000456
457################################################################################
Ryan Harrisone87ac762022-04-06 15:37:27 -0400458# Tint
459################################################################################
460
Alastair Donaldson6a1eb452021-09-02 23:49:25 +0000461set(TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS "" CACHE STRING "Used by OSS-Fuzz to control, via link options, which fuzzing engine should be used")
462
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000463set(TINT_ROOT_SOURCE_DIR ${PROJECT_SOURCE_DIR})
464
Antonio Maioranod6009722021-03-17 13:32:54 +0000465# CMake < 3.15 sets /W3 in CMAKE_CXX_FLAGS. Remove it if it's there.
466# See https://gitlab.kitware.com/cmake/cmake/-/issues/18317
467if (MSVC)
Vasyl Teliman0b3611b2021-06-24 18:10:46 +0000468 if (CMAKE_CXX_FLAGS MATCHES "/W3")
469 string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
470 endif()
Antonio Maioranod6009722021-03-17 13:32:54 +0000471endif()
472
Ryan Harrison563d3e92020-04-28 19:27:38 +0000473if (${TINT_CHECK_CHROMIUM_STYLE})
474 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -add-plugin -Xclang find-bad-constructs")
475endif()
476
dan sinclair4b71b9e2020-03-18 14:08:48 +0000477if (${TINT_BUILD_SPV_READER})
Ryan Harrisone87ac762022-04-06 15:37:27 -0400478 include_directories("${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-tools/include")
Dan Sinclair6e581892020-03-02 15:47:43 -0500479endif()
480
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000481if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC"))
482 set(COMPILER_IS_CLANG_CL TRUE)
483endif()
484
Ben Clayton78e45302023-01-26 15:57:27 +0000485if((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000486 ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND
487 (NOT COMPILER_IS_CLANG_CL)))
Ben Clayton78e45302023-01-26 15:57:27 +0000488 set(COMPILER_IS_CLANG TRUE)
489endif()
490
491if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR COMPILER_IS_CLANG)
Dan Sinclair6e581892020-03-02 15:47:43 -0500492 set(COMPILER_IS_LIKE_GNU TRUE)
493endif()
494
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000495# Enable msbuild multiprocessor builds
496if (MSVC AND NOT COMPILER_IS_CLANG_CL)
497 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
498endif()
499
Ben Clayton7687ec12021-04-16 14:43:34 +0000500set(TINT_OS_CC_SUFFIX "other")
501if (NOT TINT_BUILD_AS_OTHER_OS)
502 if(UNIX OR APPLE)
503 set(TINT_OS_CC_SUFFIX "posix")
504 set(TINT_OS_CC_SUFFIX "posix")
505 elseif(WIN32)
506 set(TINT_OS_CC_SUFFIX "windows")
507 set(TINT_OS_CC_SUFFIX "windows")
508 endif()
509endif()
510
David Neto5b46d712020-06-26 22:29:27 +0000511if(${TINT_BUILD_DOCS})
512 find_package(Doxygen)
513 if(DOXYGEN_FOUND)
Antonio Maiorano6241f962021-06-25 14:00:36 +0000514 set(DOXYGEN_WARN_AS_ERROR NO)
515 if(TINT_DOCS_WARN_AS_ERROR)
516 set(DOXYGEN_WARN_AS_ERROR YES)
517 endif()
Antonio Maioranoe25a8fc2021-06-25 14:53:06 +0000518
519 set(DOXYGEN_WARN_FORMAT "$file:$line: $text")
520 if (MSVC)
521 set(DOXYGEN_WARN_FORMAT "$file($line): $text")
522 endif()
523
David Neto5b46d712020-06-26 22:29:27 +0000524 add_custom_target(tint-docs ALL
Ben Clayton4ace8222021-05-12 08:15:41 +0000525 COMMAND ${CMAKE_COMMAND}
Antonio Maiorano6241f962021-06-25 14:00:36 +0000526 -E env
527 "DOXYGEN_OUTPUT_DIRECTORY=${CMAKE_BINARY_DIR}/docs"
528 "DOXYGEN_WARN_AS_ERROR=${DOXYGEN_WARN_AS_ERROR}"
Antonio Maioranoe25a8fc2021-06-25 14:53:06 +0000529 "DOXYGEN_WARN_FORMAT=${DOXYGEN_WARN_FORMAT}"
Ben Clayton4ace8222021-05-12 08:15:41 +0000530 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile
David Neto5b46d712020-06-26 22:29:27 +0000531 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
532 COMMENT "Generating API documentation"
533 VERBATIM)
534 else()
535 message("Doxygen not found. Skipping documentation")
536 endif(DOXYGEN_FOUND)
dan sinclairb0391c6f2020-07-15 20:54:48 +0000537endif()
Dan Sinclair6e581892020-03-02 15:47:43 -0500538
Ben Claytonbe2362b2022-01-18 18:58:16 +0000539function(tint_core_compile_options TARGET)
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000540 target_include_directories(${TARGET} PUBLIC "${TINT_ROOT_SOURCE_DIR}")
541 target_include_directories(${TARGET} PUBLIC "${TINT_ROOT_SOURCE_DIR}/include")
Dan Sinclair6e581892020-03-02 15:47:43 -0500542
dan sinclairf6fdcb12020-10-23 17:04:10 +0000543 if (${TINT_BUILD_SPV_READER} OR ${TINT_BUILD_SPV_WRITER})
544 target_include_directories(${TARGET} PUBLIC
Ryan Harrisone87ac762022-04-06 15:37:27 -0400545 "${DAWN_THIRD_PARTY_DIR}/spirv-headers/include")
dan sinclairf6fdcb12020-10-23 17:04:10 +0000546 endif()
547
Ben Claytonbe2362b2022-01-18 18:58:16 +0000548 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_SPV_READER=$<BOOL:${TINT_BUILD_SPV_READER}>)
549 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_WGSL_READER=$<BOOL:${TINT_BUILD_WGSL_READER}>)
550 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_GLSL_WRITER=$<BOOL:${TINT_BUILD_GLSL_WRITER}>)
551 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_HLSL_WRITER=$<BOOL:${TINT_BUILD_HLSL_WRITER}>)
552 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_MSL_WRITER=$<BOOL:${TINT_BUILD_MSL_WRITER}>)
553 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_SPV_WRITER=$<BOOL:${TINT_BUILD_SPV_WRITER}>)
554 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_WGSL_WRITER=$<BOOL:${TINT_BUILD_WGSL_WRITER}>)
dan sinclair0917fbb2023-03-07 18:28:38 +0000555 target_compile_definitions(${TARGET} PUBLIC
556 -DTINT_BUILD_SYNTAX_TREE_WRITER=$<BOOL:${TINT_BUILD_SYNTAX_TREE_WRITER}>)
dan sinclair92612612022-11-01 18:15:50 +0000557 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_IR=$<BOOL:${TINT_BUILD_IR}>)
Ben Claytonbe2362b2022-01-18 18:58:16 +0000558
Ben Clayton96e245e2022-04-08 18:08:36 +0000559 common_compile_options(${TARGET})
Ben Claytonbe2362b2022-01-18 18:58:16 +0000560endfunction()
561
562function(tint_default_compile_options TARGET)
563 tint_core_compile_options(${TARGET})
dan sinclair37dbf992020-03-11 18:43:12 +0000564
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000565 set(COMMON_GNU_OPTIONS
566 -Wall
567 -Werror
568 -Wextra
569 -Wno-documentation-unknown-command
570 -Wno-padded
571 -Wno-switch-enum
572 -Wno-unknown-pragmas
573 )
574
575 set(COMMON_CLANG_OPTIONS
576 -Wno-c++98-compat
577 -Wno-c++98-compat-pedantic
578 -Wno-format-pedantic
James Price79f05992022-11-23 15:50:49 +0000579 -Wno-poison-system-directories
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000580 -Wno-return-std-move-in-c++11
581 -Wno-unknown-warning-option
582 -Wno-undefined-var-template
dan sinclaircf2456b2023-01-07 23:09:14 +0000583 -Wno-unsafe-buffer-usage
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000584 -Wno-used-but-marked-unused
585 -Weverything
586 )
587
Ben Claytonbe2362b2022-01-18 18:58:16 +0000588 if (COMPILER_IS_LIKE_GNU)
Dan Sinclair6e581892020-03-02 15:47:43 -0500589 target_compile_options(${TARGET} PRIVATE
Dan Sinclair6e581892020-03-02 15:47:43 -0500590 -pedantic-errors
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000591 ${COMMON_GNU_OPTIONS}
Dan Sinclair6e581892020-03-02 15:47:43 -0500592 )
593
Ben Clayton78e45302023-01-26 15:57:27 +0000594 if (COMPILER_IS_CLANG)
Dan Sinclair6e581892020-03-02 15:47:43 -0500595 target_compile_options(${TARGET} PRIVATE
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000596 ${COMMON_CLANG_OPTIONS}
Dan Sinclair6e581892020-03-02 15:47:43 -0500597 )
598 endif()
Ben Claytonbe2362b2022-01-18 18:58:16 +0000599 endif(COMPILER_IS_LIKE_GNU)
Ben Claytonadb10d62020-10-27 21:04:59 +0000600
Dan Sinclair6e581892020-03-02 15:47:43 -0500601 if (MSVC)
602 # Specify /EHs for exception handling.
603 target_compile_options(${TARGET} PRIVATE
604 /bigobj
605 /EHsc
Antonio Maioranoac39fb42021-03-16 15:05:33 +0000606 /W4
Dan Sinclair6e581892020-03-02 15:47:43 -0500607 /WX
Ben Claytona62b5c82023-06-14 13:40:00 +0000608 /wd4068 # unknown pragma
609 /wd4127 # conditional expression is constant
610 /wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data
611 /wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data
612 /wd4324 # 'struct_name' : structure was padded due to __declspec(align())
613 /wd4459 # declaration of 'identifier' hides global declaration
614 /wd4458 # declaration of 'identifier' hides class member
615 /wd4514 # 'function' : unreferenced inline function has been removed
616 /wd4571 # catch(...) semantics changed since Visual C++ 7.1; structured exceptions (SEH) are no longer caught
617 /wd4625 # 'derived class' : copy constructor was implicitly defined as deleted because a base class copy constructor is inaccessible or deleted
618 /wd4626 # 'derived class' : assignment operator was implicitly defined as deleted because a base class assignment operator is inaccessible or deleted
619 /wd4710 # 'function' : function not inlined
620 /wd4774 # 'function' : format string 'string' requires an argument of type 'type', but variadic argument number has type 'type'
621 /wd4820 # 'bytes' bytes padding added after construct 'member_name'
622 /wd5026 # 'type': move constructor was implicitly defined as deleted
623 /wd5027 # 'type': move assignment operator was implicitly defined as deleted
Dan Sinclair6e581892020-03-02 15:47:43 -0500624 )
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000625
626 # When building with clang-cl on Windows, try to match our clang build
627 # options as much as possible.
628 if (COMPILER_IS_CLANG_CL)
629 target_compile_options(${TARGET} PRIVATE
630 ${COMMON_GNU_OPTIONS}
631 ${COMMON_CLANG_OPTIONS}
632 # Disable warnings that are usually disabled in downstream deps for
633 # gcc/clang, but aren't for clang-cl.
634 -Wno-global-constructors
635 -Wno-zero-as-null-pointer-constant
636 -Wno-shorten-64-to-32
Antonio Maioranoc5f2fe42021-12-20 21:39:35 +0000637 -Wno-shadow-field-in-constructor
638 -Wno-reserved-id-macro
Antonio Maioranob79f51e2022-02-04 23:24:43 +0000639 -Wno-language-extension-token
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000640 )
641 endif()
Dan Sinclair6e581892020-03-02 15:47:43 -0500642 endif()
Ben Claytonf2b86aa2022-12-13 14:46:02 +0000643
644 if (TINT_RANDOMIZE_HASHES)
645 if(NOT DEFINED TINT_HASH_SEED)
646 string(RANDOM LENGTH 16 ALPHABET "0123456789abcdef" seed)
647 set(TINT_HASH_SEED "0x${seed}" CACHE STRING "Tint hash seed value")
648 message("Using TINT_HASH_SEED: ${TINT_HASH_SEED}")
649 endif()
650 target_compile_definitions(${TARGET} PUBLIC "-DTINT_HASH_SEED=${TINT_HASH_SEED}")
651 endif()
Dan Sinclair6e581892020-03-02 15:47:43 -0500652endfunction()
653
Ryan Harrisone87ac762022-04-06 15:37:27 -0400654################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000655# Run on all subdirectories
656################################################################################
657
658add_subdirectory(third_party)
James Price8d9adb02022-05-22 00:41:53 +0000659
660# TODO(crbug.com/tint/455): Tint does not currently build with CMake when
661# BUILD_SHARED_LIBS=1, so always build it as static for now.
662set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS})
663set(BUILD_SHARED_LIBS 0)
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000664add_subdirectory(src/tint)
James Price8d9adb02022-05-22 00:41:53 +0000665set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED})
666
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000667add_subdirectory(generator)
668add_subdirectory(src/dawn)
Ben Clayton7b778552022-02-04 18:59:15 +0000669
670################################################################################
671# Samples
672################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000673
Antonio Maiorano0eaee0c2021-08-31 18:43:36 +0000674if (TINT_BUILD_SAMPLES)
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000675 add_subdirectory(src/tint/cmd)
Antonio Maiorano0eaee0c2021-08-31 18:43:36 +0000676endif()
Dan Sinclair6e581892020-03-02 15:47:43 -0500677
Antonio Maiorano0eaee0c2021-08-31 18:43:36 +0000678if (TINT_BUILD_FUZZERS)
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000679 add_subdirectory(src/tint/fuzzers)
Dan Sinclair6e581892020-03-02 15:47:43 -0500680endif()
681
dan sinclairb5950522020-03-19 13:03:35 +0000682add_custom_target(tint-lint
683 COMMAND ./tools/lint
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000684 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000685 COMMENT "Running linter"
686 VERBATIM)
687
688add_custom_target(tint-format
689 COMMAND ./tools/format
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000690 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000691 COMMENT "Running formatter"
692 VERBATIM)
Ben Claytonadb10d62020-10-27 21:04:59 +0000693
Ben Clayton78e45302023-01-26 15:57:27 +0000694if (DAWN_EMIT_COVERAGE)
695 add_subdirectory(tools/src/cmd/turbo-cov)
Ben Claytonadb10d62020-10-27 21:04:59 +0000696
Ben Clayton78e45302023-01-26 15:57:27 +0000697 # The tint-generate-coverage target generates a lcov.info file at the project
698 # root, holding the code coverage for all the tint_unitests.
Ben Claytonadb10d62020-10-27 21:04:59 +0000699 # This can be used by tools such as VSCode's Coverage Gutters extension to
700 # visualize code coverage in the editor.
701 get_filename_component(CLANG_BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY)
702 set(PATH_WITH_CLANG "${CLANG_BIN_DIR}:$ENV{PATH}")
703 add_custom_target(tint-generate-coverage
704 COMMAND ${CMAKE_COMMAND} -E env PATH=${PATH_WITH_CLANG} ./tools/tint-generate-coverage $<TARGET_FILE:tint_unittests>
705 DEPENDS tint_unittests
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000706 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
Ben Claytonadb10d62020-10-27 21:04:59 +0000707 COMMENT "Generating tint coverage data"
708 VERBATIM)
709endif()
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000710
Antonio Maiorano0eaee0c2021-08-31 18:43:36 +0000711if (TINT_BUILD_REMOTE_COMPILE)
712 add_subdirectory(tools/src/cmd/remote-compile)
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000713endif()