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 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 15 | cmake_minimum_required(VERSION 3.10.2) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 16 | |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 17 | # 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] | 18 | # becomes available. |
| 19 | # 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] | 20 | # 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] | 21 | # override options in third_party dependencies. We can also add the HOMEPAGE_URL |
| 22 | # entry to the project `HOMEPAGE_URL "https://dawn.googlesource.com/dawn"` |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 23 | |
| 24 | project( |
| 25 | Dawn |
| 26 | DESCRIPTION "Dawn, a WebGPU implementation" |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 27 | LANGUAGES C CXX |
| 28 | ) |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 29 | enable_testing() |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 30 | |
| 31 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 32 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 33 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) |
| 34 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
Ben Clayton | 7b0686a | 2022-01-06 09:23:11 +0000 | [diff] [blame] | 35 | set(CMAKE_CXX_STANDARD 17) |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 36 | set(CMAKE_DEBUG_POSTFIX "") |
| 37 | |
| 38 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "") |
| 39 | message(STATUS "No build type selected, default to Debug") |
| 40 | set(CMAKE_BUILD_TYPE "Debug") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 41 | endif() |
| 42 | |
| 43 | set(DAWN_BUILD_GEN_DIR "${Dawn_BINARY_DIR}/gen") |
| 44 | set(DAWN_GENERATOR_DIR "${Dawn_SOURCE_DIR}/generator") |
| 45 | set(DAWN_SRC_DIR "${Dawn_SOURCE_DIR}/src") |
Ben Clayton | 9fb7a51 | 2022-02-04 18:18:18 +0000 | [diff] [blame] | 46 | set(DAWN_INCLUDE_DIR "${Dawn_SOURCE_DIR}/include") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 47 | set(DAWN_TEMPLATE_DIR "${DAWN_GENERATOR_DIR}/templates") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 48 | |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 49 | set(DAWN_PLACEHOLDER_FILE "${DAWN_SRC_DIR}/Placeholder.cpp") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 50 | |
| 51 | ################################################################################ |
| 52 | # Configuration options |
| 53 | ################################################################################ |
| 54 | |
Ben Clayton | 30eeac7 | 2021-09-24 10:38:18 +0000 | [diff] [blame] | 55 | # option_if_not_defined(name description default) |
| 56 | # Behaves like: |
| 57 | # option(name description default) |
| 58 | # If a variable is not already defined with the given name, otherwise the |
| 59 | # function does nothing. |
| 60 | # Simplifies customization by projects that use Dawn as a dependency. |
| 61 | function (option_if_not_defined name description default) |
| 62 | if(NOT DEFINED ${name}) |
| 63 | option(${name} ${description} ${default}) |
| 64 | endif() |
| 65 | endfunction() |
| 66 | |
| 67 | # set_if_not_defined(name value description) |
| 68 | # Behaves like: |
| 69 | # set(${name} ${value} CACHE STRING ${description}) |
| 70 | # If a variable is not already defined with the given name, otherwise the |
| 71 | # function does nothing. |
| 72 | # Simplifies customization by projects that use Dawn as a dependency. |
| 73 | function (set_if_not_defined name value description) |
| 74 | if(NOT DEFINED ${name}) |
| 75 | set(${name} ${value} CACHE STRING ${description}) |
| 76 | endif() |
| 77 | endfunction() |
| 78 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 79 | # Default values for the backend-enabling options |
| 80 | set(ENABLE_D3D12 OFF) |
| 81 | set(ENABLE_METAL OFF) |
Sergey Karchevsky | 3a75b1c | 2021-06-30 15:06:43 +0000 | [diff] [blame] | 82 | set(ENABLE_OPENGLES OFF) |
| 83 | set(ENABLE_DESKTOP_GL OFF) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 84 | set(ENABLE_VULKAN OFF) |
Corentin Wallez | 2e22d92 | 2022-06-01 09:30:50 +0000 | [diff] [blame] | 85 | set(USE_WAYLAND OFF) |
Corentin Wallez | d353ca0 | 2020-02-18 02:12:35 +0000 | [diff] [blame] | 86 | set(USE_X11 OFF) |
Ben Clayton | a675075 | 2022-02-04 18:35:55 +0000 | [diff] [blame] | 87 | set(BUILD_SAMPLES OFF) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 88 | if (WIN32) |
| 89 | set(ENABLE_D3D12 ON) |
陈俊嘉 | 610de1d | 2021-06-28 08:19:28 +0000 | [diff] [blame] | 90 | if (NOT WINDOWS_STORE) |
陈俊嘉 | b2bc57a | 2021-06-24 07:00:16 +0000 | [diff] [blame] | 91 | # Enable Vulkan in win32 compilation only |
| 92 | # since UWP only supports d3d |
| 93 | set(ENABLE_VULKAN ON) |
| 94 | endif() |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 95 | elseif(APPLE) |
| 96 | set(ENABLE_METAL ON) |
Alexander Vestin | f2556ab | 2022-03-25 13:18:46 +0000 | [diff] [blame] | 97 | elseif(ANDROID) |
| 98 | set(ENABLE_VULKAN ON) |
| 99 | set(ENABLE_OPENGLES ON) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 100 | elseif(UNIX) |
Sergey Karchevsky | 3a75b1c | 2021-06-30 15:06:43 +0000 | [diff] [blame] | 101 | set(ENABLE_OPENGLES ON) |
| 102 | set(ENABLE_DESKTOP_GL ON) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 103 | set(ENABLE_VULKAN ON) |
Corentin Wallez | d353ca0 | 2020-02-18 02:12:35 +0000 | [diff] [blame] | 104 | set(USE_X11 ON) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 105 | endif() |
| 106 | |
陈俊嘉 | b2bc57a | 2021-06-24 07:00:16 +0000 | [diff] [blame] | 107 | # GLFW is not supported in UWP |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 108 | if ((WIN32 AND NOT WINDOWS_STORE) OR UNIX AND NOT ANDROID) |
陈俊嘉 | b2bc57a | 2021-06-24 07:00:16 +0000 | [diff] [blame] | 109 | set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING ON) |
| 110 | endif() |
| 111 | |
| 112 | # Current examples are depend on GLFW |
| 113 | if (DAWN_SUPPORTS_GLFW_FOR_WINDOWING) |
Ben Clayton | a675075 | 2022-02-04 18:35:55 +0000 | [diff] [blame] | 114 | set(BUILD_SAMPLES ON) |
陈俊嘉 | b2bc57a | 2021-06-24 07:00:16 +0000 | [diff] [blame] | 115 | endif() |
| 116 | |
Ben Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 117 | option_if_not_defined(DAWN_ENABLE_MSAN "Enable memory sanitizer" OFF) |
| 118 | option_if_not_defined(DAWN_ENABLE_ASAN "Enable address sanitizer" OFF) |
| 119 | option_if_not_defined(DAWN_ENABLE_UBSAN "Enable undefined behaviour sanitizer" OFF) |
| 120 | |
Ben Clayton | 30eeac7 | 2021-09-24 10:38:18 +0000 | [diff] [blame] | 121 | option_if_not_defined(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12}) |
| 122 | option_if_not_defined(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL}) |
| 123 | option_if_not_defined(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON) |
| 124 | option_if_not_defined(DAWN_ENABLE_DESKTOP_GL "Enable compilation of the OpenGL backend" ${ENABLE_DESKTOP_GL}) |
| 125 | option_if_not_defined(DAWN_ENABLE_OPENGLES "Enable compilation of the OpenGL ES backend" ${ENABLE_OPENGLES}) |
| 126 | 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] | 127 | |
Ben Clayton | 30eeac7 | 2021-09-24 10:38:18 +0000 | [diff] [blame] | 128 | 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] | 129 | 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] | 130 | option_if_not_defined(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11}) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 131 | |
Ben Clayton | a675075 | 2022-02-04 18:35:55 +0000 | [diff] [blame] | 132 | 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] | 133 | 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] | 134 | option_if_not_defined(DAWN_ENABLE_SWIFTSHADER "Enables building Swiftshader as part of the build and Vulkan adapter discovery" OFF) |
Ben Clayton | affb7a3 | 2021-09-28 11:14:42 +0000 | [diff] [blame] | 135 | |
| 136 | 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] | 137 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 138 | if (DAWN_ENABLE_OPENGLES OR DAWN_ENABLE_DESKTOP_GL) |
| 139 | set(TINT_DEFAULT_GLSL ON) |
| 140 | else() |
| 141 | set(TINT_DEFAULT_GLSL OFF) |
| 142 | endif() |
| 143 | |
| 144 | option_if_not_defined(TINT_BUILD_SAMPLES "Build samples" ${DAWN_BUILD_SAMPLES}) |
| 145 | option_if_not_defined(TINT_BUILD_DOCS "Build documentation" ON) |
| 146 | option_if_not_defined(TINT_DOCS_WARN_AS_ERROR "When building documentation, treat warnings as errors" OFF) |
| 147 | |
| 148 | option_if_not_defined(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" ${DAWN_ENABLE_VULKAN}) |
| 149 | option_if_not_defined(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON) |
| 150 | option_if_not_defined(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" ${TINT_DEFAULT_GLSL}) |
| 151 | option_if_not_defined(TINT_BUILD_HLSL_WRITER "Build the HLSL output writer" ${DAWN_ENABLE_D3D12}) |
| 152 | option_if_not_defined(TINT_BUILD_MSL_WRITER "Build the MSL output writer" ${DAWN_ENABLE_METAL}) |
| 153 | option_if_not_defined(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ${DAWN_ENABLE_VULKAN}) |
| 154 | option_if_not_defined(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON) |
| 155 | |
| 156 | option_if_not_defined(TINT_BUILD_FUZZERS "Build fuzzers" OFF) |
| 157 | option_if_not_defined(TINT_BUILD_SPIRV_TOOLS_FUZZER "Build SPIRV-Tools fuzzer" OFF) |
| 158 | option_if_not_defined(TINT_BUILD_AST_FUZZER "Build AST fuzzer" OFF) |
| 159 | option_if_not_defined(TINT_BUILD_REGEX_FUZZER "Build regex fuzzer" OFF) |
| 160 | option_if_not_defined(TINT_BUILD_BENCHMARKS "Build benchmarks" OFF) |
| 161 | option_if_not_defined(TINT_BUILD_TESTS "Build tests" ON) |
| 162 | option_if_not_defined(TINT_BUILD_AS_OTHER_OS "Override OS detection to force building of *_other.cc files" OFF) |
| 163 | option_if_not_defined(TINT_BUILD_REMOTE_COMPILE "Build the remote-compile tool for validating shaders on a remote machine" OFF) |
| 164 | |
| 165 | option_if_not_defined(TINT_ENABLE_BREAK_IN_DEBUGGER "Enable tint::debugger::Break()" OFF) |
| 166 | option_if_not_defined(TINT_EMIT_COVERAGE "Emit code coverage information" OFF) |
| 167 | option_if_not_defined(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF) |
| 168 | option_if_not_defined(TINT_SYMBOL_STORE_DEBUG_NAME "Enable storing of name in tint::ast::Symbol to help debugging the AST" OFF) |
Corentin Wallez | e557087 | 2020-10-20 14:26:10 +0000 | [diff] [blame] | 169 | |
Brandon Jones | a04663c | 2021-09-23 20:36:03 +0000 | [diff] [blame] | 170 | # Recommended setting for compability with future abseil releases. |
| 171 | set(ABSL_PROPAGATE_CXX_STD ON) |
Brandon Jones | a04663c | 2021-09-23 20:36:03 +0000 | [diff] [blame] | 172 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 173 | set_if_not_defined(DAWN_THIRD_PARTY_DIR "${Dawn_SOURCE_DIR}/third_party" "Directory in which to find third-party dependencies.") |
Ben Clayton | 30eeac7 | 2021-09-24 10:38:18 +0000 | [diff] [blame] | 174 | set_if_not_defined(DAWN_ABSEIL_DIR "${DAWN_THIRD_PARTY_DIR}/abseil-cpp" "Directory in which to find Abseil") |
| 175 | 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] | 176 | set_if_not_defined(DAWN_JINJA2_DIR "${DAWN_THIRD_PARTY_DIR}/jinja2" "Directory in which to find Jinja2") |
Stephen White | 9434949 | 2022-06-29 15:29:41 +0000 | [diff] [blame] | 177 | set_if_not_defined(DAWN_KHRONOS_DIR "${DAWN_THIRD_PARTY_DIR}/khronos" "Directory in which to find Khronos GL headers") |
Ben Clayton | 30eeac7 | 2021-09-24 10:38:18 +0000 | [diff] [blame] | 178 | set_if_not_defined(DAWN_SPIRV_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-headers/src" "Directory in which to find SPIRV-Headers") |
| 179 | set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-tools/src" "Directory in which to find SPIRV-Tools") |
Corentin Wallez | be352ea | 2022-04-11 16:48:43 +0000 | [diff] [blame] | 180 | set_if_not_defined(DAWN_SWIFTSHADER_DIR "${DAWN_THIRD_PARTY_DIR}/swiftshader" "Directory in which to find swiftshader") |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 181 | set_if_not_defined(DAWN_TINT_DIR "${Dawn_SOURCE_DIR}" "Directory in which to find Tint") |
Loko Kung | 23d09c6 | 2022-04-09 00:10:08 +0000 | [diff] [blame] | 182 | set_if_not_defined(DAWN_VULKAN_DEPS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps" "Directory in which to find vulkan-deps") |
| 183 | set_if_not_defined(DAWN_VULKAN_HEADERS_DIR "${DAWN_VULKAN_DEPS_DIR}/vulkan-headers/src" "Directory in which to find Vulkan-Headers") |
Loko Kung | 83a5d52 | 2022-04-13 19:14:46 +0000 | [diff] [blame] | 184 | set_if_not_defined(DAWN_VULKAN_TOOLS_DIR "${DAWN_VULKAN_DEPS_DIR}/vulkan-tools/src" "Directory in which to find Vulkan-Tools") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 185 | |
Ben Clayton | affb7a3 | 2021-09-28 11:14:42 +0000 | [diff] [blame] | 186 | # Dependencies for DAWN_BUILD_NODE_BINDINGS |
| 187 | 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] | 188 | 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] | 189 | 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] | 190 | 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] | 191 | |
Sergey Karchevsky | 3a75b1c | 2021-06-30 15:06:43 +0000 | [diff] [blame] | 192 | # Much of the backend code is shared among desktop OpenGL and OpenGL ES |
| 193 | if (${DAWN_ENABLE_DESKTOP_GL} OR ${DAWN_ENABLE_OPENGLES}) |
| 194 | set(DAWN_ENABLE_OPENGL ON) |
| 195 | endif() |
| 196 | |
Ben Clayton | affb7a3 | 2021-09-28 11:14:42 +0000 | [diff] [blame] | 197 | if(DAWN_ENABLE_PIC) |
| 198 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 199 | endif() |
| 200 | |
dan sinclair | 194c177 | 2022-06-21 17:54:03 +0000 | [diff] [blame] | 201 | if (${TINT_BUILD_SPIRV_TOOLS_FUZZER}) |
| 202 | message(STATUS "TINT_BUILD_SPIRV_TOOLS_FUZZER is ON - setting |
| 203 | TINT_BUILD_FUZZERS |
| 204 | TINT_BUILD_SPV_READER |
| 205 | TINT_BUILD_SPV_WRITER |
| 206 | TINT_BUILD_WGSL_READER |
| 207 | TINT_BUILD_WGSL_WRITER |
| 208 | TINT_BUILD_GLSL_WRITER |
| 209 | TINT_BUILD_HLSL_WRITER |
| 210 | TINT_BUILD_MSL_WRITER to ON") |
| 211 | set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE) |
| 212 | set(TINT_BUILD_SPV_READER ON CACHE BOOL "Build SPIR-V reader" FORCE) |
| 213 | set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE) |
| 214 | set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE) |
| 215 | set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE) |
| 216 | set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE) |
| 217 | set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE) |
| 218 | set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE) |
| 219 | endif() |
| 220 | |
| 221 | if (${TINT_BUILD_AST_FUZZER}) |
| 222 | message(STATUS "TINT_BUILD_AST_FUZZER is ON - setting |
| 223 | TINT_BUILD_FUZZERS |
| 224 | TINT_BUILD_WGSL_READER |
| 225 | TINT_BUILD_WGSL_WRITER |
| 226 | TINT_BUILD_SPV_WRITER |
| 227 | TINT_BUILD_MSL_WRITER |
| 228 | TINT_BUILD_GLSL_WRITER |
| 229 | TINT_BUILD_HLSL_WRITER to ON") |
| 230 | set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE) |
| 231 | set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE) |
| 232 | set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE) |
| 233 | set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE) |
| 234 | set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE) |
| 235 | set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build GLSL writer" FORCE) |
| 236 | set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE) |
| 237 | endif() |
| 238 | |
| 239 | if (${TINT_BUILD_REGEX_FUZZER}) |
| 240 | message(STATUS "TINT_BUILD_REGEX_FUZZER is ON - setting |
| 241 | TINT_BUILD_FUZZERS |
| 242 | TINT_BUILD_WGSL_READER |
| 243 | TINT_BUILD_WGSL_WRITER |
| 244 | TINT_BUILD_SPV_WRITER |
| 245 | TINT_BUILD_MSL_WRITER |
| 246 | TINT_BUILD_GLSL_WRITER |
| 247 | TINT_BUILD_HLSL_WRITER to ON") |
| 248 | set(TINT_BUILD_FUZZERS ON CACHE BOOL "Build tint fuzzers" FORCE) |
| 249 | set(TINT_BUILD_WGSL_READER ON CACHE BOOL "Build WGSL reader" FORCE) |
| 250 | set(TINT_BUILD_WGSL_WRITER ON CACHE BOOL "Build WGSL writer" FORCE) |
| 251 | set(TINT_BUILD_SPV_WRITER ON CACHE BOOL "Build SPIR-V writer" FORCE) |
| 252 | set(TINT_BUILD_MSL_WRITER ON CACHE BOOL "Build MSL writer" FORCE) |
| 253 | set(TINT_BUILD_GLSL_WRITER ON CACHE BOOL "Build GLSL writer" FORCE) |
| 254 | set(TINT_BUILD_HLSL_WRITER ON CACHE BOOL "Build HLSL writer" FORCE) |
| 255 | endif() |
| 256 | |
| 257 | message(STATUS "Dawn build D3D12 backend: ${DAWN_ENABLE_D3D12}") |
| 258 | message(STATUS "Dawn build Metal backend: ${DAWN_ENABLE_METAL}") |
| 259 | message(STATUS "Dawn build Vulkan backend: ${DAWN_ENABLE_VULKAN}") |
| 260 | message(STATUS "Dawn build OpenGL backend: ${DAWN_ENABLE_DESKTOP_GL}") |
| 261 | message(STATUS "Dawn build OpenGL ES backend: ${DAWN_ENABLE_OPENGLES}") |
| 262 | message(STATUS "Dawn build Null backend: ${DAWN_ENABLE_NULL}") |
| 263 | |
| 264 | message(STATUS "Dawn build with asserts in all configurations: ${DAWN_ALWAYS_ASSERT}") |
| 265 | message(STATUS "Dawn build Wayland support: ${DAWN_USE_WAYLAND}") |
| 266 | message(STATUS "Dawn build X11 support: ${DAWN_USE_X11}") |
| 267 | |
| 268 | message(STATUS "Dawn build samples: ${DAWN_BUILD_SAMPLES}") |
| 269 | message(STATUS "Dawn build Node bindings: ${DAWN_BUILD_NODE_BINDINGS}") |
| 270 | message(STATUS "Dawn build Swiftshader: ${DAWN_ENABLE_SWIFTSHADER}") |
| 271 | |
| 272 | message(STATUS "Dawn build PIC: ${DAWN_ENABLE_PIC}") |
| 273 | |
| 274 | message(STATUS "Dawn build with ASAN: ${DAWN_ENABLE_ASAN}") |
| 275 | message(STATUS "Dawn build with MSAN: ${DAWN_ENABLE_MSAN}") |
| 276 | message(STATUS "Dawn build with UBSAN: ${DAWN_ENABLE_UBSAN}") |
| 277 | |
| 278 | message(STATUS "Tint build samples: ${TINT_BUILD_SAMPLES}") |
| 279 | message(STATUS "Tint build docs: ${TINT_BUILD_DOCS}") |
| 280 | message(STATUS "Tint build docs with warn as error: ${TINT_DOCS_WARN_AS_ERROR}") |
| 281 | message(STATUS "Tint build SPIR-V reader: ${TINT_BUILD_SPV_READER}") |
| 282 | message(STATUS "Tint build WGSL reader: ${TINT_BUILD_WGSL_READER}") |
| 283 | message(STATUS "Tint build GLSL writer: ${TINT_BUILD_GLSL_WRITER}") |
| 284 | message(STATUS "Tint build HLSL writer: ${TINT_BUILD_HLSL_WRITER}") |
| 285 | message(STATUS "Tint build MSL writer: ${TINT_BUILD_MSL_WRITER}") |
| 286 | message(STATUS "Tint build SPIR-V writer: ${TINT_BUILD_SPV_WRITER}") |
| 287 | message(STATUS "Tint build WGSL writer: ${TINT_BUILD_WGSL_WRITER}") |
| 288 | message(STATUS "Tint build fuzzers: ${TINT_BUILD_FUZZERS}") |
| 289 | message(STATUS "Tint build SPIRV-Tools fuzzer: ${TINT_BUILD_SPIRV_TOOLS_FUZZER}") |
| 290 | message(STATUS "Tint build AST fuzzer: ${TINT_BUILD_AST_FUZZER}") |
| 291 | message(STATUS "Tint build regex fuzzer: ${TINT_BUILD_REGEX_FUZZER}") |
| 292 | message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}") |
| 293 | message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}") |
| 294 | message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}") |
| 295 | message(STATUS "Tint build remote-compile tool: ${TINT_BUILD_REMOTE_COMPILE}") |
| 296 | |
| 297 | if (NOT ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS} STREQUAL "") |
| 298 | message(STATUS "Using provided LIB_FUZZING_ENGINE options: ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS}") |
| 299 | endif() |
| 300 | |
| 301 | message(STATUS "Using python3") |
| 302 | find_package(PythonInterp 3 REQUIRED) |
| 303 | |
| 304 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 305 | ################################################################################ |
Ben Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 306 | # common_compile_options - sets compiler and linker options common for dawn and |
| 307 | # tint on the given target |
| 308 | ################################################################################ |
| 309 | function(common_compile_options TARGET) |
| 310 | if (COMPILER_IS_LIKE_GNU) |
| 311 | target_compile_options(${TARGET} PRIVATE |
| 312 | -fno-exceptions |
| 313 | -fno-rtti |
Corentin Wallez | 2b3dcf4 | 2022-05-16 09:16:41 +0000 | [diff] [blame] | 314 | -fvisibility-inlines-hidden |
Ben Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 315 | ) |
| 316 | |
| 317 | if (${DAWN_ENABLE_MSAN}) |
| 318 | target_compile_options(${TARGET} PRIVATE -fsanitize=memory) |
| 319 | target_link_options(${TARGET} PRIVATE -fsanitize=memory) |
| 320 | elseif (${DAWN_ENABLE_ASAN}) |
| 321 | target_compile_options(${TARGET} PRIVATE -fsanitize=address) |
| 322 | target_link_options(${TARGET} PRIVATE -fsanitize=address) |
| 323 | elseif (${DAWN_ENABLE_UBSAN}) |
| 324 | target_compile_options(${TARGET} PRIVATE -fsanitize=undefined) |
| 325 | target_link_options(${TARGET} PRIVATE -fsanitize=undefined) |
| 326 | endif() |
| 327 | endif(COMPILER_IS_LIKE_GNU) |
| 328 | endfunction() |
| 329 | |
| 330 | ################################################################################ |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 331 | # Dawn's public and internal "configs" |
| 332 | ################################################################################ |
| 333 | |
| 334 | # The public config contains only the include paths for the Dawn headers. |
| 335 | add_library(dawn_public_config INTERFACE) |
| 336 | target_include_directories(dawn_public_config INTERFACE |
Ben Clayton | 9fb7a51 | 2022-02-04 18:18:18 +0000 | [diff] [blame] | 337 | "${DAWN_INCLUDE_DIR}" |
| 338 | "${DAWN_BUILD_GEN_DIR}/include" |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 339 | ) |
| 340 | |
| 341 | # The internal config conatins additional path but includes the dawn_public_config include paths |
| 342 | add_library(dawn_internal_config INTERFACE) |
| 343 | target_include_directories(dawn_internal_config INTERFACE |
| 344 | "${DAWN_SRC_DIR}" |
| 345 | "${DAWN_BUILD_GEN_DIR}/src" |
| 346 | ) |
| 347 | target_link_libraries(dawn_internal_config INTERFACE dawn_public_config) |
| 348 | |
| 349 | # Compile definitions for the internal config |
| 350 | if (DAWN_ALWAYS_ASSERT OR $<CONFIG:Debug>) |
| 351 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_ASSERTS") |
| 352 | endif() |
| 353 | if (DAWN_ENABLE_D3D12) |
| 354 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D12") |
| 355 | endif() |
| 356 | if (DAWN_ENABLE_METAL) |
| 357 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_METAL") |
| 358 | endif() |
| 359 | if (DAWN_ENABLE_NULL) |
| 360 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_NULL") |
| 361 | endif() |
Sergey Karchevsky | 3a75b1c | 2021-06-30 15:06:43 +0000 | [diff] [blame] | 362 | if (DAWN_ENABLE_DESKTOP_GL) |
| 363 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_DESKTOP_GL") |
| 364 | endif() |
| 365 | if (DAWN_ENABLE_OPENGLES) |
| 366 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGLES") |
| 367 | endif() |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 368 | if (DAWN_ENABLE_OPENGL) |
| 369 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGL") |
| 370 | endif() |
| 371 | if (DAWN_ENABLE_VULKAN) |
| 372 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_VULKAN") |
| 373 | endif() |
Corentin Wallez | 2e22d92 | 2022-06-01 09:30:50 +0000 | [diff] [blame] | 374 | if (DAWN_USE_WAYLAND) |
| 375 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WAYLAND") |
| 376 | endif() |
Corentin Wallez | d353ca0 | 2020-02-18 02:12:35 +0000 | [diff] [blame] | 377 | if (DAWN_USE_X11) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 378 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11") |
| 379 | endif() |
Corentin Wallez | 3346697 | 2020-02-24 13:27:28 +0000 | [diff] [blame] | 380 | if (WIN32) |
| 381 | target_compile_definitions(dawn_internal_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN") |
| 382 | endif() |
| 383 | |
Corentin Wallez | 7c8bc94 | 2022-01-05 09:26:46 +0000 | [diff] [blame] | 384 | set(CMAKE_CXX_STANDARD "17") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 385 | |
| 386 | ################################################################################ |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 387 | # Tint |
| 388 | ################################################################################ |
| 389 | |
Alastair Donaldson | 6a1eb45 | 2021-09-02 23:49:25 +0000 | [diff] [blame] | 390 | set(TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS "" CACHE STRING "Used by OSS-Fuzz to control, via link options, which fuzzing engine should be used") |
| 391 | |
Ben Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 392 | set(TINT_ROOT_SOURCE_DIR ${PROJECT_SOURCE_DIR}) |
| 393 | |
Antonio Maiorano | d600972 | 2021-03-17 13:32:54 +0000 | [diff] [blame] | 394 | # CMake < 3.15 sets /W3 in CMAKE_CXX_FLAGS. Remove it if it's there. |
| 395 | # See https://gitlab.kitware.com/cmake/cmake/-/issues/18317 |
| 396 | if (MSVC) |
Vasyl Teliman | 0b3611b | 2021-06-24 18:10:46 +0000 | [diff] [blame] | 397 | if (CMAKE_CXX_FLAGS MATCHES "/W3") |
| 398 | string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 399 | endif() |
Antonio Maiorano | d600972 | 2021-03-17 13:32:54 +0000 | [diff] [blame] | 400 | endif() |
| 401 | |
Ryan Harrison | 563d3e9 | 2020-04-28 19:27:38 +0000 | [diff] [blame] | 402 | if (${TINT_CHECK_CHROMIUM_STYLE}) |
| 403 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -add-plugin -Xclang find-bad-constructs") |
| 404 | endif() |
| 405 | |
dan sinclair | 4b71b9e | 2020-03-18 14:08:48 +0000 | [diff] [blame] | 406 | if (${TINT_BUILD_SPV_READER}) |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 407 | include_directories("${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-tools/include") |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 408 | endif() |
| 409 | |
Antonio Maiorano | 88d3d2e | 2021-03-23 20:51:09 +0000 | [diff] [blame] | 410 | if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")) |
| 411 | set(COMPILER_IS_CLANG_CL TRUE) |
| 412 | endif() |
| 413 | |
| 414 | if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR |
| 415 | (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR |
| 416 | ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND |
| 417 | (NOT COMPILER_IS_CLANG_CL))) |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 418 | set(COMPILER_IS_LIKE_GNU TRUE) |
| 419 | endif() |
| 420 | |
Antonio Maiorano | 88d3d2e | 2021-03-23 20:51:09 +0000 | [diff] [blame] | 421 | # Enable msbuild multiprocessor builds |
| 422 | if (MSVC AND NOT COMPILER_IS_CLANG_CL) |
| 423 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") |
| 424 | endif() |
| 425 | |
Ben Clayton | 7687ec1 | 2021-04-16 14:43:34 +0000 | [diff] [blame] | 426 | set(TINT_OS_CC_SUFFIX "other") |
| 427 | if (NOT TINT_BUILD_AS_OTHER_OS) |
| 428 | if(UNIX OR APPLE) |
| 429 | set(TINT_OS_CC_SUFFIX "posix") |
| 430 | set(TINT_OS_CC_SUFFIX "posix") |
| 431 | elseif(WIN32) |
| 432 | set(TINT_OS_CC_SUFFIX "windows") |
| 433 | set(TINT_OS_CC_SUFFIX "windows") |
| 434 | endif() |
| 435 | endif() |
| 436 | |
David Neto | 5b46d71 | 2020-06-26 22:29:27 +0000 | [diff] [blame] | 437 | if(${TINT_BUILD_DOCS}) |
| 438 | find_package(Doxygen) |
| 439 | if(DOXYGEN_FOUND) |
Antonio Maiorano | 6241f96 | 2021-06-25 14:00:36 +0000 | [diff] [blame] | 440 | set(DOXYGEN_WARN_AS_ERROR NO) |
| 441 | if(TINT_DOCS_WARN_AS_ERROR) |
| 442 | set(DOXYGEN_WARN_AS_ERROR YES) |
| 443 | endif() |
Antonio Maiorano | e25a8fc | 2021-06-25 14:53:06 +0000 | [diff] [blame] | 444 | |
| 445 | set(DOXYGEN_WARN_FORMAT "$file:$line: $text") |
| 446 | if (MSVC) |
| 447 | set(DOXYGEN_WARN_FORMAT "$file($line): $text") |
| 448 | endif() |
| 449 | |
David Neto | 5b46d71 | 2020-06-26 22:29:27 +0000 | [diff] [blame] | 450 | add_custom_target(tint-docs ALL |
Ben Clayton | 4ace822 | 2021-05-12 08:15:41 +0000 | [diff] [blame] | 451 | COMMAND ${CMAKE_COMMAND} |
Antonio Maiorano | 6241f96 | 2021-06-25 14:00:36 +0000 | [diff] [blame] | 452 | -E env |
| 453 | "DOXYGEN_OUTPUT_DIRECTORY=${CMAKE_BINARY_DIR}/docs" |
| 454 | "DOXYGEN_WARN_AS_ERROR=${DOXYGEN_WARN_AS_ERROR}" |
Antonio Maiorano | e25a8fc | 2021-06-25 14:53:06 +0000 | [diff] [blame] | 455 | "DOXYGEN_WARN_FORMAT=${DOXYGEN_WARN_FORMAT}" |
Ben Clayton | 4ace822 | 2021-05-12 08:15:41 +0000 | [diff] [blame] | 456 | ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile |
David Neto | 5b46d71 | 2020-06-26 22:29:27 +0000 | [diff] [blame] | 457 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 458 | COMMENT "Generating API documentation" |
| 459 | VERBATIM) |
| 460 | else() |
| 461 | message("Doxygen not found. Skipping documentation") |
| 462 | endif(DOXYGEN_FOUND) |
dan sinclair | b0391c6f | 2020-07-15 20:54:48 +0000 | [diff] [blame] | 463 | endif() |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 464 | |
Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 465 | function(tint_core_compile_options TARGET) |
Ben Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 466 | target_include_directories(${TARGET} PUBLIC "${TINT_ROOT_SOURCE_DIR}") |
| 467 | target_include_directories(${TARGET} PUBLIC "${TINT_ROOT_SOURCE_DIR}/include") |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 468 | |
dan sinclair | f6fdcb1 | 2020-10-23 17:04:10 +0000 | [diff] [blame] | 469 | if (${TINT_BUILD_SPV_READER} OR ${TINT_BUILD_SPV_WRITER}) |
| 470 | target_include_directories(${TARGET} PUBLIC |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 471 | "${DAWN_THIRD_PARTY_DIR}/spirv-headers/include") |
dan sinclair | f6fdcb1 | 2020-10-23 17:04:10 +0000 | [diff] [blame] | 472 | endif() |
| 473 | |
Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 474 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_SPV_READER=$<BOOL:${TINT_BUILD_SPV_READER}>) |
| 475 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_WGSL_READER=$<BOOL:${TINT_BUILD_WGSL_READER}>) |
| 476 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_GLSL_WRITER=$<BOOL:${TINT_BUILD_GLSL_WRITER}>) |
| 477 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_HLSL_WRITER=$<BOOL:${TINT_BUILD_HLSL_WRITER}>) |
| 478 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_MSL_WRITER=$<BOOL:${TINT_BUILD_MSL_WRITER}>) |
| 479 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_SPV_WRITER=$<BOOL:${TINT_BUILD_SPV_WRITER}>) |
| 480 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_WGSL_WRITER=$<BOOL:${TINT_BUILD_WGSL_WRITER}>) |
| 481 | |
Ben Clayton | 96e245e | 2022-04-08 18:08:36 +0000 | [diff] [blame] | 482 | common_compile_options(${TARGET}) |
Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 483 | |
| 484 | if (TINT_EMIT_COVERAGE) |
| 485 | if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") |
| 486 | target_compile_options(${TARGET} PRIVATE "--coverage") |
| 487 | target_link_options(${TARGET} PRIVATE "gcov") |
| 488 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 489 | target_compile_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping") |
| 490 | target_link_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping") |
| 491 | else() |
| 492 | message(FATAL_ERROR "Coverage generation not supported for the ${CMAKE_CXX_COMPILER_ID} toolchain") |
| 493 | endif() |
| 494 | endif(TINT_EMIT_COVERAGE) |
| 495 | endfunction() |
| 496 | |
| 497 | function(tint_default_compile_options TARGET) |
| 498 | tint_core_compile_options(${TARGET}) |
dan sinclair | 37dbf99 | 2020-03-11 18:43:12 +0000 | [diff] [blame] | 499 | |
Antonio Maiorano | 5bdece5 | 2021-04-27 19:24:47 +0000 | [diff] [blame] | 500 | set(COMMON_GNU_OPTIONS |
| 501 | -Wall |
| 502 | -Werror |
| 503 | -Wextra |
| 504 | -Wno-documentation-unknown-command |
| 505 | -Wno-padded |
| 506 | -Wno-switch-enum |
| 507 | -Wno-unknown-pragmas |
| 508 | ) |
| 509 | |
| 510 | set(COMMON_CLANG_OPTIONS |
| 511 | -Wno-c++98-compat |
| 512 | -Wno-c++98-compat-pedantic |
| 513 | -Wno-format-pedantic |
| 514 | -Wno-return-std-move-in-c++11 |
| 515 | -Wno-unknown-warning-option |
| 516 | -Wno-undefined-var-template |
| 517 | -Wno-used-but-marked-unused |
| 518 | -Weverything |
| 519 | ) |
| 520 | |
Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 521 | if (COMPILER_IS_LIKE_GNU) |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 522 | target_compile_options(${TARGET} PRIVATE |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 523 | -pedantic-errors |
Antonio Maiorano | 5bdece5 | 2021-04-27 19:24:47 +0000 | [diff] [blame] | 524 | ${COMMON_GNU_OPTIONS} |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 525 | ) |
| 526 | |
| 527 | if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") OR |
| 528 | ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")) |
| 529 | target_compile_options(${TARGET} PRIVATE |
Antonio Maiorano | 5bdece5 | 2021-04-27 19:24:47 +0000 | [diff] [blame] | 530 | ${COMMON_CLANG_OPTIONS} |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 531 | ) |
| 532 | endif() |
Ben Clayton | be2362b | 2022-01-18 18:58:16 +0000 | [diff] [blame] | 533 | endif(COMPILER_IS_LIKE_GNU) |
Ben Clayton | adb10d6 | 2020-10-27 21:04:59 +0000 | [diff] [blame] | 534 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 535 | if (MSVC) |
| 536 | # Specify /EHs for exception handling. |
| 537 | target_compile_options(${TARGET} PRIVATE |
| 538 | /bigobj |
| 539 | /EHsc |
Antonio Maiorano | ac39fb4 | 2021-03-16 15:05:33 +0000 | [diff] [blame] | 540 | /W4 |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 541 | /WX |
| 542 | /wd4068 |
Antonio Maiorano | d600972 | 2021-03-17 13:32:54 +0000 | [diff] [blame] | 543 | /wd4127 |
dan sinclair | 6ca2699 | 2020-05-04 18:58:24 +0000 | [diff] [blame] | 544 | /wd4244 |
| 545 | /wd4267 |
Antonio Maiorano | e547605 | 2021-03-23 14:03:58 +0000 | [diff] [blame] | 546 | /wd4324 |
Antonio Maiorano | d600972 | 2021-03-17 13:32:54 +0000 | [diff] [blame] | 547 | /wd4458 |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 548 | /wd4514 |
| 549 | /wd4571 |
| 550 | /wd4625 |
| 551 | /wd4626 |
| 552 | /wd4710 |
| 553 | /wd4774 |
| 554 | /wd4820 |
| 555 | /wd5026 |
| 556 | /wd5027 |
| 557 | ) |
Antonio Maiorano | 5bdece5 | 2021-04-27 19:24:47 +0000 | [diff] [blame] | 558 | |
| 559 | # When building with clang-cl on Windows, try to match our clang build |
| 560 | # options as much as possible. |
| 561 | if (COMPILER_IS_CLANG_CL) |
| 562 | target_compile_options(${TARGET} PRIVATE |
| 563 | ${COMMON_GNU_OPTIONS} |
| 564 | ${COMMON_CLANG_OPTIONS} |
| 565 | # Disable warnings that are usually disabled in downstream deps for |
| 566 | # gcc/clang, but aren't for clang-cl. |
| 567 | -Wno-global-constructors |
| 568 | -Wno-zero-as-null-pointer-constant |
| 569 | -Wno-shorten-64-to-32 |
Antonio Maiorano | c5f2fe4 | 2021-12-20 21:39:35 +0000 | [diff] [blame] | 570 | -Wno-shadow-field-in-constructor |
| 571 | -Wno-reserved-id-macro |
Antonio Maiorano | b79f51e | 2022-02-04 23:24:43 +0000 | [diff] [blame] | 572 | -Wno-language-extension-token |
Antonio Maiorano | 5bdece5 | 2021-04-27 19:24:47 +0000 | [diff] [blame] | 573 | ) |
| 574 | endif() |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 575 | endif() |
| 576 | endfunction() |
| 577 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 578 | ################################################################################ |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 579 | # Run on all subdirectories |
| 580 | ################################################################################ |
| 581 | |
| 582 | add_subdirectory(third_party) |
James Price | 8d9adb0 | 2022-05-22 00:41:53 +0000 | [diff] [blame] | 583 | |
| 584 | # TODO(crbug.com/tint/455): Tint does not currently build with CMake when |
| 585 | # BUILD_SHARED_LIBS=1, so always build it as static for now. |
| 586 | set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS}) |
| 587 | set(BUILD_SHARED_LIBS 0) |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 588 | add_subdirectory(src/tint) |
James Price | 8d9adb0 | 2022-05-22 00:41:53 +0000 | [diff] [blame] | 589 | set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED}) |
| 590 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 591 | add_subdirectory(generator) |
| 592 | add_subdirectory(src/dawn) |
Ben Clayton | 7b77855 | 2022-02-04 18:59:15 +0000 | [diff] [blame] | 593 | |
| 594 | ################################################################################ |
| 595 | # Samples |
| 596 | ################################################################################ |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 597 | |
Antonio Maiorano | 0eaee0c | 2021-08-31 18:43:36 +0000 | [diff] [blame] | 598 | if (TINT_BUILD_SAMPLES) |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 599 | add_subdirectory(src/tint/cmd) |
Antonio Maiorano | 0eaee0c | 2021-08-31 18:43:36 +0000 | [diff] [blame] | 600 | endif() |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 601 | |
Antonio Maiorano | 0eaee0c | 2021-08-31 18:43:36 +0000 | [diff] [blame] | 602 | if (TINT_BUILD_FUZZERS) |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 603 | add_subdirectory(src/tint/fuzzers) |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 604 | endif() |
| 605 | |
dan sinclair | b595052 | 2020-03-19 13:03:35 +0000 | [diff] [blame] | 606 | add_custom_target(tint-lint |
| 607 | COMMAND ./tools/lint |
Ben Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 608 | WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR} |
dan sinclair | b595052 | 2020-03-19 13:03:35 +0000 | [diff] [blame] | 609 | COMMENT "Running linter" |
| 610 | VERBATIM) |
| 611 | |
| 612 | add_custom_target(tint-format |
| 613 | COMMAND ./tools/format |
Ben Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 614 | WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR} |
dan sinclair | b595052 | 2020-03-19 13:03:35 +0000 | [diff] [blame] | 615 | COMMENT "Running formatter" |
| 616 | VERBATIM) |
Ben Clayton | adb10d6 | 2020-10-27 21:04:59 +0000 | [diff] [blame] | 617 | |
| 618 | |
Antonio Maiorano | 0eaee0c | 2021-08-31 18:43:36 +0000 | [diff] [blame] | 619 | if (TINT_EMIT_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
Ben Clayton | adb10d6 | 2020-10-27 21:04:59 +0000 | [diff] [blame] | 620 | # Generates a lcov.info file at the project root. |
| 621 | # This can be used by tools such as VSCode's Coverage Gutters extension to |
| 622 | # visualize code coverage in the editor. |
| 623 | get_filename_component(CLANG_BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY) |
| 624 | set(PATH_WITH_CLANG "${CLANG_BIN_DIR}:$ENV{PATH}") |
| 625 | add_custom_target(tint-generate-coverage |
| 626 | COMMAND ${CMAKE_COMMAND} -E env PATH=${PATH_WITH_CLANG} ./tools/tint-generate-coverage $<TARGET_FILE:tint_unittests> |
| 627 | DEPENDS tint_unittests |
Ben Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 628 | WORKING_DIRECTORY ${TINT_ROOT_SOURCE_DIR} |
Ben Clayton | adb10d6 | 2020-10-27 21:04:59 +0000 | [diff] [blame] | 629 | COMMENT "Generating tint coverage data" |
| 630 | VERBATIM) |
| 631 | endif() |
Ben Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 632 | |
Antonio Maiorano | 0eaee0c | 2021-08-31 18:43:36 +0000 | [diff] [blame] | 633 | if (TINT_BUILD_REMOTE_COMPILE) |
| 634 | add_subdirectory(tools/src/cmd/remote-compile) |
Ben Clayton | 54cfa0b | 2021-07-08 19:35:53 +0000 | [diff] [blame] | 635 | endif() |