blob: 7dc8b0152f1d77e026d2c7ca129f11f0e3653538 [file] [log] [blame]
Ryan Harrisone87ac762022-04-06 15:37:27 -04001# Copyright 2022 The Dawn & Tint Authors
Corentin Wallez7fe6efb2020-02-05 17:16:05 +00002#
Austin Engcc2516a2023-10-17 20:57:54 +00003# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions are met:
Corentin Wallez7fe6efb2020-02-05 17:16:05 +00005#
Austin Engcc2516a2023-10-17 20:57:54 +00006# 1. Redistributions of source code must retain the above copyright notice, this
7# list of conditions and the following disclaimer.
Corentin Wallez7fe6efb2020-02-05 17:16:05 +00008#
Austin Engcc2516a2023-10-17 20:57:54 +00009# 2. Redistributions in binary form must reproduce the above copyright notice,
10# this list of conditions and the following disclaimer in the documentation
11# and/or other materials provided with the distribution.
12#
13# 3. Neither the name of the copyright holder nor the names of its
14# contributors may be used to endorse or promote products derived from
15# this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000027
Erin Meluccid1e92bb2024-03-27 15:43:05 +000028# As per https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md
29cmake_minimum_required(VERSION 3.13)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000030
Erin Meluccid1e92bb2024-03-27 15:43:05 +000031# - Since we are past CMake 3.12 we can add CONFIGURE_DEPENDS to DawnGenerator to rerun CMake
Corentin Walleza3014cc2024-03-27 13:53:14 +000032# in case any of the generator files changes. We should also remove the CACHE "" FORCE stuff to
Erin Meluccid1e92bb2024-03-27 15:43:05 +000033# override options in third_party dependencies.
Corentin Walleza3014cc2024-03-27 13:53:14 +000034# - When upgrading to CMake 3.20 we can take advantage of the GENERATED property being global in
35# DawnGenerator. We should also use the path utilities in install_if_enabled.
36
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000037project(
38 Dawn
39 DESCRIPTION "Dawn, a WebGPU implementation"
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000040 LANGUAGES C CXX
Erin Meluccid1e92bb2024-03-27 15:43:05 +000041 HOMEPAGE_URL "https://dawn.googlesource.com/dawn"
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000042)
Dan Sinclair6e581892020-03-02 15:47:43 -050043enable_testing()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000044
45set_property(GLOBAL PROPERTY USE_FOLDERS ON)
46
Dan Sinclair6e581892020-03-02 15:47:43 -050047set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
48set(CMAKE_POSITION_INDEPENDENT_CODE ON)
dan sinclair05d278e2023-08-30 21:05:31 +000049set(CMAKE_CXX_STANDARD 17)
Dan Sinclair6e581892020-03-02 15:47:43 -050050set(CMAKE_DEBUG_POSTFIX "")
dan sinclair2df80912023-11-20 13:22:14 +000051set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Dan Sinclair6e581892020-03-02 15:47:43 -050052
53if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
54 message(STATUS "No build type selected, default to Debug")
55 set(CMAKE_BUILD_TYPE "Debug")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000056endif()
57
58set(DAWN_BUILD_GEN_DIR "${Dawn_BINARY_DIR}/gen")
59set(DAWN_GENERATOR_DIR "${Dawn_SOURCE_DIR}/generator")
60set(DAWN_SRC_DIR "${Dawn_SOURCE_DIR}/src")
Ben Clayton9fb7a512022-02-04 18:18:18 +000061set(DAWN_INCLUDE_DIR "${Dawn_SOURCE_DIR}/include")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000062set(DAWN_TEMPLATE_DIR "${DAWN_GENERATOR_DIR}/templates")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000063
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000064################################################################################
65# Configuration options
66################################################################################
67
Ben Clayton30eeac72021-09-24 10:38:18 +000068# option_if_not_defined(name description default)
69# Behaves like:
70# option(name description default)
71# If a variable is not already defined with the given name, otherwise the
72# function does nothing.
73# Simplifies customization by projects that use Dawn as a dependency.
74function (option_if_not_defined name description default)
75 if(NOT DEFINED ${name})
76 option(${name} ${description} ${default})
77 endif()
78endfunction()
79
80# set_if_not_defined(name value description)
81# Behaves like:
82# set(${name} ${value} CACHE STRING ${description})
83# If a variable is not already defined with the given name, otherwise the
84# function does nothing.
85# Simplifies customization by projects that use Dawn as a dependency.
86function (set_if_not_defined name value description)
87 if(NOT DEFINED ${name})
88 set(${name} ${value} CACHE STRING ${description})
89 endif()
90endfunction()
91
munozac511ffb2023-09-25 14:01:03 +000092function (install_if_enabled target)
93 if(NOT DAWN_ENABLE_INSTALL)
94 return()
95 endif()
96
97 install(TARGETS ${target}
98 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
99 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
100 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
101 )
102
103 get_target_property(targetHeaders ${target} INTERFACE_SOURCES)
104 if (NOT targetHeaders)
105 return()
106 endif()
107
108 foreach(headerFile ${targetHeaders})
109 # Starting from CMake 3.20 there is the cmake_path command that could simplify this code.
110 # Compute the install subdirectory for the header by stripping out the path to
111 # the include / gen/include directory...
112 string(FIND "${headerFile}" "${DAWN_INCLUDE_DIR}" foundIndex)
113 if (foundIndex EQUAL 0)
114 string(LENGTH "${DAWN_INCLUDE_DIR}/" lengthToRemove)
115 endif()
116 string(FIND "${headerFile}" "${DAWN_BUILD_GEN_DIR}/include/" foundIndex)
117 if (foundIndex EQUAL 0)
118 string(LENGTH "${DAWN_BUILD_GEN_DIR}/include/" lengthToRemove)
119 endif()
120 string(SUBSTRING "${headerFile}" "${lengthToRemove}" -1 headerRelDir)
121
122 # ... then remove everything after the last /
123 string(FIND "${headerRelDir}" "/" foundIndex REVERSE)
124 string(SUBSTRING "${headerRelDir}" 0 ${foundIndex} headerRelDir)
125
126 install(FILES "${headerFile}" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${headerRelDir})
127 endforeach()
128endfunction()
129
130
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000131# Default values for the backend-enabling options
Peng Huang925b7762023-05-01 16:13:00 +0000132set(ENABLE_D3D11 OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000133set(ENABLE_D3D12 OFF)
134set(ENABLE_METAL OFF)
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000135set(ENABLE_OPENGLES OFF)
136set(ENABLE_DESKTOP_GL OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000137set(ENABLE_VULKAN OFF)
Corentin Wallez2e22d922022-06-01 09:30:50 +0000138set(USE_WAYLAND OFF)
Corentin Wallezd353ca02020-02-18 02:12:35 +0000139set(USE_X11 OFF)
Stephen Gutekanst55623702023-07-01 11:43:55 +0000140set(USE_WINDOWS_UI OFF)
Ben Claytona6750752022-02-04 18:35:55 +0000141set(BUILD_SAMPLES OFF)
AlexVestin5c3645c2023-10-18 14:08:26 +0000142set(TARGET_MACOS OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000143if (WIN32)
Peng Huang925b7762023-05-01 16:13:00 +0000144 set(ENABLE_D3D11 ON)
Stephen Gutekanst55623702023-07-01 11:43:55 +0000145 set(USE_WINDOWS_UI ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000146 set(ENABLE_D3D12 ON)
陈俊嘉610de1d2021-06-28 08:19:28 +0000147 if (NOT WINDOWS_STORE)
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000148 # Enable Vulkan in win32 compilation only
149 # since UWP only supports d3d
150 set(ENABLE_VULKAN ON)
151 endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000152elseif(APPLE)
153 set(ENABLE_METAL ON)
AlexVestin5c3645c2023-10-18 14:08:26 +0000154 if(CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "MacOS")
155 set(TARGET_MACOS ON)
156 endif()
Alexander Vestinf2556ab2022-03-25 13:18:46 +0000157elseif(ANDROID)
158 set(ENABLE_VULKAN ON)
159 set(ENABLE_OPENGLES ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000160elseif(UNIX)
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000161 set(ENABLE_OPENGLES ON)
162 set(ENABLE_DESKTOP_GL ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000163 set(ENABLE_VULKAN ON)
Corentin Wallezd353ca02020-02-18 02:12:35 +0000164 set(USE_X11 ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000165endif()
166
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000167# GLFW is not supported in UWP
Albin Bernhardssonb8a1b6d2023-07-13 08:51:17 +0000168set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING OFF)
Sonakshi Saxena13446112023-08-23 12:32:14 +0000169
170if ((WIN32 AND NOT WINDOWS_STORE) OR (UNIX AND NOT ANDROID))
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000171 set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING ON)
172endif()
173
174# Current examples are depend on GLFW
175if (DAWN_SUPPORTS_GLFW_FOR_WINDOWING)
Ben Claytona6750752022-02-04 18:35:55 +0000176 set(BUILD_SAMPLES ON)
陈俊嘉b2bc57a2021-06-24 07:00:16 +0000177endif()
178
Ben Clayton96e245e2022-04-08 18:08:36 +0000179option_if_not_defined(DAWN_ENABLE_ASAN "Enable address sanitizer" OFF)
munozac511ffb2023-09-25 14:01:03 +0000180option_if_not_defined(DAWN_ENABLE_INSTALL "Enable install step for Dawn libraries" OFF)
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000181option_if_not_defined(DAWN_ENABLE_TSAN "Enable thread sanitizer" OFF)
182option_if_not_defined(DAWN_ENABLE_MSAN "Enable memory sanitizer" OFF)
Ben Clayton96e245e2022-04-08 18:08:36 +0000183option_if_not_defined(DAWN_ENABLE_UBSAN "Enable undefined behaviour sanitizer" OFF)
184
Peng Huang5c2f1672023-05-01 23:05:42 +0000185option_if_not_defined(DAWN_ENABLE_D3D11 "Enable compilation of the D3D11 backend" ${ENABLE_D3D11})
Ben Clayton30eeac72021-09-24 10:38:18 +0000186option_if_not_defined(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12})
187option_if_not_defined(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL})
188option_if_not_defined(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON)
189option_if_not_defined(DAWN_ENABLE_DESKTOP_GL "Enable compilation of the OpenGL backend" ${ENABLE_DESKTOP_GL})
190option_if_not_defined(DAWN_ENABLE_OPENGLES "Enable compilation of the OpenGL ES backend" ${ENABLE_OPENGLES})
191option_if_not_defined(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backend" ${ENABLE_VULKAN})
dan sinclair194c1772022-06-21 17:54:03 +0000192
Ben Clayton30eeac72021-09-24 10:38:18 +0000193option_if_not_defined(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF)
Corentin Wallez2e22d922022-06-01 09:30:50 +0000194option_if_not_defined(DAWN_USE_WAYLAND "Enable support for Wayland surface" ${USE_WAYLAND})
Ben Clayton30eeac72021-09-24 10:38:18 +0000195option_if_not_defined(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11})
Erin Melucci38b58e42023-06-14 16:45:33 +0000196option_if_not_defined(DAWN_USE_GLFW "Enable compilation of the GLFW windowing utils" ${DAWN_SUPPORTS_GLFW_FOR_WINDOWING})
Stephen Gutekanst55623702023-07-01 11:43:55 +0000197option_if_not_defined(DAWN_USE_WINDOWS_UI "Enable support for Windows UI surface" ${USE_WINDOWS_UI})
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000198option_if_not_defined(DAWN_USE_BUILT_DXC "Enable building and using DXC by the D3D12 backend" OFF)
Antonio Maioranob4d05de2024-04-16 19:36:58 +0000199option_if_not_defined(DAWN_DXC_DISABLE_ASSERTS_DEBUG "Disable asserts in DXC in debug builds" OFF)
AlexVestin5c3645c2023-10-18 14:08:26 +0000200option_if_not_defined(DAWN_TARGET_MACOS "Manually link Apple core frameworks" ${TARGET_MACOS})
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000201
Ben Claytona6750752022-02-04 18:35:55 +0000202option_if_not_defined(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" ${BUILD_SAMPLES})
Ben Claytonaffb7a32021-09-28 11:14:42 +0000203option_if_not_defined(DAWN_BUILD_NODE_BINDINGS "Enables building Dawn's NodeJS bindings" OFF)
Corentin Wallezbe352ea2022-04-11 16:48:43 +0000204option_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 +0000205option_if_not_defined(DAWN_BUILD_BENCHMARKS "Build Dawn benchmarks" OFF)
Ben Claytonaffb7a32021-09-28 11:14:42 +0000206
Corentin Wallez1450d1d2024-05-06 18:52:34 +0000207option_if_not_defined(DAWN_WERROR "Build with -Werror (or equivalent)" OFF)
Ben Claytonaffb7a32021-09-28 11:14:42 +0000208option_if_not_defined(DAWN_ENABLE_PIC "Build with Position-Independent-Code enabled" OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000209
Ben Claytone38993f2022-12-10 00:15:57 +0000210option_if_not_defined(DAWN_EMIT_COVERAGE "Emit code coverage information" OFF)
Ben Claytonf927bcb2022-12-12 21:21:54 +0000211set_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 +0000212
dan sinclair194c1772022-06-21 17:54:03 +0000213if (DAWN_ENABLE_OPENGLES OR DAWN_ENABLE_DESKTOP_GL)
214 set(TINT_DEFAULT_GLSL ON)
215else()
216 set(TINT_DEFAULT_GLSL OFF)
217endif()
218
munozac511ffb2023-09-25 14:01:03 +0000219option_if_not_defined(TINT_ENABLE_INSTALL "Enable install step for Tint libraries" OFF)
Ben Clayton3a3cb362023-08-16 01:05:21 +0000220option_if_not_defined(TINT_BUILD_CMD_TOOLS "Build the Tint command line tools" ON)
dan sinclair194c1772022-06-21 17:54:03 +0000221
Ben Clayton3a3cb362023-08-16 01:05:21 +0000222if (NOT DAWN_USE_GLFW AND (TINT_BUILD_CMD_TOOLS OR DAWN_BUILD_SAMPLES))
Erin Melucci38b58e42023-06-14 16:45:33 +0000223 message(SEND_ERROR "Dawn samples require GLFW")
224endif()
225
dan sinclair194c1772022-06-21 17:54:03 +0000226option_if_not_defined(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" ${DAWN_ENABLE_VULKAN})
227option_if_not_defined(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON)
228option_if_not_defined(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" ${TINT_DEFAULT_GLSL})
Ben Claytonf1b8a012023-10-11 17:15:52 +0000229option_if_not_defined(TINT_BUILD_GLSL_VALIDATOR "Build the GLSL output validator" ON)
dan sinclair194c1772022-06-21 17:54:03 +0000230option_if_not_defined(TINT_BUILD_HLSL_WRITER "Build the HLSL output writer" ${DAWN_ENABLE_D3D12})
231option_if_not_defined(TINT_BUILD_MSL_WRITER "Build the MSL output writer" ${DAWN_ENABLE_METAL})
232option_if_not_defined(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ${DAWN_ENABLE_VULKAN})
233option_if_not_defined(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON)
234
dan sinclair0917fbb2023-03-07 18:28:38 +0000235option_if_not_defined(TINT_BUILD_SYNTAX_TREE_WRITER "Build the syntax tree writer" OFF)
dan sinclairc22b8b9d2022-11-01 17:02:31 +0000236
Ryan Harrison724dd782024-05-16 16:27:48 +0000237option_if_not_defined(TINT_BUILD_IR_BINARY "Build IR binary format support" ON)
238
239
dan sinclair194c1772022-06-21 17:54:03 +0000240option_if_not_defined(TINT_BUILD_FUZZERS "Build fuzzers" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000241option_if_not_defined(TINT_BUILD_AST_FUZZER "Build AST fuzzer" OFF)
242option_if_not_defined(TINT_BUILD_REGEX_FUZZER "Build regex fuzzer" OFF)
Austin Eng6a7bba52023-04-17 18:11:51 +0000243option_if_not_defined(TINT_BUILD_BENCHMARKS "Build Tint benchmarks" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000244option_if_not_defined(TINT_BUILD_TESTS "Build tests" ON)
245option_if_not_defined(TINT_BUILD_AS_OTHER_OS "Override OS detection to force building of *_other.cc files" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000246
Ben Claytonf9a5b712024-03-13 17:37:33 +0000247option_if_not_defined(TINT_BUILD_TINTD "Build the WGSL language server" OFF)
Ben Claytonf9a5b712024-03-13 17:37:33 +0000248
Ben Clayton8fc9b862023-04-19 15:03:19 +0000249set_if_not_defined(TINT_EXTERNAL_BENCHMARK_CORPUS_DIR "" "Directory that holds a corpus of external shaders to benchmark.")
250
dan sinclair194c1772022-06-21 17:54:03 +0000251option_if_not_defined(TINT_ENABLE_BREAK_IN_DEBUGGER "Enable tint::debugger::Break()" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000252option_if_not_defined(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF)
Ben Claytonf2b86aa2022-12-13 14:46:02 +0000253option_if_not_defined(TINT_RANDOMIZE_HASHES "Randomize the hash seed value to detect non-deterministic output" OFF)
Corentin Walleze5570872020-10-20 14:26:10 +0000254
Brandon Jonesa04663c2021-09-23 20:36:03 +0000255# Recommended setting for compability with future abseil releases.
256set(ABSL_PROPAGATE_CXX_STD ON)
Brandon Jonesa04663c2021-09-23 20:36:03 +0000257
dan sinclair194c1772022-06-21 17:54:03 +0000258set_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 +0000259set_if_not_defined(DAWN_VULKAN_DEPS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps" "Directory in which to find vulkan-deps")
260
Ben Clayton30eeac72021-09-24 10:38:18 +0000261set_if_not_defined(DAWN_ABSEIL_DIR "${DAWN_THIRD_PARTY_DIR}/abseil-cpp" "Directory in which to find Abseil")
262set_if_not_defined(DAWN_GLFW_DIR "${DAWN_THIRD_PARTY_DIR}/glfw" "Directory in which to find GLFW")
Ben Clayton30eeac72021-09-24 10:38:18 +0000263set_if_not_defined(DAWN_JINJA2_DIR "${DAWN_THIRD_PARTY_DIR}/jinja2" "Directory in which to find Jinja2")
Arthur Sonzognic5f72f72023-11-29 15:27:40 +0000264set_if_not_defined(DAWN_MARKUPSAFE_DIR "${DAWN_THIRD_PARTY_DIR}/markupsafe" "Directory in which to find MarkupSafe")
Arthur Sonzogni58f8ed22023-11-30 09:30:52 +0000265set_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 +0000266set_if_not_defined(DAWN_SWIFTSHADER_DIR "${DAWN_THIRD_PARTY_DIR}/swiftshader" "Directory in which to find swiftshader")
Ben Claytonfb07fa92023-11-17 18:48:59 +0000267set_if_not_defined(DAWN_PROTOBUF_DIR "${DAWN_THIRD_PARTY_DIR}/protobuf" "Directory in which to find protobuf")
dan sinclairc1f6dbd2023-04-11 15:45:18 +0000268
269set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_VULKAN_DEPS_DIR}/spirv-tools/src" "Directory in which to find SPIRV-Tools")
270set_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 +0000271set_if_not_defined(DAWN_VULKAN_HEADERS_DIR "${DAWN_VULKAN_DEPS_DIR}/vulkan-headers/src" "Directory in which to find Vulkan-Headers")
James Price0fe9e442023-09-22 21:51:31 +0000272set_if_not_defined(DAWN_VULKAN_UTILITY_LIBRARIES_DIR "${DAWN_VULKAN_DEPS_DIR}/vulkan-utility-libraries/src" "Directory in which to find Vulkan-Utility-Libraries")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000273
Ben Claytonaffb7a32021-09-28 11:14:42 +0000274# Dependencies for DAWN_BUILD_NODE_BINDINGS
275set_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 +0000276set_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 +0000277set_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 +0000278set_if_not_defined(GO_EXECUTABLE "go" "Golang executable for running the IDL generator")
Ben Claytonaffb7a32021-09-28 11:14:42 +0000279
Elie Michel9ae8ed22023-05-12 20:19:41 +0000280option_if_not_defined(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" OFF)
281
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000282# Much of the backend code is shared among desktop OpenGL and OpenGL ES
283if (${DAWN_ENABLE_DESKTOP_GL} OR ${DAWN_ENABLE_OPENGLES})
284 set(DAWN_ENABLE_OPENGL ON)
285endif()
286
Ben Claytonaffb7a32021-09-28 11:14:42 +0000287if(DAWN_ENABLE_PIC)
288 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
289endif()
290
dan sinclair194c1772022-06-21 17:54:03 +0000291if (${TINT_BUILD_AST_FUZZER})
292 message(STATUS "TINT_BUILD_AST_FUZZER is ON - setting
293 TINT_BUILD_FUZZERS
294 TINT_BUILD_WGSL_READER
295 TINT_BUILD_WGSL_WRITER
296 TINT_BUILD_SPV_WRITER
297 TINT_BUILD_MSL_WRITER
298 TINT_BUILD_GLSL_WRITER
299 TINT_BUILD_HLSL_WRITER to ON")
300 set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE)
301 set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE)
302 set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE)
303 set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE)
304 set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE)
305 set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build GLSL writer" FORCE)
306 set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
307endif()
308
309if (${TINT_BUILD_REGEX_FUZZER})
310 message(STATUS "TINT_BUILD_REGEX_FUZZER is ON - setting
311 TINT_BUILD_FUZZERS
312 TINT_BUILD_WGSL_READER
313 TINT_BUILD_WGSL_WRITER
314 TINT_BUILD_SPV_WRITER
315 TINT_BUILD_MSL_WRITER
316 TINT_BUILD_GLSL_WRITER
317 TINT_BUILD_HLSL_WRITER to ON")
318 set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE)
319 set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE)
320 set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE)
321 set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE)
322 set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE)
323 set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build GLSL writer" FORCE)
324 set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
325endif()
326
Peng Huang5c2f1672023-05-01 23:05:42 +0000327message(STATUS "Dawn build D3D11 backend: ${DAWN_ENABLE_D3D11}")
dan sinclair194c1772022-06-21 17:54:03 +0000328message(STATUS "Dawn build D3D12 backend: ${DAWN_ENABLE_D3D12}")
329message(STATUS "Dawn build Metal backend: ${DAWN_ENABLE_METAL}")
330message(STATUS "Dawn build Vulkan backend: ${DAWN_ENABLE_VULKAN}")
331message(STATUS "Dawn build OpenGL backend: ${DAWN_ENABLE_DESKTOP_GL}")
332message(STATUS "Dawn build OpenGL ES backend: ${DAWN_ENABLE_OPENGLES}")
333message(STATUS "Dawn build Null backend: ${DAWN_ENABLE_NULL}")
334
335message(STATUS "Dawn build with asserts in all configurations: ${DAWN_ALWAYS_ASSERT}")
336message(STATUS "Dawn build Wayland support: ${DAWN_USE_WAYLAND}")
337message(STATUS "Dawn build X11 support: ${DAWN_USE_X11}")
AlexVestin5c3645c2023-10-18 14:08:26 +0000338message(STATUS "Dawn build GLFW support: ${DAWN_USE_GLFW}")
Stephen Gutekanst55623702023-07-01 11:43:55 +0000339message(STATUS "Dawn build Windows UI support: ${DAWN_USE_WINDOWS_UI}")
Antonio Maioranoc69356e2023-11-23 18:04:51 +0000340message(STATUS "Dawn build and use DXC: ${DAWN_USE_BUILT_DXC}")
Antonio Maioranob4d05de2024-04-16 19:36:58 +0000341message(STATUS "Dawn disable DXC asserts in debug builds: ${DAWN_DXC_DISABLE_ASSERTS_DEBUG}")
dan sinclair194c1772022-06-21 17:54:03 +0000342
343message(STATUS "Dawn build samples: ${DAWN_BUILD_SAMPLES}")
344message(STATUS "Dawn build Node bindings: ${DAWN_BUILD_NODE_BINDINGS}")
345message(STATUS "Dawn build Swiftshader: ${DAWN_ENABLE_SWIFTSHADER}")
Austin Eng6a7bba52023-04-17 18:11:51 +0000346message(STATUS "Dawn build benchmarks: ${DAWN_BUILD_BENCHMARKS}")
dan sinclair194c1772022-06-21 17:54:03 +0000347
348message(STATUS "Dawn build PIC: ${DAWN_ENABLE_PIC}")
349
350message(STATUS "Dawn build with ASAN: ${DAWN_ENABLE_ASAN}")
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000351message(STATUS "Dawn build with TSAN: ${DAWN_ENABLE_TSAN}")
dan sinclair194c1772022-06-21 17:54:03 +0000352message(STATUS "Dawn build with MSAN: ${DAWN_ENABLE_MSAN}")
353message(STATUS "Dawn build with UBSAN: ${DAWN_ENABLE_UBSAN}")
354
Ben Clayton3a3cb362023-08-16 01:05:21 +0000355message(STATUS "Tint build command line executable tools: ${TINT_BUILD_CMD_TOOLS}")
dan sinclair194c1772022-06-21 17:54:03 +0000356message(STATUS "Tint build SPIR-V reader: ${TINT_BUILD_SPV_READER}")
357message(STATUS "Tint build WGSL reader: ${TINT_BUILD_WGSL_READER}")
358message(STATUS "Tint build GLSL writer: ${TINT_BUILD_GLSL_WRITER}")
Ben Claytonf1b8a012023-10-11 17:15:52 +0000359message(STATUS "Tint build GLSL validator: ${TINT_BUILD_GLSL_VALIDATOR}")
dan sinclair194c1772022-06-21 17:54:03 +0000360message(STATUS "Tint build HLSL writer: ${TINT_BUILD_HLSL_WRITER}")
361message(STATUS "Tint build MSL writer: ${TINT_BUILD_MSL_WRITER}")
362message(STATUS "Tint build SPIR-V writer: ${TINT_BUILD_SPV_WRITER}")
363message(STATUS "Tint build WGSL writer: ${TINT_BUILD_WGSL_WRITER}")
dan sinclair0917fbb2023-03-07 18:28:38 +0000364message(STATUS "Tint build Syntax Tree writer: ${TINT_BUILD_SYNTAX_TREE_WRITER}")
dan sinclair194c1772022-06-21 17:54:03 +0000365message(STATUS "Tint build fuzzers: ${TINT_BUILD_FUZZERS}")
dan sinclair194c1772022-06-21 17:54:03 +0000366message(STATUS "Tint build AST fuzzer: ${TINT_BUILD_AST_FUZZER}")
367message(STATUS "Tint build regex fuzzer: ${TINT_BUILD_REGEX_FUZZER}")
368message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}")
369message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}")
370message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}")
Ben Clayton8fc9b862023-04-19 15:03:19 +0000371message(STATUS "Tint external benchmark corpus dir: ${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}")
372
dan sinclair194c1772022-06-21 17:54:03 +0000373
374if (NOT ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS} STREQUAL "")
375 message(STATUS "Using provided LIB_FUZZING_ENGINE options: ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS}")
376endif()
377
Corentin Wallez179e84a2024-03-27 20:20:15 +0000378find_package(Python3 REQUIRED)
Corentin Wallez2f18c9a2024-04-02 08:51:45 +0000379message(STATUS "Dawn: using python at ${Python3_EXECUTABLE}")
dan sinclair194c1772022-06-21 17:54:03 +0000380
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000381################################################################################
Ben Clayton96e245e2022-04-08 18:08:36 +0000382# common_compile_options - sets compiler and linker options common for dawn and
383# tint on the given target
384################################################################################
385function(common_compile_options TARGET)
386 if (COMPILER_IS_LIKE_GNU)
387 target_compile_options(${TARGET} PRIVATE
388 -fno-exceptions
389 -fno-rtti
dan sinclaircf2456b2023-01-07 23:09:14 +0000390
391 -Wno-deprecated-builtins
dan sinclair07c32cb2023-01-09 15:10:33 +0000392 -Wno-unknown-warning-option
Antonio Maioranoe4d64ed2024-03-04 21:15:03 +0000393 -Wno-switch-default
Ben Clayton96e245e2022-04-08 18:08:36 +0000394 )
Corentin Wallez1450d1d2024-05-06 18:52:34 +0000395 if (${DAWN_WERROR})
396 target_compile_options(${TARGET} PRIVATE -Werror)
397 endif()
Ben Clayton96e245e2022-04-08 18:08:36 +0000398
Antonio Maiorano39357642024-03-27 18:23:32 +0000399 set(SANITIZER_OPTIONS "")
Ben Clayton96e245e2022-04-08 18:08:36 +0000400 if (${DAWN_ENABLE_MSAN})
Antonio Maiorano39357642024-03-27 18:23:32 +0000401 list(APPEND SANITIZER_OPTIONS "-fsanitize=memory")
402 endif()
403 if (${DAWN_ENABLE_ASAN})
404 list(APPEND SANITIZER_OPTIONS "-fsanitize=address")
405 endif()
406 if (${DAWN_ENABLE_TSAN})
407 list(APPEND SANITIZER_OPTIONS "-fsanitize=thread")
408 endif()
409 if (${DAWN_ENABLE_UBSAN})
410 list(APPEND SANITIZER_OPTIONS "-fsanitize=undefined" "-fsanitize=float-divide-by-zero")
411 endif()
412 if (SANITIZER_OPTIONS)
413 target_compile_options(${TARGET} PUBLIC ${SANITIZER_OPTIONS})
414 target_link_options(${TARGET} PUBLIC ${SANITIZER_OPTIONS})
Ben Clayton96e245e2022-04-08 18:08:36 +0000415 endif()
416 endif(COMPILER_IS_LIKE_GNU)
Setoc6927202022-09-14 16:41:07 +0000417
418 if(MSVC)
419 target_compile_options(${TARGET} PUBLIC /utf-8)
420 endif()
Ben Claytone38993f2022-12-10 00:15:57 +0000421
422 if (DAWN_EMIT_COVERAGE)
Ben Clayton54264d32023-01-10 21:55:43 +0000423 target_compile_definitions(${TARGET} PRIVATE "DAWN_EMIT_COVERAGE")
Ben Claytone38993f2022-12-10 00:15:57 +0000424 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
425 target_compile_options(${TARGET} PRIVATE "--coverage")
426 target_link_options(${TARGET} PRIVATE "gcov")
Ben Clayton78e45302023-01-26 15:57:27 +0000427 elseif(COMPILER_IS_CLANG OR COMPILER_IS_CLANG_CL)
Ben Claytone38993f2022-12-10 00:15:57 +0000428 target_compile_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping")
429 target_link_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping")
430 else()
431 message(FATAL_ERROR "Coverage generation not supported for the ${CMAKE_CXX_COMPILER_ID} toolchain")
432 endif()
433 endif(DAWN_EMIT_COVERAGE)
Ben Clayton96e245e2022-04-08 18:08:36 +0000434endfunction()
435
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000436if (${DAWN_ENABLE_TSAN})
437 add_compile_options(-stdlib=libc++)
438 add_link_options(-stdlib=libc++)
439endif()
440
Ben Clayton96e245e2022-04-08 18:08:36 +0000441################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000442# Dawn's public and internal "configs"
443################################################################################
444
Ben Clayton94181522022-11-09 20:55:33 +0000445set(IS_DEBUG_BUILD 0)
446string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
447if ((NOT ${build_type} STREQUAL "RELEASE") AND (NOT ${build_type} STREQUAL "RELWITHDEBINFO"))
448 set(IS_DEBUG_BUILD 1)
449endif()
450
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000451# The public config contains only the include paths for the Dawn headers.
452add_library(dawn_public_config INTERFACE)
453target_include_directories(dawn_public_config INTERFACE
Ben Clayton9fb7a512022-02-04 18:18:18 +0000454 "${DAWN_INCLUDE_DIR}"
455 "${DAWN_BUILD_GEN_DIR}/include"
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000456)
457
458# The internal config conatins additional path but includes the dawn_public_config include paths
459add_library(dawn_internal_config INTERFACE)
460target_include_directories(dawn_internal_config INTERFACE
461 "${DAWN_SRC_DIR}"
462 "${DAWN_BUILD_GEN_DIR}/src"
463)
464target_link_libraries(dawn_internal_config INTERFACE dawn_public_config)
465
466# Compile definitions for the internal config
Ben Clayton94181522022-11-09 20:55:33 +0000467if (DAWN_ALWAYS_ASSERT OR IS_DEBUG_BUILD)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000468 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_ASSERTS")
469endif()
Peng Huang5c2f1672023-05-01 23:05:42 +0000470if (DAWN_ENABLE_D3D11)
471 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D11")
472endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000473if (DAWN_ENABLE_D3D12)
474 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D12")
475endif()
476if (DAWN_ENABLE_METAL)
477 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_METAL")
478endif()
479if (DAWN_ENABLE_NULL)
480 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_NULL")
481endif()
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000482if (DAWN_ENABLE_DESKTOP_GL)
483 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_DESKTOP_GL")
484endif()
485if (DAWN_ENABLE_OPENGLES)
486 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGLES")
487endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000488if (DAWN_ENABLE_OPENGL)
489 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGL")
490endif()
491if (DAWN_ENABLE_VULKAN)
492 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_VULKAN")
493endif()
Corentin Wallez2e22d922022-06-01 09:30:50 +0000494if (DAWN_USE_WAYLAND)
495 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WAYLAND")
496endif()
Corentin Wallezd353ca02020-02-18 02:12:35 +0000497if (DAWN_USE_X11)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000498 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11")
499endif()
Stephen Gutekanst55623702023-07-01 11:43:55 +0000500if (DAWN_USE_WINDOWS_UI)
501 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WINDOWS_UI")
502endif()
Corentin Wallez33466972020-02-24 13:27:28 +0000503if (WIN32)
504 target_compile_definitions(dawn_internal_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN")
505endif()
506
dan sinclair05d278e2023-08-30 21:05:31 +0000507set(CMAKE_CXX_STANDARD "17")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000508
509################################################################################
Ryan Harrisone87ac762022-04-06 15:37:27 -0400510# Tint
511################################################################################
512
Alastair Donaldson6a1eb452021-09-02 23:49:25 +0000513set(TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS "" CACHE STRING "Used by OSS-Fuzz to control, via link options, which fuzzing engine should be used")
514
Ben Claytonfb07fa92023-11-17 18:48:59 +0000515set(TINT_ROOT_SOURCE_DIR ${PROJECT_SOURCE_DIR})
Ben Clayton3a3cb362023-08-16 01:05:21 +0000516set(TINT_SPIRV_HEADERS_DIR ${DAWN_SPIRV_HEADERS_DIR})
517set(TINT_SPIRV_TOOLS_DIR ${DAWN_SPIRV_TOOLS_DIR})
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000518
Antonio Maioranod6009722021-03-17 13:32:54 +0000519# CMake < 3.15 sets /W3 in CMAKE_CXX_FLAGS. Remove it if it's there.
520# See https://gitlab.kitware.com/cmake/cmake/-/issues/18317
521if (MSVC)
Vasyl Teliman0b3611b2021-06-24 18:10:46 +0000522 if (CMAKE_CXX_FLAGS MATCHES "/W3")
523 string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
524 endif()
Antonio Maioranod6009722021-03-17 13:32:54 +0000525endif()
526
Ryan Harrison563d3e92020-04-28 19:27:38 +0000527if (${TINT_CHECK_CHROMIUM_STYLE})
528 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -add-plugin -Xclang find-bad-constructs")
529endif()
530
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000531if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC"))
532 set(COMPILER_IS_CLANG_CL TRUE)
533endif()
534
Ben Clayton78e45302023-01-26 15:57:27 +0000535if((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000536 ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND
537 (NOT COMPILER_IS_CLANG_CL)))
Ben Clayton78e45302023-01-26 15:57:27 +0000538 set(COMPILER_IS_CLANG TRUE)
539endif()
540
Ben Clayton7d956612023-10-03 10:14:55 +0000541if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
542 set(COMPILER_IS_GNU TRUE)
543endif()
544
Ben Clayton78e45302023-01-26 15:57:27 +0000545if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR COMPILER_IS_CLANG)
Dan Sinclair6e581892020-03-02 15:47:43 -0500546 set(COMPILER_IS_LIKE_GNU TRUE)
547endif()
548
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000549# Enable msbuild multiprocessor builds
550if (MSVC AND NOT COMPILER_IS_CLANG_CL)
551 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
552endif()
553
Ryan Harrisone87ac762022-04-06 15:37:27 -0400554################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000555# Run on all subdirectories
556################################################################################
Austin Eng01f13352023-11-30 19:52:59 +0000557if (EXISTS "${DAWN_PROTOBUF_DIR}/cmake")
Ben Clayton01fa7c82024-01-31 21:07:17 +0000558 if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND WIN32)
559 set(protobuf_HAVE_BUILTIN_ATOMICS 1)
560 endif()
561
Ben Claytonfb07fa92023-11-17 18:48:59 +0000562 # Needs to come before SPIR-V Tools
563 include("third_party/protobuf.cmake")
564endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000565
566add_subdirectory(third_party)
James Price8d9adb02022-05-22 00:41:53 +0000567
568# TODO(crbug.com/tint/455): Tint does not currently build with CMake when
569# BUILD_SHARED_LIBS=1, so always build it as static for now.
570set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS})
571set(BUILD_SHARED_LIBS 0)
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000572add_subdirectory(src/tint)
James Price8d9adb02022-05-22 00:41:53 +0000573set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED})
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000574add_subdirectory(generator)
575add_subdirectory(src/dawn)
Ben Clayton7b778552022-02-04 18:59:15 +0000576
577################################################################################
578# Samples
579################################################################################
dan sinclairb5950522020-03-19 13:03:35 +0000580add_custom_target(tint-lint
581 COMMAND ./tools/lint
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000582 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000583 COMMENT "Running linter"
584 VERBATIM)
585
586add_custom_target(tint-format
587 COMMAND ./tools/format
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000588 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000589 COMMENT "Running formatter"
590 VERBATIM)
Ben Claytonadb10d62020-10-27 21:04:59 +0000591
Ben Clayton78e45302023-01-26 15:57:27 +0000592if (DAWN_EMIT_COVERAGE)
593 add_subdirectory(tools/src/cmd/turbo-cov)
Ben Claytonadb10d62020-10-27 21:04:59 +0000594
Ben Clayton78e45302023-01-26 15:57:27 +0000595 # The tint-generate-coverage target generates a lcov.info file at the project
596 # root, holding the code coverage for all the tint_unitests.
Ben Claytonadb10d62020-10-27 21:04:59 +0000597 # This can be used by tools such as VSCode's Coverage Gutters extension to
598 # visualize code coverage in the editor.
599 get_filename_component(CLANG_BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY)
600 set(PATH_WITH_CLANG "${CLANG_BIN_DIR}:$ENV{PATH}")
601 add_custom_target(tint-generate-coverage
602 COMMAND ${CMAKE_COMMAND} -E env PATH=${PATH_WITH_CLANG} ./tools/tint-generate-coverage $<TARGET_FILE:tint_unittests>
603 DEPENDS tint_unittests
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000604 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
Ben Claytonadb10d62020-10-27 21:04:59 +0000605 COMMENT "Generating tint coverage data"
606 VERBATIM)
607endif()