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