blob: efba2fba92bbb108550e554159a0286899a11e18 [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
Ryan Harrisone87ac762022-04-06 15:37:27 -0400112if ((WIN32 AND NOT WINDOWS_STORE) OR UNIX AND NOT ANDROID)
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000113 set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING ON)
114endif()
115
116# Current examples are depend on GLFW
117if (DAWN_SUPPORTS_GLFW_FOR_WINDOWING)
Ben Claytona6750752022-02-04 18:35:55 +0000118 set(BUILD_SAMPLES ON)
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000119endif()
120
Ben Clayton96e245e2022-04-08 18:08:36 +0000121option_if_not_defined(DAWN_ENABLE_ASAN "Enable address sanitizer" OFF)
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000122option_if_not_defined(DAWN_ENABLE_TSAN "Enable thread sanitizer" OFF)
123option_if_not_defined(DAWN_ENABLE_MSAN "Enable memory sanitizer" OFF)
Ben Clayton96e245e2022-04-08 18:08:36 +0000124option_if_not_defined(DAWN_ENABLE_UBSAN "Enable undefined behaviour sanitizer" OFF)
125
Peng Huang5c2f1672023-05-01 23:05:42 +0000126option_if_not_defined(DAWN_ENABLE_D3D11 "Enable compilation of the D3D11 backend" ${ENABLE_D3D11})
Ben Clayton30eeac72021-09-24 10:38:18 +0000127option_if_not_defined(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12})
128option_if_not_defined(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL})
129option_if_not_defined(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON)
130option_if_not_defined(DAWN_ENABLE_DESKTOP_GL "Enable compilation of the OpenGL backend" ${ENABLE_DESKTOP_GL})
131option_if_not_defined(DAWN_ENABLE_OPENGLES "Enable compilation of the OpenGL ES backend" ${ENABLE_OPENGLES})
132option_if_not_defined(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backend" ${ENABLE_VULKAN})
dan sinclair194c1772022-06-21 17:54:03 +0000133
Ben Clayton30eeac72021-09-24 10:38:18 +0000134option_if_not_defined(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF)
Corentin Wallez2e22d922022-06-01 09:30:50 +0000135option_if_not_defined(DAWN_USE_WAYLAND "Enable support for Wayland surface" ${USE_WAYLAND})
Ben Clayton30eeac72021-09-24 10:38:18 +0000136option_if_not_defined(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11})
Erin Melucci38b58e42023-06-14 16:45:33 +0000137option_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 +0000138option_if_not_defined(DAWN_USE_WINDOWS_UI "Enable support for Windows UI surface" ${USE_WINDOWS_UI})
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000139
Ben Claytona6750752022-02-04 18:35:55 +0000140option_if_not_defined(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" ${BUILD_SAMPLES})
Ben Claytonaffb7a32021-09-28 11:14:42 +0000141option_if_not_defined(DAWN_BUILD_NODE_BINDINGS "Enables building Dawn's NodeJS bindings" OFF)
Corentin Wallezbe352ea2022-04-11 16:48:43 +0000142option_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 +0000143option_if_not_defined(DAWN_BUILD_BENCHMARKS "Build Dawn benchmarks" OFF)
Ben Claytonaffb7a32021-09-28 11:14:42 +0000144
145option_if_not_defined(DAWN_ENABLE_PIC "Build with Position-Independent-Code enabled" OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000146
Ben Claytone38993f2022-12-10 00:15:57 +0000147option_if_not_defined(DAWN_EMIT_COVERAGE "Emit code coverage information" OFF)
Ben Claytonf927bcb2022-12-12 21:21:54 +0000148set_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 +0000149
dan sinclair194c1772022-06-21 17:54:03 +0000150if (DAWN_ENABLE_OPENGLES OR DAWN_ENABLE_DESKTOP_GL)
151 set(TINT_DEFAULT_GLSL ON)
152else()
153 set(TINT_DEFAULT_GLSL OFF)
154endif()
155
156option_if_not_defined(TINT_BUILD_SAMPLES "Build samples" ${DAWN_BUILD_SAMPLES})
157option_if_not_defined(TINT_BUILD_DOCS "Build documentation" ON)
158option_if_not_defined(TINT_DOCS_WARN_AS_ERROR "When building documentation, treat warnings as errors" OFF)
159
Erin Melucci38b58e42023-06-14 16:45:33 +0000160if (NOT DAWN_USE_GLFW AND (TINT_BUILD_SAMPLES OR DAWN_BUILD_SAMPLES))
161 message(SEND_ERROR "Dawn samples require GLFW")
162endif()
163
dan sinclair194c1772022-06-21 17:54:03 +0000164option_if_not_defined(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" ${DAWN_ENABLE_VULKAN})
165option_if_not_defined(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON)
166option_if_not_defined(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" ${TINT_DEFAULT_GLSL})
167option_if_not_defined(TINT_BUILD_HLSL_WRITER "Build the HLSL output writer" ${DAWN_ENABLE_D3D12})
168option_if_not_defined(TINT_BUILD_MSL_WRITER "Build the MSL output writer" ${DAWN_ENABLE_METAL})
169option_if_not_defined(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ${DAWN_ENABLE_VULKAN})
170option_if_not_defined(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON)
171
dan sinclair0917fbb2023-03-07 18:28:38 +0000172option_if_not_defined(TINT_BUILD_SYNTAX_TREE_WRITER "Build the syntax tree writer" OFF)
dan sinclair92612612022-11-01 18:15:50 +0000173option_if_not_defined(TINT_BUILD_IR "Build the IR" ON)
dan sinclairc22b8b9d2022-11-01 17:02:31 +0000174
dan sinclair194c1772022-06-21 17:54:03 +0000175option_if_not_defined(TINT_BUILD_FUZZERS "Build fuzzers" OFF)
176option_if_not_defined(TINT_BUILD_SPIRV_TOOLS_FUZZER "Build SPIRV-Tools fuzzer" OFF)
177option_if_not_defined(TINT_BUILD_AST_FUZZER "Build AST fuzzer" OFF)
178option_if_not_defined(TINT_BUILD_REGEX_FUZZER "Build regex fuzzer" OFF)
Austin Eng6a7bba52023-04-17 18:11:51 +0000179option_if_not_defined(TINT_BUILD_BENCHMARKS "Build Tint benchmarks" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000180option_if_not_defined(TINT_BUILD_TESTS "Build tests" ON)
181option_if_not_defined(TINT_BUILD_AS_OTHER_OS "Override OS detection to force building of *_other.cc files" OFF)
182option_if_not_defined(TINT_BUILD_REMOTE_COMPILE "Build the remote-compile tool for validating shaders on a remote machine" OFF)
183
Ben Clayton8fc9b862023-04-19 15:03:19 +0000184set_if_not_defined(TINT_EXTERNAL_BENCHMARK_CORPUS_DIR "" "Directory that holds a corpus of external shaders to benchmark.")
185
dan sinclair194c1772022-06-21 17:54:03 +0000186option_if_not_defined(TINT_ENABLE_BREAK_IN_DEBUGGER "Enable tint::debugger::Break()" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000187option_if_not_defined(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF)
Ben Claytonf2b86aa2022-12-13 14:46:02 +0000188option_if_not_defined(TINT_RANDOMIZE_HASHES "Randomize the hash seed value to detect non-deterministic output" OFF)
Corentin Walleze5570872020-10-20 14:26:10 +0000189
Brandon Jonesa04663c2021-09-23 20:36:03 +0000190# Recommended setting for compability with future abseil releases.
191set(ABSL_PROPAGATE_CXX_STD ON)
Brandon Jonesa04663c2021-09-23 20:36:03 +0000192
dan sinclair194c1772022-06-21 17:54:03 +0000193set_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 +0000194set_if_not_defined(DAWN_VULKAN_DEPS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps" "Directory in which to find vulkan-deps")
195
Ben Clayton30eeac72021-09-24 10:38:18 +0000196set_if_not_defined(DAWN_ABSEIL_DIR "${DAWN_THIRD_PARTY_DIR}/abseil-cpp" "Directory in which to find Abseil")
197set_if_not_defined(DAWN_GLFW_DIR "${DAWN_THIRD_PARTY_DIR}/glfw" "Directory in which to find GLFW")
Ben Clayton30eeac72021-09-24 10:38:18 +0000198set_if_not_defined(DAWN_JINJA2_DIR "${DAWN_THIRD_PARTY_DIR}/jinja2" "Directory in which to find Jinja2")
dan sinclair6b67a902023-04-07 07:52:36 +0000199set_if_not_defined(DAWN_MARKUPSAFE_DIR "${DAWN_THIRD_PARTY_DIR}/markupsafe" "Directory in which to find MarkupSafe")
Stephen White94349492022-06-29 15:29:41 +0000200set_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 +0000201set_if_not_defined(DAWN_SWIFTSHADER_DIR "${DAWN_THIRD_PARTY_DIR}/swiftshader" "Directory in which to find swiftshader")
dan sinclairc1f6dbd2023-04-11 15:45:18 +0000202
203set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_VULKAN_DEPS_DIR}/spirv-tools/src" "Directory in which to find SPIRV-Tools")
204set_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 +0000205set_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 +0000206set_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 +0000207
Ben Claytonaffb7a32021-09-28 11:14:42 +0000208# Dependencies for DAWN_BUILD_NODE_BINDINGS
209set_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 +0000210set_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 +0000211set_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 +0000212set_if_not_defined(GO_EXECUTABLE "go" "Golang executable for running the IDL generator")
Ben Claytonaffb7a32021-09-28 11:14:42 +0000213
Elie Michel9ae8ed22023-05-12 20:19:41 +0000214option_if_not_defined(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" OFF)
215
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000216# Much of the backend code is shared among desktop OpenGL and OpenGL ES
217if (${DAWN_ENABLE_DESKTOP_GL} OR ${DAWN_ENABLE_OPENGLES})
218 set(DAWN_ENABLE_OPENGL ON)
219endif()
220
Ben Claytonaffb7a32021-09-28 11:14:42 +0000221if(DAWN_ENABLE_PIC)
222 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
223endif()
224
dan sinclair194c1772022-06-21 17:54:03 +0000225if (${TINT_BUILD_SPIRV_TOOLS_FUZZER})
226 message(STATUS "TINT_BUILD_SPIRV_TOOLS_FUZZER is ON - setting
227 TINT_BUILD_FUZZERS
228 TINT_BUILD_SPV_READER
229 TINT_BUILD_SPV_WRITER
230 TINT_BUILD_WGSL_READER
231 TINT_BUILD_WGSL_WRITER
232 TINT_BUILD_GLSL_WRITER
233 TINT_BUILD_HLSL_WRITER
234 TINT_BUILD_MSL_WRITER to ON")
235 set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE)
236 set(TINT_BUILD_SPV_READER ON CACHE BOOL "Build SPIR-V reader" FORCE)
237 set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE)
238 set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE)
239 set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE)
240 set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
241 set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
242 set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE)
243endif()
244
245if (${TINT_BUILD_AST_FUZZER})
246 message(STATUS "TINT_BUILD_AST_FUZZER is ON - setting
247 TINT_BUILD_FUZZERS
248 TINT_BUILD_WGSL_READER
249 TINT_BUILD_WGSL_WRITER
250 TINT_BUILD_SPV_WRITER
251 TINT_BUILD_MSL_WRITER
252 TINT_BUILD_GLSL_WRITER
253 TINT_BUILD_HLSL_WRITER to ON")
254 set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE)
255 set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE)
256 set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE)
257 set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE)
258 set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE)
259 set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build GLSL writer" FORCE)
260 set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
261endif()
262
263if (${TINT_BUILD_REGEX_FUZZER})
264 message(STATUS "TINT_BUILD_REGEX_FUZZER is ON - setting
265 TINT_BUILD_FUZZERS
266 TINT_BUILD_WGSL_READER
267 TINT_BUILD_WGSL_WRITER
268 TINT_BUILD_SPV_WRITER
269 TINT_BUILD_MSL_WRITER
270 TINT_BUILD_GLSL_WRITER
271 TINT_BUILD_HLSL_WRITER to ON")
272 set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE)
273 set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE)
274 set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE)
275 set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE)
276 set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE)
277 set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build GLSL writer" FORCE)
278 set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
279endif()
280
Peng Huang5c2f1672023-05-01 23:05:42 +0000281message(STATUS "Dawn build D3D11 backend: ${DAWN_ENABLE_D3D11}")
dan sinclair194c1772022-06-21 17:54:03 +0000282message(STATUS "Dawn build D3D12 backend: ${DAWN_ENABLE_D3D12}")
283message(STATUS "Dawn build Metal backend: ${DAWN_ENABLE_METAL}")
284message(STATUS "Dawn build Vulkan backend: ${DAWN_ENABLE_VULKAN}")
285message(STATUS "Dawn build OpenGL backend: ${DAWN_ENABLE_DESKTOP_GL}")
286message(STATUS "Dawn build OpenGL ES backend: ${DAWN_ENABLE_OPENGLES}")
287message(STATUS "Dawn build Null backend: ${DAWN_ENABLE_NULL}")
288
289message(STATUS "Dawn build with asserts in all configurations: ${DAWN_ALWAYS_ASSERT}")
290message(STATUS "Dawn build Wayland support: ${DAWN_USE_WAYLAND}")
291message(STATUS "Dawn build X11 support: ${DAWN_USE_X11}")
Stephen Gutekanst55623702023-07-01 11:43:55 +0000292message(STATUS "Dawn build Windows UI support: ${DAWN_USE_WINDOWS_UI}")
dan sinclair194c1772022-06-21 17:54:03 +0000293
294message(STATUS "Dawn build samples: ${DAWN_BUILD_SAMPLES}")
295message(STATUS "Dawn build Node bindings: ${DAWN_BUILD_NODE_BINDINGS}")
296message(STATUS "Dawn build Swiftshader: ${DAWN_ENABLE_SWIFTSHADER}")
Austin Eng6a7bba52023-04-17 18:11:51 +0000297message(STATUS "Dawn build benchmarks: ${DAWN_BUILD_BENCHMARKS}")
dan sinclair194c1772022-06-21 17:54:03 +0000298
299message(STATUS "Dawn build PIC: ${DAWN_ENABLE_PIC}")
300
301message(STATUS "Dawn build with ASAN: ${DAWN_ENABLE_ASAN}")
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000302message(STATUS "Dawn build with TSAN: ${DAWN_ENABLE_TSAN}")
dan sinclair194c1772022-06-21 17:54:03 +0000303message(STATUS "Dawn build with MSAN: ${DAWN_ENABLE_MSAN}")
304message(STATUS "Dawn build with UBSAN: ${DAWN_ENABLE_UBSAN}")
305
306message(STATUS "Tint build samples: ${TINT_BUILD_SAMPLES}")
307message(STATUS "Tint build docs: ${TINT_BUILD_DOCS}")
308message(STATUS "Tint build docs with warn as error: ${TINT_DOCS_WARN_AS_ERROR}")
309message(STATUS "Tint build SPIR-V reader: ${TINT_BUILD_SPV_READER}")
310message(STATUS "Tint build WGSL reader: ${TINT_BUILD_WGSL_READER}")
311message(STATUS "Tint build GLSL writer: ${TINT_BUILD_GLSL_WRITER}")
312message(STATUS "Tint build HLSL writer: ${TINT_BUILD_HLSL_WRITER}")
313message(STATUS "Tint build MSL writer: ${TINT_BUILD_MSL_WRITER}")
314message(STATUS "Tint build SPIR-V writer: ${TINT_BUILD_SPV_WRITER}")
315message(STATUS "Tint build WGSL writer: ${TINT_BUILD_WGSL_WRITER}")
dan sinclair0917fbb2023-03-07 18:28:38 +0000316message(STATUS "Tint build Syntax Tree writer: ${TINT_BUILD_SYNTAX_TREE_WRITER}")
dan sinclair92612612022-11-01 18:15:50 +0000317message(STATUS "Tint build IR: ${TINT_BUILD_IR}")
dan sinclair194c1772022-06-21 17:54:03 +0000318message(STATUS "Tint build fuzzers: ${TINT_BUILD_FUZZERS}")
319message(STATUS "Tint build SPIRV-Tools fuzzer: ${TINT_BUILD_SPIRV_TOOLS_FUZZER}")
320message(STATUS "Tint build AST fuzzer: ${TINT_BUILD_AST_FUZZER}")
321message(STATUS "Tint build regex fuzzer: ${TINT_BUILD_REGEX_FUZZER}")
322message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}")
323message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}")
324message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}")
325message(STATUS "Tint build remote-compile tool: ${TINT_BUILD_REMOTE_COMPILE}")
Ben Clayton8fc9b862023-04-19 15:03:19 +0000326message(STATUS "Tint external benchmark corpus dir: ${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}")
327
dan sinclair194c1772022-06-21 17:54:03 +0000328
329if (NOT ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS} STREQUAL "")
330 message(STATUS "Using provided LIB_FUZZING_ENGINE options: ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS}")
331endif()
332
333message(STATUS "Using python3")
334find_package(PythonInterp 3 REQUIRED)
335
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000336################################################################################
Ben Clayton96e245e2022-04-08 18:08:36 +0000337# common_compile_options - sets compiler and linker options common for dawn and
338# tint on the given target
339################################################################################
340function(common_compile_options TARGET)
341 if (COMPILER_IS_LIKE_GNU)
342 target_compile_options(${TARGET} PRIVATE
343 -fno-exceptions
344 -fno-rtti
dan sinclaircf2456b2023-01-07 23:09:14 +0000345
346 -Wno-deprecated-builtins
dan sinclair07c32cb2023-01-09 15:10:33 +0000347 -Wno-unknown-warning-option
Ben Clayton96e245e2022-04-08 18:08:36 +0000348 )
349
350 if (${DAWN_ENABLE_MSAN})
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000351 target_compile_options(${TARGET} PUBLIC -fsanitize=memory)
352 target_link_options(${TARGET} PUBLIC -fsanitize=memory)
Ben Clayton96e245e2022-04-08 18:08:36 +0000353 elseif (${DAWN_ENABLE_ASAN})
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000354 target_compile_options(${TARGET} PUBLIC -fsanitize=address)
355 target_link_options(${TARGET} PUBLIC -fsanitize=address)
356 elseif (${DAWN_ENABLE_TSAN})
357 target_compile_options(${TARGET} PUBLIC -fsanitize=thread)
358 target_link_options(${TARGET} PUBLIC -fsanitize=thread)
Ben Clayton96e245e2022-04-08 18:08:36 +0000359 elseif (${DAWN_ENABLE_UBSAN})
Antonio Maioranodeb2ec92023-03-24 18:44:02 +0000360 target_compile_options(${TARGET} PUBLIC -fsanitize=undefined -fsanitize=float-divide-by-zero)
361 target_link_options(${TARGET} PUBLIC -fsanitize=undefined -fsanitize=float-divide-by-zero)
Ben Clayton96e245e2022-04-08 18:08:36 +0000362 endif()
363 endif(COMPILER_IS_LIKE_GNU)
Setoc6927202022-09-14 16:41:07 +0000364
365 if(MSVC)
366 target_compile_options(${TARGET} PUBLIC /utf-8)
367 endif()
Ben Claytone38993f2022-12-10 00:15:57 +0000368
369 if (DAWN_EMIT_COVERAGE)
Ben Clayton54264d32023-01-10 21:55:43 +0000370 target_compile_definitions(${TARGET} PRIVATE "DAWN_EMIT_COVERAGE")
Ben Claytone38993f2022-12-10 00:15:57 +0000371 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
372 target_compile_options(${TARGET} PRIVATE "--coverage")
373 target_link_options(${TARGET} PRIVATE "gcov")
Ben Clayton78e45302023-01-26 15:57:27 +0000374 elseif(COMPILER_IS_CLANG OR COMPILER_IS_CLANG_CL)
Ben Claytone38993f2022-12-10 00:15:57 +0000375 target_compile_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping")
376 target_link_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping")
377 else()
378 message(FATAL_ERROR "Coverage generation not supported for the ${CMAKE_CXX_COMPILER_ID} toolchain")
379 endif()
380 endif(DAWN_EMIT_COVERAGE)
Ben Clayton96e245e2022-04-08 18:08:36 +0000381endfunction()
382
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000383if (${DAWN_ENABLE_TSAN})
384 add_compile_options(-stdlib=libc++)
385 add_link_options(-stdlib=libc++)
386endif()
387
Ben Clayton96e245e2022-04-08 18:08:36 +0000388################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000389# Dawn's public and internal "configs"
390################################################################################
391
Ben Clayton94181522022-11-09 20:55:33 +0000392set(IS_DEBUG_BUILD 0)
393string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
394if ((NOT ${build_type} STREQUAL "RELEASE") AND (NOT ${build_type} STREQUAL "RELWITHDEBINFO"))
395 set(IS_DEBUG_BUILD 1)
396endif()
397
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000398# The public config contains only the include paths for the Dawn headers.
399add_library(dawn_public_config INTERFACE)
400target_include_directories(dawn_public_config INTERFACE
Ben Clayton9fb7a512022-02-04 18:18:18 +0000401 "${DAWN_INCLUDE_DIR}"
402 "${DAWN_BUILD_GEN_DIR}/include"
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000403)
404
405# The internal config conatins additional path but includes the dawn_public_config include paths
406add_library(dawn_internal_config INTERFACE)
407target_include_directories(dawn_internal_config INTERFACE
408 "${DAWN_SRC_DIR}"
409 "${DAWN_BUILD_GEN_DIR}/src"
410)
411target_link_libraries(dawn_internal_config INTERFACE dawn_public_config)
412
413# Compile definitions for the internal config
Ben Clayton94181522022-11-09 20:55:33 +0000414if (DAWN_ALWAYS_ASSERT OR IS_DEBUG_BUILD)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000415 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_ASSERTS")
416endif()
Peng Huang5c2f1672023-05-01 23:05:42 +0000417if (DAWN_ENABLE_D3D11)
418 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D11")
419endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000420if (DAWN_ENABLE_D3D12)
421 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D12")
422endif()
423if (DAWN_ENABLE_METAL)
424 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_METAL")
425endif()
426if (DAWN_ENABLE_NULL)
427 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_NULL")
428endif()
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000429if (DAWN_ENABLE_DESKTOP_GL)
430 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_DESKTOP_GL")
431endif()
432if (DAWN_ENABLE_OPENGLES)
433 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGLES")
434endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000435if (DAWN_ENABLE_OPENGL)
436 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGL")
437endif()
438if (DAWN_ENABLE_VULKAN)
439 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_VULKAN")
440endif()
Corentin Wallez2e22d922022-06-01 09:30:50 +0000441if (DAWN_USE_WAYLAND)
442 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WAYLAND")
443endif()
Corentin Wallezd353ca02020-02-18 02:12:35 +0000444if (DAWN_USE_X11)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000445 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11")
446endif()
Stephen Gutekanst55623702023-07-01 11:43:55 +0000447if (DAWN_USE_WINDOWS_UI)
448 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WINDOWS_UI")
449endif()
Corentin Wallez33466972020-02-24 13:27:28 +0000450if (WIN32)
451 target_compile_definitions(dawn_internal_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN")
452endif()
453
Corentin Wallez7c8bc942022-01-05 09:26:46 +0000454set(CMAKE_CXX_STANDARD "17")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000455
456################################################################################
Ryan Harrisone87ac762022-04-06 15:37:27 -0400457# Tint
458################################################################################
459
Alastair Donaldson6a1eb452021-09-02 23:49:25 +0000460set(TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS "" CACHE STRING "Used by OSS-Fuzz to control, via link options, which fuzzing engine should be used")
461
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000462set(TINT_ROOT_SOURCE_DIR ${PROJECT_SOURCE_DIR})
463
Antonio Maioranod6009722021-03-17 13:32:54 +0000464# CMake < 3.15 sets /W3 in CMAKE_CXX_FLAGS. Remove it if it's there.
465# See https://gitlab.kitware.com/cmake/cmake/-/issues/18317
466if (MSVC)
Vasyl Teliman0b3611b2021-06-24 18:10:46 +0000467 if (CMAKE_CXX_FLAGS MATCHES "/W3")
468 string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
469 endif()
Antonio Maioranod6009722021-03-17 13:32:54 +0000470endif()
471
Ryan Harrison563d3e92020-04-28 19:27:38 +0000472if (${TINT_CHECK_CHROMIUM_STYLE})
473 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -add-plugin -Xclang find-bad-constructs")
474endif()
475
dan sinclair4b71b9e2020-03-18 14:08:48 +0000476if (${TINT_BUILD_SPV_READER})
Ryan Harrisone87ac762022-04-06 15:37:27 -0400477 include_directories("${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-tools/include")
Dan Sinclair6e581892020-03-02 15:47:43 -0500478endif()
479
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000480if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC"))
481 set(COMPILER_IS_CLANG_CL TRUE)
482endif()
483
Ben Clayton78e45302023-01-26 15:57:27 +0000484if((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000485 ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND
486 (NOT COMPILER_IS_CLANG_CL)))
Ben Clayton78e45302023-01-26 15:57:27 +0000487 set(COMPILER_IS_CLANG TRUE)
488endif()
489
490if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR COMPILER_IS_CLANG)
Dan Sinclair6e581892020-03-02 15:47:43 -0500491 set(COMPILER_IS_LIKE_GNU TRUE)
492endif()
493
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000494# Enable msbuild multiprocessor builds
495if (MSVC AND NOT COMPILER_IS_CLANG_CL)
496 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
497endif()
498
Ben Clayton7687ec12021-04-16 14:43:34 +0000499set(TINT_OS_CC_SUFFIX "other")
500if (NOT TINT_BUILD_AS_OTHER_OS)
501 if(UNIX OR APPLE)
502 set(TINT_OS_CC_SUFFIX "posix")
503 set(TINT_OS_CC_SUFFIX "posix")
504 elseif(WIN32)
505 set(TINT_OS_CC_SUFFIX "windows")
506 set(TINT_OS_CC_SUFFIX "windows")
507 endif()
508endif()
509
David Neto5b46d712020-06-26 22:29:27 +0000510if(${TINT_BUILD_DOCS})
511 find_package(Doxygen)
512 if(DOXYGEN_FOUND)
Antonio Maiorano6241f962021-06-25 14:00:36 +0000513 set(DOXYGEN_WARN_AS_ERROR NO)
514 if(TINT_DOCS_WARN_AS_ERROR)
515 set(DOXYGEN_WARN_AS_ERROR YES)
516 endif()
Antonio Maioranoe25a8fc2021-06-25 14:53:06 +0000517
518 set(DOXYGEN_WARN_FORMAT "$file:$line: $text")
519 if (MSVC)
520 set(DOXYGEN_WARN_FORMAT "$file($line): $text")
521 endif()
522
David Neto5b46d712020-06-26 22:29:27 +0000523 add_custom_target(tint-docs ALL
Ben Clayton4ace8222021-05-12 08:15:41 +0000524 COMMAND ${CMAKE_COMMAND}
Antonio Maiorano6241f962021-06-25 14:00:36 +0000525 -E env
526 "DOXYGEN_OUTPUT_DIRECTORY=${CMAKE_BINARY_DIR}/docs"
527 "DOXYGEN_WARN_AS_ERROR=${DOXYGEN_WARN_AS_ERROR}"
Antonio Maioranoe25a8fc2021-06-25 14:53:06 +0000528 "DOXYGEN_WARN_FORMAT=${DOXYGEN_WARN_FORMAT}"
Ben Clayton4ace8222021-05-12 08:15:41 +0000529 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile
David Neto5b46d712020-06-26 22:29:27 +0000530 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
531 COMMENT "Generating API documentation"
532 VERBATIM)
533 else()
534 message("Doxygen not found. Skipping documentation")
535 endif(DOXYGEN_FOUND)
dan sinclairb0391c6f2020-07-15 20:54:48 +0000536endif()
Dan Sinclair6e581892020-03-02 15:47:43 -0500537
Ben Claytonbe2362b2022-01-18 18:58:16 +0000538function(tint_core_compile_options TARGET)
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000539 target_include_directories(${TARGET} PUBLIC "${TINT_ROOT_SOURCE_DIR}")
540 target_include_directories(${TARGET} PUBLIC "${TINT_ROOT_SOURCE_DIR}/include")
Dan Sinclair6e581892020-03-02 15:47:43 -0500541
dan sinclairf6fdcb12020-10-23 17:04:10 +0000542 if (${TINT_BUILD_SPV_READER} OR ${TINT_BUILD_SPV_WRITER})
543 target_include_directories(${TARGET} PUBLIC
Ryan Harrisone87ac762022-04-06 15:37:27 -0400544 "${DAWN_THIRD_PARTY_DIR}/spirv-headers/include")
dan sinclairf6fdcb12020-10-23 17:04:10 +0000545 endif()
546
Ben Claytonbe2362b2022-01-18 18:58:16 +0000547 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_SPV_READER=$<BOOL:${TINT_BUILD_SPV_READER}>)
548 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_WGSL_READER=$<BOOL:${TINT_BUILD_WGSL_READER}>)
549 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_GLSL_WRITER=$<BOOL:${TINT_BUILD_GLSL_WRITER}>)
550 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_HLSL_WRITER=$<BOOL:${TINT_BUILD_HLSL_WRITER}>)
551 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_MSL_WRITER=$<BOOL:${TINT_BUILD_MSL_WRITER}>)
552 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_SPV_WRITER=$<BOOL:${TINT_BUILD_SPV_WRITER}>)
553 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_WGSL_WRITER=$<BOOL:${TINT_BUILD_WGSL_WRITER}>)
dan sinclair0917fbb2023-03-07 18:28:38 +0000554 target_compile_definitions(${TARGET} PUBLIC
555 -DTINT_BUILD_SYNTAX_TREE_WRITER=$<BOOL:${TINT_BUILD_SYNTAX_TREE_WRITER}>)
dan sinclair92612612022-11-01 18:15:50 +0000556 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_IR=$<BOOL:${TINT_BUILD_IR}>)
Ben Claytonbe2362b2022-01-18 18:58:16 +0000557
Ben Clayton96e245e2022-04-08 18:08:36 +0000558 common_compile_options(${TARGET})
Ben Claytonbe2362b2022-01-18 18:58:16 +0000559endfunction()
560
561function(tint_default_compile_options TARGET)
562 tint_core_compile_options(${TARGET})
dan sinclair37dbf992020-03-11 18:43:12 +0000563
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000564 set(COMMON_GNU_OPTIONS
565 -Wall
566 -Werror
567 -Wextra
568 -Wno-documentation-unknown-command
569 -Wno-padded
570 -Wno-switch-enum
571 -Wno-unknown-pragmas
572 )
573
574 set(COMMON_CLANG_OPTIONS
575 -Wno-c++98-compat
576 -Wno-c++98-compat-pedantic
577 -Wno-format-pedantic
James Price79f05992022-11-23 15:50:49 +0000578 -Wno-poison-system-directories
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000579 -Wno-return-std-move-in-c++11
580 -Wno-unknown-warning-option
581 -Wno-undefined-var-template
dan sinclaircf2456b2023-01-07 23:09:14 +0000582 -Wno-unsafe-buffer-usage
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000583 -Wno-used-but-marked-unused
584 -Weverything
585 )
586
Ben Claytonbe2362b2022-01-18 18:58:16 +0000587 if (COMPILER_IS_LIKE_GNU)
Dan Sinclair6e581892020-03-02 15:47:43 -0500588 target_compile_options(${TARGET} PRIVATE
Dan Sinclair6e581892020-03-02 15:47:43 -0500589 -pedantic-errors
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000590 ${COMMON_GNU_OPTIONS}
Dan Sinclair6e581892020-03-02 15:47:43 -0500591 )
592
Ben Clayton78e45302023-01-26 15:57:27 +0000593 if (COMPILER_IS_CLANG)
Dan Sinclair6e581892020-03-02 15:47:43 -0500594 target_compile_options(${TARGET} PRIVATE
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000595 ${COMMON_CLANG_OPTIONS}
Dan Sinclair6e581892020-03-02 15:47:43 -0500596 )
597 endif()
Ben Claytonbe2362b2022-01-18 18:58:16 +0000598 endif(COMPILER_IS_LIKE_GNU)
Ben Claytonadb10d62020-10-27 21:04:59 +0000599
Dan Sinclair6e581892020-03-02 15:47:43 -0500600 if (MSVC)
601 # Specify /EHs for exception handling.
602 target_compile_options(${TARGET} PRIVATE
603 /bigobj
604 /EHsc
Antonio Maioranoac39fb42021-03-16 15:05:33 +0000605 /W4
Dan Sinclair6e581892020-03-02 15:47:43 -0500606 /WX
Ben Claytona62b5c82023-06-14 13:40:00 +0000607 /wd4068 # unknown pragma
608 /wd4127 # conditional expression is constant
609 /wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data
610 /wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data
611 /wd4324 # 'struct_name' : structure was padded due to __declspec(align())
612 /wd4459 # declaration of 'identifier' hides global declaration
613 /wd4458 # declaration of 'identifier' hides class member
614 /wd4514 # 'function' : unreferenced inline function has been removed
615 /wd4571 # catch(...) semantics changed since Visual C++ 7.1; structured exceptions (SEH) are no longer caught
616 /wd4625 # 'derived class' : copy constructor was implicitly defined as deleted because a base class copy constructor is inaccessible or deleted
617 /wd4626 # 'derived class' : assignment operator was implicitly defined as deleted because a base class assignment operator is inaccessible or deleted
618 /wd4710 # 'function' : function not inlined
619 /wd4774 # 'function' : format string 'string' requires an argument of type 'type', but variadic argument number has type 'type'
620 /wd4820 # 'bytes' bytes padding added after construct 'member_name'
621 /wd5026 # 'type': move constructor was implicitly defined as deleted
622 /wd5027 # 'type': move assignment operator was implicitly defined as deleted
Dan Sinclair6e581892020-03-02 15:47:43 -0500623 )
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000624
625 # When building with clang-cl on Windows, try to match our clang build
626 # options as much as possible.
627 if (COMPILER_IS_CLANG_CL)
628 target_compile_options(${TARGET} PRIVATE
629 ${COMMON_GNU_OPTIONS}
630 ${COMMON_CLANG_OPTIONS}
631 # Disable warnings that are usually disabled in downstream deps for
632 # gcc/clang, but aren't for clang-cl.
633 -Wno-global-constructors
634 -Wno-zero-as-null-pointer-constant
635 -Wno-shorten-64-to-32
Antonio Maioranoc5f2fe42021-12-20 21:39:35 +0000636 -Wno-shadow-field-in-constructor
637 -Wno-reserved-id-macro
Antonio Maioranob79f51e2022-02-04 23:24:43 +0000638 -Wno-language-extension-token
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000639 )
640 endif()
Dan Sinclair6e581892020-03-02 15:47:43 -0500641 endif()
Ben Claytonf2b86aa2022-12-13 14:46:02 +0000642
643 if (TINT_RANDOMIZE_HASHES)
644 if(NOT DEFINED TINT_HASH_SEED)
645 string(RANDOM LENGTH 16 ALPHABET "0123456789abcdef" seed)
646 set(TINT_HASH_SEED "0x${seed}" CACHE STRING "Tint hash seed value")
647 message("Using TINT_HASH_SEED: ${TINT_HASH_SEED}")
648 endif()
649 target_compile_definitions(${TARGET} PUBLIC "-DTINT_HASH_SEED=${TINT_HASH_SEED}")
650 endif()
Dan Sinclair6e581892020-03-02 15:47:43 -0500651endfunction()
652
Ryan Harrisone87ac762022-04-06 15:37:27 -0400653################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000654# Run on all subdirectories
655################################################################################
656
657add_subdirectory(third_party)
James Price8d9adb02022-05-22 00:41:53 +0000658
659# TODO(crbug.com/tint/455): Tint does not currently build with CMake when
660# BUILD_SHARED_LIBS=1, so always build it as static for now.
661set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS})
662set(BUILD_SHARED_LIBS 0)
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000663add_subdirectory(src/tint)
James Price8d9adb02022-05-22 00:41:53 +0000664set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED})
665
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000666add_subdirectory(generator)
667add_subdirectory(src/dawn)
Ben Clayton7b778552022-02-04 18:59:15 +0000668
669################################################################################
670# Samples
671################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000672
Antonio Maiorano0eaee0c2021-08-31 18:43:36 +0000673if (TINT_BUILD_SAMPLES)
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000674 add_subdirectory(src/tint/cmd)
Antonio Maiorano0eaee0c2021-08-31 18:43:36 +0000675endif()
Dan Sinclair6e581892020-03-02 15:47:43 -0500676
Antonio Maiorano0eaee0c2021-08-31 18:43:36 +0000677if (TINT_BUILD_FUZZERS)
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000678 add_subdirectory(src/tint/fuzzers)
Dan Sinclair6e581892020-03-02 15:47:43 -0500679endif()
680
dan sinclairb5950522020-03-19 13:03:35 +0000681add_custom_target(tint-lint
682 COMMAND ./tools/lint
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000683 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000684 COMMENT "Running linter"
685 VERBATIM)
686
687add_custom_target(tint-format
688 COMMAND ./tools/format
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000689 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000690 COMMENT "Running formatter"
691 VERBATIM)
Ben Claytonadb10d62020-10-27 21:04:59 +0000692
Ben Clayton78e45302023-01-26 15:57:27 +0000693if (DAWN_EMIT_COVERAGE)
694 add_subdirectory(tools/src/cmd/turbo-cov)
Ben Claytonadb10d62020-10-27 21:04:59 +0000695
Ben Clayton78e45302023-01-26 15:57:27 +0000696 # The tint-generate-coverage target generates a lcov.info file at the project
697 # root, holding the code coverage for all the tint_unitests.
Ben Claytonadb10d62020-10-27 21:04:59 +0000698 # This can be used by tools such as VSCode's Coverage Gutters extension to
699 # visualize code coverage in the editor.
700 get_filename_component(CLANG_BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY)
701 set(PATH_WITH_CLANG "${CLANG_BIN_DIR}:$ENV{PATH}")
702 add_custom_target(tint-generate-coverage
703 COMMAND ${CMAKE_COMMAND} -E env PATH=${PATH_WITH_CLANG} ./tools/tint-generate-coverage $<TARGET_FILE:tint_unittests>
704 DEPENDS tint_unittests
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000705 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
Ben Claytonadb10d62020-10-27 21:04:59 +0000706 COMMENT "Generating tint coverage data"
707 VERBATIM)
708endif()
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000709
Antonio Maiorano0eaee0c2021-08-31 18:43:36 +0000710if (TINT_BUILD_REMOTE_COMPILE)
711 add_subdirectory(tools/src/cmd/remote-compile)
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000712endif()