blob: 137cde17b88ffa653869e01ee507948a9828d6df [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
Dan Sinclair6e581892020-03-02 15:47:43 -050028cmake_minimum_required(VERSION 3.10.2)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000029
dan sinclairfb5a4922022-04-19 22:25:45 +000030# When upgrading to CMake 3.11 we can remove DAWN_PLACEHOLDER_FILE because source-less add_library
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000031# becomes available.
32# When upgrading to CMake 3.12 we should add CONFIGURE_DEPENDS to DawnGenerator to rerun CMake in
Corentin Wallez42450c62020-04-10 17:04:31 +000033# case any of the generator files changes. We should also remove the CACHE "" FORCE stuff to
dan sinclair1877c272020-10-20 19:46:21 +000034# override options in third_party dependencies. We can also add the HOMEPAGE_URL
35# entry to the project `HOMEPAGE_URL "https://dawn.googlesource.com/dawn"`
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000036
37project(
38 Dawn
39 DESCRIPTION "Dawn, a WebGPU implementation"
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000040 LANGUAGES C CXX
41)
Dan Sinclair6e581892020-03-02 15:47:43 -050042enable_testing()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000043
44set_property(GLOBAL PROPERTY USE_FOLDERS ON)
45
Dan Sinclair6e581892020-03-02 15:47:43 -050046set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
47set(CMAKE_POSITION_INDEPENDENT_CODE ON)
dan sinclair05d278e2023-08-30 21:05:31 +000048set(CMAKE_CXX_STANDARD 17)
Dan Sinclair6e581892020-03-02 15:47:43 -050049set(CMAKE_DEBUG_POSTFIX "")
50
51if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
52 message(STATUS "No build type selected, default to Debug")
53 set(CMAKE_BUILD_TYPE "Debug")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000054endif()
55
56set(DAWN_BUILD_GEN_DIR "${Dawn_BINARY_DIR}/gen")
57set(DAWN_GENERATOR_DIR "${Dawn_SOURCE_DIR}/generator")
58set(DAWN_SRC_DIR "${Dawn_SOURCE_DIR}/src")
Ben Clayton9fb7a512022-02-04 18:18:18 +000059set(DAWN_INCLUDE_DIR "${Dawn_SOURCE_DIR}/include")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000060set(DAWN_TEMPLATE_DIR "${DAWN_GENERATOR_DIR}/templates")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000061
dan sinclairfb5a4922022-04-19 22:25:45 +000062set(DAWN_PLACEHOLDER_FILE "${DAWN_SRC_DIR}/Placeholder.cpp")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000063
64################################################################################
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})
AlexVestin5c3645c2023-10-18 14:08:26 +0000198option_if_not_defined(DAWN_TARGET_MACOS "Manually link Apple core frameworks" ${TARGET_MACOS})
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000199
Ben Claytona6750752022-02-04 18:35:55 +0000200option_if_not_defined(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" ${BUILD_SAMPLES})
Ben Claytonaffb7a32021-09-28 11:14:42 +0000201option_if_not_defined(DAWN_BUILD_NODE_BINDINGS "Enables building Dawn's NodeJS bindings" OFF)
Corentin Wallezbe352ea2022-04-11 16:48:43 +0000202option_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 +0000203option_if_not_defined(DAWN_BUILD_BENCHMARKS "Build Dawn benchmarks" OFF)
Ben Claytonaffb7a32021-09-28 11:14:42 +0000204
205option_if_not_defined(DAWN_ENABLE_PIC "Build with Position-Independent-Code enabled" OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000206
Ben Claytone38993f2022-12-10 00:15:57 +0000207option_if_not_defined(DAWN_EMIT_COVERAGE "Emit code coverage information" OFF)
Ben Claytonf927bcb2022-12-12 21:21:54 +0000208set_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 +0000209
dan sinclair194c1772022-06-21 17:54:03 +0000210if (DAWN_ENABLE_OPENGLES OR DAWN_ENABLE_DESKTOP_GL)
211 set(TINT_DEFAULT_GLSL ON)
212else()
213 set(TINT_DEFAULT_GLSL OFF)
214endif()
215
munozac511ffb2023-09-25 14:01:03 +0000216option_if_not_defined(TINT_ENABLE_INSTALL "Enable install step for Tint libraries" OFF)
Ben Clayton3a3cb362023-08-16 01:05:21 +0000217option_if_not_defined(TINT_BUILD_CMD_TOOLS "Build the Tint command line tools" ON)
dan sinclair194c1772022-06-21 17:54:03 +0000218option_if_not_defined(TINT_BUILD_DOCS "Build documentation" ON)
219option_if_not_defined(TINT_DOCS_WARN_AS_ERROR "When building documentation, treat warnings as errors" OFF)
220
Ben Clayton3a3cb362023-08-16 01:05:21 +0000221if (NOT DAWN_USE_GLFW AND (TINT_BUILD_CMD_TOOLS OR DAWN_BUILD_SAMPLES))
Erin Melucci38b58e42023-06-14 16:45:33 +0000222 message(SEND_ERROR "Dawn samples require GLFW")
223endif()
224
dan sinclair194c1772022-06-21 17:54:03 +0000225option_if_not_defined(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" ${DAWN_ENABLE_VULKAN})
226option_if_not_defined(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON)
227option_if_not_defined(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" ${TINT_DEFAULT_GLSL})
Ben Claytonf1b8a012023-10-11 17:15:52 +0000228option_if_not_defined(TINT_BUILD_GLSL_VALIDATOR "Build the GLSL output validator" ON)
dan sinclair194c1772022-06-21 17:54:03 +0000229option_if_not_defined(TINT_BUILD_HLSL_WRITER "Build the HLSL output writer" ${DAWN_ENABLE_D3D12})
230option_if_not_defined(TINT_BUILD_MSL_WRITER "Build the MSL output writer" ${DAWN_ENABLE_METAL})
231option_if_not_defined(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ${DAWN_ENABLE_VULKAN})
232option_if_not_defined(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON)
233
dan sinclair0917fbb2023-03-07 18:28:38 +0000234option_if_not_defined(TINT_BUILD_SYNTAX_TREE_WRITER "Build the syntax tree writer" OFF)
dan sinclairc22b8b9d2022-11-01 17:02:31 +0000235
dan sinclair194c1772022-06-21 17:54:03 +0000236option_if_not_defined(TINT_BUILD_FUZZERS "Build fuzzers" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000237option_if_not_defined(TINT_BUILD_AST_FUZZER "Build AST fuzzer" OFF)
238option_if_not_defined(TINT_BUILD_REGEX_FUZZER "Build regex fuzzer" OFF)
Austin Eng6a7bba52023-04-17 18:11:51 +0000239option_if_not_defined(TINT_BUILD_BENCHMARKS "Build Tint benchmarks" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000240option_if_not_defined(TINT_BUILD_TESTS "Build tests" ON)
241option_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 +0000242
Ben Clayton8fc9b862023-04-19 15:03:19 +0000243set_if_not_defined(TINT_EXTERNAL_BENCHMARK_CORPUS_DIR "" "Directory that holds a corpus of external shaders to benchmark.")
244
dan sinclair194c1772022-06-21 17:54:03 +0000245option_if_not_defined(TINT_ENABLE_BREAK_IN_DEBUGGER "Enable tint::debugger::Break()" OFF)
dan sinclair194c1772022-06-21 17:54:03 +0000246option_if_not_defined(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF)
Ben Claytonf2b86aa2022-12-13 14:46:02 +0000247option_if_not_defined(TINT_RANDOMIZE_HASHES "Randomize the hash seed value to detect non-deterministic output" OFF)
Corentin Walleze5570872020-10-20 14:26:10 +0000248
Brandon Jonesa04663c2021-09-23 20:36:03 +0000249# Recommended setting for compability with future abseil releases.
250set(ABSL_PROPAGATE_CXX_STD ON)
Brandon Jonesa04663c2021-09-23 20:36:03 +0000251
dan sinclair194c1772022-06-21 17:54:03 +0000252set_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 +0000253set_if_not_defined(DAWN_VULKAN_DEPS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps" "Directory in which to find vulkan-deps")
254
Ben Clayton30eeac72021-09-24 10:38:18 +0000255set_if_not_defined(DAWN_ABSEIL_DIR "${DAWN_THIRD_PARTY_DIR}/abseil-cpp" "Directory in which to find Abseil")
256set_if_not_defined(DAWN_GLFW_DIR "${DAWN_THIRD_PARTY_DIR}/glfw" "Directory in which to find GLFW")
Ben Clayton30eeac72021-09-24 10:38:18 +0000257set_if_not_defined(DAWN_JINJA2_DIR "${DAWN_THIRD_PARTY_DIR}/jinja2" "Directory in which to find Jinja2")
dan sinclair6b67a902023-04-07 07:52:36 +0000258set_if_not_defined(DAWN_MARKUPSAFE_DIR "${DAWN_THIRD_PARTY_DIR}/markupsafe" "Directory in which to find MarkupSafe")
Stephen White94349492022-06-29 15:29:41 +0000259set_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 +0000260set_if_not_defined(DAWN_SWIFTSHADER_DIR "${DAWN_THIRD_PARTY_DIR}/swiftshader" "Directory in which to find swiftshader")
dan sinclairc1f6dbd2023-04-11 15:45:18 +0000261
262set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_VULKAN_DEPS_DIR}/spirv-tools/src" "Directory in which to find SPIRV-Tools")
263set_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 +0000264set_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 +0000265set_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 +0000266
Ben Claytonaffb7a32021-09-28 11:14:42 +0000267# Dependencies for DAWN_BUILD_NODE_BINDINGS
268set_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 +0000269set_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 +0000270set_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 +0000271set_if_not_defined(GO_EXECUTABLE "go" "Golang executable for running the IDL generator")
Ben Claytonaffb7a32021-09-28 11:14:42 +0000272
Elie Michel9ae8ed22023-05-12 20:19:41 +0000273option_if_not_defined(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" OFF)
274
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000275# Much of the backend code is shared among desktop OpenGL and OpenGL ES
276if (${DAWN_ENABLE_DESKTOP_GL} OR ${DAWN_ENABLE_OPENGLES})
277 set(DAWN_ENABLE_OPENGL ON)
278endif()
279
Ben Claytonaffb7a32021-09-28 11:14:42 +0000280if(DAWN_ENABLE_PIC)
281 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
282endif()
283
dan sinclair194c1772022-06-21 17:54:03 +0000284if (${TINT_BUILD_AST_FUZZER})
285 message(STATUS "TINT_BUILD_AST_FUZZER is ON - setting
286 TINT_BUILD_FUZZERS
287 TINT_BUILD_WGSL_READER
288 TINT_BUILD_WGSL_WRITER
289 TINT_BUILD_SPV_WRITER
290 TINT_BUILD_MSL_WRITER
291 TINT_BUILD_GLSL_WRITER
292 TINT_BUILD_HLSL_WRITER to ON")
293 set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE)
294 set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE)
295 set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE)
296 set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE)
297 set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE)
298 set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build GLSL writer" FORCE)
299 set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
300endif()
301
302if (${TINT_BUILD_REGEX_FUZZER})
303 message(STATUS "TINT_BUILD_REGEX_FUZZER is ON - setting
304 TINT_BUILD_FUZZERS
305 TINT_BUILD_WGSL_READER
306 TINT_BUILD_WGSL_WRITER
307 TINT_BUILD_SPV_WRITER
308 TINT_BUILD_MSL_WRITER
309 TINT_BUILD_GLSL_WRITER
310 TINT_BUILD_HLSL_WRITER to ON")
311 set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE)
312 set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE)
313 set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE)
314 set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE)
315 set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE)
316 set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build GLSL writer" FORCE)
317 set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE)
318endif()
319
Peng Huang5c2f1672023-05-01 23:05:42 +0000320message(STATUS "Dawn build D3D11 backend: ${DAWN_ENABLE_D3D11}")
dan sinclair194c1772022-06-21 17:54:03 +0000321message(STATUS "Dawn build D3D12 backend: ${DAWN_ENABLE_D3D12}")
322message(STATUS "Dawn build Metal backend: ${DAWN_ENABLE_METAL}")
323message(STATUS "Dawn build Vulkan backend: ${DAWN_ENABLE_VULKAN}")
324message(STATUS "Dawn build OpenGL backend: ${DAWN_ENABLE_DESKTOP_GL}")
325message(STATUS "Dawn build OpenGL ES backend: ${DAWN_ENABLE_OPENGLES}")
326message(STATUS "Dawn build Null backend: ${DAWN_ENABLE_NULL}")
327
328message(STATUS "Dawn build with asserts in all configurations: ${DAWN_ALWAYS_ASSERT}")
329message(STATUS "Dawn build Wayland support: ${DAWN_USE_WAYLAND}")
330message(STATUS "Dawn build X11 support: ${DAWN_USE_X11}")
AlexVestin5c3645c2023-10-18 14:08:26 +0000331message(STATUS "Dawn build GLFW support: ${DAWN_USE_GLFW}")
Stephen Gutekanst55623702023-07-01 11:43:55 +0000332message(STATUS "Dawn build Windows UI support: ${DAWN_USE_WINDOWS_UI}")
dan sinclair194c1772022-06-21 17:54:03 +0000333
334message(STATUS "Dawn build samples: ${DAWN_BUILD_SAMPLES}")
335message(STATUS "Dawn build Node bindings: ${DAWN_BUILD_NODE_BINDINGS}")
336message(STATUS "Dawn build Swiftshader: ${DAWN_ENABLE_SWIFTSHADER}")
Austin Eng6a7bba52023-04-17 18:11:51 +0000337message(STATUS "Dawn build benchmarks: ${DAWN_BUILD_BENCHMARKS}")
dan sinclair194c1772022-06-21 17:54:03 +0000338
339message(STATUS "Dawn build PIC: ${DAWN_ENABLE_PIC}")
340
341message(STATUS "Dawn build with ASAN: ${DAWN_ENABLE_ASAN}")
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000342message(STATUS "Dawn build with TSAN: ${DAWN_ENABLE_TSAN}")
dan sinclair194c1772022-06-21 17:54:03 +0000343message(STATUS "Dawn build with MSAN: ${DAWN_ENABLE_MSAN}")
344message(STATUS "Dawn build with UBSAN: ${DAWN_ENABLE_UBSAN}")
345
Ben Clayton3a3cb362023-08-16 01:05:21 +0000346message(STATUS "Tint build command line executable tools: ${TINT_BUILD_CMD_TOOLS}")
dan sinclair194c1772022-06-21 17:54:03 +0000347message(STATUS "Tint build docs: ${TINT_BUILD_DOCS}")
348message(STATUS "Tint build docs with warn as error: ${TINT_DOCS_WARN_AS_ERROR}")
349message(STATUS "Tint build SPIR-V reader: ${TINT_BUILD_SPV_READER}")
350message(STATUS "Tint build WGSL reader: ${TINT_BUILD_WGSL_READER}")
351message(STATUS "Tint build GLSL writer: ${TINT_BUILD_GLSL_WRITER}")
Ben Claytonf1b8a012023-10-11 17:15:52 +0000352message(STATUS "Tint build GLSL validator: ${TINT_BUILD_GLSL_VALIDATOR}")
dan sinclair194c1772022-06-21 17:54:03 +0000353message(STATUS "Tint build HLSL writer: ${TINT_BUILD_HLSL_WRITER}")
354message(STATUS "Tint build MSL writer: ${TINT_BUILD_MSL_WRITER}")
355message(STATUS "Tint build SPIR-V writer: ${TINT_BUILD_SPV_WRITER}")
356message(STATUS "Tint build WGSL writer: ${TINT_BUILD_WGSL_WRITER}")
dan sinclair0917fbb2023-03-07 18:28:38 +0000357message(STATUS "Tint build Syntax Tree writer: ${TINT_BUILD_SYNTAX_TREE_WRITER}")
dan sinclair194c1772022-06-21 17:54:03 +0000358message(STATUS "Tint build fuzzers: ${TINT_BUILD_FUZZERS}")
dan sinclair194c1772022-06-21 17:54:03 +0000359message(STATUS "Tint build AST fuzzer: ${TINT_BUILD_AST_FUZZER}")
360message(STATUS "Tint build regex fuzzer: ${TINT_BUILD_REGEX_FUZZER}")
361message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}")
362message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}")
363message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}")
Ben Clayton8fc9b862023-04-19 15:03:19 +0000364message(STATUS "Tint external benchmark corpus dir: ${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}")
365
dan sinclair194c1772022-06-21 17:54:03 +0000366
367if (NOT ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS} STREQUAL "")
368 message(STATUS "Using provided LIB_FUZZING_ENGINE options: ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS}")
369endif()
370
371message(STATUS "Using python3")
372find_package(PythonInterp 3 REQUIRED)
373
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000374################################################################################
Ben Clayton96e245e2022-04-08 18:08:36 +0000375# common_compile_options - sets compiler and linker options common for dawn and
376# tint on the given target
377################################################################################
378function(common_compile_options TARGET)
379 if (COMPILER_IS_LIKE_GNU)
380 target_compile_options(${TARGET} PRIVATE
381 -fno-exceptions
382 -fno-rtti
dan sinclaircf2456b2023-01-07 23:09:14 +0000383
384 -Wno-deprecated-builtins
dan sinclair07c32cb2023-01-09 15:10:33 +0000385 -Wno-unknown-warning-option
Ben Clayton96e245e2022-04-08 18:08:36 +0000386 )
387
388 if (${DAWN_ENABLE_MSAN})
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000389 target_compile_options(${TARGET} PUBLIC -fsanitize=memory)
390 target_link_options(${TARGET} PUBLIC -fsanitize=memory)
Ben Clayton96e245e2022-04-08 18:08:36 +0000391 elseif (${DAWN_ENABLE_ASAN})
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000392 target_compile_options(${TARGET} PUBLIC -fsanitize=address)
393 target_link_options(${TARGET} PUBLIC -fsanitize=address)
394 elseif (${DAWN_ENABLE_TSAN})
395 target_compile_options(${TARGET} PUBLIC -fsanitize=thread)
396 target_link_options(${TARGET} PUBLIC -fsanitize=thread)
Ben Clayton96e245e2022-04-08 18:08:36 +0000397 elseif (${DAWN_ENABLE_UBSAN})
Antonio Maioranodeb2ec92023-03-24 18:44:02 +0000398 target_compile_options(${TARGET} PUBLIC -fsanitize=undefined -fsanitize=float-divide-by-zero)
399 target_link_options(${TARGET} PUBLIC -fsanitize=undefined -fsanitize=float-divide-by-zero)
Ben Clayton96e245e2022-04-08 18:08:36 +0000400 endif()
401 endif(COMPILER_IS_LIKE_GNU)
Setoc6927202022-09-14 16:41:07 +0000402
403 if(MSVC)
404 target_compile_options(${TARGET} PUBLIC /utf-8)
405 endif()
Ben Claytone38993f2022-12-10 00:15:57 +0000406
407 if (DAWN_EMIT_COVERAGE)
Ben Clayton54264d32023-01-10 21:55:43 +0000408 target_compile_definitions(${TARGET} PRIVATE "DAWN_EMIT_COVERAGE")
Ben Claytone38993f2022-12-10 00:15:57 +0000409 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
410 target_compile_options(${TARGET} PRIVATE "--coverage")
411 target_link_options(${TARGET} PRIVATE "gcov")
Ben Clayton78e45302023-01-26 15:57:27 +0000412 elseif(COMPILER_IS_CLANG OR COMPILER_IS_CLANG_CL)
Ben Claytone38993f2022-12-10 00:15:57 +0000413 target_compile_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping")
414 target_link_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping")
415 else()
416 message(FATAL_ERROR "Coverage generation not supported for the ${CMAKE_CXX_COMPILER_ID} toolchain")
417 endif()
418 endif(DAWN_EMIT_COVERAGE)
Ben Clayton96e245e2022-04-08 18:08:36 +0000419endfunction()
420
Ben Claytond0ccb1a2022-08-19 21:33:01 +0000421if (${DAWN_ENABLE_TSAN})
422 add_compile_options(-stdlib=libc++)
423 add_link_options(-stdlib=libc++)
424endif()
425
Ben Clayton96e245e2022-04-08 18:08:36 +0000426################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000427# Dawn's public and internal "configs"
428################################################################################
429
Ben Clayton94181522022-11-09 20:55:33 +0000430set(IS_DEBUG_BUILD 0)
431string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
432if ((NOT ${build_type} STREQUAL "RELEASE") AND (NOT ${build_type} STREQUAL "RELWITHDEBINFO"))
433 set(IS_DEBUG_BUILD 1)
434endif()
435
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000436# The public config contains only the include paths for the Dawn headers.
437add_library(dawn_public_config INTERFACE)
438target_include_directories(dawn_public_config INTERFACE
Ben Clayton9fb7a512022-02-04 18:18:18 +0000439 "${DAWN_INCLUDE_DIR}"
440 "${DAWN_BUILD_GEN_DIR}/include"
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000441)
442
443# The internal config conatins additional path but includes the dawn_public_config include paths
444add_library(dawn_internal_config INTERFACE)
445target_include_directories(dawn_internal_config INTERFACE
446 "${DAWN_SRC_DIR}"
447 "${DAWN_BUILD_GEN_DIR}/src"
448)
449target_link_libraries(dawn_internal_config INTERFACE dawn_public_config)
450
451# Compile definitions for the internal config
Ben Clayton94181522022-11-09 20:55:33 +0000452if (DAWN_ALWAYS_ASSERT OR IS_DEBUG_BUILD)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000453 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_ASSERTS")
454endif()
Peng Huang5c2f1672023-05-01 23:05:42 +0000455if (DAWN_ENABLE_D3D11)
456 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D11")
457endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000458if (DAWN_ENABLE_D3D12)
459 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D12")
460endif()
461if (DAWN_ENABLE_METAL)
462 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_METAL")
463endif()
464if (DAWN_ENABLE_NULL)
465 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_NULL")
466endif()
Sergey Karchevsky3a75b1c2021-06-30 15:06:43 +0000467if (DAWN_ENABLE_DESKTOP_GL)
468 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_DESKTOP_GL")
469endif()
470if (DAWN_ENABLE_OPENGLES)
471 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGLES")
472endif()
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000473if (DAWN_ENABLE_OPENGL)
474 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGL")
475endif()
476if (DAWN_ENABLE_VULKAN)
477 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_VULKAN")
478endif()
Corentin Wallez2e22d922022-06-01 09:30:50 +0000479if (DAWN_USE_WAYLAND)
480 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WAYLAND")
481endif()
Corentin Wallezd353ca02020-02-18 02:12:35 +0000482if (DAWN_USE_X11)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000483 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11")
484endif()
Stephen Gutekanst55623702023-07-01 11:43:55 +0000485if (DAWN_USE_WINDOWS_UI)
486 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WINDOWS_UI")
487endif()
Corentin Wallez33466972020-02-24 13:27:28 +0000488if (WIN32)
489 target_compile_definitions(dawn_internal_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN")
490endif()
491
dan sinclair05d278e2023-08-30 21:05:31 +0000492set(CMAKE_CXX_STANDARD "17")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000493
494################################################################################
Ryan Harrisone87ac762022-04-06 15:37:27 -0400495# Tint
496################################################################################
497
Alastair Donaldson6a1eb452021-09-02 23:49:25 +0000498set(TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS "" CACHE STRING "Used by OSS-Fuzz to control, via link options, which fuzzing engine should be used")
499
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000500set(TINT_ROOT_SOURCE_DIR ${PROJECT_SOURCE_DIR})
Ben Clayton3a3cb362023-08-16 01:05:21 +0000501set(TINT_SPIRV_HEADERS_DIR ${DAWN_SPIRV_HEADERS_DIR})
502set(TINT_SPIRV_TOOLS_DIR ${DAWN_SPIRV_TOOLS_DIR})
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000503
Antonio Maioranod6009722021-03-17 13:32:54 +0000504# CMake < 3.15 sets /W3 in CMAKE_CXX_FLAGS. Remove it if it's there.
505# See https://gitlab.kitware.com/cmake/cmake/-/issues/18317
506if (MSVC)
Vasyl Teliman0b3611b2021-06-24 18:10:46 +0000507 if (CMAKE_CXX_FLAGS MATCHES "/W3")
508 string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
509 endif()
Antonio Maioranod6009722021-03-17 13:32:54 +0000510endif()
511
Ryan Harrison563d3e92020-04-28 19:27:38 +0000512if (${TINT_CHECK_CHROMIUM_STYLE})
513 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -add-plugin -Xclang find-bad-constructs")
514endif()
515
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000516if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC"))
517 set(COMPILER_IS_CLANG_CL TRUE)
518endif()
519
Ben Clayton78e45302023-01-26 15:57:27 +0000520if((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000521 ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND
522 (NOT COMPILER_IS_CLANG_CL)))
Ben Clayton78e45302023-01-26 15:57:27 +0000523 set(COMPILER_IS_CLANG TRUE)
524endif()
525
Ben Clayton7d956612023-10-03 10:14:55 +0000526if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
527 set(COMPILER_IS_GNU TRUE)
528endif()
529
Ben Clayton78e45302023-01-26 15:57:27 +0000530if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR COMPILER_IS_CLANG)
Dan Sinclair6e581892020-03-02 15:47:43 -0500531 set(COMPILER_IS_LIKE_GNU TRUE)
532endif()
533
Antonio Maiorano88d3d2e2021-03-23 20:51:09 +0000534# Enable msbuild multiprocessor builds
535if (MSVC AND NOT COMPILER_IS_CLANG_CL)
536 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
537endif()
538
David Neto5b46d712020-06-26 22:29:27 +0000539if(${TINT_BUILD_DOCS})
540 find_package(Doxygen)
541 if(DOXYGEN_FOUND)
Antonio Maiorano6241f962021-06-25 14:00:36 +0000542 set(DOXYGEN_WARN_AS_ERROR NO)
543 if(TINT_DOCS_WARN_AS_ERROR)
544 set(DOXYGEN_WARN_AS_ERROR YES)
545 endif()
Antonio Maioranoe25a8fc2021-06-25 14:53:06 +0000546
547 set(DOXYGEN_WARN_FORMAT "$file:$line: $text")
548 if (MSVC)
549 set(DOXYGEN_WARN_FORMAT "$file($line): $text")
550 endif()
551
David Neto5b46d712020-06-26 22:29:27 +0000552 add_custom_target(tint-docs ALL
Ben Clayton4ace8222021-05-12 08:15:41 +0000553 COMMAND ${CMAKE_COMMAND}
Antonio Maiorano6241f962021-06-25 14:00:36 +0000554 -E env
555 "DOXYGEN_OUTPUT_DIRECTORY=${CMAKE_BINARY_DIR}/docs"
556 "DOXYGEN_WARN_AS_ERROR=${DOXYGEN_WARN_AS_ERROR}"
Antonio Maioranoe25a8fc2021-06-25 14:53:06 +0000557 "DOXYGEN_WARN_FORMAT=${DOXYGEN_WARN_FORMAT}"
Ben Clayton4ace8222021-05-12 08:15:41 +0000558 ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile
David Neto5b46d712020-06-26 22:29:27 +0000559 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
560 COMMENT "Generating API documentation"
561 VERBATIM)
562 else()
563 message("Doxygen not found. Skipping documentation")
564 endif(DOXYGEN_FOUND)
dan sinclairb0391c6f2020-07-15 20:54:48 +0000565endif()
Dan Sinclair6e581892020-03-02 15:47:43 -0500566
Ryan Harrisone87ac762022-04-06 15:37:27 -0400567################################################################################
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000568# Run on all subdirectories
569################################################################################
570
571add_subdirectory(third_party)
James Price8d9adb02022-05-22 00:41:53 +0000572
573# TODO(crbug.com/tint/455): Tint does not currently build with CMake when
574# BUILD_SHARED_LIBS=1, so always build it as static for now.
575set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS})
576set(BUILD_SHARED_LIBS 0)
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000577add_subdirectory(src/tint)
James Price8d9adb02022-05-22 00:41:53 +0000578set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED})
579
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000580add_subdirectory(generator)
581add_subdirectory(src/dawn)
Ben Clayton7b778552022-02-04 18:59:15 +0000582
583################################################################################
584# Samples
585################################################################################
dan sinclairb5950522020-03-19 13:03:35 +0000586add_custom_target(tint-lint
587 COMMAND ./tools/lint
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000588 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000589 COMMENT "Running linter"
590 VERBATIM)
591
592add_custom_target(tint-format
593 COMMAND ./tools/format
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000594 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
dan sinclairb5950522020-03-19 13:03:35 +0000595 COMMENT "Running formatter"
596 VERBATIM)
Ben Claytonadb10d62020-10-27 21:04:59 +0000597
Ben Clayton78e45302023-01-26 15:57:27 +0000598if (DAWN_EMIT_COVERAGE)
599 add_subdirectory(tools/src/cmd/turbo-cov)
Ben Claytonadb10d62020-10-27 21:04:59 +0000600
Ben Clayton78e45302023-01-26 15:57:27 +0000601 # The tint-generate-coverage target generates a lcov.info file at the project
602 # root, holding the code coverage for all the tint_unitests.
Ben Claytonadb10d62020-10-27 21:04:59 +0000603 # This can be used by tools such as VSCode's Coverage Gutters extension to
604 # visualize code coverage in the editor.
605 get_filename_component(CLANG_BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY)
606 set(PATH_WITH_CLANG "${CLANG_BIN_DIR}:$ENV{PATH}")
607 add_custom_target(tint-generate-coverage
608 COMMAND ${CMAKE_COMMAND} -E env PATH=${PATH_WITH_CLANG} ./tools/tint-generate-coverage $<TARGET_FILE:tint_unittests>
609 DEPENDS tint_unittests
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000610 WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR}
Ben Claytonadb10d62020-10-27 21:04:59 +0000611 COMMENT "Generating tint coverage data"
612 VERBATIM)
613endif()
Ben Clayton54cfa0b2021-07-08 19:35:53 +0000614