Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 1 | # Copyright 2022 The Dawn & Tint Authors |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 2 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | # Redistribution and use in source and binary forms, with or without |
| 4 | # modification, are permitted provided that the following conditions are met: |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 5 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 6 | # 1. Redistributions of source code must retain the above copyright notice, this |
| 7 | # list of conditions and the following disclaimer. |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 8 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 9 | # 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 Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 27 | |
Erin Melucci | d1e92bb | 2024-03-27 15:43:05 +0000 | [diff] [blame] | 28 | # As per https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md |
| 29 | cmake_minimum_required(VERSION 3.13) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 30 | |
Erin Melucci | d1e92bb | 2024-03-27 15:43:05 +0000 | [diff] [blame] | 31 | # - Since we are past CMake 3.12 we can add CONFIGURE_DEPENDS to DawnGenerator to rerun CMake |
Corentin Wallez | a3014cc | 2024-03-27 13:53:14 +0000 | [diff] [blame] | 32 | # in case any of the generator files changes. We should also remove the CACHE "" FORCE stuff to |
Erin Melucci | d1e92bb | 2024-03-27 15:43:05 +0000 | [diff] [blame] | 33 | # override options in third_party dependencies. |
Corentin Wallez | a3014cc | 2024-03-27 13:53:14 +0000 | [diff] [blame] | 34 | # - 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 Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 37 | project( |
| 38 | Dawn |
| 39 | DESCRIPTION "Dawn, a WebGPU implementation" |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 40 | LANGUAGES C CXX |
Erin Melucci | d1e92bb | 2024-03-27 15:43:05 +0000 | [diff] [blame] | 41 | HOMEPAGE_URL "https://dawn.googlesource.com/dawn" |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 42 | ) |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 43 | enable_testing() |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 44 | |
| 45 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 46 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 47 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) |
| 48 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
dan sinclair | 05d278e | 2023-08-30 21:05:31 +0000 | [diff] [blame] | 49 | set(CMAKE_CXX_STANDARD 17) |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 50 | set(CMAKE_DEBUG_POSTFIX "") |
dan sinclair | 2df8091 | 2023-11-20 13:22:14 +0000 | [diff] [blame] | 51 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 52 | |
| 53 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "") |
| 54 | message(STATUS "No build type selected, default to Debug") |
| 55 | set(CMAKE_BUILD_TYPE "Debug") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 56 | endif() |
| 57 | |
| 58 | set(DAWN_BUILD_GEN_DIR "${Dawn_BINARY_DIR}/gen") |
| 59 | set(DAWN_GENERATOR_DIR "${Dawn_SOURCE_DIR}/generator") |
| 60 | set(DAWN_SRC_DIR "${Dawn_SOURCE_DIR}/src") |
Ben Clayton | 9fb7a51 | 2022-02-04 18:18:18 +0000 | [diff] [blame] | 61 | set(DAWN_INCLUDE_DIR "${Dawn_SOURCE_DIR}/include") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 62 | set(DAWN_TEMPLATE_DIR "${DAWN_GENERATOR_DIR}/templates") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 63 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 64 | ################################################################################ |
| 65 | # Configuration options |
| 66 | ################################################################################ |
| 67 | |
Ben Clayton | 30eeac7 | 2021-09-24 10:38:18 +0000 | [diff] [blame] | 68 | # 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. |
| 74 | function (option_if_not_defined name description default) |
| 75 | if(NOT DEFINED ${name}) |
| 76 | option(${name} ${description} ${default}) |
| 77 | endif() |
| 78 | endfunction() |
| 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. |
| 86 | function (set_if_not_defined name value description) |
| 87 | if(NOT DEFINED ${name}) |
| 88 | set(${name} ${value} CACHE STRING ${description}) |
| 89 | endif() |
| 90 | endfunction() |
| 91 | |
munoza | c511ffb | 2023-09-25 14:01:03 +0000 | [diff] [blame] | 92 | function (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() |
| 128 | endfunction() |
| 129 | |
| 130 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 131 | # Default values for the backend-enabling options |
Peng Huang | 925b776 | 2023-05-01 16:13:00 +0000 | [diff] [blame] | 132 | set(ENABLE_D3D11 OFF) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 133 | set(ENABLE_D3D12 OFF) |
| 134 | set(ENABLE_METAL OFF) |
Sergey Karchevsky | 3a75b1c | 2021-06-30 15:06:43 +0000 | [diff] [blame] | 135 | set(ENABLE_OPENGLES OFF) |
| 136 | set(ENABLE_DESKTOP_GL OFF) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 137 | set(ENABLE_VULKAN OFF) |
Corentin Wallez | 2e22d92 | 2022-06-01 09:30:50 +0000 | [diff] [blame] | 138 | set(USE_WAYLAND OFF) |
Corentin Wallez | d353ca0 | 2020-02-18 02:12:35 +0000 | [diff] [blame] | 139 | set(USE_X11 OFF) |
Stephen Gutekanst | 5562370 | 2023-07-01 11:43:55 +0000 | [diff] [blame] | 140 | set(USE_WINDOWS_UI OFF) |
Ben Clayton | a675075 | 2022-02-04 18:35:55 +0000 | [diff] [blame] | 141 | set(BUILD_SAMPLES OFF) |
AlexVestin | 5c3645c | 2023-10-18 14:08:26 +0000 | [diff] [blame] | 142 | set(TARGET_MACOS OFF) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 143 | if (WIN32) |
Peng Huang | 925b776 | 2023-05-01 16:13:00 +0000 | [diff] [blame] | 144 | set(ENABLE_D3D11 ON) |
Stephen Gutekanst | 5562370 | 2023-07-01 11:43:55 +0000 | [diff] [blame] | 145 | set(USE_WINDOWS_UI ON) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 146 | set(ENABLE_D3D12 ON) |
陈俊嘉 | 610de1d | 2021-06-28 08:19:28 +0000 | [diff] [blame] | 147 | if (NOT WINDOWS_STORE) |
陈俊嘉 | b2bc57a | 2021-06-24 07:00:16 +0000 | [diff] [blame] | 148 | # Enable Vulkan in win32 compilation only |
| 149 | # since UWP only supports d3d |
| 150 | set(ENABLE_VULKAN ON) |
| 151 | endif() |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 152 | elseif(APPLE) |
| 153 | set(ENABLE_METAL ON) |
AlexVestin | 5c3645c | 2023-10-18 14:08:26 +0000 | [diff] [blame] | 154 | if(CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "MacOS") |
| 155 | set(TARGET_MACOS ON) |
| 156 | endif() |
Alexander Vestin | f2556ab | 2022-03-25 13:18:46 +0000 | [diff] [blame] | 157 | elseif(ANDROID) |
| 158 | set(ENABLE_VULKAN ON) |
| 159 | set(ENABLE_OPENGLES ON) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 160 | elseif(UNIX) |
Sergey Karchevsky | 3a75b1c | 2021-06-30 15:06:43 +0000 | [diff] [blame] | 161 | set(ENABLE_OPENGLES ON) |
| 162 | set(ENABLE_DESKTOP_GL ON) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 163 | set(ENABLE_VULKAN ON) |
Corentin Wallez | d353ca0 | 2020-02-18 02:12:35 +0000 | [diff] [blame] | 164 | set(USE_X11 ON) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 165 | endif() |
| 166 | |
陈俊嘉 | b2bc57a | 2021-06-24 07:00:16 +0000 | [diff] [blame] | 167 | # GLFW is not supported in UWP |
Albin Bernhardsson | b8a1b6d | 2023-07-13 08:51:17 +0000 | [diff] [blame] | 168 | set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING OFF) |
Sonakshi Saxena | 1344611 | 2023-08-23 12:32:14 +0000 | [diff] [blame] | 169 | |
| 170 | if ((WIN32 AND NOT WINDOWS_STORE) OR (UNIX AND NOT ANDROID)) |
陈俊嘉 | b2bc57a | 2021-06-24 07:00:16 +0000 | [diff] [blame] | 171 | set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING ON) |
| 172 | endif() |
| 173 | |
| 174 | # Current examples are depend on GLFW |
| 175 | if (DAWN_SUPPORTS_GLFW_FOR_WINDOWING) |
Ben Clayton | a675075 | 2022-02-04 18:35:55 +0000 | [diff] [blame] | 176 | set(BUILD_SAMPLES ON) |
陈俊嘉 | b2bc57a | 2021-06-24 07:00:16 +0000 | [diff] [blame] | 177 | endif() |
| 178 | |
Ben Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 179 | option_if_not_defined(DAWN_ENABLE_ASAN "Enable address sanitizer" OFF) |
munoza | c511ffb | 2023-09-25 14:01:03 +0000 | [diff] [blame] | 180 | option_if_not_defined(DAWN_ENABLE_INSTALL "Enable install step for Dawn libraries" OFF) |
Ben Clayton | d0ccb1a | 2022-08-19 21:33:01 +0000 | [diff] [blame] | 181 | option_if_not_defined(DAWN_ENABLE_TSAN "Enable thread sanitizer" OFF) |
| 182 | option_if_not_defined(DAWN_ENABLE_MSAN "Enable memory sanitizer" OFF) |
Ben Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 183 | option_if_not_defined(DAWN_ENABLE_UBSAN "Enable undefined behaviour sanitizer" OFF) |
| 184 | |
Peng Huang | 5c2f167 | 2023-05-01 23:05:42 +0000 | [diff] [blame] | 185 | option_if_not_defined(DAWN_ENABLE_D3D11 "Enable compilation of the D3D11 backend" ${ENABLE_D3D11}) |
Ben Clayton | 30eeac7 | 2021-09-24 10:38:18 +0000 | [diff] [blame] | 186 | option_if_not_defined(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12}) |
| 187 | option_if_not_defined(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL}) |
| 188 | option_if_not_defined(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON) |
| 189 | option_if_not_defined(DAWN_ENABLE_DESKTOP_GL "Enable compilation of the OpenGL backend" ${ENABLE_DESKTOP_GL}) |
| 190 | option_if_not_defined(DAWN_ENABLE_OPENGLES "Enable compilation of the OpenGL ES backend" ${ENABLE_OPENGLES}) |
| 191 | option_if_not_defined(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backend" ${ENABLE_VULKAN}) |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 192 | |
Ben Clayton | 30eeac7 | 2021-09-24 10:38:18 +0000 | [diff] [blame] | 193 | option_if_not_defined(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF) |
Corentin Wallez | 2e22d92 | 2022-06-01 09:30:50 +0000 | [diff] [blame] | 194 | option_if_not_defined(DAWN_USE_WAYLAND "Enable support for Wayland surface" ${USE_WAYLAND}) |
Ben Clayton | 30eeac7 | 2021-09-24 10:38:18 +0000 | [diff] [blame] | 195 | option_if_not_defined(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11}) |
Erin Melucci | 38b58e4 | 2023-06-14 16:45:33 +0000 | [diff] [blame] | 196 | option_if_not_defined(DAWN_USE_GLFW "Enable compilation of the GLFW windowing utils" ${DAWN_SUPPORTS_GLFW_FOR_WINDOWING}) |
Stephen Gutekanst | 5562370 | 2023-07-01 11:43:55 +0000 | [diff] [blame] | 197 | option_if_not_defined(DAWN_USE_WINDOWS_UI "Enable support for Windows UI surface" ${USE_WINDOWS_UI}) |
Antonio Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 198 | option_if_not_defined(DAWN_USE_BUILT_DXC "Enable building and using DXC by the D3D12 backend" OFF) |
Antonio Maiorano | b4d05de | 2024-04-16 19:36:58 +0000 | [diff] [blame] | 199 | option_if_not_defined(DAWN_DXC_DISABLE_ASSERTS_DEBUG "Disable asserts in DXC in debug builds" OFF) |
AlexVestin | 5c3645c | 2023-10-18 14:08:26 +0000 | [diff] [blame] | 200 | option_if_not_defined(DAWN_TARGET_MACOS "Manually link Apple core frameworks" ${TARGET_MACOS}) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 201 | |
Ben Clayton | a675075 | 2022-02-04 18:35:55 +0000 | [diff] [blame] | 202 | option_if_not_defined(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" ${BUILD_SAMPLES}) |
Ben Clayton | affb7a3 | 2021-09-28 11:14:42 +0000 | [diff] [blame] | 203 | option_if_not_defined(DAWN_BUILD_NODE_BINDINGS "Enables building Dawn's NodeJS bindings" OFF) |
Corentin Wallez | be352ea | 2022-04-11 16:48:43 +0000 | [diff] [blame] | 204 | option_if_not_defined(DAWN_ENABLE_SWIFTSHADER "Enables building Swiftshader as part of the build and Vulkan adapter discovery" OFF) |
Austin Eng | 6a7bba5 | 2023-04-17 18:11:51 +0000 | [diff] [blame] | 205 | option_if_not_defined(DAWN_BUILD_BENCHMARKS "Build Dawn benchmarks" OFF) |
Ben Clayton | affb7a3 | 2021-09-28 11:14:42 +0000 | [diff] [blame] | 206 | |
Corentin Wallez | 1450d1d | 2024-05-06 18:52:34 +0000 | [diff] [blame] | 207 | option_if_not_defined(DAWN_WERROR "Build with -Werror (or equivalent)" OFF) |
Ben Clayton | affb7a3 | 2021-09-28 11:14:42 +0000 | [diff] [blame] | 208 | option_if_not_defined(DAWN_ENABLE_PIC "Build with Position-Independent-Code enabled" OFF) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 209 | |
Ben Clayton | e38993f | 2022-12-10 00:15:57 +0000 | [diff] [blame] | 210 | option_if_not_defined(DAWN_EMIT_COVERAGE "Emit code coverage information" OFF) |
Ben Clayton | f927bcb | 2022-12-12 21:21:54 +0000 | [diff] [blame] | 211 | set_if_not_defined(LLVM_SOURCE_DIR "${Dawn_LLVM_SOURCE_DIR}" "Directory to an LLVM source checkout. Required to build turbo-cov") |
Ben Clayton | e38993f | 2022-12-10 00:15:57 +0000 | [diff] [blame] | 212 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 213 | if (DAWN_ENABLE_OPENGLES OR DAWN_ENABLE_DESKTOP_GL) |
| 214 | set(TINT_DEFAULT_GLSL ON) |
| 215 | else() |
| 216 | set(TINT_DEFAULT_GLSL OFF) |
| 217 | endif() |
| 218 | |
munoza | c511ffb | 2023-09-25 14:01:03 +0000 | [diff] [blame] | 219 | option_if_not_defined(TINT_ENABLE_INSTALL "Enable install step for Tint libraries" OFF) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 220 | option_if_not_defined(TINT_BUILD_CMD_TOOLS "Build the Tint command line tools" ON) |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 221 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 222 | if (NOT DAWN_USE_GLFW AND (TINT_BUILD_CMD_TOOLS OR DAWN_BUILD_SAMPLES)) |
Erin Melucci | 38b58e4 | 2023-06-14 16:45:33 +0000 | [diff] [blame] | 223 | message(SEND_ERROR "Dawn samples require GLFW") |
| 224 | endif() |
| 225 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 226 | option_if_not_defined(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" ${DAWN_ENABLE_VULKAN}) |
| 227 | option_if_not_defined(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON) |
| 228 | option_if_not_defined(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" ${TINT_DEFAULT_GLSL}) |
Ben Clayton | f1b8a01 | 2023-10-11 17:15:52 +0000 | [diff] [blame] | 229 | option_if_not_defined(TINT_BUILD_GLSL_VALIDATOR "Build the GLSL output validator" ON) |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 230 | option_if_not_defined(TINT_BUILD_HLSL_WRITER "Build the HLSL output writer" ${DAWN_ENABLE_D3D12}) |
| 231 | option_if_not_defined(TINT_BUILD_MSL_WRITER "Build the MSL output writer" ${DAWN_ENABLE_METAL}) |
| 232 | option_if_not_defined(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ${DAWN_ENABLE_VULKAN}) |
| 233 | option_if_not_defined(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON) |
| 234 | |
dan sinclair | 0917fbb | 2023-03-07 18:28:38 +0000 | [diff] [blame] | 235 | option_if_not_defined(TINT_BUILD_SYNTAX_TREE_WRITER "Build the syntax tree writer" OFF) |
dan sinclair | c22b8b9d | 2022-11-01 17:02:31 +0000 | [diff] [blame] | 236 | |
Ryan Harrison | 724dd78 | 2024-05-16 16:27:48 +0000 | [diff] [blame] | 237 | option_if_not_defined(TINT_BUILD_IR_BINARY "Build IR binary format support" ON) |
| 238 | |
| 239 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 240 | option_if_not_defined(TINT_BUILD_FUZZERS "Build fuzzers" OFF) |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 241 | option_if_not_defined(TINT_BUILD_AST_FUZZER "Build AST fuzzer" OFF) |
| 242 | option_if_not_defined(TINT_BUILD_REGEX_FUZZER "Build regex fuzzer" OFF) |
Austin Eng | 6a7bba5 | 2023-04-17 18:11:51 +0000 | [diff] [blame] | 243 | option_if_not_defined(TINT_BUILD_BENCHMARKS "Build Tint benchmarks" OFF) |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 244 | option_if_not_defined(TINT_BUILD_TESTS "Build tests" ON) |
| 245 | option_if_not_defined(TINT_BUILD_AS_OTHER_OS "Override OS detection to force building of *_other.cc files" OFF) |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 246 | |
Ben Clayton | f9a5b71 | 2024-03-13 17:37:33 +0000 | [diff] [blame] | 247 | option_if_not_defined(TINT_BUILD_TINTD "Build the WGSL language server" OFF) |
Ben Clayton | f9a5b71 | 2024-03-13 17:37:33 +0000 | [diff] [blame] | 248 | |
Ben Clayton | 8fc9b86 | 2023-04-19 15:03:19 +0000 | [diff] [blame] | 249 | set_if_not_defined(TINT_EXTERNAL_BENCHMARK_CORPUS_DIR "" "Directory that holds a corpus of external shaders to benchmark.") |
| 250 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 251 | option_if_not_defined(TINT_ENABLE_BREAK_IN_DEBUGGER "Enable tint::debugger::Break()" OFF) |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 252 | option_if_not_defined(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF) |
Ben Clayton | f2b86aa | 2022-12-13 14:46:02 +0000 | [diff] [blame] | 253 | option_if_not_defined(TINT_RANDOMIZE_HASHES "Randomize the hash seed value to detect non-deterministic output" OFF) |
Corentin Wallez | e557087 | 2020-10-20 14:26:10 +0000 | [diff] [blame] | 254 | |
Brandon Jones | a04663c | 2021-09-23 20:36:03 +0000 | [diff] [blame] | 255 | # Recommended setting for compability with future abseil releases. |
| 256 | set(ABSL_PROPAGATE_CXX_STD ON) |
Brandon Jones | a04663c | 2021-09-23 20:36:03 +0000 | [diff] [blame] | 257 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 258 | set_if_not_defined(DAWN_THIRD_PARTY_DIR "${Dawn_SOURCE_DIR}/third_party" "Directory in which to find third-party dependencies.") |
dan sinclair | c1f6dbd | 2023-04-11 15:45:18 +0000 | [diff] [blame] | 259 | set_if_not_defined(DAWN_VULKAN_DEPS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps" "Directory in which to find vulkan-deps") |
| 260 | |
Ben Clayton | 30eeac7 | 2021-09-24 10:38:18 +0000 | [diff] [blame] | 261 | set_if_not_defined(DAWN_ABSEIL_DIR "${DAWN_THIRD_PARTY_DIR}/abseil-cpp" "Directory in which to find Abseil") |
| 262 | set_if_not_defined(DAWN_GLFW_DIR "${DAWN_THIRD_PARTY_DIR}/glfw" "Directory in which to find GLFW") |
Ben Clayton | 30eeac7 | 2021-09-24 10:38:18 +0000 | [diff] [blame] | 263 | set_if_not_defined(DAWN_JINJA2_DIR "${DAWN_THIRD_PARTY_DIR}/jinja2" "Directory in which to find Jinja2") |
Arthur Sonzogni | c5f72f7 | 2023-11-29 15:27:40 +0000 | [diff] [blame] | 264 | set_if_not_defined(DAWN_MARKUPSAFE_DIR "${DAWN_THIRD_PARTY_DIR}/markupsafe" "Directory in which to find MarkupSafe") |
Arthur Sonzogni | 58f8ed2 | 2023-11-30 09:30:52 +0000 | [diff] [blame] | 265 | set_if_not_defined(DAWN_KHRONOS_DIR "${DAWN_THIRD_PARTY_DIR}/khronos" "Directory in which to find Khronos GL headers") |
Corentin Wallez | be352ea | 2022-04-11 16:48:43 +0000 | [diff] [blame] | 266 | set_if_not_defined(DAWN_SWIFTSHADER_DIR "${DAWN_THIRD_PARTY_DIR}/swiftshader" "Directory in which to find swiftshader") |
Ben Clayton | fb07fa9 | 2023-11-17 18:48:59 +0000 | [diff] [blame] | 267 | set_if_not_defined(DAWN_PROTOBUF_DIR "${DAWN_THIRD_PARTY_DIR}/protobuf" "Directory in which to find protobuf") |
dan sinclair | c1f6dbd | 2023-04-11 15:45:18 +0000 | [diff] [blame] | 268 | |
| 269 | set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_VULKAN_DEPS_DIR}/spirv-tools/src" "Directory in which to find SPIRV-Tools") |
| 270 | set_if_not_defined(DAWN_SPIRV_HEADERS_DIR "${DAWN_VULKAN_DEPS_DIR}/spirv-headers/src" "Directory in which to find SPIRV-Headers") |
Loko Kung | 23d09c6 | 2022-04-09 00:10:08 +0000 | [diff] [blame] | 271 | set_if_not_defined(DAWN_VULKAN_HEADERS_DIR "${DAWN_VULKAN_DEPS_DIR}/vulkan-headers/src" "Directory in which to find Vulkan-Headers") |
James Price | 0fe9e44 | 2023-09-22 21:51:31 +0000 | [diff] [blame] | 272 | set_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 Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 273 | |
Ben Clayton | affb7a3 | 2021-09-28 11:14:42 +0000 | [diff] [blame] | 274 | # Dependencies for DAWN_BUILD_NODE_BINDINGS |
| 275 | set_if_not_defined(NODE_ADDON_API_DIR "${DAWN_THIRD_PARTY_DIR}/node-addon-api" "Directory in which to find node-addon-api") |
Ben Clayton | 72e3ba6 | 2021-09-30 18:04:01 +0000 | [diff] [blame] | 276 | set_if_not_defined(NODE_API_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/node-api-headers" "Directory in which to find node-api-headers") |
Ben Clayton | affb7a3 | 2021-09-28 11:14:42 +0000 | [diff] [blame] | 277 | set_if_not_defined(WEBGPU_IDL_PATH "${DAWN_THIRD_PARTY_DIR}/gpuweb/webgpu.idl" "Path to the webgpu.idl definition file") |
Austin Eng | 4948c81 | 2021-10-15 14:28:32 +0000 | [diff] [blame] | 278 | set_if_not_defined(GO_EXECUTABLE "go" "Golang executable for running the IDL generator") |
Ben Clayton | affb7a3 | 2021-09-28 11:14:42 +0000 | [diff] [blame] | 279 | |
Elie Michel | 9ae8ed2 | 2023-05-12 20:19:41 +0000 | [diff] [blame] | 280 | option_if_not_defined(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" OFF) |
| 281 | |
Sergey Karchevsky | 3a75b1c | 2021-06-30 15:06:43 +0000 | [diff] [blame] | 282 | # Much of the backend code is shared among desktop OpenGL and OpenGL ES |
| 283 | if (${DAWN_ENABLE_DESKTOP_GL} OR ${DAWN_ENABLE_OPENGLES}) |
| 284 | set(DAWN_ENABLE_OPENGL ON) |
| 285 | endif() |
| 286 | |
Ben Clayton | affb7a3 | 2021-09-28 11:14:42 +0000 | [diff] [blame] | 287 | if(DAWN_ENABLE_PIC) |
| 288 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 289 | endif() |
| 290 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 291 | if (${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) |
| 307 | endif() |
| 308 | |
| 309 | if (${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) |
| 325 | endif() |
| 326 | |
Peng Huang | 5c2f167 | 2023-05-01 23:05:42 +0000 | [diff] [blame] | 327 | message(STATUS "Dawn build D3D11 backend: ${DAWN_ENABLE_D3D11}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 328 | message(STATUS "Dawn build D3D12 backend: ${DAWN_ENABLE_D3D12}") |
| 329 | message(STATUS "Dawn build Metal backend: ${DAWN_ENABLE_METAL}") |
| 330 | message(STATUS "Dawn build Vulkan backend: ${DAWN_ENABLE_VULKAN}") |
| 331 | message(STATUS "Dawn build OpenGL backend: ${DAWN_ENABLE_DESKTOP_GL}") |
| 332 | message(STATUS "Dawn build OpenGL ES backend: ${DAWN_ENABLE_OPENGLES}") |
| 333 | message(STATUS "Dawn build Null backend: ${DAWN_ENABLE_NULL}") |
| 334 | |
| 335 | message(STATUS "Dawn build with asserts in all configurations: ${DAWN_ALWAYS_ASSERT}") |
| 336 | message(STATUS "Dawn build Wayland support: ${DAWN_USE_WAYLAND}") |
| 337 | message(STATUS "Dawn build X11 support: ${DAWN_USE_X11}") |
AlexVestin | 5c3645c | 2023-10-18 14:08:26 +0000 | [diff] [blame] | 338 | message(STATUS "Dawn build GLFW support: ${DAWN_USE_GLFW}") |
Stephen Gutekanst | 5562370 | 2023-07-01 11:43:55 +0000 | [diff] [blame] | 339 | message(STATUS "Dawn build Windows UI support: ${DAWN_USE_WINDOWS_UI}") |
Antonio Maiorano | c69356e | 2023-11-23 18:04:51 +0000 | [diff] [blame] | 340 | message(STATUS "Dawn build and use DXC: ${DAWN_USE_BUILT_DXC}") |
Antonio Maiorano | b4d05de | 2024-04-16 19:36:58 +0000 | [diff] [blame] | 341 | message(STATUS "Dawn disable DXC asserts in debug builds: ${DAWN_DXC_DISABLE_ASSERTS_DEBUG}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 342 | |
| 343 | message(STATUS "Dawn build samples: ${DAWN_BUILD_SAMPLES}") |
| 344 | message(STATUS "Dawn build Node bindings: ${DAWN_BUILD_NODE_BINDINGS}") |
| 345 | message(STATUS "Dawn build Swiftshader: ${DAWN_ENABLE_SWIFTSHADER}") |
Austin Eng | 6a7bba5 | 2023-04-17 18:11:51 +0000 | [diff] [blame] | 346 | message(STATUS "Dawn build benchmarks: ${DAWN_BUILD_BENCHMARKS}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 347 | |
| 348 | message(STATUS "Dawn build PIC: ${DAWN_ENABLE_PIC}") |
| 349 | |
| 350 | message(STATUS "Dawn build with ASAN: ${DAWN_ENABLE_ASAN}") |
Ben Clayton | d0ccb1a | 2022-08-19 21:33:01 +0000 | [diff] [blame] | 351 | message(STATUS "Dawn build with TSAN: ${DAWN_ENABLE_TSAN}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 352 | message(STATUS "Dawn build with MSAN: ${DAWN_ENABLE_MSAN}") |
| 353 | message(STATUS "Dawn build with UBSAN: ${DAWN_ENABLE_UBSAN}") |
| 354 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 355 | message(STATUS "Tint build command line executable tools: ${TINT_BUILD_CMD_TOOLS}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 356 | message(STATUS "Tint build SPIR-V reader: ${TINT_BUILD_SPV_READER}") |
| 357 | message(STATUS "Tint build WGSL reader: ${TINT_BUILD_WGSL_READER}") |
| 358 | message(STATUS "Tint build GLSL writer: ${TINT_BUILD_GLSL_WRITER}") |
Ben Clayton | f1b8a01 | 2023-10-11 17:15:52 +0000 | [diff] [blame] | 359 | message(STATUS "Tint build GLSL validator: ${TINT_BUILD_GLSL_VALIDATOR}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 360 | message(STATUS "Tint build HLSL writer: ${TINT_BUILD_HLSL_WRITER}") |
| 361 | message(STATUS "Tint build MSL writer: ${TINT_BUILD_MSL_WRITER}") |
| 362 | message(STATUS "Tint build SPIR-V writer: ${TINT_BUILD_SPV_WRITER}") |
| 363 | message(STATUS "Tint build WGSL writer: ${TINT_BUILD_WGSL_WRITER}") |
dan sinclair | 0917fbb | 2023-03-07 18:28:38 +0000 | [diff] [blame] | 364 | message(STATUS "Tint build Syntax Tree writer: ${TINT_BUILD_SYNTAX_TREE_WRITER}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 365 | message(STATUS "Tint build fuzzers: ${TINT_BUILD_FUZZERS}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 366 | message(STATUS "Tint build AST fuzzer: ${TINT_BUILD_AST_FUZZER}") |
| 367 | message(STATUS "Tint build regex fuzzer: ${TINT_BUILD_REGEX_FUZZER}") |
| 368 | message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}") |
| 369 | message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}") |
| 370 | message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}") |
Ben Clayton | 8fc9b86 | 2023-04-19 15:03:19 +0000 | [diff] [blame] | 371 | message(STATUS "Tint external benchmark corpus dir: ${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}") |
| 372 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 373 | |
| 374 | if (NOT ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS} STREQUAL "") |
| 375 | message(STATUS "Using provided LIB_FUZZING_ENGINE options: ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS}") |
| 376 | endif() |
| 377 | |
Corentin Wallez | 179e84a | 2024-03-27 20:20:15 +0000 | [diff] [blame] | 378 | find_package(Python3 REQUIRED) |
Corentin Wallez | 2f18c9a | 2024-04-02 08:51:45 +0000 | [diff] [blame] | 379 | message(STATUS "Dawn: using python at ${Python3_EXECUTABLE}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 380 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 381 | ################################################################################ |
Ben Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 382 | # common_compile_options - sets compiler and linker options common for dawn and |
| 383 | # tint on the given target |
| 384 | ################################################################################ |
| 385 | function(common_compile_options TARGET) |
| 386 | if (COMPILER_IS_LIKE_GNU) |
| 387 | target_compile_options(${TARGET} PRIVATE |
| 388 | -fno-exceptions |
| 389 | -fno-rtti |
dan sinclair | cf2456b | 2023-01-07 23:09:14 +0000 | [diff] [blame] | 390 | |
| 391 | -Wno-deprecated-builtins |
dan sinclair | 07c32cb | 2023-01-09 15:10:33 +0000 | [diff] [blame] | 392 | -Wno-unknown-warning-option |
Antonio Maiorano | e4d64ed | 2024-03-04 21:15:03 +0000 | [diff] [blame] | 393 | -Wno-switch-default |
Ben Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 394 | ) |
Corentin Wallez | 1450d1d | 2024-05-06 18:52:34 +0000 | [diff] [blame] | 395 | if (${DAWN_WERROR}) |
| 396 | target_compile_options(${TARGET} PRIVATE -Werror) |
| 397 | endif() |
Ben Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 398 | |
Antonio Maiorano | 3935764 | 2024-03-27 18:23:32 +0000 | [diff] [blame] | 399 | set(SANITIZER_OPTIONS "") |
Ben Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 400 | if (${DAWN_ENABLE_MSAN}) |
Antonio Maiorano | 3935764 | 2024-03-27 18:23:32 +0000 | [diff] [blame] | 401 | 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 Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 415 | endif() |
| 416 | endif(COMPILER_IS_LIKE_GNU) |
Seto | c692720 | 2022-09-14 16:41:07 +0000 | [diff] [blame] | 417 | |
| 418 | if(MSVC) |
| 419 | target_compile_options(${TARGET} PUBLIC /utf-8) |
| 420 | endif() |
Ben Clayton | e38993f | 2022-12-10 00:15:57 +0000 | [diff] [blame] | 421 | |
| 422 | if (DAWN_EMIT_COVERAGE) |
Ben Clayton | 54264d3 | 2023-01-10 21:55:43 +0000 | [diff] [blame] | 423 | target_compile_definitions(${TARGET} PRIVATE "DAWN_EMIT_COVERAGE") |
Ben Clayton | e38993f | 2022-12-10 00:15:57 +0000 | [diff] [blame] | 424 | if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") |
| 425 | target_compile_options(${TARGET} PRIVATE "--coverage") |
| 426 | target_link_options(${TARGET} PRIVATE "gcov") |
Ben Clayton | 78e4530 | 2023-01-26 15:57:27 +0000 | [diff] [blame] | 427 | elseif(COMPILER_IS_CLANG OR COMPILER_IS_CLANG_CL) |
Ben Clayton | e38993f | 2022-12-10 00:15:57 +0000 | [diff] [blame] | 428 | 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 Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 434 | endfunction() |
| 435 | |
Ben Clayton | d0ccb1a | 2022-08-19 21:33:01 +0000 | [diff] [blame] | 436 | if (${DAWN_ENABLE_TSAN}) |
| 437 | add_compile_options(-stdlib=libc++) |
| 438 | add_link_options(-stdlib=libc++) |
| 439 | endif() |
| 440 | |
Ben Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 441 | ################################################################################ |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 442 | # Dawn's public and internal "configs" |
| 443 | ################################################################################ |
| 444 | |
Ben Clayton | 9418152 | 2022-11-09 20:55:33 +0000 | [diff] [blame] | 445 | set(IS_DEBUG_BUILD 0) |
| 446 | string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type) |
| 447 | if ((NOT ${build_type} STREQUAL "RELEASE") AND (NOT ${build_type} STREQUAL "RELWITHDEBINFO")) |
| 448 | set(IS_DEBUG_BUILD 1) |
| 449 | endif() |
| 450 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 451 | # The public config contains only the include paths for the Dawn headers. |
| 452 | add_library(dawn_public_config INTERFACE) |
| 453 | target_include_directories(dawn_public_config INTERFACE |
Ben Clayton | 9fb7a51 | 2022-02-04 18:18:18 +0000 | [diff] [blame] | 454 | "${DAWN_INCLUDE_DIR}" |
| 455 | "${DAWN_BUILD_GEN_DIR}/include" |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 456 | ) |
| 457 | |
| 458 | # The internal config conatins additional path but includes the dawn_public_config include paths |
| 459 | add_library(dawn_internal_config INTERFACE) |
| 460 | target_include_directories(dawn_internal_config INTERFACE |
| 461 | "${DAWN_SRC_DIR}" |
| 462 | "${DAWN_BUILD_GEN_DIR}/src" |
| 463 | ) |
| 464 | target_link_libraries(dawn_internal_config INTERFACE dawn_public_config) |
| 465 | |
| 466 | # Compile definitions for the internal config |
Ben Clayton | 9418152 | 2022-11-09 20:55:33 +0000 | [diff] [blame] | 467 | if (DAWN_ALWAYS_ASSERT OR IS_DEBUG_BUILD) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 468 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_ASSERTS") |
| 469 | endif() |
Peng Huang | 5c2f167 | 2023-05-01 23:05:42 +0000 | [diff] [blame] | 470 | if (DAWN_ENABLE_D3D11) |
| 471 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D11") |
| 472 | endif() |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 473 | if (DAWN_ENABLE_D3D12) |
| 474 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D12") |
| 475 | endif() |
| 476 | if (DAWN_ENABLE_METAL) |
| 477 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_METAL") |
| 478 | endif() |
| 479 | if (DAWN_ENABLE_NULL) |
| 480 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_NULL") |
| 481 | endif() |
Sergey Karchevsky | 3a75b1c | 2021-06-30 15:06:43 +0000 | [diff] [blame] | 482 | if (DAWN_ENABLE_DESKTOP_GL) |
| 483 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_DESKTOP_GL") |
| 484 | endif() |
| 485 | if (DAWN_ENABLE_OPENGLES) |
| 486 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGLES") |
| 487 | endif() |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 488 | if (DAWN_ENABLE_OPENGL) |
| 489 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGL") |
| 490 | endif() |
| 491 | if (DAWN_ENABLE_VULKAN) |
| 492 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_VULKAN") |
| 493 | endif() |
Corentin Wallez | 2e22d92 | 2022-06-01 09:30:50 +0000 | [diff] [blame] | 494 | if (DAWN_USE_WAYLAND) |
| 495 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WAYLAND") |
| 496 | endif() |
Corentin Wallez | d353ca0 | 2020-02-18 02:12:35 +0000 | [diff] [blame] | 497 | if (DAWN_USE_X11) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 498 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11") |
| 499 | endif() |
Stephen Gutekanst | 5562370 | 2023-07-01 11:43:55 +0000 | [diff] [blame] | 500 | if (DAWN_USE_WINDOWS_UI) |
| 501 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WINDOWS_UI") |
| 502 | endif() |
Corentin Wallez | 3346697 | 2020-02-24 13:27:28 +0000 | [diff] [blame] | 503 | if (WIN32) |
| 504 | target_compile_definitions(dawn_internal_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN") |
| 505 | endif() |
| 506 | |
dan sinclair | 05d278e | 2023-08-30 21:05:31 +0000 | [diff] [blame] | 507 | set(CMAKE_CXX_STANDARD "17") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 508 | |
| 509 | ################################################################################ |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 510 | # Tint |
| 511 | ################################################################################ |
| 512 | |
Alastair Donaldson | 6a1eb45 | 2021-09-02 23:49:25 +0000 | [diff] [blame] | 513 | set(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 Clayton | fb07fa9 | 2023-11-17 18:48:59 +0000 | [diff] [blame] | 515 | set(TINT_ROOT_SOURCE_DIR ${PROJECT_SOURCE_DIR}) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 516 | set(TINT_SPIRV_HEADERS_DIR ${DAWN_SPIRV_HEADERS_DIR}) |
| 517 | set(TINT_SPIRV_TOOLS_DIR ${DAWN_SPIRV_TOOLS_DIR}) |
Ben Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 518 | |
Antonio Maiorano | d600972 | 2021-03-17 13:32:54 +0000 | [diff] [blame] | 519 | # 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 |
| 521 | if (MSVC) |
Vasyl Teliman | 0b3611b | 2021-06-24 18:10:46 +0000 | [diff] [blame] | 522 | if (CMAKE_CXX_FLAGS MATCHES "/W3") |
| 523 | string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 524 | endif() |
Antonio Maiorano | d600972 | 2021-03-17 13:32:54 +0000 | [diff] [blame] | 525 | endif() |
| 526 | |
Ryan Harrison | 563d3e9 | 2020-04-28 19:27:38 +0000 | [diff] [blame] | 527 | if (${TINT_CHECK_CHROMIUM_STYLE}) |
| 528 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -add-plugin -Xclang find-bad-constructs") |
| 529 | endif() |
| 530 | |
Antonio Maiorano | 88d3d2e | 2021-03-23 20:51:09 +0000 | [diff] [blame] | 531 | if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")) |
| 532 | set(COMPILER_IS_CLANG_CL TRUE) |
| 533 | endif() |
| 534 | |
Ben Clayton | 78e4530 | 2023-01-26 15:57:27 +0000 | [diff] [blame] | 535 | if((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR |
Antonio Maiorano | 88d3d2e | 2021-03-23 20:51:09 +0000 | [diff] [blame] | 536 | ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND |
| 537 | (NOT COMPILER_IS_CLANG_CL))) |
Ben Clayton | 78e4530 | 2023-01-26 15:57:27 +0000 | [diff] [blame] | 538 | set(COMPILER_IS_CLANG TRUE) |
| 539 | endif() |
| 540 | |
Ben Clayton | 7d95661 | 2023-10-03 10:14:55 +0000 | [diff] [blame] | 541 | if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 542 | set(COMPILER_IS_GNU TRUE) |
| 543 | endif() |
| 544 | |
Ben Clayton | 78e4530 | 2023-01-26 15:57:27 +0000 | [diff] [blame] | 545 | if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR COMPILER_IS_CLANG) |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 546 | set(COMPILER_IS_LIKE_GNU TRUE) |
| 547 | endif() |
| 548 | |
Antonio Maiorano | 88d3d2e | 2021-03-23 20:51:09 +0000 | [diff] [blame] | 549 | # Enable msbuild multiprocessor builds |
| 550 | if (MSVC AND NOT COMPILER_IS_CLANG_CL) |
| 551 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") |
| 552 | endif() |
| 553 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 554 | ################################################################################ |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 555 | # Run on all subdirectories |
| 556 | ################################################################################ |
Austin Eng | 01f1335 | 2023-11-30 19:52:59 +0000 | [diff] [blame] | 557 | if (EXISTS "${DAWN_PROTOBUF_DIR}/cmake") |
Ben Clayton | 01fa7c8 | 2024-01-31 21:07:17 +0000 | [diff] [blame] | 558 | if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND WIN32) |
| 559 | set(protobuf_HAVE_BUILTIN_ATOMICS 1) |
| 560 | endif() |
| 561 | |
Ben Clayton | fb07fa9 | 2023-11-17 18:48:59 +0000 | [diff] [blame] | 562 | # Needs to come before SPIR-V Tools |
| 563 | include("third_party/protobuf.cmake") |
| 564 | endif() |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 565 | |
| 566 | add_subdirectory(third_party) |
James Price | 8d9adb0 | 2022-05-22 00:41:53 +0000 | [diff] [blame] | 567 | |
| 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. |
| 570 | set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS}) |
| 571 | set(BUILD_SHARED_LIBS 0) |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 572 | add_subdirectory(src/tint) |
James Price | 8d9adb0 | 2022-05-22 00:41:53 +0000 | [diff] [blame] | 573 | set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED}) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 574 | add_subdirectory(generator) |
| 575 | add_subdirectory(src/dawn) |
Ben Clayton | 7b77855 | 2022-02-04 18:59:15 +0000 | [diff] [blame] | 576 | |
| 577 | ################################################################################ |
| 578 | # Samples |
| 579 | ################################################################################ |
dan sinclair | b595052 | 2020-03-19 13:03:35 +0000 | [diff] [blame] | 580 | add_custom_target(tint-lint |
| 581 | COMMAND ./tools/lint |
Ben Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 582 | WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR} |
dan sinclair | b595052 | 2020-03-19 13:03:35 +0000 | [diff] [blame] | 583 | COMMENT "Running linter" |
| 584 | VERBATIM) |
| 585 | |
| 586 | add_custom_target(tint-format |
| 587 | COMMAND ./tools/format |
Ben Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 588 | WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR} |
dan sinclair | b595052 | 2020-03-19 13:03:35 +0000 | [diff] [blame] | 589 | COMMENT "Running formatter" |
| 590 | VERBATIM) |
Ben Clayton | adb10d6 | 2020-10-27 21:04:59 +0000 | [diff] [blame] | 591 | |
Ben Clayton | 78e4530 | 2023-01-26 15:57:27 +0000 | [diff] [blame] | 592 | if (DAWN_EMIT_COVERAGE) |
| 593 | add_subdirectory(tools/src/cmd/turbo-cov) |
Ben Clayton | adb10d6 | 2020-10-27 21:04:59 +0000 | [diff] [blame] | 594 | |
Ben Clayton | 78e4530 | 2023-01-26 15:57:27 +0000 | [diff] [blame] | 595 | # 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 Clayton | adb10d6 | 2020-10-27 21:04:59 +0000 | [diff] [blame] | 597 | # 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 Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 604 | WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR} |
Ben Clayton | adb10d6 | 2020-10-27 21:04:59 +0000 | [diff] [blame] | 605 | COMMENT "Generating tint coverage data" |
| 606 | VERBATIM) |
| 607 | endif() |