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 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 28 | cmake_minimum_required(VERSION 3.10.2) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 29 | |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 30 | # When upgrading to CMake 3.11 we can remove DAWN_PLACEHOLDER_FILE because source-less add_library |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 31 | # becomes available. |
| 32 | # When upgrading to CMake 3.12 we should add CONFIGURE_DEPENDS to DawnGenerator to rerun CMake in |
Corentin Wallez | 42450c6 | 2020-04-10 17:04:31 +0000 | [diff] [blame] | 33 | # case any of the generator files changes. We should also remove the CACHE "" FORCE stuff to |
dan sinclair | 1877c27 | 2020-10-20 19:46:21 +0000 | [diff] [blame] | 34 | # 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 Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 36 | |
| 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 |
| 41 | ) |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 42 | enable_testing() |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 43 | |
| 44 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 45 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 46 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) |
| 47 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
dan sinclair | 05d278e | 2023-08-30 21:05:31 +0000 | [diff] [blame] | 48 | set(CMAKE_CXX_STANDARD 17) |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 49 | set(CMAKE_DEBUG_POSTFIX "") |
| 50 | |
| 51 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "") |
| 52 | message(STATUS "No build type selected, default to Debug") |
| 53 | set(CMAKE_BUILD_TYPE "Debug") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 54 | endif() |
| 55 | |
| 56 | set(DAWN_BUILD_GEN_DIR "${Dawn_BINARY_DIR}/gen") |
| 57 | set(DAWN_GENERATOR_DIR "${Dawn_SOURCE_DIR}/generator") |
| 58 | set(DAWN_SRC_DIR "${Dawn_SOURCE_DIR}/src") |
Ben Clayton | 9fb7a51 | 2022-02-04 18:18:18 +0000 | [diff] [blame] | 59 | set(DAWN_INCLUDE_DIR "${Dawn_SOURCE_DIR}/include") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 60 | set(DAWN_TEMPLATE_DIR "${DAWN_GENERATOR_DIR}/templates") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 61 | |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 62 | set(DAWN_PLACEHOLDER_FILE "${DAWN_SRC_DIR}/Placeholder.cpp") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 63 | |
| 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}) |
AlexVestin | 5c3645c | 2023-10-18 14:08:26 +0000 | [diff] [blame] | 198 | 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] | 199 | |
Ben Clayton | a675075 | 2022-02-04 18:35:55 +0000 | [diff] [blame] | 200 | 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] | 201 | 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] | 202 | 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] | 203 | option_if_not_defined(DAWN_BUILD_BENCHMARKS "Build Dawn benchmarks" OFF) |
Ben Clayton | affb7a3 | 2021-09-28 11:14:42 +0000 | [diff] [blame] | 204 | |
| 205 | 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] | 206 | |
Ben Clayton | e38993f | 2022-12-10 00:15:57 +0000 | [diff] [blame] | 207 | option_if_not_defined(DAWN_EMIT_COVERAGE "Emit code coverage information" OFF) |
Ben Clayton | f927bcb | 2022-12-12 21:21:54 +0000 | [diff] [blame] | 208 | 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] | 209 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 210 | if (DAWN_ENABLE_OPENGLES OR DAWN_ENABLE_DESKTOP_GL) |
| 211 | set(TINT_DEFAULT_GLSL ON) |
| 212 | else() |
| 213 | set(TINT_DEFAULT_GLSL OFF) |
| 214 | endif() |
| 215 | |
munoza | c511ffb | 2023-09-25 14:01:03 +0000 | [diff] [blame] | 216 | 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] | 217 | 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] | 218 | option_if_not_defined(TINT_BUILD_DOCS "Build documentation" ON) |
| 219 | option_if_not_defined(TINT_DOCS_WARN_AS_ERROR "When building documentation, treat warnings as errors" OFF) |
| 220 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 221 | 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] | 222 | message(SEND_ERROR "Dawn samples require GLFW") |
| 223 | endif() |
| 224 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 225 | option_if_not_defined(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" ${DAWN_ENABLE_VULKAN}) |
| 226 | option_if_not_defined(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON) |
| 227 | 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] | 228 | 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] | 229 | option_if_not_defined(TINT_BUILD_HLSL_WRITER "Build the HLSL output writer" ${DAWN_ENABLE_D3D12}) |
| 230 | option_if_not_defined(TINT_BUILD_MSL_WRITER "Build the MSL output writer" ${DAWN_ENABLE_METAL}) |
| 231 | option_if_not_defined(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ${DAWN_ENABLE_VULKAN}) |
| 232 | option_if_not_defined(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON) |
| 233 | |
dan sinclair | 0917fbb | 2023-03-07 18:28:38 +0000 | [diff] [blame] | 234 | 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] | 235 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 236 | option_if_not_defined(TINT_BUILD_FUZZERS "Build fuzzers" OFF) |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 237 | option_if_not_defined(TINT_BUILD_AST_FUZZER "Build AST fuzzer" OFF) |
| 238 | option_if_not_defined(TINT_BUILD_REGEX_FUZZER "Build regex fuzzer" OFF) |
Austin Eng | 6a7bba5 | 2023-04-17 18:11:51 +0000 | [diff] [blame] | 239 | option_if_not_defined(TINT_BUILD_BENCHMARKS "Build Tint benchmarks" OFF) |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 240 | option_if_not_defined(TINT_BUILD_TESTS "Build tests" ON) |
| 241 | 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] | 242 | |
Ben Clayton | 8fc9b86 | 2023-04-19 15:03:19 +0000 | [diff] [blame] | 243 | set_if_not_defined(TINT_EXTERNAL_BENCHMARK_CORPUS_DIR "" "Directory that holds a corpus of external shaders to benchmark.") |
| 244 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 245 | 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] | 246 | 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] | 247 | 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] | 248 | |
Brandon Jones | a04663c | 2021-09-23 20:36:03 +0000 | [diff] [blame] | 249 | # Recommended setting for compability with future abseil releases. |
| 250 | set(ABSL_PROPAGATE_CXX_STD ON) |
Brandon Jones | a04663c | 2021-09-23 20:36:03 +0000 | [diff] [blame] | 251 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 252 | 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] | 253 | set_if_not_defined(DAWN_VULKAN_DEPS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps" "Directory in which to find vulkan-deps") |
| 254 | |
Ben Clayton | 30eeac7 | 2021-09-24 10:38:18 +0000 | [diff] [blame] | 255 | set_if_not_defined(DAWN_ABSEIL_DIR "${DAWN_THIRD_PARTY_DIR}/abseil-cpp" "Directory in which to find Abseil") |
| 256 | 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] | 257 | set_if_not_defined(DAWN_JINJA2_DIR "${DAWN_THIRD_PARTY_DIR}/jinja2" "Directory in which to find Jinja2") |
dan sinclair | 6b67a90 | 2023-04-07 07:52:36 +0000 | [diff] [blame] | 258 | set_if_not_defined(DAWN_MARKUPSAFE_DIR "${DAWN_THIRD_PARTY_DIR}/markupsafe" "Directory in which to find MarkupSafe") |
Stephen White | 9434949 | 2022-06-29 15:29:41 +0000 | [diff] [blame] | 259 | 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] | 260 | set_if_not_defined(DAWN_SWIFTSHADER_DIR "${DAWN_THIRD_PARTY_DIR}/swiftshader" "Directory in which to find swiftshader") |
dan sinclair | c1f6dbd | 2023-04-11 15:45:18 +0000 | [diff] [blame] | 261 | |
| 262 | set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_VULKAN_DEPS_DIR}/spirv-tools/src" "Directory in which to find SPIRV-Tools") |
| 263 | 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] | 264 | 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] | 265 | 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] | 266 | |
Ben Clayton | affb7a3 | 2021-09-28 11:14:42 +0000 | [diff] [blame] | 267 | # Dependencies for DAWN_BUILD_NODE_BINDINGS |
| 268 | 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] | 269 | 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] | 270 | 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] | 271 | 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] | 272 | |
Elie Michel | 9ae8ed2 | 2023-05-12 20:19:41 +0000 | [diff] [blame] | 273 | option_if_not_defined(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" OFF) |
| 274 | |
Sergey Karchevsky | 3a75b1c | 2021-06-30 15:06:43 +0000 | [diff] [blame] | 275 | # Much of the backend code is shared among desktop OpenGL and OpenGL ES |
| 276 | if (${DAWN_ENABLE_DESKTOP_GL} OR ${DAWN_ENABLE_OPENGLES}) |
| 277 | set(DAWN_ENABLE_OPENGL ON) |
| 278 | endif() |
| 279 | |
Ben Clayton | affb7a3 | 2021-09-28 11:14:42 +0000 | [diff] [blame] | 280 | if(DAWN_ENABLE_PIC) |
| 281 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 282 | endif() |
| 283 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 284 | if (${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) |
| 300 | endif() |
| 301 | |
| 302 | if (${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) |
| 318 | endif() |
| 319 | |
Peng Huang | 5c2f167 | 2023-05-01 23:05:42 +0000 | [diff] [blame] | 320 | message(STATUS "Dawn build D3D11 backend: ${DAWN_ENABLE_D3D11}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 321 | message(STATUS "Dawn build D3D12 backend: ${DAWN_ENABLE_D3D12}") |
| 322 | message(STATUS "Dawn build Metal backend: ${DAWN_ENABLE_METAL}") |
| 323 | message(STATUS "Dawn build Vulkan backend: ${DAWN_ENABLE_VULKAN}") |
| 324 | message(STATUS "Dawn build OpenGL backend: ${DAWN_ENABLE_DESKTOP_GL}") |
| 325 | message(STATUS "Dawn build OpenGL ES backend: ${DAWN_ENABLE_OPENGLES}") |
| 326 | message(STATUS "Dawn build Null backend: ${DAWN_ENABLE_NULL}") |
| 327 | |
| 328 | message(STATUS "Dawn build with asserts in all configurations: ${DAWN_ALWAYS_ASSERT}") |
| 329 | message(STATUS "Dawn build Wayland support: ${DAWN_USE_WAYLAND}") |
| 330 | message(STATUS "Dawn build X11 support: ${DAWN_USE_X11}") |
AlexVestin | 5c3645c | 2023-10-18 14:08:26 +0000 | [diff] [blame] | 331 | message(STATUS "Dawn build GLFW support: ${DAWN_USE_GLFW}") |
Stephen Gutekanst | 5562370 | 2023-07-01 11:43:55 +0000 | [diff] [blame] | 332 | message(STATUS "Dawn build Windows UI support: ${DAWN_USE_WINDOWS_UI}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 333 | |
| 334 | message(STATUS "Dawn build samples: ${DAWN_BUILD_SAMPLES}") |
| 335 | message(STATUS "Dawn build Node bindings: ${DAWN_BUILD_NODE_BINDINGS}") |
| 336 | message(STATUS "Dawn build Swiftshader: ${DAWN_ENABLE_SWIFTSHADER}") |
Austin Eng | 6a7bba5 | 2023-04-17 18:11:51 +0000 | [diff] [blame] | 337 | message(STATUS "Dawn build benchmarks: ${DAWN_BUILD_BENCHMARKS}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 338 | |
| 339 | message(STATUS "Dawn build PIC: ${DAWN_ENABLE_PIC}") |
| 340 | |
| 341 | message(STATUS "Dawn build with ASAN: ${DAWN_ENABLE_ASAN}") |
Ben Clayton | d0ccb1a | 2022-08-19 21:33:01 +0000 | [diff] [blame] | 342 | message(STATUS "Dawn build with TSAN: ${DAWN_ENABLE_TSAN}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 343 | message(STATUS "Dawn build with MSAN: ${DAWN_ENABLE_MSAN}") |
| 344 | message(STATUS "Dawn build with UBSAN: ${DAWN_ENABLE_UBSAN}") |
| 345 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 346 | message(STATUS "Tint build command line executable tools: ${TINT_BUILD_CMD_TOOLS}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 347 | message(STATUS "Tint build docs: ${TINT_BUILD_DOCS}") |
| 348 | message(STATUS "Tint build docs with warn as error: ${TINT_DOCS_WARN_AS_ERROR}") |
| 349 | message(STATUS "Tint build SPIR-V reader: ${TINT_BUILD_SPV_READER}") |
| 350 | message(STATUS "Tint build WGSL reader: ${TINT_BUILD_WGSL_READER}") |
| 351 | message(STATUS "Tint build GLSL writer: ${TINT_BUILD_GLSL_WRITER}") |
Ben Clayton | f1b8a01 | 2023-10-11 17:15:52 +0000 | [diff] [blame] | 352 | message(STATUS "Tint build GLSL validator: ${TINT_BUILD_GLSL_VALIDATOR}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 353 | message(STATUS "Tint build HLSL writer: ${TINT_BUILD_HLSL_WRITER}") |
| 354 | message(STATUS "Tint build MSL writer: ${TINT_BUILD_MSL_WRITER}") |
| 355 | message(STATUS "Tint build SPIR-V writer: ${TINT_BUILD_SPV_WRITER}") |
| 356 | message(STATUS "Tint build WGSL writer: ${TINT_BUILD_WGSL_WRITER}") |
dan sinclair | 0917fbb | 2023-03-07 18:28:38 +0000 | [diff] [blame] | 357 | message(STATUS "Tint build Syntax Tree writer: ${TINT_BUILD_SYNTAX_TREE_WRITER}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 358 | message(STATUS "Tint build fuzzers: ${TINT_BUILD_FUZZERS}") |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 359 | message(STATUS "Tint build AST fuzzer: ${TINT_BUILD_AST_FUZZER}") |
| 360 | message(STATUS "Tint build regex fuzzer: ${TINT_BUILD_REGEX_FUZZER}") |
| 361 | message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}") |
| 362 | message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}") |
| 363 | message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}") |
Ben Clayton | 8fc9b86 | 2023-04-19 15:03:19 +0000 | [diff] [blame] | 364 | message(STATUS "Tint external benchmark corpus dir: ${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}") |
| 365 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 366 | |
| 367 | if (NOT ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS} STREQUAL "") |
| 368 | message(STATUS "Using provided LIB_FUZZING_ENGINE options: ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS}") |
| 369 | endif() |
| 370 | |
| 371 | message(STATUS "Using python3") |
| 372 | find_package(PythonInterp 3 REQUIRED) |
| 373 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 374 | ################################################################################ |
Ben Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 375 | # common_compile_options - sets compiler and linker options common for dawn and |
| 376 | # tint on the given target |
| 377 | ################################################################################ |
| 378 | function(common_compile_options TARGET) |
| 379 | if (COMPILER_IS_LIKE_GNU) |
| 380 | target_compile_options(${TARGET} PRIVATE |
| 381 | -fno-exceptions |
| 382 | -fno-rtti |
dan sinclair | cf2456b | 2023-01-07 23:09:14 +0000 | [diff] [blame] | 383 | |
| 384 | -Wno-deprecated-builtins |
dan sinclair | 07c32cb | 2023-01-09 15:10:33 +0000 | [diff] [blame] | 385 | -Wno-unknown-warning-option |
Ben Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 386 | ) |
| 387 | |
| 388 | if (${DAWN_ENABLE_MSAN}) |
Ben Clayton | d0ccb1a | 2022-08-19 21:33:01 +0000 | [diff] [blame] | 389 | target_compile_options(${TARGET} PUBLIC -fsanitize=memory) |
| 390 | target_link_options(${TARGET} PUBLIC -fsanitize=memory) |
Ben Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 391 | elseif (${DAWN_ENABLE_ASAN}) |
Ben Clayton | d0ccb1a | 2022-08-19 21:33:01 +0000 | [diff] [blame] | 392 | 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 Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 397 | elseif (${DAWN_ENABLE_UBSAN}) |
Antonio Maiorano | deb2ec9 | 2023-03-24 18:44:02 +0000 | [diff] [blame] | 398 | 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 Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 400 | endif() |
| 401 | endif(COMPILER_IS_LIKE_GNU) |
Seto | c692720 | 2022-09-14 16:41:07 +0000 | [diff] [blame] | 402 | |
| 403 | if(MSVC) |
| 404 | target_compile_options(${TARGET} PUBLIC /utf-8) |
| 405 | endif() |
Ben Clayton | e38993f | 2022-12-10 00:15:57 +0000 | [diff] [blame] | 406 | |
| 407 | if (DAWN_EMIT_COVERAGE) |
Ben Clayton | 54264d3 | 2023-01-10 21:55:43 +0000 | [diff] [blame] | 408 | target_compile_definitions(${TARGET} PRIVATE "DAWN_EMIT_COVERAGE") |
Ben Clayton | e38993f | 2022-12-10 00:15:57 +0000 | [diff] [blame] | 409 | if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") |
| 410 | target_compile_options(${TARGET} PRIVATE "--coverage") |
| 411 | target_link_options(${TARGET} PRIVATE "gcov") |
Ben Clayton | 78e4530 | 2023-01-26 15:57:27 +0000 | [diff] [blame] | 412 | elseif(COMPILER_IS_CLANG OR COMPILER_IS_CLANG_CL) |
Ben Clayton | e38993f | 2022-12-10 00:15:57 +0000 | [diff] [blame] | 413 | 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 Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 419 | endfunction() |
| 420 | |
Ben Clayton | d0ccb1a | 2022-08-19 21:33:01 +0000 | [diff] [blame] | 421 | if (${DAWN_ENABLE_TSAN}) |
| 422 | add_compile_options(-stdlib=libc++) |
| 423 | add_link_options(-stdlib=libc++) |
| 424 | endif() |
| 425 | |
Ben Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 426 | ################################################################################ |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 427 | # Dawn's public and internal "configs" |
| 428 | ################################################################################ |
| 429 | |
Ben Clayton | 9418152 | 2022-11-09 20:55:33 +0000 | [diff] [blame] | 430 | set(IS_DEBUG_BUILD 0) |
| 431 | string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type) |
| 432 | if ((NOT ${build_type} STREQUAL "RELEASE") AND (NOT ${build_type} STREQUAL "RELWITHDEBINFO")) |
| 433 | set(IS_DEBUG_BUILD 1) |
| 434 | endif() |
| 435 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 436 | # The public config contains only the include paths for the Dawn headers. |
| 437 | add_library(dawn_public_config INTERFACE) |
| 438 | target_include_directories(dawn_public_config INTERFACE |
Ben Clayton | 9fb7a51 | 2022-02-04 18:18:18 +0000 | [diff] [blame] | 439 | "${DAWN_INCLUDE_DIR}" |
| 440 | "${DAWN_BUILD_GEN_DIR}/include" |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 441 | ) |
| 442 | |
| 443 | # The internal config conatins additional path but includes the dawn_public_config include paths |
| 444 | add_library(dawn_internal_config INTERFACE) |
| 445 | target_include_directories(dawn_internal_config INTERFACE |
| 446 | "${DAWN_SRC_DIR}" |
| 447 | "${DAWN_BUILD_GEN_DIR}/src" |
| 448 | ) |
| 449 | target_link_libraries(dawn_internal_config INTERFACE dawn_public_config) |
| 450 | |
| 451 | # Compile definitions for the internal config |
Ben Clayton | 9418152 | 2022-11-09 20:55:33 +0000 | [diff] [blame] | 452 | if (DAWN_ALWAYS_ASSERT OR IS_DEBUG_BUILD) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 453 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_ASSERTS") |
| 454 | endif() |
Peng Huang | 5c2f167 | 2023-05-01 23:05:42 +0000 | [diff] [blame] | 455 | if (DAWN_ENABLE_D3D11) |
| 456 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D11") |
| 457 | endif() |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 458 | if (DAWN_ENABLE_D3D12) |
| 459 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D12") |
| 460 | endif() |
| 461 | if (DAWN_ENABLE_METAL) |
| 462 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_METAL") |
| 463 | endif() |
| 464 | if (DAWN_ENABLE_NULL) |
| 465 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_NULL") |
| 466 | endif() |
Sergey Karchevsky | 3a75b1c | 2021-06-30 15:06:43 +0000 | [diff] [blame] | 467 | if (DAWN_ENABLE_DESKTOP_GL) |
| 468 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_DESKTOP_GL") |
| 469 | endif() |
| 470 | if (DAWN_ENABLE_OPENGLES) |
| 471 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGLES") |
| 472 | endif() |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 473 | if (DAWN_ENABLE_OPENGL) |
| 474 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGL") |
| 475 | endif() |
| 476 | if (DAWN_ENABLE_VULKAN) |
| 477 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_VULKAN") |
| 478 | endif() |
Corentin Wallez | 2e22d92 | 2022-06-01 09:30:50 +0000 | [diff] [blame] | 479 | if (DAWN_USE_WAYLAND) |
| 480 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WAYLAND") |
| 481 | endif() |
Corentin Wallez | d353ca0 | 2020-02-18 02:12:35 +0000 | [diff] [blame] | 482 | if (DAWN_USE_X11) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 483 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11") |
| 484 | endif() |
Stephen Gutekanst | 5562370 | 2023-07-01 11:43:55 +0000 | [diff] [blame] | 485 | if (DAWN_USE_WINDOWS_UI) |
| 486 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WINDOWS_UI") |
| 487 | endif() |
Corentin Wallez | 3346697 | 2020-02-24 13:27:28 +0000 | [diff] [blame] | 488 | if (WIN32) |
| 489 | target_compile_definitions(dawn_internal_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN") |
| 490 | endif() |
| 491 | |
dan sinclair | 05d278e | 2023-08-30 21:05:31 +0000 | [diff] [blame] | 492 | set(CMAKE_CXX_STANDARD "17") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 493 | |
| 494 | ################################################################################ |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 495 | # Tint |
| 496 | ################################################################################ |
| 497 | |
Alastair Donaldson | 6a1eb45 | 2021-09-02 23:49:25 +0000 | [diff] [blame] | 498 | set(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 Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 500 | set(TINT_ROOT_SOURCE_DIR ${PROJECT_SOURCE_DIR}) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 501 | set(TINT_SPIRV_HEADERS_DIR ${DAWN_SPIRV_HEADERS_DIR}) |
| 502 | set(TINT_SPIRV_TOOLS_DIR ${DAWN_SPIRV_TOOLS_DIR}) |
Ben Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 503 | |
Antonio Maiorano | d600972 | 2021-03-17 13:32:54 +0000 | [diff] [blame] | 504 | # 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 |
| 506 | if (MSVC) |
Vasyl Teliman | 0b3611b | 2021-06-24 18:10:46 +0000 | [diff] [blame] | 507 | if (CMAKE_CXX_FLAGS MATCHES "/W3") |
| 508 | string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 509 | endif() |
Antonio Maiorano | d600972 | 2021-03-17 13:32:54 +0000 | [diff] [blame] | 510 | endif() |
| 511 | |
Ryan Harrison | 563d3e9 | 2020-04-28 19:27:38 +0000 | [diff] [blame] | 512 | if (${TINT_CHECK_CHROMIUM_STYLE}) |
| 513 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -add-plugin -Xclang find-bad-constructs") |
| 514 | endif() |
| 515 | |
Antonio Maiorano | 88d3d2e | 2021-03-23 20:51:09 +0000 | [diff] [blame] | 516 | if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")) |
| 517 | set(COMPILER_IS_CLANG_CL TRUE) |
| 518 | endif() |
| 519 | |
Ben Clayton | 78e4530 | 2023-01-26 15:57:27 +0000 | [diff] [blame] | 520 | if((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR |
Antonio Maiorano | 88d3d2e | 2021-03-23 20:51:09 +0000 | [diff] [blame] | 521 | ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND |
| 522 | (NOT COMPILER_IS_CLANG_CL))) |
Ben Clayton | 78e4530 | 2023-01-26 15:57:27 +0000 | [diff] [blame] | 523 | set(COMPILER_IS_CLANG TRUE) |
| 524 | endif() |
| 525 | |
Ben Clayton | 7d95661 | 2023-10-03 10:14:55 +0000 | [diff] [blame] | 526 | if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 527 | set(COMPILER_IS_GNU TRUE) |
| 528 | endif() |
| 529 | |
Ben Clayton | 78e4530 | 2023-01-26 15:57:27 +0000 | [diff] [blame] | 530 | if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR COMPILER_IS_CLANG) |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 531 | set(COMPILER_IS_LIKE_GNU TRUE) |
| 532 | endif() |
| 533 | |
Antonio Maiorano | 88d3d2e | 2021-03-23 20:51:09 +0000 | [diff] [blame] | 534 | # Enable msbuild multiprocessor builds |
| 535 | if (MSVC AND NOT COMPILER_IS_CLANG_CL) |
| 536 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") |
| 537 | endif() |
| 538 | |
David Neto | 5b46d71 | 2020-06-26 22:29:27 +0000 | [diff] [blame] | 539 | if(${TINT_BUILD_DOCS}) |
| 540 | find_package(Doxygen) |
| 541 | if(DOXYGEN_FOUND) |
Antonio Maiorano | 6241f96 | 2021-06-25 14:00:36 +0000 | [diff] [blame] | 542 | set(DOXYGEN_WARN_AS_ERROR NO) |
| 543 | if(TINT_DOCS_WARN_AS_ERROR) |
| 544 | set(DOXYGEN_WARN_AS_ERROR YES) |
| 545 | endif() |
Antonio Maiorano | e25a8fc | 2021-06-25 14:53:06 +0000 | [diff] [blame] | 546 | |
| 547 | set(DOXYGEN_WARN_FORMAT "$file:$line: $text") |
| 548 | if (MSVC) |
| 549 | set(DOXYGEN_WARN_FORMAT "$file($line): $text") |
| 550 | endif() |
| 551 | |
David Neto | 5b46d71 | 2020-06-26 22:29:27 +0000 | [diff] [blame] | 552 | add_custom_target(tint-docs ALL |
Ben Clayton | 4ace822 | 2021-05-12 08:15:41 +0000 | [diff] [blame] | 553 | COMMAND ${CMAKE_COMMAND} |
Antonio Maiorano | 6241f96 | 2021-06-25 14:00:36 +0000 | [diff] [blame] | 554 | -E env |
| 555 | "DOXYGEN_OUTPUT_DIRECTORY=${CMAKE_BINARY_DIR}/docs" |
| 556 | "DOXYGEN_WARN_AS_ERROR=${DOXYGEN_WARN_AS_ERROR}" |
Antonio Maiorano | e25a8fc | 2021-06-25 14:53:06 +0000 | [diff] [blame] | 557 | "DOXYGEN_WARN_FORMAT=${DOXYGEN_WARN_FORMAT}" |
Ben Clayton | 4ace822 | 2021-05-12 08:15:41 +0000 | [diff] [blame] | 558 | ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile |
David Neto | 5b46d71 | 2020-06-26 22:29:27 +0000 | [diff] [blame] | 559 | 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 sinclair | b0391c6f | 2020-07-15 20:54:48 +0000 | [diff] [blame] | 565 | endif() |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 566 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 567 | ################################################################################ |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 568 | # Run on all subdirectories |
| 569 | ################################################################################ |
| 570 | |
| 571 | add_subdirectory(third_party) |
James Price | 8d9adb0 | 2022-05-22 00:41:53 +0000 | [diff] [blame] | 572 | |
| 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. |
| 575 | set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS}) |
| 576 | set(BUILD_SHARED_LIBS 0) |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 577 | add_subdirectory(src/tint) |
James Price | 8d9adb0 | 2022-05-22 00:41:53 +0000 | [diff] [blame] | 578 | set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED}) |
| 579 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 580 | add_subdirectory(generator) |
| 581 | add_subdirectory(src/dawn) |
Ben Clayton | 7b77855 | 2022-02-04 18:59:15 +0000 | [diff] [blame] | 582 | |
| 583 | ################################################################################ |
| 584 | # Samples |
| 585 | ################################################################################ |
dan sinclair | b595052 | 2020-03-19 13:03:35 +0000 | [diff] [blame] | 586 | add_custom_target(tint-lint |
| 587 | COMMAND ./tools/lint |
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 linter" |
| 590 | VERBATIM) |
| 591 | |
| 592 | add_custom_target(tint-format |
| 593 | COMMAND ./tools/format |
Ben Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 594 | WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR} |
dan sinclair | b595052 | 2020-03-19 13:03:35 +0000 | [diff] [blame] | 595 | COMMENT "Running formatter" |
| 596 | VERBATIM) |
Ben Clayton | adb10d6 | 2020-10-27 21:04:59 +0000 | [diff] [blame] | 597 | |
Ben Clayton | 78e4530 | 2023-01-26 15:57:27 +0000 | [diff] [blame] | 598 | if (DAWN_EMIT_COVERAGE) |
| 599 | add_subdirectory(tools/src/cmd/turbo-cov) |
Ben Clayton | adb10d6 | 2020-10-27 21:04:59 +0000 | [diff] [blame] | 600 | |
Ben Clayton | 78e4530 | 2023-01-26 15:57:27 +0000 | [diff] [blame] | 601 | # 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 Clayton | adb10d6 | 2020-10-27 21:04:59 +0000 | [diff] [blame] | 603 | # 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 Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 610 | WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR} |
Ben Clayton | adb10d6 | 2020-10-27 21:04:59 +0000 | [diff] [blame] | 611 | COMMENT "Generating tint coverage data" |
| 612 | VERBATIM) |
| 613 | endif() |
Ben Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 614 | |