Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 1 | # Copyright 2020 The Tint Authors. |
| 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 | |
| 15 | cmake_minimum_required(VERSION 3.10.2) |
| 16 | |
| 17 | project(tint) |
| 18 | enable_testing() |
| 19 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) |
| 20 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 21 | set(CMAKE_CXX_STANDARD 14) |
| 22 | set(CMAKE_DEBUG_POSTFIX "") |
| 23 | |
| 24 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "") |
| 25 | message(STATUS "No build type selected, default to Debug") |
| 26 | set(CMAKE_BUILD_TYPE "Debug") |
| 27 | endif() |
| 28 | |
Ben Clayton | 6341fa5 | 2021-03-09 13:55:37 +0000 | [diff] [blame] | 29 | # TINT_IS_SUBPROJECT is 1 if added via add_subdirectory() from another project. |
| 30 | get_directory_property(TINT_IS_SUBPROJECT PARENT_DIRECTORY) |
| 31 | if(TINT_IS_SUBPROJECT) |
| 32 | set(TINT_IS_SUBPROJECT 1) |
| 33 | |
| 34 | # If tint is used as a subproject, default to disabling the building of |
| 35 | # documentation and tests. These are unlikely to be desirable, but can be |
| 36 | # enabled. |
| 37 | set(TINT_BUILD_DOCS_DEFAULT OFF) |
| 38 | set(TINT_BUILD_TESTS_DEFAULT OFF) |
| 39 | else() |
| 40 | set(TINT_BUILD_DOCS_DEFAULT ON) |
| 41 | set(TINT_BUILD_TESTS_DEFAULT ON) |
| 42 | endif() |
| 43 | |
| 44 | option(TINT_BUILD_DOCS "Build documentation" ${TINT_BUILD_DOCS_DEFAULT}) |
dan sinclair | 4b71b9e | 2020-03-18 14:08:48 +0000 | [diff] [blame] | 45 | option(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" ON) |
Ben Clayton | ed2b978 | 2020-12-01 18:04:17 +0000 | [diff] [blame] | 46 | option(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON) |
dan sinclair | feffa9d | 2020-07-20 22:13:37 +0000 | [diff] [blame] | 47 | option(TINT_BUILD_HLSL_WRITER "Build the HLSL output writer" ON) |
dan sinclair | 2a59901 | 2020-06-23 17:48:40 +0000 | [diff] [blame] | 48 | option(TINT_BUILD_MSL_WRITER "Build the MSL output writer" ON) |
dan sinclair | 4b71b9e | 2020-03-18 14:08:48 +0000 | [diff] [blame] | 49 | option(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" ON) |
| 50 | option(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON) |
dan sinclair | 4b71b9e | 2020-03-18 14:08:48 +0000 | [diff] [blame] | 51 | option(TINT_BUILD_FUZZERS "Build fuzzers" OFF) |
Vasyl Teliman | 0b3611b | 2021-06-24 18:10:46 +0000 | [diff] [blame] | 52 | option(TINT_BUILD_SPIRV_TOOLS_FUZZER "Build SPIRV-Tools fuzzer" OFF) |
Ben Clayton | 6341fa5 | 2021-03-09 13:55:37 +0000 | [diff] [blame] | 53 | option(TINT_BUILD_TESTS "Build tests" ${TINT_BUILD_TESTS_DEFAULT}) |
Ben Clayton | 7687ec1 | 2021-04-16 14:43:34 +0000 | [diff] [blame] | 54 | option(TINT_BUILD_AS_OTHER_OS "Override OS detection to force building of *_other.cc files" OFF) |
Ryan Harrison | 563d3e9 | 2020-04-28 19:27:38 +0000 | [diff] [blame] | 55 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 56 | option(TINT_ENABLE_MSAN "Enable memory sanitizer" OFF) |
| 57 | option(TINT_ENABLE_ASAN "Enable address sanitizer" OFF) |
| 58 | option(TINT_ENABLE_UBSAN "Enable undefined behaviour sanitizer" OFF) |
| 59 | |
Ben Clayton | adb10d6 | 2020-10-27 21:04:59 +0000 | [diff] [blame] | 60 | option(TINT_EMIT_COVERAGE "Emit code coverage information" OFF) |
| 61 | |
Ryan Harrison | 563d3e9 | 2020-04-28 19:27:38 +0000 | [diff] [blame] | 62 | option(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF) |
| 63 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 64 | message(STATUS "Tint build docs: ${TINT_BUILD_DOCS}") |
dan sinclair | 4b71b9e | 2020-03-18 14:08:48 +0000 | [diff] [blame] | 65 | message(STATUS "Tint build SPIR-V reader: ${TINT_BUILD_SPV_READER}") |
| 66 | message(STATUS "Tint build WGSL reader: ${TINT_BUILD_WGSL_READER}") |
dan sinclair | feffa9d | 2020-07-20 22:13:37 +0000 | [diff] [blame] | 67 | message(STATUS "Tint build HLSL writer: ${TINT_BUILD_HLSL_WRITER}") |
dan sinclair | 2a59901 | 2020-06-23 17:48:40 +0000 | [diff] [blame] | 68 | message(STATUS "Tint build MSL writer: ${TINT_BUILD_MSL_WRITER}") |
dan sinclair | 4b71b9e | 2020-03-18 14:08:48 +0000 | [diff] [blame] | 69 | message(STATUS "Tint build SPIR-V writer: ${TINT_BUILD_SPV_WRITER}") |
| 70 | message(STATUS "Tint build WGSL writer: ${TINT_BUILD_WGSL_WRITER}") |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 71 | message(STATUS "Tint build fuzzers: ${TINT_BUILD_FUZZERS}") |
Vasyl Teliman | 0b3611b | 2021-06-24 18:10:46 +0000 | [diff] [blame] | 72 | message(STATUS "Tint build SPIRV-Tools fuzzer: ${TINT_BUILD_SPIRV_TOOLS_FUZZER}") |
Corentin Wallez | f3717fa | 2020-12-09 14:47:30 +0000 | [diff] [blame] | 73 | message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}") |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 74 | message(STATUS "Tint build with ASAN: ${TINT_ENABLE_ASAN}") |
| 75 | message(STATUS "Tint build with MSAN: ${TINT_ENABLE_MSAN}") |
| 76 | message(STATUS "Tint build with UBSAN: ${TINT_ENABLE_UBSAN}") |
Ryan Harrison | 563d3e9 | 2020-04-28 19:27:38 +0000 | [diff] [blame] | 77 | message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}") |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 78 | |
| 79 | message(STATUS "Using python3") |
| 80 | find_package(PythonInterp 3 REQUIRED) |
| 81 | |
Vasyl Teliman | 0b3611b | 2021-06-24 18:10:46 +0000 | [diff] [blame] | 82 | if (${TINT_BUILD_SPIRV_TOOLS_FUZZER}) |
| 83 | message(STATUS "TINT_BUILD_SPIRV_TOOLS_FUZZER is ON - setting |
| 84 | TINT_BUILD_FUZZERS, |
| 85 | TINT_BUILD_SPV_READER, |
| 86 | TINT_BUILD_WGSL_READER, |
| 87 | TINT_BUILD_WGSL_WRITER, |
| 88 | TINT_BUILD_HLSL_WRITER, |
| 89 | TINT_BUILD_MSL_WRITER, |
| 90 | TINT_BUILD_SPV_WRITER to ON") |
| 91 | set(TINT_BUILD_FUZZERS ON) |
| 92 | set(TINT_BUILD_SPV_READER ON) |
| 93 | set(TINT_BUILD_WGSL_READER ON) |
| 94 | set(TINT_BUILD_WGSL_WRITER ON) |
| 95 | set(TINT_BUILD_HLSL_WRITER ON) |
| 96 | set(TINT_BUILD_MSL_WRITER ON) |
| 97 | set(TINT_BUILD_SPV_WRITER ON) |
| 98 | endif() |
| 99 | |
Antonio Maiorano | d600972 | 2021-03-17 13:32:54 +0000 | [diff] [blame] | 100 | # CMake < 3.15 sets /W3 in CMAKE_CXX_FLAGS. Remove it if it's there. |
| 101 | # See https://gitlab.kitware.com/cmake/cmake/-/issues/18317 |
| 102 | if (MSVC) |
Vasyl Teliman | 0b3611b | 2021-06-24 18:10:46 +0000 | [diff] [blame] | 103 | if (CMAKE_CXX_FLAGS MATCHES "/W3") |
| 104 | string(REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 105 | endif() |
Antonio Maiorano | d600972 | 2021-03-17 13:32:54 +0000 | [diff] [blame] | 106 | endif() |
| 107 | |
Ryan Harrison | 563d3e9 | 2020-04-28 19:27:38 +0000 | [diff] [blame] | 108 | if (${TINT_CHECK_CHROMIUM_STYLE}) |
| 109 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -add-plugin -Xclang find-bad-constructs") |
| 110 | endif() |
| 111 | |
dan sinclair | 4b71b9e | 2020-03-18 14:08:48 +0000 | [diff] [blame] | 112 | if (${TINT_BUILD_SPV_READER}) |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 113 | include_directories("${PROJECT_SOURCE_DIR}/third_party/spirv-tools/include") |
| 114 | endif() |
| 115 | |
Antonio Maiorano | 88d3d2e | 2021-03-23 20:51:09 +0000 | [diff] [blame] | 116 | if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")) |
| 117 | set(COMPILER_IS_CLANG_CL TRUE) |
| 118 | endif() |
| 119 | |
| 120 | if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR |
| 121 | (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR |
| 122 | ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND |
| 123 | (NOT COMPILER_IS_CLANG_CL))) |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 124 | set(COMPILER_IS_LIKE_GNU TRUE) |
| 125 | endif() |
| 126 | |
Antonio Maiorano | 88d3d2e | 2021-03-23 20:51:09 +0000 | [diff] [blame] | 127 | # Enable msbuild multiprocessor builds |
| 128 | if (MSVC AND NOT COMPILER_IS_CLANG_CL) |
| 129 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") |
| 130 | endif() |
| 131 | |
Ben Clayton | 7687ec1 | 2021-04-16 14:43:34 +0000 | [diff] [blame] | 132 | set(TINT_OS_CC_SUFFIX "other") |
| 133 | if (NOT TINT_BUILD_AS_OTHER_OS) |
| 134 | if(UNIX OR APPLE) |
| 135 | set(TINT_OS_CC_SUFFIX "posix") |
| 136 | set(TINT_OS_CC_SUFFIX "posix") |
| 137 | elseif(WIN32) |
| 138 | set(TINT_OS_CC_SUFFIX "windows") |
| 139 | set(TINT_OS_CC_SUFFIX "windows") |
| 140 | endif() |
| 141 | endif() |
| 142 | |
David Neto | 5b46d71 | 2020-06-26 22:29:27 +0000 | [diff] [blame] | 143 | if(${TINT_BUILD_DOCS}) |
| 144 | find_package(Doxygen) |
| 145 | if(DOXYGEN_FOUND) |
| 146 | add_custom_target(tint-docs ALL |
Ben Clayton | 4ace822 | 2021-05-12 08:15:41 +0000 | [diff] [blame] | 147 | COMMAND ${CMAKE_COMMAND} |
| 148 | -E env "DOXYGEN_OUTPUT_DIRECTORY=${CMAKE_BINARY_DIR}/docs" |
| 149 | ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile |
David Neto | 5b46d71 | 2020-06-26 22:29:27 +0000 | [diff] [blame] | 150 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 151 | COMMENT "Generating API documentation" |
| 152 | VERBATIM) |
| 153 | else() |
| 154 | message("Doxygen not found. Skipping documentation") |
| 155 | endif(DOXYGEN_FOUND) |
dan sinclair | b0391c6 | 2020-07-15 20:54:48 +0000 | [diff] [blame] | 156 | endif() |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 157 | |
| 158 | function(tint_default_compile_options TARGET) |
dan sinclair | f6fdcb1 | 2020-10-23 17:04:10 +0000 | [diff] [blame] | 159 | target_include_directories(${TARGET} PUBLIC "${PROJECT_SOURCE_DIR}") |
| 160 | target_include_directories(${TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/include") |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 161 | |
dan sinclair | f6fdcb1 | 2020-10-23 17:04:10 +0000 | [diff] [blame] | 162 | if (${TINT_BUILD_SPV_READER} OR ${TINT_BUILD_SPV_WRITER}) |
| 163 | target_include_directories(${TARGET} PUBLIC |
| 164 | "${PROJECT_SOURCE_DIR}/third_party/spirv-headers/include") |
| 165 | endif() |
| 166 | |
| 167 | target_compile_definitions(${TARGET} PUBLIC |
dan sinclair | 4b71b9e | 2020-03-18 14:08:48 +0000 | [diff] [blame] | 168 | -DTINT_BUILD_SPV_READER=$<BOOL:${TINT_BUILD_SPV_READER}>) |
dan sinclair | f6fdcb1 | 2020-10-23 17:04:10 +0000 | [diff] [blame] | 169 | target_compile_definitions(${TARGET} PUBLIC |
dan sinclair | 4b71b9e | 2020-03-18 14:08:48 +0000 | [diff] [blame] | 170 | -DTINT_BUILD_WGSL_READER=$<BOOL:${TINT_BUILD_WGSL_READER}>) |
dan sinclair | f6fdcb1 | 2020-10-23 17:04:10 +0000 | [diff] [blame] | 171 | target_compile_definitions(${TARGET} PUBLIC |
dan sinclair | feffa9d | 2020-07-20 22:13:37 +0000 | [diff] [blame] | 172 | -DTINT_BUILD_HLSL_WRITER=$<BOOL:${TINT_BUILD_HLSL_WRITER}>) |
dan sinclair | f6fdcb1 | 2020-10-23 17:04:10 +0000 | [diff] [blame] | 173 | target_compile_definitions(${TARGET} PUBLIC |
dan sinclair | 2a59901 | 2020-06-23 17:48:40 +0000 | [diff] [blame] | 174 | -DTINT_BUILD_MSL_WRITER=$<BOOL:${TINT_BUILD_MSL_WRITER}>) |
dan sinclair | f6fdcb1 | 2020-10-23 17:04:10 +0000 | [diff] [blame] | 175 | target_compile_definitions(${TARGET} PUBLIC |
dan sinclair | 4b71b9e | 2020-03-18 14:08:48 +0000 | [diff] [blame] | 176 | -DTINT_BUILD_SPV_WRITER=$<BOOL:${TINT_BUILD_SPV_WRITER}>) |
dan sinclair | f6fdcb1 | 2020-10-23 17:04:10 +0000 | [diff] [blame] | 177 | target_compile_definitions(${TARGET} PUBLIC |
dan sinclair | 4b71b9e | 2020-03-18 14:08:48 +0000 | [diff] [blame] | 178 | -DTINT_BUILD_WGSL_WRITER=$<BOOL:${TINT_BUILD_WGSL_WRITER}>) |
dan sinclair | 37dbf99 | 2020-03-11 18:43:12 +0000 | [diff] [blame] | 179 | |
Antonio Maiorano | 5bdece5 | 2021-04-27 19:24:47 +0000 | [diff] [blame] | 180 | set(COMMON_GNU_OPTIONS |
| 181 | -Wall |
| 182 | -Werror |
| 183 | -Wextra |
| 184 | -Wno-documentation-unknown-command |
| 185 | -Wno-padded |
| 186 | -Wno-switch-enum |
| 187 | -Wno-unknown-pragmas |
| 188 | ) |
| 189 | |
| 190 | set(COMMON_CLANG_OPTIONS |
| 191 | -Wno-c++98-compat |
| 192 | -Wno-c++98-compat-pedantic |
| 193 | -Wno-format-pedantic |
| 194 | -Wno-return-std-move-in-c++11 |
| 195 | -Wno-unknown-warning-option |
| 196 | -Wno-undefined-var-template |
| 197 | -Wno-used-but-marked-unused |
| 198 | -Weverything |
| 199 | ) |
| 200 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 201 | if (${COMPILER_IS_LIKE_GNU}) |
| 202 | target_compile_options(${TARGET} PRIVATE |
| 203 | -std=c++14 |
| 204 | -fno-exceptions |
| 205 | -fno-rtti |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 206 | -pedantic-errors |
Antonio Maiorano | 5bdece5 | 2021-04-27 19:24:47 +0000 | [diff] [blame] | 207 | ${COMMON_GNU_OPTIONS} |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 208 | ) |
| 209 | |
| 210 | if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") OR |
| 211 | ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")) |
| 212 | target_compile_options(${TARGET} PRIVATE |
Antonio Maiorano | 5bdece5 | 2021-04-27 19:24:47 +0000 | [diff] [blame] | 213 | ${COMMON_CLANG_OPTIONS} |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 214 | ) |
| 215 | endif() |
| 216 | |
| 217 | if (${TINT_ENABLE_MSAN}) |
| 218 | target_compile_options(${TARGET} PRIVATE -fsanitize=memory) |
| 219 | target_link_options(${TARGET} PRIVATE -fsanitize=memory) |
| 220 | elseif (${TINT_ENABLE_ASAN}) |
| 221 | target_compile_options(${TARGET} PRIVATE -fsanitize=address) |
| 222 | target_link_options(${TARGET} PRIVATE -fsanitize=address) |
| 223 | elseif (${TINT_ENABLE_UBSAN}) |
| 224 | target_compile_options(${TARGET} PRIVATE -fsanitize=undefined) |
| 225 | target_link_options(${TARGET} PRIVATE -fsanitize=undefined) |
| 226 | endif() |
| 227 | endif() |
| 228 | |
Ben Clayton | adb10d6 | 2020-10-27 21:04:59 +0000 | [diff] [blame] | 229 | if (${TINT_EMIT_COVERAGE}) |
| 230 | if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") |
| 231 | target_compile_options(${TARGET} PRIVATE "--coverage") |
| 232 | target_link_options(${TARGET} PRIVATE "gcov") |
| 233 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 234 | target_compile_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping") |
| 235 | target_link_options(${TARGET} PRIVATE "-fprofile-instr-generate" "-fcoverage-mapping") |
| 236 | else() |
| 237 | message(FATAL_ERROR "Coverage generation not supported for the ${CMAKE_CXX_COMPILER_ID} toolchain") |
| 238 | endif() |
| 239 | endif() |
| 240 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 241 | if (MSVC) |
| 242 | # Specify /EHs for exception handling. |
| 243 | target_compile_options(${TARGET} PRIVATE |
| 244 | /bigobj |
| 245 | /EHsc |
Antonio Maiorano | ac39fb4 | 2021-03-16 15:05:33 +0000 | [diff] [blame] | 246 | /W4 |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 247 | /WX |
| 248 | /wd4068 |
Antonio Maiorano | d600972 | 2021-03-17 13:32:54 +0000 | [diff] [blame] | 249 | /wd4127 |
dan sinclair | 6ca2699 | 2020-05-04 18:58:24 +0000 | [diff] [blame] | 250 | /wd4244 |
| 251 | /wd4267 |
Antonio Maiorano | e547605 | 2021-03-23 14:03:58 +0000 | [diff] [blame] | 252 | /wd4324 |
Antonio Maiorano | d600972 | 2021-03-17 13:32:54 +0000 | [diff] [blame] | 253 | /wd4458 |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 254 | /wd4514 |
| 255 | /wd4571 |
| 256 | /wd4625 |
| 257 | /wd4626 |
| 258 | /wd4710 |
| 259 | /wd4774 |
| 260 | /wd4820 |
| 261 | /wd5026 |
| 262 | /wd5027 |
| 263 | ) |
Antonio Maiorano | 5bdece5 | 2021-04-27 19:24:47 +0000 | [diff] [blame] | 264 | |
| 265 | # When building with clang-cl on Windows, try to match our clang build |
| 266 | # options as much as possible. |
| 267 | if (COMPILER_IS_CLANG_CL) |
| 268 | target_compile_options(${TARGET} PRIVATE |
| 269 | ${COMMON_GNU_OPTIONS} |
| 270 | ${COMMON_CLANG_OPTIONS} |
| 271 | # Disable warnings that are usually disabled in downstream deps for |
| 272 | # gcc/clang, but aren't for clang-cl. |
| 273 | -Wno-global-constructors |
| 274 | -Wno-zero-as-null-pointer-constant |
| 275 | -Wno-shorten-64-to-32 |
| 276 | ) |
| 277 | endif() |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 278 | endif() |
dan sinclair | 6ca2699 | 2020-05-04 18:58:24 +0000 | [diff] [blame] | 279 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 280 | endfunction() |
| 281 | |
| 282 | add_subdirectory(third_party) |
| 283 | add_subdirectory(src) |
| 284 | add_subdirectory(samples) |
| 285 | |
| 286 | if (${TINT_BUILD_FUZZERS}) |
Ryan Harrison | 13a6529 | 2020-04-23 13:51:39 +0000 | [diff] [blame] | 287 | add_subdirectory(fuzzers) |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 288 | endif() |
| 289 | |
dan sinclair | b595052 | 2020-03-19 13:03:35 +0000 | [diff] [blame] | 290 | add_custom_target(tint-lint |
| 291 | COMMAND ./tools/lint |
| 292 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} |
| 293 | COMMENT "Running linter" |
| 294 | VERBATIM) |
| 295 | |
| 296 | add_custom_target(tint-format |
| 297 | COMMAND ./tools/format |
| 298 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} |
| 299 | COMMENT "Running formatter" |
| 300 | VERBATIM) |
Ben Clayton | adb10d6 | 2020-10-27 21:04:59 +0000 | [diff] [blame] | 301 | |
| 302 | |
| 303 | if (${TINT_EMIT_COVERAGE} AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 304 | # Generates a lcov.info file at the project root. |
| 305 | # This can be used by tools such as VSCode's Coverage Gutters extension to |
| 306 | # visualize code coverage in the editor. |
| 307 | get_filename_component(CLANG_BIN_DIR ${CMAKE_C_COMPILER} DIRECTORY) |
| 308 | set(PATH_WITH_CLANG "${CLANG_BIN_DIR}:$ENV{PATH}") |
| 309 | add_custom_target(tint-generate-coverage |
| 310 | COMMAND ${CMAKE_COMMAND} -E env PATH=${PATH_WITH_CLANG} ./tools/tint-generate-coverage $<TARGET_FILE:tint_unittests> |
| 311 | DEPENDS tint_unittests |
| 312 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} |
| 313 | COMMENT "Generating tint coverage data" |
| 314 | VERBATIM) |
| 315 | endif() |