blob: 32229964eae92339c96d5f001f7320091913c21d [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)
Ben Claytona6750752022-02-04 18:35:55 +000088set(BUILD_SAMPLES OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000089if (WIN32)
Peng Huang925b7762023-05-01 16:13:00 +000090 set(ENABLE_D3D11 ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000091 set(ENABLE_D3D12 ON)
陈俊嘉610de1d2021-06-28 08:19:28 +000092 if (NOT WINDOWS_STORE)
陈俊嘉b2bc57a2021-06-24 07:00:16 +000093 # Enable Vulkan in win32 compilation only
94 # since UWP only supports d3d
95 set(ENABLE_VULKAN ON)
96 endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000097elseif(APPLE)
98 set(ENABLE_METAL ON)
Alexander Vestinf2556ab2022-03-25 13:18:46 +000099elseif(ANDROID)
100 set(ENABLE_VULKAN ON)
101 set(ENABLE_OPENGLES ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000102elseif(UNIX)
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000103 set(ENABLE_OPENGLES ON)
104 set(ENABLE_DESKTOP_GL ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000105 set(ENABLE_VULKAN ON)
Corentin Wallezd353ca02020-02-18 02:12:35 +0000106 set(USE_X11 ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000107endif()
108
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000109# GLFW is not supported in UWP
Ryan Harrisone87ac762022-04-06 15:37:27 -0400110if ((WIN32 AND NOT WINDOWS_STORE) OR UNIX AND NOT ANDROID)
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000111 set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING ON)
112endif()
113
114# Current examples are depend on GLFW
115if (DAWN_SUPPORTS_GLFW_FOR_WINDOWING)
Ben Claytona6750752022-02-04 18:35:55 +0000116 set(BUILD_SAMPLES ON)
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000117endif()
118
Ben Clayton96e245e2022-04-08 18:08:36 +0000119option_if_not_defined(DAWN_ENABLE_ASAN "Enable address sanitizer" OFF)
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000120option_if_not_defined(DAWN_ENABLE_TSAN "Enable thread sanitizer" OFF)
121option_if_not_defined(DAWN_ENABLE_MSAN "Enable memory sanitizer" OFF)
Ben Clayton96e245e2022-04-08 18:08:36 +0000122option_if_not_defined(DAWN_ENABLE_UBSAN "Enable undefined behaviour sanitizer" OFF)
123
Peng Huang5c2f1672023-05-01 23:05:42 +0000124option_if_not_defined(DAWN_ENABLE_D3D11 "Enable compilation of the D3D11 backend" ${ENABLE_D3D11})
Ben Clayton30eeac72021-09-24 10:38:18 +0000125option_if_not_defined(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12})
126option_if_not_defined(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL})
127option_if_not_defined(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON)
128option_if_not_defined(DAWN_ENABLE_DESKTOP_GL "Enable compilation of the OpenGL backend" ${ENABLE_DESKTOP_GL})
129option_if_not_defined(DAWN_ENABLE_OPENGLES "Enable compilation of the OpenGL ES backend" ${ENABLE_OPENGLES})
130option_if_not_defined(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backend" ${ENABLE_VULKAN})
dan sinclair194c1772022-06-21 17:54:03 +0000131
Ben Clayton30eeac72021-09-24 10:38:18 +0000132option_if_not_defined(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF)
Corentin Wallez2e22d922022-06-01 09:30:50 +0000133option_if_not_defined(DAWN_USE_WAYLAND "Enable support for Wayland surface" ${USE_WAYLAND})
Ben Clayton30eeac72021-09-24 10:38:18 +0000134option_if_not_defined(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11})
Erin Melucci38b58e42023-06-14 16:45:33 +0000135option_if_not_defined(DAWN_USE_GLFW "Enable compilation of the GLFW windowing utils" ${DAWN_SUPPORTS_GLFW_FOR_WINDOWING})
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000136
Ben Claytona6750752022-02-04 18:35:55 +0000137option_if_not_defined(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" ${BUILD_SAMPLES})
Ben Claytonaffb7a32021-09-28 11:14:42 +0000138option_if_not_defined(DAWN_BUILD_NODE_BINDINGS "Enables building Dawn's NodeJS bindings" OFF)
Corentin Wallezbe352ea2022-04-11 16:48:43 +0000139option_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 +0000140option_if_not_defined(DAWN_BUILD_BENCHMARKS "Build Dawn benchmarks" OFF)
Ben Claytonaffb7a32021-09-28 11:14:42 +0000141
142option_if_not_defined(DAWN_ENABLE_PIC "Build with Position-Independent-Code enabled" OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000143
Ben Claytone38993f2022-12-10 00:15:57 +0000144option_if_not_defined(DAWN_EMIT_COVERAGE "Emit code coverage information" OFF)
Ben Claytonf927bcb2022-12-12 21:21:54 +0000145set_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 +0000146
dan sinclair194c1772022-06-21 17:54:03 +0000147if (DAWN_ENABLE_OPENGLES OR DAWN_ENABLE_DESKTOP_GL)
148 set(TINT_DEFAULT_GLSL ON)
149else()
150 set(TINT_DEFAULT_GLSL OFF)
151endif()
152
153option_if_not_defined(TINT_BUILD_SAMPLES "Build samples" ${DAWN_BUILD_SAMPLES})
154option_if_not_defined(TINT_BUILD_DOCS "Build documentation" ON)
155option_if_not_defined(TINT_DOCS_WARN_AS_ERROR "When building documentation, treat warnings as errors" OFF)
156
Erin Melucci38b58e42023-06-14 16:45:33 +0000157if (NOT DAWN_USE_GLFW AND (TINT_BUILD_SAMPLES OR DAWN_BUILD_SAMPLES))
158 message(SEND_ERROR "Dawn samples require GLFW")
159endif()
160
dan sinclair194c1772022-06-21 17:54:03 +0000161option_if_not_defined(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" ${DAWN_ENABLE_VULKAN})
162option_if_not_defined(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON)
163option_if_not_defined(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" ${TINT_DEFAULT_GLSL})
164option_if_not_defined(TINT_BUILD_HLSL_WRITER "Build the HLSL output writer" ${DAWN_ENABLE_D3D12})
165option_if_not_defined(TINT_BUILD_MSL_WRITER "Build the MSL output writer" ${DAWN_ENABLE_METAL})
166option_if_not_defined(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ${DAWN_ENABLE_VULKAN})
167option_if_not_defined(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON)
168
dan sinclair0917fbb2023-03-07 18:28:38 +0000169option_if_not_defined(TINT_BUILD_SYNTAX_TREE_WRITER "Build the syntax tree writer" OFF)
dan sinclair92612612022-11-01 18:15:50 +0000170option_if_not_defined(TINT_BUILD_IR "Build the IR" ON)
dan sinclairc22b8b9d2022-11-01 17:02:31 +0000171
dan sinclair194c1772022-06-21 17:54:03 +0000172option_if_not_defined(TINT_BUILD_FUZZERS "Build fuzzers" OFF)
173option_if_not_defined(TINT_BUILD_SPIRV_TOOLS_FUZZER "Build SPIRV-Tools fuzzer" OFF)
174option_if_not_defined(TINT_BUILD_AST_FUZZER "Build AST fuzzer" OFF)
175option_if_not_defined(TINT_BUILD_REGEX_FUZZER "Build regex fuzzer" OFF)
Austin Eng6a7bba52023-04-17 18:11:51 +0000176option_if_not_defined(TINT_BUILD_BENCHMARKS "Build Tint benchmarks" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000177option_if_not_defined(TINT_BUILD_TESTS "Build tests" ON)
178option_if_not_defined(TINT_BUILD_AS_OTHER_OS "Override OS detection to force building of *_other.cc files" OFF)
179option_if_not_defined(TINT_BUILD_REMOTE_COMPILE "Build the remote-compile tool for validating shaders on a remote machine" OFF)
180
Ben Clayton8fc9b862023-04-19 15:03:19 +0000181set_if_not_defined(TINT_EXTERNAL_BENCHMARK_CORPUS_DIR "" "Directory that holds a corpus of external shaders to benchmark.")
182
dan sinclair194c1772022-06-21 17:54:03 +0000183option_if_not_defined(TINT_ENABLE_BREAK_IN_DEBUGGER "Enable tint::debugger::Break()" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000184option_if_not_defined(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF)
Ben Claytonf2b86aa2022-12-13 14:46:02 +0000185option_if_not_defined(TINT_RANDOMIZE_HASHES "Randomize the hash seed value to detect non-deterministic output" OFF)
Corentin Walleze5570872020-10-20 14:26:10 +0000186
Brandon Jonesa04663c2021-09-23 20:36:03 +0000187# Recommended setting for compability with future abseil releases.
188set(ABSL_PROPAGATE_CXX_STD ON)
Brandon Jonesa04663c2021-09-23 20:36:03 +0000189
dan sinclair194c1772022-06-21 17:54:03 +0000190set_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 +0000191set_if_not_defined(DAWN_VULKAN_DEPS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps" "Directory in which to find vulkan-deps")
192
Ben Clayton30eeac72021-09-24 10:38:18 +0000193set_if_not_defined(DAWN_ABSEIL_DIR "${DAWN_THIRD_PARTY_DIR}/abseil-cpp" "Directory in which to find Abseil")
194set_if_not_defined(DAWN_GLFW_DIR "${DAWN_THIRD_PARTY_DIR}/glfw" "Directory in which to find GLFW")
Ben Clayton30eeac72021-09-24 10:38:18 +0000195set_if_not_defined(DAWN_JINJA2_DIR "${DAWN_THIRD_PARTY_DIR}/jinja2" "Directory in which to find Jinja2")
dan sinclair6b67a902023-04-07 07:52:36 +0000196set_if_not_defined(DAWN_MARKUPSAFE_DIR "${DAWN_THIRD_PARTY_DIR}/markupsafe" "Directory in which to find MarkupSafe")
Stephen White94349492022-06-29 15:29:41 +0000197set_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 +0000198set_if_not_defined(DAWN_SWIFTSHADER_DIR "${DAWN_THIRD_PARTY_DIR}/swiftshader" "Directory in which to find swiftshader")
dan sinclairc1f6dbd2023-04-11 15:45:18 +0000199
200set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_VULKAN_DEPS_DIR}/spirv-tools/src" "Directory in which to find SPIRV-Tools")
201set_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 +0000202set_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 +0000203set_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 +0000204
Ben Claytonaffb7a32021-09-28 11:14:42 +0000205# Dependencies for DAWN_BUILD_NODE_BINDINGS
206set_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 +0000207set_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 +0000208set_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 +0000209set_if_not_defined(GO_EXECUTABLE "go" "Golang executable for running the IDL generator")
Ben Claytonaffb7a32021-09-28 11:14:42 +0000210
Elie Michel9ae8ed22023-05-12 20:19:41 +0000211option_if_not_defined(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" OFF)
212
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000213# Much of the backend code is shared among desktop OpenGL and OpenGL ES
214if (${DAWN_ENABLE_DESKTOP_GL} OR ${DAWN_ENABLE_OPENGLES})
215 set(DAWN_ENABLE_OPENGL ON)
216endif()
217
Ben Claytonaffb7a32021-09-28 11:14:42 +0000218if(DAWN_ENABLE_PIC)
219 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
220endif()
221
dan sinclair194c1772022-06-21 17:54:03 +0000222if (${TINT_BUILD_SPIRV_TOOLS_FUZZER})
223 message(STATUS "TINT_BUILD_SPIRV_TOOLS_FUZZER is ON - setting
224 TINT_BUILD_FUZZERS
225 TINT_BUILD_SPV_READER
226 TINT_BUILD_SPV_WRITER
227 TINT_BUILD_WGSL_READER
228 TINT_BUILD_WGSL_WRITER
229 TINT_BUILD_GLSL_WRITER
230 TINT_BUILD_HLSL_WRITER
231 TINT_BUILD_MSL_WRITER to ON")
232 set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE)
233 set(TINT_BUILD_SPV_READER ON CACHE BOOL "Build SPIR-V reader" FORCE)
234 set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE)
235 set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE)
236 set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE)
237 set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
238 set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
239 set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE)
240endif()
241
242if (${TINT_BUILD_AST_FUZZER})
243 message(STATUS "TINT_BUILD_AST_FUZZER is ON - setting
244 TINT_BUILD_FUZZERS
245 TINT_BUILD_WGSL_READER
246 TINT_BUILD_WGSL_WRITER
247 TINT_BUILD_SPV_WRITER
248 TINT_BUILD_MSL_WRITER
249 TINT_BUILD_GLSL_WRITER
250 TINT_BUILD_HLSL_WRITER to ON")
251 set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE)
252 set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE)
253 set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE)
254 set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE)
255 set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE)
256 set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build GLSL writer" FORCE)
257 set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
258endif()
259
260if (${TINT_BUILD_REGEX_FUZZER})
261 message(STATUS "TINT_BUILD_REGEX_FUZZER is ON - setting
262 TINT_BUILD_FUZZERS
263 TINT_BUILD_WGSL_READER
264 TINT_BUILD_WGSL_WRITER
265 TINT_BUILD_SPV_WRITER
266 TINT_BUILD_MSL_WRITER
267 TINT_BUILD_GLSL_WRITER
268 TINT_BUILD_HLSL_WRITER to ON")
269 set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE)
270 set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE)
271 set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE)
272 set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE)
273 set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE)
274 set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build GLSL writer" FORCE)
275 set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
276endif()
277
Peng Huang5c2f1672023-05-01 23:05:42 +0000278message(STATUS "Dawn build D3D11 backend: ${DAWN_ENABLE_D3D11}")
dan sinclair194c1772022-06-21 17:54:03 +0000279message(STATUS "Dawn build D3D12 backend: ${DAWN_ENABLE_D3D12}")
280message(STATUS "Dawn build Metal backend: ${DAWN_ENABLE_METAL}")
281message(STATUS "Dawn build Vulkan backend: ${DAWN_ENABLE_VULKAN}")
282message(STATUS "Dawn build OpenGL backend: ${DAWN_ENABLE_DESKTOP_GL}")
283message(STATUS "Dawn build OpenGL ES backend: ${DAWN_ENABLE_OPENGLES}")
284message(STATUS "Dawn build Null backend: ${DAWN_ENABLE_NULL}")
285
286message(STATUS "Dawn build with asserts in all configurations: ${DAWN_ALWAYS_ASSERT}")
287message(STATUS "Dawn build Wayland support: ${DAWN_USE_WAYLAND}")
288message(STATUS "Dawn build X11 support: ${DAWN_USE_X11}")
289
290message(STATUS "Dawn build samples: ${DAWN_BUILD_SAMPLES}")
291message(STATUS "Dawn build Node bindings: ${DAWN_BUILD_NODE_BINDINGS}")
292message(STATUS "Dawn build Swiftshader: ${DAWN_ENABLE_SWIFTSHADER}")
Austin Eng6a7bba52023-04-17 18:11:51 +0000293message(STATUS "Dawn build benchmarks: ${DAWN_BUILD_BENCHMARKS}")
dan sinclair194c1772022-06-21 17:54:03 +0000294
295message(STATUS "Dawn build PIC: ${DAWN_ENABLE_PIC}")
296
297message(STATUS "Dawn build with ASAN: ${DAWN_ENABLE_ASAN}")
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000298message(STATUS "Dawn build with TSAN: ${DAWN_ENABLE_TSAN}")
dan sinclair194c1772022-06-21 17:54:03 +0000299message(STATUS "Dawn build with MSAN: ${DAWN_ENABLE_MSAN}")
300message(STATUS "Dawn build with UBSAN: ${DAWN_ENABLE_UBSAN}")
301
302message(STATUS "Tint build samples: ${TINT_BUILD_SAMPLES}")
303message(STATUS "Tint build docs: ${TINT_BUILD_DOCS}")
304message(STATUS "Tint build docs with warn as error: ${TINT_DOCS_WARN_AS_ERROR}")
305message(STATUS "Tint build SPIR-V reader: ${TINT_BUILD_SPV_READER}")
306message(STATUS "Tint build WGSL reader: ${TINT_BUILD_WGSL_READER}")
307message(STATUS "Tint build GLSL writer: ${TINT_BUILD_GLSL_WRITER}")
308message(STATUS "Tint build HLSL writer: ${TINT_BUILD_HLSL_WRITER}")
309message(STATUS "Tint build MSL writer: ${TINT_BUILD_MSL_WRITER}")
310message(STATUS "Tint build SPIR-V writer: ${TINT_BUILD_SPV_WRITER}")
311message(STATUS "Tint build WGSL writer: ${TINT_BUILD_WGSL_WRITER}")
dan sinclair0917fbb2023-03-07 18:28:38 +0000312message(STATUS "Tint build Syntax Tree writer: ${TINT_BUILD_SYNTAX_TREE_WRITER}")
dan sinclair92612612022-11-01 18:15:50 +0000313message(STATUS "Tint build IR: ${TINT_BUILD_IR}")
dan sinclair194c1772022-06-21 17:54:03 +0000314message(STATUS "Tint build fuzzers: ${TINT_BUILD_FUZZERS}")
315message(STATUS "Tint build SPIRV-Tools fuzzer: ${TINT_BUILD_SPIRV_TOOLS_FUZZER}")
316message(STATUS "Tint build AST fuzzer: ${TINT_BUILD_AST_FUZZER}")
317message(STATUS "Tint build regex fuzzer: ${TINT_BUILD_REGEX_FUZZER}")
318message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}")
319message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}")
320message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}")
321message(STATUS "Tint build remote-compile tool: ${TINT_BUILD_REMOTE_COMPILE}")
Ben Clayton8fc9b862023-04-19 15:03:19 +0000322message(STATUS "Tint external benchmark corpus dir: ${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}")
323
dan sinclair194c1772022-06-21 17:54:03 +0000324
325if (NOT ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS} STREQUAL "")
326 message(STATUS "Using provided LIB_FUZZING_ENGINE options: ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS}")
327endif()
328
329message(STATUS "Using python3")
330find_package(PythonInterp 3 REQUIRED)
331
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000332################################################################################
Ben Clayton96e245e2022-04-08 18:08:36 +0000333# common_compile_options - sets compiler and linker options common for dawn and
334# tint on the given target
335################################################################################
336function(common_compile_options TARGET)
337 if (COMPILER_IS_LIKE_GNU)
338 target_compile_options(${TARGET} PRIVATE
339 -fno-exceptions
340 -fno-rtti
dan sinclaircf2456b2023-01-07 23:09:14 +0000341
342 -Wno-deprecated-builtins
dan sinclair07c32cb2023-01-09 15:10:33 +0000343 -Wno-unknown-warning-option
Ben Clayton96e245e2022-04-08 18:08:36 +0000344 )
345
346 if (${DAWN_ENABLE_MSAN})
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000347 target_compile_options(${TARGET} PUBLIC -fsanitize=memory)
348 target_link_options(${TARGET} PUBLIC -fsanitize=memory)
Ben Clayton96e245e2022-04-08 18:08:36 +0000349 elseif (${DAWN_ENABLE_ASAN})
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000350 target_compile_options(${TARGET} PUBLIC -fsanitize=address)
351 target_link_options(${TARGET} PUBLIC -fsanitize=address)
352 elseif (${DAWN_ENABLE_TSAN})
353 target_compile_options(${TARGET} PUBLIC -fsanitize=thread)
354 target_link_options(${TARGET} PUBLIC -fsanitize=thread)
Ben Clayton96e245e2022-04-08 18:08:36 +0000355 elseif (${DAWN_ENABLE_UBSAN})
Antonio Maioranodeb2ec92023-03-24 18:44:02 +0000356 target_compile_options(${TARGET} PUBLIC -fsanitize=undefined -fsanitize=float-divide-by-zero)
357 target_link_options(${TARGET} PUBLIC -fsanitize=undefined -fsanitize=float-divide-by-zero)
Ben Clayton96e245e2022-04-08 18:08:36 +0000358 endif()
359 endif(COMPILER_IS_LIKE_GNU)
Setoc6927202022-09-14 16:41:07 +0000360
361 if(MSVC)
362 target_compile_options(${TARGET} PUBLIC /utf-8)
363 endif()
Ben Claytone38993f2022-12-10 00:15:57 +0000364
365 if (DAWN_EMIT_COVERAGE)
Ben Clayton54264d32023-01-10 21:55:43 +0000366 target_compile_definitions(${TARGET} PRIVATE "DAWN_EMIT_COVERAGE")
Ben Claytone38993f2022-12-10 00:15:57 +0000367 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
368 target_compile_options(${TARGET} PRIVATE "--coverage")
369 target_link_options(${TARGET} PRIVATE "gcov")
Ben Clayton78e45302023-01-26 15:57:27 +0000370 elseif(COMPILER_IS_CLANG OR COMPILER_IS_CLANG_CL)
Ben Claytone38993f2022-12-10 00:15:57 +0000371 target_compile_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping")
372 target_link_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping")
373 else()
374 message(FATAL_ERROR "Coverage generation not supported for the ${CMAKE_CXX_COMPILER_ID} toolchain")
375 endif()
376 endif(DAWN_EMIT_COVERAGE)
Ben Clayton96e245e2022-04-08 18:08:36 +0000377endfunction()
378
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000379if (${DAWN_ENABLE_TSAN})
380 add_compile_options(-stdlib=libc++)
381 add_link_options(-stdlib=libc++)
382endif()
383
Ben Clayton96e245e2022-04-08 18:08:36 +0000384################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000385# Dawn's public and internal "configs"
386################################################################################
387
Ben Clayton94181522022-11-09 20:55:33 +0000388set(IS_DEBUG_BUILD 0)
389string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
390if ((NOT ${build_type} STREQUAL "RELEASE") AND (NOT ${build_type} STREQUAL "RELWITHDEBINFO"))
391 set(IS_DEBUG_BUILD 1)
392endif()
393
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000394# The public config contains only the include paths for the Dawn headers.
395add_library(dawn_public_config INTERFACE)
396target_include_directories(dawn_public_config INTERFACE
Ben Clayton9fb7a512022-02-04 18:18:18 +0000397 "${DAWN_INCLUDE_DIR}"
398 "${DAWN_BUILD_GEN_DIR}/include"
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000399)
400
401# The internal config conatins additional path but includes the dawn_public_config include paths
402add_library(dawn_internal_config INTERFACE)
403target_include_directories(dawn_internal_config INTERFACE
404 "${DAWN_SRC_DIR}"
405 "${DAWN_BUILD_GEN_DIR}/src"
406)
407target_link_libraries(dawn_internal_config INTERFACE dawn_public_config)
408
409# Compile definitions for the internal config
Ben Clayton94181522022-11-09 20:55:33 +0000410if (DAWN_ALWAYS_ASSERT OR IS_DEBUG_BUILD)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000411 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_ASSERTS")
412endif()
Peng Huang5c2f1672023-05-01 23:05:42 +0000413if (DAWN_ENABLE_D3D11)
414 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D11")
415endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000416if (DAWN_ENABLE_D3D12)
417 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D12")
418endif()
419if (DAWN_ENABLE_METAL)
420 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_METAL")
421endif()
422if (DAWN_ENABLE_NULL)
423 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_NULL")
424endif()
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000425if (DAWN_ENABLE_DESKTOP_GL)
426 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_DESKTOP_GL")
427endif()
428if (DAWN_ENABLE_OPENGLES)
429 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGLES")
430endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000431if (DAWN_ENABLE_OPENGL)
432 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGL")
433endif()
434if (DAWN_ENABLE_VULKAN)
435 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_VULKAN")
436endif()
Corentin Wallez2e22d922022-06-01 09:30:50 +0000437if (DAWN_USE_WAYLAND)
438 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WAYLAND")
439endif()
Corentin Wallezd353ca02020-02-18 02:12:35 +0000440if (DAWN_USE_X11)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000441 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11")
442endif()
Corentin Wallez33466972020-02-24 13:27:28 +0000443if (WIN32)
444 target_compile_definitions(dawn_internal_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN")
445endif()
446
Corentin Wallez7c8bc942022-01-05 09:26:46 +0000447set(CMAKE_CXX_STANDARD "17")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000448
449################################################################################
Ryan Harrisone87ac762022-04-06 15:37:27 -0400450# Tint
451################################################################################
452
Alastair Donaldson6a1eb452021-09-02 23:49:25 +0000453set(TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS "" CACHE STRING "Used by OSS-Fuzz to control, via link options, which fuzzing engine should be used")
454
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000455set(TINT_ROOT_SOURCE_DIR ${PROJECT_SOURCE_DIR})
456
Antonio Maioranod6009722021-03-17 13:32:54 +0000457# CMake < 3.15 sets /W3 in CMAKE_CXX_FLAGS. Remove it if it's there.
458# See https://gitlab.kitware.com/cmake/cmake/-/issues/18317
459if (MSVC)
Vasyl Teliman0b3611b2021-06-24 18:10:46 +0000460 if (CMAKE_CXX_FLAGS MATCHES "/W3")
461 string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
462 endif()
Antonio Maioranod6009722021-03-17 13:32:54 +0000463endif()
464
Ryan Harrison563d3e92020-04-28 19:27:38 +0000465if (${TINT_CHECK_CHROMIUM_STYLE})
466 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -add-plugin -Xclang find-bad-constructs")
467endif()
468
dan sinclair4b71b9e2020-03-18 14:08:48 +0000469if (${TINT_BUILD_SPV_READER})
Ryan Harrisone87ac762022-04-06 15:37:27 -0400470 include_directories("${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-tools/include")
Dan Sinclair6e581892020-03-02 15:47:43 -0500471endif()
472
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000473if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC"))
474 set(COMPILER_IS_CLANG_CL TRUE)
475endif()
476
Ben Clayton78e45302023-01-26 15:57:27 +0000477if((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000478 ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND
479 (NOT COMPILER_IS_CLANG_CL)))
Ben Clayton78e45302023-01-26 15:57:27 +0000480 set(COMPILER_IS_CLANG TRUE)
481endif()
482
483if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR COMPILER_IS_CLANG)
Dan Sinclair6e581892020-03-02 15:47:43 -0500484 set(COMPILER_IS_LIKE_GNU TRUE)
485endif()
486
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000487# Enable msbuild multiprocessor builds
488if (MSVC AND NOT COMPILER_IS_CLANG_CL)
489 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
490endif()
491
Ben Clayton7687ec12021-04-16 14:43:34 +0000492set(TINT_OS_CC_SUFFIX "other")
493if (NOT TINT_BUILD_AS_OTHER_OS)
494 if(UNIX OR APPLE)
495 set(TINT_OS_CC_SUFFIX "posix")
496 set(TINT_OS_CC_SUFFIX "posix")
497 elseif(WIN32)
498 set(TINT_OS_CC_SUFFIX "windows")
499 set(TINT_OS_CC_SUFFIX "windows")
500 endif()
501endif()
502
David Neto5b46d712020-06-26 22:29:27 +0000503if(${TINT_BUILD_DOCS})
504 find_package(Doxygen)
505 if(DOXYGEN_FOUND)
Antonio Maiorano6241f962021-06-25 14:00:36 +0000506 set(DOXYGEN_WARN_AS_ERROR NO)
507 if(TINT_DOCS_WARN_AS_ERROR)
508 set(DOXYGEN_WARN_AS_ERROR YES)
509 endif()
Antonio Maioranoe25a8fc2021-06-25 14:53:06 +0000510
511 set(DOXYGEN_WARN_FORMAT "$file:$line: $text")
512 if (MSVC)
513 set(DOXYGEN_WARN_FORMAT "$file($line): $text")
514 endif()
515
David Neto5b46d712020-06-26 22:29:27 +0000516 add_custom_target(tint-docs ALL
Ben Clayton4ace8222021-05-12 08:15:41 +0000517 COMMAND ${CMAKE_COMMAND}
Antonio Maiorano6241f962021-06-25 14:00:36 +0000518 -E env
519 "DOXYGEN_OUTPUT_DIRECTORY=${CMAKE_BINARY_DIR}/docs"
520 "DOXYGEN_WARN_AS_ERROR=${DOXYGEN_WARN_AS_ERROR}"
Antonio Maioranoe25a8fc2021-06-25 14:53:06 +0000521 "DOXYGEN_WARN_FORMAT=${DOXYGEN_WARN_FORMAT}"
Ben Clayton4ace8222021-05-12 08:15:41 +0000522 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile
David Neto5b46d712020-06-26 22:29:27 +0000523 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
524 COMMENT "Generating API documentation"
525 VERBATIM)
526 else()
527 message("Doxygen not found. Skipping documentation")
528 endif(DOXYGEN_FOUND)
dan sinclairb0391c6f2020-07-15 20:54:48 +0000529endif()
Dan Sinclair6e581892020-03-02 15:47:43 -0500530
Ben Claytonbe2362b2022-01-18 18:58:16 +0000531function(tint_core_compile_options TARGET)
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000532 target_include_directories(${TARGET} PUBLIC "${TINT_ROOT_SOURCE_DIR}")
533 target_include_directories(${TARGET} PUBLIC "${TINT_ROOT_SOURCE_DIR}/include")
Dan Sinclair6e581892020-03-02 15:47:43 -0500534
dan sinclairf6fdcb12020-10-23 17:04:10 +0000535 if (${TINT_BUILD_SPV_READER} OR ${TINT_BUILD_SPV_WRITER})
536 target_include_directories(${TARGET} PUBLIC
Ryan Harrisone87ac762022-04-06 15:37:27 -0400537 "${DAWN_THIRD_PARTY_DIR}/spirv-headers/include")
dan sinclairf6fdcb12020-10-23 17:04:10 +0000538 endif()
539
Ben Claytonbe2362b2022-01-18 18:58:16 +0000540 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_SPV_READER=$<BOOL:${TINT_BUILD_SPV_READER}>)
541 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_WGSL_READER=$<BOOL:${TINT_BUILD_WGSL_READER}>)
542 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_GLSL_WRITER=$<BOOL:${TINT_BUILD_GLSL_WRITER}>)
543 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_HLSL_WRITER=$<BOOL:${TINT_BUILD_HLSL_WRITER}>)
544 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_MSL_WRITER=$<BOOL:${TINT_BUILD_MSL_WRITER}>)
545 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_SPV_WRITER=$<BOOL:${TINT_BUILD_SPV_WRITER}>)
546 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_WGSL_WRITER=$<BOOL:${TINT_BUILD_WGSL_WRITER}>)
dan sinclair0917fbb2023-03-07 18:28:38 +0000547 target_compile_definitions(${TARGET} PUBLIC
548 -DTINT_BUILD_SYNTAX_TREE_WRITER=$<BOOL:${TINT_BUILD_SYNTAX_TREE_WRITER}>)
dan sinclair92612612022-11-01 18:15:50 +0000549 target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_IR=$<BOOL:${TINT_BUILD_IR}>)
Ben Claytonbe2362b2022-01-18 18:58:16 +0000550
Ben Clayton96e245e2022-04-08 18:08:36 +0000551 common_compile_options(${TARGET})
Ben Claytonbe2362b2022-01-18 18:58:16 +0000552endfunction()
553
554function(tint_default_compile_options TARGET)
555 tint_core_compile_options(${TARGET})
dan sinclair37dbf992020-03-11 18:43:12 +0000556
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000557 set(COMMON_GNU_OPTIONS
558 -Wall
559 -Werror
560 -Wextra
561 -Wno-documentation-unknown-command
562 -Wno-padded
563 -Wno-switch-enum
564 -Wno-unknown-pragmas
565 )
566
567 set(COMMON_CLANG_OPTIONS
568 -Wno-c++98-compat
569 -Wno-c++98-compat-pedantic
570 -Wno-format-pedantic
James Price79f05992022-11-23 15:50:49 +0000571 -Wno-poison-system-directories
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000572 -Wno-return-std-move-in-c++11
573 -Wno-unknown-warning-option
574 -Wno-undefined-var-template
dan sinclaircf2456b2023-01-07 23:09:14 +0000575 -Wno-unsafe-buffer-usage
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000576 -Wno-used-but-marked-unused
577 -Weverything
578 )
579
Ben Claytonbe2362b2022-01-18 18:58:16 +0000580 if (COMPILER_IS_LIKE_GNU)
Dan Sinclair6e581892020-03-02 15:47:43 -0500581 target_compile_options(${TARGET} PRIVATE
Dan Sinclair6e581892020-03-02 15:47:43 -0500582 -pedantic-errors
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000583 ${COMMON_GNU_OPTIONS}
Dan Sinclair6e581892020-03-02 15:47:43 -0500584 )
585
Ben Clayton78e45302023-01-26 15:57:27 +0000586 if (COMPILER_IS_CLANG)
Dan Sinclair6e581892020-03-02 15:47:43 -0500587 target_compile_options(${TARGET} PRIVATE
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000588 ${COMMON_CLANG_OPTIONS}
Dan Sinclair6e581892020-03-02 15:47:43 -0500589 )
590 endif()
Ben Claytonbe2362b2022-01-18 18:58:16 +0000591 endif(COMPILER_IS_LIKE_GNU)
Ben Claytonadb10d62020-10-27 21:04:59 +0000592
Dan Sinclair6e581892020-03-02 15:47:43 -0500593 if (MSVC)
594 # Specify /EHs for exception handling.
595 target_compile_options(${TARGET} PRIVATE
596 /bigobj
597 /EHsc
Antonio Maioranoac39fb42021-03-16 15:05:33 +0000598 /W4
Dan Sinclair6e581892020-03-02 15:47:43 -0500599 /WX
Ben Claytona62b5c82023-06-14 13:40:00 +0000600 /wd4068 # unknown pragma
601 /wd4127 # conditional expression is constant
602 /wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data
603 /wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data
604 /wd4324 # 'struct_name' : structure was padded due to __declspec(align())
605 /wd4459 # declaration of 'identifier' hides global declaration
606 /wd4458 # declaration of 'identifier' hides class member
607 /wd4514 # 'function' : unreferenced inline function has been removed
608 /wd4571 # catch(...) semantics changed since Visual C++ 7.1; structured exceptions (SEH) are no longer caught
609 /wd4625 # 'derived class' : copy constructor was implicitly defined as deleted because a base class copy constructor is inaccessible or deleted
610 /wd4626 # 'derived class' : assignment operator was implicitly defined as deleted because a base class assignment operator is inaccessible or deleted
611 /wd4710 # 'function' : function not inlined
612 /wd4774 # 'function' : format string 'string' requires an argument of type 'type', but variadic argument number has type 'type'
613 /wd4820 # 'bytes' bytes padding added after construct 'member_name'
614 /wd5026 # 'type': move constructor was implicitly defined as deleted
615 /wd5027 # 'type': move assignment operator was implicitly defined as deleted
Dan Sinclair6e581892020-03-02 15:47:43 -0500616 )
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000617
618 # When building with clang-cl on Windows, try to match our clang build
619 # options as much as possible.
620 if (COMPILER_IS_CLANG_CL)
621 target_compile_options(${TARGET} PRIVATE
622 ${COMMON_GNU_OPTIONS}
623 ${COMMON_CLANG_OPTIONS}
624 # Disable warnings that are usually disabled in downstream deps for
625 # gcc/clang, but aren't for clang-cl.
626 -Wno-global-constructors
627 -Wno-zero-as-null-pointer-constant
628 -Wno-shorten-64-to-32
Antonio Maioranoc5f2fe42021-12-20 21:39:35 +0000629 -Wno-shadow-field-in-constructor
630 -Wno-reserved-id-macro
Antonio Maioranob79f51e2022-02-04 23:24:43 +0000631 -Wno-language-extension-token
Antonio Maiorano5bdece52021-04-27 19:24:47 +0000632 )
633 endif()
Dan Sinclair6e581892020-03-02 15:47:43 -0500634 endif()
Ben Claytonf2b86aa2022-12-13 14:46:02 +0000635
636 if (TINT_RANDOMIZE_HASHES)
637 if(NOT DEFINED TINT_HASH_SEED)
638 string(RANDOM LENGTH 16 ALPHABET "0123456789abcdef" seed)
639 set(TINT_HASH_SEED "0x${seed}" CACHE STRING "Tint hash seed value")
640 message("Using TINT_HASH_SEED: ${TINT_HASH_SEED}")
641 endif()
642 target_compile_definitions(${TARGET} PUBLIC "-DTINT_HASH_SEED=${TINT_HASH_SEED}")
643 endif()
Dan Sinclair6e581892020-03-02 15:47:43 -0500644endfunction()
645
Ryan Harrisone87ac762022-04-06 15:37:27 -0400646################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000647# Run on all subdirectories
648################################################################################
649
650add_subdirectory(third_party)
James Price8d9adb02022-05-22 00:41:53 +0000651
652# TODO(crbug.com/tint/455): Tint does not currently build with CMake when
653# BUILD_SHARED_LIBS=1, so always build it as static for now.
654set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS})
655set(BUILD_SHARED_LIBS 0)
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000656add_subdirectory(src/tint)
James Price8d9adb02022-05-22 00:41:53 +0000657set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED})
658
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000659add_subdirectory(generator)
660add_subdirectory(src/dawn)
Ben Clayton7b778552022-02-04 18:59:15 +0000661
662################################################################################
663# Samples
664################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000665
Antonio Maiorano0eaee0c2021-08-31 18:43:36 +0000666if (TINT_BUILD_SAMPLES)
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000667 add_subdirectory(src/tint/cmd)
Antonio Maiorano0eaee0c2021-08-31 18:43:36 +0000668endif()
Dan Sinclair6e581892020-03-02 15:47:43 -0500669
Antonio Maiorano0eaee0c2021-08-31 18:43:36 +0000670if (TINT_BUILD_FUZZERS)
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000671 add_subdirectory(src/tint/fuzzers)
Dan Sinclair6e581892020-03-02 15:47:43 -0500672endif()
673
dan sinclairb5950522020-03-19 13:03:35 +0000674add_custom_target(tint-lint
675 COMMAND ./tools/lint
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000676 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000677 COMMENT "Running linter"
678 VERBATIM)
679
680add_custom_target(tint-format
681 COMMAND ./tools/format
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000682 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000683 COMMENT "Running formatter"
684 VERBATIM)
Ben Claytonadb10d62020-10-27 21:04:59 +0000685
Ben Clayton78e45302023-01-26 15:57:27 +0000686if (DAWN_EMIT_COVERAGE)
687 add_subdirectory(tools/src/cmd/turbo-cov)
Ben Claytonadb10d62020-10-27 21:04:59 +0000688
Ben Clayton78e45302023-01-26 15:57:27 +0000689 # The tint-generate-coverage target generates a lcov.info file at the project
690 # root, holding the code coverage for all the tint_unitests.
Ben Claytonadb10d62020-10-27 21:04:59 +0000691 # This can be used by tools such as VSCode's Coverage Gutters extension to
692 # visualize code coverage in the editor.
693 get_filename_component(CLANG_BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY)
694 set(PATH_WITH_CLANG "${CLANG_BIN_DIR}:$ENV{PATH}")
695 add_custom_target(tint-generate-coverage
696 COMMAND ${CMAKE_COMMAND} -E env PATH=${PATH_WITH_CLANG} ./tools/tint-generate-coverage $<TARGET_FILE:tint_unittests>
697 DEPENDS tint_unittests
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000698 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
Ben Claytonadb10d62020-10-27 21:04:59 +0000699 COMMENT "Generating tint coverage data"
700 VERBATIM)
701endif()
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000702
Antonio Maiorano0eaee0c2021-08-31 18:43:36 +0000703if (TINT_BUILD_REMOTE_COMPILE)
704 add_subdirectory(tools/src/cmd/remote-compile)
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000705endif()