Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 1 | # Copyright 2020 The Dawn & Tint Authors |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +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: |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +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. |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +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. |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 27 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 28 | ################################################################################ |
| 29 | # Target flags |
| 30 | ################################################################################ |
| 31 | if(NOT TINT_BUILD_AS_OTHER_OS) |
Ben Clayton | e977f54 | 2023-08-22 10:30:58 +0000 | [diff] [blame] | 32 | if(APPLE) # Must come before UNIX |
Ben Clayton | 5c69ff4 | 2023-11-23 13:32:36 +0000 | [diff] [blame] | 33 | set(TINT_BUILD_IS_MAC TRUE) |
| 34 | set(TINT_BUILD_IS_MAC TRUE) |
Ben Clayton | e977f54 | 2023-08-22 10:30:58 +0000 | [diff] [blame] | 35 | elseif(UNIX) |
Ben Clayton | 5c69ff4 | 2023-11-23 13:32:36 +0000 | [diff] [blame] | 36 | set(TINT_BUILD_IS_LINUX TRUE) |
| 37 | set(TINT_BUILD_IS_LINUX TRUE) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 38 | elseif(WIN32) |
Ben Clayton | 5c69ff4 | 2023-11-23 13:32:36 +0000 | [diff] [blame] | 39 | set(TINT_BUILD_IS_WIN TRUE) |
| 40 | set(TINT_BUILD_IS_WIN TRUE) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 41 | endif() |
| 42 | endif() |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 43 | |
Ryan Harrison | 4578809 | 2024-06-19 02:26:57 +0000 | [diff] [blame] | 44 | ################################################################################ |
| 45 | # Dependent flag checks |
| 46 | ################################################################################ |
| 47 | |
Ryan Harrison | 74fa8ae | 2024-07-09 13:58:16 +0000 | [diff] [blame] | 48 | if (TINT_BUILD_IR_BINARY) |
| 49 | if (NOT DAWN_BUILD_PROTOBUF) |
| 50 | message(FATAL_ERROR "Building IR binary format 'TINT_BUILD_IR_BINARY' is " |
| 51 | "enabled, but building protobuf 'DAWN_BUILD_PROTOBUF' " |
| 52 | "is not") |
| 53 | endif() |
| 54 | if (NOT TARGET libprotobuf) |
| 55 | message(FATAL_ERROR "Building IR binary format 'TINT_BUILD_IR_BINARY' is " |
| 56 | "enabled, but protobuf target is not available, " |
| 57 | "possibly missing '${DAWN_THIRD_PARTY_DIR}/protobuf'") |
| 58 | endif() |
Ryan Harrison | 4578809 | 2024-06-19 02:26:57 +0000 | [diff] [blame] | 59 | endif() |
| 60 | |
| 61 | if (TINT_BUILD_IR_FUZZER AND NOT TINT_BUILD_IR_BINARY) |
Ryan Harrison | 74fa8ae | 2024-07-09 13:58:16 +0000 | [diff] [blame] | 62 | message(FATAL_ERROR "Building IR fuzzer 'TINT_BUILD_IR_FUZZER' is enabled, " |
| 63 | "but building IR binary format 'TINT_BUILD_IR_BINARY' is " |
| 64 | "not") |
Ben Clayton | 90c7cc2 | 2023-12-01 11:16:00 +0000 | [diff] [blame] | 65 | endif() |
| 66 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 67 | ################################################################################ |
| 68 | # Helper functions |
| 69 | ################################################################################ |
| 70 | function(tint_core_compile_options TARGET) |
| 71 | target_include_directories(${TARGET} PUBLIC "${TINT_ROOT_SOURCE_DIR}") |
| 72 | target_include_directories(${TARGET} PUBLIC "${TINT_ROOT_SOURCE_DIR}/include") |
Ben Clayton | f1b8a01 | 2023-10-11 17:15:52 +0000 | [diff] [blame] | 73 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_GLSL_VALIDATOR=$<BOOL:${TINT_BUILD_GLSL_VALIDATOR}>) |
Ben Clayton | 5c69ff4 | 2023-11-23 13:32:36 +0000 | [diff] [blame] | 74 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_GLSL_WRITER=$<BOOL:${TINT_BUILD_GLSL_WRITER}>) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 75 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_HLSL_WRITER=$<BOOL:${TINT_BUILD_HLSL_WRITER}>) |
Ben Clayton | 90c7cc2 | 2023-12-01 11:16:00 +0000 | [diff] [blame] | 76 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_IR_BINARY=$<BOOL:${TINT_BUILD_IR_BINARY}>) |
Ryan Harrison | 4578809 | 2024-06-19 02:26:57 +0000 | [diff] [blame] | 77 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_IR_FUZZER=$<BOOL:${TINT_BUILD_IR_FUZZER}>) |
Ben Clayton | 5c69ff4 | 2023-11-23 13:32:36 +0000 | [diff] [blame] | 78 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_IS_LINUX=$<BOOL:${TINT_BUILD_IS_LINUX}>) |
| 79 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_IS_MAC=$<BOOL:${TINT_BUILD_IS_MAC}>) |
| 80 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_IS_WIN=$<BOOL:${TINT_BUILD_IS_WIN}>) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 81 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_MSL_WRITER=$<BOOL:${TINT_BUILD_MSL_WRITER}>) |
Ben Clayton | 5c69ff4 | 2023-11-23 13:32:36 +0000 | [diff] [blame] | 82 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_SPV_READER=$<BOOL:${TINT_BUILD_SPV_READER}>) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 83 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_SPV_WRITER=$<BOOL:${TINT_BUILD_SPV_WRITER}>) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 84 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_SYNTAX_TREE_WRITER=$<BOOL:${TINT_BUILD_SYNTAX_TREE_WRITER}>) |
Ben Clayton | 5c69ff4 | 2023-11-23 13:32:36 +0000 | [diff] [blame] | 85 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_WGSL_READER=$<BOOL:${TINT_BUILD_WGSL_READER}>) |
| 86 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_WGSL_WRITER=$<BOOL:${TINT_BUILD_WGSL_WRITER}>) |
Ben Clayton | f9a5b71 | 2024-03-13 17:37:33 +0000 | [diff] [blame] | 87 | target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_TINTD=$<BOOL:${TINT_BUILD_TINTD}>) |
Ben Clayton | 5c69ff4 | 2023-11-23 13:32:36 +0000 | [diff] [blame] | 88 | |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 89 | if(TINT_BUILD_FUZZERS) |
| 90 | target_compile_options(${TARGET} PRIVATE "-fsanitize=fuzzer") |
| 91 | endif() |
| 92 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 93 | common_compile_options(${TARGET}) |
| 94 | endfunction() |
| 95 | |
| 96 | function(tint_default_compile_options TARGET) |
| 97 | tint_core_compile_options(${TARGET}) |
| 98 | |
| 99 | set_target_properties(${TARGET} PROPERTIES LINKER_LANGUAGE CXX) |
| 100 | |
| 101 | set(COMMON_GNU_OPTIONS |
| 102 | -Wall |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 103 | -Wextra |
| 104 | -Wno-documentation-unknown-command |
| 105 | -Wno-padded |
| 106 | -Wno-switch-enum |
| 107 | -Wno-unknown-pragmas |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 108 | ) |
Corentin Wallez | 1450d1d | 2024-05-06 18:52:34 +0000 | [diff] [blame] | 109 | if (${DAWN_WERROR}) |
| 110 | list(APPEND COMMON_GNU_OPTIONS -Werror) |
| 111 | endif() |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 112 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 113 | set(COMMON_CLANG_OPTIONS |
| 114 | -Wno-c++98-compat |
| 115 | -Wno-c++98-compat-pedantic |
| 116 | -Wno-format-pedantic |
Ben Clayton | 6a23597 | 2023-11-28 16:41:17 +0000 | [diff] [blame] | 117 | -Wno-gnu-zero-variadic-macro-arguments |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 118 | -Wno-poison-system-directories |
| 119 | -Wno-return-std-move-in-c++11 |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 120 | -Wno-undefined-var-template |
Ben Clayton | 6a23597 | 2023-11-28 16:41:17 +0000 | [diff] [blame] | 121 | -Wno-unknown-warning-option |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 122 | -Wno-unsafe-buffer-usage |
| 123 | -Wno-used-but-marked-unused |
| 124 | -Weverything |
| 125 | ) |
dan sinclair | 16b4cf8 | 2022-11-03 21:10:40 +0000 | [diff] [blame] | 126 | |
Ben Clayton | 7d95661 | 2023-10-03 10:14:55 +0000 | [diff] [blame] | 127 | if(COMPILER_IS_GNU) |
| 128 | # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635 |
| 129 | # Despite the bug being closed, false-positives still seen in GCC-13. |
| 130 | target_compile_options(${TARGET} PRIVATE -Wno-maybe-uninitialized) |
| 131 | endif(COMPILER_IS_GNU) |
| 132 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 133 | if(COMPILER_IS_LIKE_GNU) |
| 134 | target_compile_options(${TARGET} PRIVATE |
| 135 | -pedantic-errors |
| 136 | ${COMMON_GNU_OPTIONS} |
dan sinclair | 16b4cf8 | 2022-11-03 21:10:40 +0000 | [diff] [blame] | 137 | ) |
dan sinclair | 16b4cf8 | 2022-11-03 21:10:40 +0000 | [diff] [blame] | 138 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 139 | if(COMPILER_IS_CLANG) |
Ben Clayton | 064766e | 2023-09-26 15:17:27 +0000 | [diff] [blame] | 140 | if(IS_DEBUG_BUILD) |
Ben Clayton | 7d95661 | 2023-10-03 10:14:55 +0000 | [diff] [blame] | 141 | target_compile_options(${TARGET} PRIVATE -fstandalone-debug) |
Ben Clayton | 064766e | 2023-09-26 15:17:27 +0000 | [diff] [blame] | 142 | endif() |
Ben Clayton | 7d95661 | 2023-10-03 10:14:55 +0000 | [diff] [blame] | 143 | target_compile_options(${TARGET} PRIVATE ${COMMON_CLANG_OPTIONS}) |
dan sinclair | 16b4cf8 | 2022-11-03 21:10:40 +0000 | [diff] [blame] | 144 | endif() |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 145 | endif(COMPILER_IS_LIKE_GNU) |
| 146 | |
| 147 | if(MSVC) |
| 148 | # Specify /EHs for exception handling. |
| 149 | target_compile_options(${TARGET} PRIVATE |
| 150 | /bigobj |
| 151 | /EHsc |
| 152 | /W4 |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 153 | /wd4068 # unknown pragma |
| 154 | /wd4127 # conditional expression is constant |
| 155 | /wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data |
| 156 | /wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data |
| 157 | /wd4324 # 'struct_name' : structure was padded due to __declspec(align()) |
| 158 | /wd4459 # declaration of 'identifier' hides global declaration |
| 159 | /wd4458 # declaration of 'identifier' hides class member |
| 160 | /wd4514 # 'function' : unreferenced inline function has been removed |
| 161 | /wd4571 # catch(...) semantics changed since Visual C++ 7.1; structured exceptions (SEH) are no longer caught |
| 162 | /wd4625 # 'derived class' : copy constructor was implicitly defined as deleted because a base class copy constructor is inaccessible or deleted |
| 163 | /wd4626 # 'derived class' : assignment operator was implicitly defined as deleted because a base class assignment operator is inaccessible or deleted |
| 164 | /wd4710 # 'function' : function not inlined |
| 165 | /wd4774 # 'function' : format string 'string' requires an argument of type 'type', but variadic argument number has type 'type' |
| 166 | /wd4820 # 'bytes' bytes padding added after construct 'member_name' |
| 167 | /wd5026 # 'type': move constructor was implicitly defined as deleted |
| 168 | /wd5027 # 'type': move assignment operator was implicitly defined as deleted |
| 169 | ) |
Corentin Wallez | 1450d1d | 2024-05-06 18:52:34 +0000 | [diff] [blame] | 170 | if (${DAWN_WERROR}) |
| 171 | target_compile_options(${TARGET} PRIVATE /WX) |
| 172 | endif() |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 173 | |
Ben Clayton | 7cdaffe | 2024-05-08 16:24:07 +0000 | [diff] [blame] | 174 | # Some versions of MSVC ignores the [[noreturn]] on ~InternalCompilerError(), triggering a |
Arthur Sonzogni | 3aaa0a3 | 2024-05-31 14:01:04 +0000 | [diff] [blame] | 175 | # warning if it is the last statement on a function that has a return value. |
Ben Clayton | 7cdaffe | 2024-05-08 16:24:07 +0000 | [diff] [blame] | 176 | target_compile_options(${TARGET} PRIVATE |
| 177 | /wd4715 # not all control paths return a value |
| 178 | ) |
| 179 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 180 | if(COMPILER_IS_CLANG_CL) |
Ben Clayton | 7cdaffe | 2024-05-08 16:24:07 +0000 | [diff] [blame] | 181 | # When building with clang-cl on Windows, try to match our clang build |
| 182 | # options as much as possible. |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 183 | target_compile_options(${TARGET} PRIVATE |
| 184 | ${COMMON_GNU_OPTIONS} |
| 185 | ${COMMON_CLANG_OPTIONS} |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 186 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 187 | # Disable warnings that are usually disabled in downstream deps for |
| 188 | # gcc/clang, but aren't for clang-cl. |
| 189 | -Wno-global-constructors |
| 190 | -Wno-zero-as-null-pointer-constant |
| 191 | -Wno-shorten-64-to-32 |
| 192 | -Wno-shadow-field-in-constructor |
| 193 | -Wno-reserved-id-macro |
| 194 | -Wno-language-extension-token |
| 195 | ) |
Ben Clayton | 7cdaffe | 2024-05-08 16:24:07 +0000 | [diff] [blame] | 196 | else() |
| 197 | if(NOT $CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 198 | # MSVC sometimes warns code is unreachable after inlining of code, which |
| 199 | # is impossible to silence with pragmas. |
| 200 | target_compile_options(${TARGET} PRIVATE |
| 201 | /wd4702 # unreachable code |
| 202 | ) |
| 203 | endif() |
dan sinclair | 16b4cf8 | 2022-11-03 21:10:40 +0000 | [diff] [blame] | 204 | endif() |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 205 | endif() |
| 206 | |
| 207 | if(TINT_RANDOMIZE_HASHES) |
| 208 | if(NOT DEFINED TINT_HASH_SEED) |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 209 | string(RANDOM LENGTH 16 ALPHABET "0123456789abcdef" seed) |
| 210 | set(TINT_HASH_SEED "0x${seed}" CACHE STRING "Tint hash seed value") |
| 211 | message("Using TINT_HASH_SEED: ${TINT_HASH_SEED}") |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 212 | endif() |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 213 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 214 | target_compile_definitions(${TARGET} PUBLIC "-DTINT_HASH_SEED=${TINT_HASH_SEED}") |
| 215 | endif() |
dan sinclair | 16b4cf8 | 2022-11-03 21:10:40 +0000 | [diff] [blame] | 216 | endfunction() |
| 217 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 218 | function(tint_spvheaders_compile_options TARGET) |
| 219 | target_link_libraries(${TARGET} PRIVATE SPIRV-Headers) |
| 220 | target_include_directories(${TARGET} PRIVATE "${TINT_SPIRV_HEADERS_DIR}/include") |
| 221 | endfunction() |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 222 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 223 | function(tint_spvtools_compile_options TARGET) |
| 224 | target_link_libraries(${TARGET} PRIVATE SPIRV-Tools) |
| 225 | target_include_directories(${TARGET} PRIVATE "${TINT_SPIRV_TOOLS_DIR}/include") |
| 226 | endfunction() |
| 227 | |
Ben Clayton | f2de7ea | 2023-11-16 15:34:12 +0000 | [diff] [blame] | 228 | function(tint_lib_compile_options TARGET) |
| 229 | if (TINT_ENABLE_INSTALL) |
| 230 | install(TARGETS ${TARGET} |
| 231 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 232 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 233 | ) |
| 234 | endif() |
| 235 | tint_default_compile_options(${TARGET}) |
| 236 | endfunction() |
| 237 | |
| 238 | function(tint_proto_compile_options TARGET) |
| 239 | if (TINT_ENABLE_INSTALL) |
| 240 | install(TARGETS ${TARGET} |
| 241 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 242 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 243 | ) |
| 244 | endif() |
| 245 | tint_core_compile_options(${TARGET}) |
| 246 | endfunction() |
| 247 | |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 248 | function(tint_test_compile_options TARGET) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 249 | tint_default_compile_options(${TARGET}) |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 250 | set_target_properties(${TARGET} PROPERTIES FOLDER "Tests") |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 251 | |
| 252 | if(NOT MSVC) |
| 253 | target_compile_options(${TARGET} PRIVATE |
| 254 | -Wno-global-constructors |
| 255 | -Wno-weak-vtables |
| 256 | ) |
| 257 | endif() |
| 258 | endfunction() |
| 259 | |
| 260 | function(tint_bench_compile_options TARGET) |
| 261 | tint_core_compile_options(${TARGET}) |
James Price | bfc1de9 | 2024-07-30 03:10:37 +0000 | [diff] [blame] | 262 | add_dependencies(${TARGET} tint_generate_benchmark_inputs) |
James Price | d38709c | 2024-07-29 20:30:11 +0000 | [diff] [blame] | 263 | target_include_directories(${TARGET} PUBLIC "${DAWN_BUILD_GEN_DIR}") |
Ben Clayton | 7cdaffe | 2024-05-08 16:24:07 +0000 | [diff] [blame] | 264 | set_target_properties(${TARGET} PROPERTIES FOLDER "Benchmarks") |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 265 | endfunction() |
| 266 | |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 267 | function(tint_fuzz_compile_options TARGET) |
| 268 | tint_core_compile_options(${TARGET}) |
| 269 | set_target_properties(${TARGET} PROPERTIES FOLDER "Fuzzers") |
| 270 | endfunction() |
| 271 | |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 272 | function(tint_test_cmd_compile_options TARGET) |
| 273 | tint_test_compile_options(${TARGET}) |
| 274 | |
| 275 | if(MSVC) |
| 276 | # TODO(crbug.com/tint/1749): MSVC debug builds can suffer from stack |
| 277 | # overflows when resolving deeply nested expression chains or statements. |
| 278 | # Production builds neither use MSVC nor debug, so just bump the stack size |
| 279 | # for this build combination. |
| 280 | if(IS_DEBUG_BUILD) |
| 281 | target_link_options(${TARGET} PRIVATE "/STACK:4194304") # 4MB, default is 1MB |
| 282 | endif() |
| 283 | endif() |
| 284 | |
| 285 | target_link_libraries(${TARGET} PRIVATE gmock) |
| 286 | endfunction() |
| 287 | |
| 288 | function(tint_bench_cmd_compile_options TARGET) |
| 289 | tint_bench_compile_options(${TARGET}) |
| 290 | target_link_libraries(${TARGET} PRIVATE benchmark::benchmark) |
| 291 | endfunction() |
| 292 | |
Ben Clayton | a9cc4c1 | 2023-09-29 21:36:17 +0000 | [diff] [blame] | 293 | function(tint_fuzz_cmd_compile_options TARGET) |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 294 | tint_fuzz_compile_options(${TARGET}) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 295 | |
| 296 | if(NOT "${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS}" STREQUAL "") |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 297 | # This is set when the fuzzers are being built by OSS-Fuzz. In this case the |
| 298 | # variable provides the necessary linker flags, and OSS-Fuzz will take care |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 299 | # of passing suitable compiler flags. |
| 300 | target_link_options(${TARGET} PUBLIC ${TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS}) |
| 301 | else() |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 302 | # When the fuzzers are being built outside of OSS-Fuzz, specific libFuzzer |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 303 | # arguments to enable fuzzing are used. |
| 304 | target_link_options(${TARGET} PUBLIC -fsanitize=fuzzer -fsanitize-coverage=trace-cmp) |
| 305 | endif() |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 306 | |
| 307 | # Link the version of tint_api with -sanitize=fuzzer enabled |
| 308 | target_link_libraries(${TARGET} PRIVATE "tint_api_sanitize_fuzzer") |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 309 | endfunction() |
| 310 | |
Ben Clayton | e9ab1b6 | 2024-04-15 17:21:30 +0000 | [diff] [blame] | 311 | # TODO(crbug.com/tint/2223): Remove this when fuzzers are fully migrated to gen build |
Ben Clayton | a9cc4c1 | 2023-09-29 21:36:17 +0000 | [diff] [blame] | 312 | function(tint_fuzzer_compile_options TARGET) |
| 313 | tint_fuzz_cmd_compile_options(${TARGET}) |
| 314 | target_link_libraries(${TARGET} PRIVATE "tint_api_sanitize_fuzzer") |
| 315 | endfunction() |
| 316 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 317 | if(TINT_ENABLE_BREAK_IN_DEBUGGER) |
dan sinclair | 22b4dd2 | 2023-07-21 00:40:07 +0000 | [diff] [blame] | 318 | set_source_files_properties(utils/debug/debugger.cc |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 319 | PROPERTIES COMPILE_DEFINITIONS "TINT_ENABLE_BREAK_IN_DEBUGGER=1") |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 320 | endif() |
| 321 | |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 322 | ################################################################################ |
Ben Clayton | 59f4888 | 2023-09-06 03:51:44 +0000 | [diff] [blame] | 323 | # Benchmarks |
| 324 | ################################################################################ |
James Price | d38709c | 2024-07-29 20:30:11 +0000 | [diff] [blame] | 325 | if(TINT_BUILD_BENCHMARKS) |
| 326 | set(SCRIPT "${TINT_ROOT_SOURCE_DIR}/src/tint/cmd/bench/generate_benchmark_inputs.py") |
James Price | f60fdcc | 2024-08-13 14:08:44 +0000 | [diff] [blame^] | 327 | set(GENERATED_HEADER_REL_PATH "gen/src/tint/cmd/bench/benchmark_inputs.h") |
| 328 | set(GENERATED_HEADER_ABS_PATH "${Dawn_BINARY_DIR}/${GENERATED_HEADER_REL_PATH}") |
| 329 | set(ARGS ${Python3_EXECUTABLE} ${SCRIPT} ${Dawn_BINARY_DIR} ${GENERATED_HEADER_REL_PATH}) |
James Price | d38709c | 2024-07-29 20:30:11 +0000 | [diff] [blame] | 330 | add_custom_command( |
| 331 | COMMAND ${ARGS} |
James Price | f60fdcc | 2024-08-13 14:08:44 +0000 | [diff] [blame^] | 332 | OUTPUT ${GENERATED_HEADER_ABS_PATH} |
James Price | d38709c | 2024-07-29 20:30:11 +0000 | [diff] [blame] | 333 | DEPENDS ${SCRIPT} |
James Price | f60fdcc | 2024-08-13 14:08:44 +0000 | [diff] [blame^] | 334 | DEPFILE ${GENERATED_HEADER_ABS_PATH}.d |
| 335 | COMMENT "Tint benchmark: Generating ${GENERATED_HEADER_ABS_PATH}." |
James Price | d38709c | 2024-07-29 20:30:11 +0000 | [diff] [blame] | 336 | ) |
James Price | f60fdcc | 2024-08-13 14:08:44 +0000 | [diff] [blame^] | 337 | add_custom_target(tint_generate_benchmark_inputs DEPENDS ${GENERATED_HEADER_ABS_PATH}) |
James Price | d38709c | 2024-07-29 20:30:11 +0000 | [diff] [blame] | 338 | endif() |
Ben Clayton | 59f4888 | 2023-09-06 03:51:44 +0000 | [diff] [blame] | 339 | |
| 340 | ################################################################################ |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 341 | # Functions used by BUILD.cmake files |
| 342 | # The CMake build handles the target kinds in different ways: |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 343 | # 'cmd' - Translates to a CMake executable target. |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 344 | # 'lib' - Translates to a CMake static library. |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 345 | # 'test' - Translates to a CMake object library, configured for compiling and |
| 346 | # linking against google-test. |
| 347 | # 'bench' - Translates to a CMake object library, configured for compiling and |
| 348 | # linking against google-benchmark. |
Ben Clayton | a9cc4c1 | 2023-09-29 21:36:17 +0000 | [diff] [blame] | 349 | # 'fuzz' - Translates to a CMake object library, configured for compiling and |
| 350 | # linking against libfuzzer. |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 351 | # 'test_cmd' - Translates to a CMake executable target linked against google-test. |
| 352 | # 'bench_cmd' - Translates to a CMake executable target linked against google-benchmark. |
Ben Clayton | a9cc4c1 | 2023-09-29 21:36:17 +0000 | [diff] [blame] | 353 | # 'fuzz_cmd' - Translates to a CMake executable target linked against libfuzz. |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 354 | # See also: docs/tint/gen.md |
| 355 | ################################################################################ |
| 356 | |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 357 | # tint_check_target_is_enabled(IS_ENABLED KIND) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 358 | # |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 359 | # Checks whether a target of the kind KIND is enabled. |
| 360 | # Assigns TRUE or FALSE to IS_ENABLED based on whether the target is enabled. |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 361 | # |
| 362 | # Parameters: |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 363 | # IS_ENABLED - the output variable |
| 364 | # KIND - the target kind |
| 365 | function(tint_check_target_is_enabled IS_ENABLED KIND) |
| 366 | set(IS_ENABLED FALSE PARENT_SCOPE) # Default to disabled |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 367 | if(${KIND} STREQUAL cmd) |
Ben Clayton | 38fb812 | 2023-08-17 00:18:41 +0000 | [diff] [blame] | 368 | if(TINT_BUILD_CMD_TOOLS) |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 369 | set(IS_ENABLED TRUE PARENT_SCOPE) |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 370 | endif() |
Ben Clayton | f2de7ea | 2023-11-16 15:34:12 +0000 | [diff] [blame] | 371 | elseif((${KIND} STREQUAL lib) OR (${KIND} STREQUAL proto)) |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 372 | set(IS_ENABLED TRUE PARENT_SCOPE) |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 373 | elseif((${KIND} STREQUAL test) OR (${KIND} STREQUAL test_cmd)) |
| 374 | if(TINT_BUILD_TESTS) |
| 375 | set(IS_ENABLED TRUE PARENT_SCOPE) |
| 376 | endif() |
| 377 | elseif((${KIND} STREQUAL bench) OR (${KIND} STREQUAL bench_cmd)) |
| 378 | if(TINT_BUILD_BENCHMARKS) |
| 379 | set(IS_ENABLED TRUE PARENT_SCOPE) |
| 380 | endif() |
Ben Clayton | a9cc4c1 | 2023-09-29 21:36:17 +0000 | [diff] [blame] | 381 | elseif((${KIND} STREQUAL fuzz) OR (${KIND} STREQUAL fuzz_cmd)) |
| 382 | if(TINT_BUILD_FUZZERS) |
| 383 | set(IS_ENABLED TRUE PARENT_SCOPE) |
| 384 | endif() |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 385 | else() |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 386 | message(FATAL_ERROR "unhandled target kind ${KIND}") |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 387 | endif() |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 388 | endfunction() |
| 389 | |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 390 | # tint_add_target(TARGET KIND [SOURCES...]) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 391 | # |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 392 | # Registers a Tint target with the provided sources. |
| 393 | # Additional sources can be appended with subsequent calls to tint_target_add_sources() |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 394 | # |
| 395 | # Parameters: |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 396 | # TARGET - The target name |
| 397 | # KIND - The target kind |
| 398 | # SOURCES - a list of source files, relative to this directory |
| 399 | function(tint_add_target TARGET KIND) |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 400 | set(TARGET "${TARGET}${TINT_TARGET_SUFFIX}") # Apply suffix |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 401 | set(SOURCES ${ARGN}) |
| 402 | |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 403 | tint_check_target_is_enabled(IS_ENABLED ${KIND}) |
| 404 | if(NOT IS_ENABLED) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 405 | return() # Target is disabled via build flags |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 406 | endif() |
| 407 | |
| 408 | if(${KIND} STREQUAL lib) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 409 | add_library(${TARGET} STATIC EXCLUDE_FROM_ALL) |
Ben Clayton | f2de7ea | 2023-11-16 15:34:12 +0000 | [diff] [blame] | 410 | tint_lib_compile_options(${TARGET}) |
| 411 | elseif(${KIND} STREQUAL proto) |
| 412 | add_library(${TARGET} STATIC EXCLUDE_FROM_ALL) |
| 413 | list(APPEND TINT_PROTO_TARGETS ${TARGET}) |
| 414 | set(TINT_PROTO_TARGETS ${TINT_PROTO_TARGETS} PARENT_SCOPE) |
| 415 | tint_proto_compile_options(${TARGET}) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 416 | elseif(${KIND} STREQUAL cmd) |
| 417 | add_executable(${TARGET}) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 418 | tint_default_compile_options(${TARGET}) |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 419 | elseif(${KIND} STREQUAL test_cmd) |
| 420 | add_executable(${TARGET}) |
| 421 | tint_test_cmd_compile_options(${TARGET}) |
| 422 | elseif(${KIND} STREQUAL bench_cmd) |
| 423 | add_executable(${TARGET}) |
| 424 | tint_bench_cmd_compile_options(${TARGET}) |
Ben Clayton | a9cc4c1 | 2023-09-29 21:36:17 +0000 | [diff] [blame] | 425 | elseif(${KIND} STREQUAL fuzz_cmd) |
| 426 | add_executable(${TARGET}) |
| 427 | tint_fuzz_cmd_compile_options(${TARGET}) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 428 | elseif(${KIND} STREQUAL test) |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 429 | add_library(${TARGET} OBJECT EXCLUDE_FROM_ALL) |
| 430 | tint_test_compile_options(${TARGET}) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 431 | elseif(${KIND} STREQUAL bench) |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 432 | add_library(${TARGET} OBJECT EXCLUDE_FROM_ALL) |
| 433 | tint_bench_compile_options(${TARGET}) |
Ben Clayton | a9cc4c1 | 2023-09-29 21:36:17 +0000 | [diff] [blame] | 434 | elseif(${KIND} STREQUAL fuzz) |
| 435 | add_library(${TARGET} OBJECT EXCLUDE_FROM_ALL) |
| 436 | tint_fuzz_compile_options(${TARGET}) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 437 | else() |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 438 | message(FATAL_ERROR "unhandled target kind ${KIND}") |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 439 | endif() |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 440 | |
| 441 | # Add the sources to the target |
| 442 | target_sources(${TARGET} PRIVATE ${SOURCES}) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 443 | endfunction() |
| 444 | |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 445 | # tint_target_add_sources(TARGET [SOURCES...]) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 446 | # |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 447 | # Adds source files to a Tint target |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 448 | # |
| 449 | # Parameters: |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 450 | # TARGET - The target name |
| 451 | # KIND - The target kind |
| 452 | # SOURCES - a list of source files, relative to this directory |
| 453 | function(tint_target_add_sources TARGET KIND) |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 454 | set(TARGET "${TARGET}${TINT_TARGET_SUFFIX}") # Apply suffix |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 455 | set(SOURCES ${ARGN}) |
| 456 | |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 457 | tint_check_target_is_enabled(IS_ENABLED ${KIND}) |
| 458 | if(NOT IS_ENABLED) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 459 | return() # Target is disabled via build flags |
| 460 | endif() |
| 461 | |
| 462 | target_sources(${TARGET} PRIVATE ${SOURCES}) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 463 | endfunction() |
| 464 | |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 465 | # tint_target_add_dependencies(TARGET DEPENDENCIES...) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 466 | # |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 467 | # Adds dependencies to a Tint target. |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 468 | # |
| 469 | # Parameters: |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 470 | # TARGET - The target name |
| 471 | # KIND - The target kind |
| 472 | # DEPENDENCIES - a list of target names |
| 473 | function(tint_target_add_dependencies TARGET KIND) |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 474 | set(TARGET "${TARGET}${TINT_TARGET_SUFFIX}") # Apply suffix |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 475 | set(DEPENDENCIES ${ARGN}) |
| 476 | |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 477 | tint_check_target_is_enabled(IS_ENABLED ${KIND}) |
| 478 | if(NOT IS_ENABLED) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 479 | return() # Target is disabled via build flags |
| 480 | endif() |
| 481 | |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 482 | # Apply target suffix |
| 483 | set(SUFFIXED_DEPENDENCIES "") |
| 484 | foreach(DEPENDENCY ${DEPENDENCIES}) |
| 485 | list(APPEND SUFFIXED_DEPENDENCIES "${DEPENDENCY}${TINT_TARGET_SUFFIX}") |
| 486 | endforeach() |
| 487 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 488 | # Register the dependencies |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 489 | target_link_libraries(${TARGET} PRIVATE ${SUFFIXED_DEPENDENCIES}) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 490 | endfunction() |
| 491 | |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 492 | # tint_target_add_external_dependencies(TARGET KIND DEPENDENCIES...) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 493 | # |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 494 | # Adds external dependencies to a Tint target. |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 495 | # |
| 496 | # Parameters: |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 497 | # TARGET - The target name |
| 498 | # KIND - The target kind |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 499 | # DEPENDENCIES - a list of external target names |
| 500 | # |
Ben Clayton | de3e873 | 2023-08-22 10:30:58 +0000 | [diff] [blame] | 501 | # See src/tint/externals.json for the list of external dependencies. |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 502 | function(tint_target_add_external_dependencies TARGET KIND) |
| 503 | set(TARGET "${TARGET}${TINT_TARGET_SUFFIX}") # Apply suffix |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 504 | set(DEPENDENCIES ${ARGN}) |
| 505 | |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 506 | tint_check_target_is_enabled(IS_ENABLED ${KIND}) |
| 507 | if(NOT IS_ENABLED) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 508 | return() # Target is disabled via build flags |
| 509 | endif() |
| 510 | |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 511 | foreach(DEPENDENCY ${DEPENDENCIES}) # Each external dependency requires special handling... |
| 512 | if(${DEPENDENCY} STREQUAL "abseil") |
| 513 | target_link_libraries(${TARGET} PRIVATE |
Jaswant Panchumarti | 90793bd | 2024-06-10 15:35:12 +0000 | [diff] [blame] | 514 | absl::strings |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 515 | ) |
James Price | 5976efe | 2024-05-07 13:48:43 +0000 | [diff] [blame] | 516 | elseif(${DEPENDENCY} STREQUAL "dl") |
| 517 | target_link_libraries(${TARGET} PRIVATE ${CMAKE_DL_LIBS}) |
Antonio Maiorano | 4ac690d | 2024-05-01 17:56:33 +0000 | [diff] [blame] | 518 | elseif(${DEPENDENCY} STREQUAL "dxc-include") |
| 519 | target_include_directories(${TARGET} PRIVATE "${DAWN_THIRD_PARTY_DIR}/dxc/include") |
Antonio Maiorano | 49be28e | 2024-06-19 02:11:43 +0000 | [diff] [blame] | 520 | elseif(${DEPENDENCY} STREQUAL "dxcompiler-for-fuzzer") |
| 521 | if(TINT_BUILD_FUZZERS) # TODO: and target arch is not x86 |
| 522 | target_link_libraries(${TARGET} PRIVATE dxcompiler) |
| 523 | endif() |
Ben Clayton | f9a5b71 | 2024-03-13 17:37:33 +0000 | [diff] [blame] | 524 | elseif(${DEPENDENCY} STREQUAL "jsoncpp") |
| 525 | target_link_libraries(${TARGET} PRIVATE jsoncpp_static) |
| 526 | elseif(${DEPENDENCY} STREQUAL "langsvr") |
| 527 | target_link_libraries(${TARGET} PRIVATE langsvr) |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 528 | elseif(${DEPENDENCY} STREQUAL "glslang") |
| 529 | target_link_libraries(${TARGET} PRIVATE glslang) |
| 530 | if(NOT MSVC) |
| 531 | target_compile_options(${TARGET} PRIVATE |
| 532 | -Wno-reserved-id-macro |
| 533 | -Wno-shadow-field-in-constructor |
| 534 | -Wno-shadow |
| 535 | -Wno-weak-vtables |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 536 | ) |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 537 | endif() |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 538 | elseif(${DEPENDENCY} STREQUAL "glslang-res-limits") |
| 539 | target_link_libraries(${TARGET} PRIVATE |
| 540 | glslang-default-resource-limits |
| 541 | ) |
Ben Clayton | 9d1b610 | 2023-09-29 12:12:48 +0000 | [diff] [blame] | 542 | elseif(${DEPENDENCY} STREQUAL "google-benchmark") |
| 543 | set_target_properties(${TARGET} PROPERTIES FOLDER "Benchmarks") |
| 544 | target_link_libraries(${TARGET} PRIVATE benchmark::benchmark) |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 545 | elseif(${DEPENDENCY} STREQUAL "gtest") |
| 546 | target_include_directories(${TARGET} PRIVATE ${gmock_SOURCE_DIR}/include) |
| 547 | target_link_libraries(${TARGET} PRIVATE gmock) |
Ryan Harrison | 25e23b3 | 2024-05-27 23:21:05 +0000 | [diff] [blame] | 548 | elseif(${DEPENDENCY} STREQUAL "libprotobuf-mutator") |
| 549 | target_link_libraries(${TARGET} PRIVATE libprotobuf-mutator) |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 550 | elseif(${DEPENDENCY} STREQUAL "metal") |
| 551 | find_library(CoreGraphicsFramework CoreGraphics REQUIRED) |
| 552 | find_library(FoundationFramework Foundation REQUIRED) |
| 553 | find_library(MetalFramework Metal REQUIRED) |
| 554 | target_link_libraries(${TARGET} PRIVATE |
| 555 | ${CoreGraphicsFramework} |
| 556 | ${FoundationFramework} |
| 557 | ${MetalFramework} |
| 558 | ) |
| 559 | elseif(${DEPENDENCY} STREQUAL "spirv-headers") |
| 560 | tint_spvheaders_compile_options(${TARGET}) |
| 561 | elseif(${DEPENDENCY} STREQUAL "spirv-tools") |
| 562 | tint_spvtools_compile_options(${TARGET}) |
| 563 | elseif(${DEPENDENCY} STREQUAL "spirv-opt-internal") |
| 564 | target_link_libraries(${TARGET} PRIVATE |
| 565 | SPIRV-Tools-opt |
| 566 | ) |
| 567 | target_include_directories(${TARGET} PRIVATE |
| 568 | "${TINT_SPIRV_TOOLS_DIR}" |
| 569 | "${TINT_SPIRV_TOOLS_DIR}/include" |
| 570 | "${TINT_SPIRV_TOOLS_DIR}/source" |
| 571 | "${spirv-tools_BINARY_DIR}" |
| 572 | ) |
| 573 | elseif(${DEPENDENCY} STREQUAL "thread") |
| 574 | find_package(Threads REQUIRED) |
| 575 | target_link_libraries(${TARGET} PRIVATE Threads::Threads) |
| 576 | elseif(${DEPENDENCY} STREQUAL "winsock") |
| 577 | target_link_libraries(${TARGET} PRIVATE ws2_32) |
| 578 | else() |
| 579 | message(FATAL_ERROR "unhandled external dependency ${DEPENDENCY}") |
| 580 | endif() |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 581 | endforeach() |
| 582 | endfunction() |
| 583 | |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 584 | # tint_target_set_output_name(TARGET KIND OUTPUT_NAME) |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 585 | # |
| 586 | # Overrides the output name for the given target |
| 587 | # |
| 588 | # Parameters: |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 589 | # TARGET - The target name |
| 590 | # KIND - The target kind |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 591 | # OUTPUT_NAME - the new name for the target output |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 592 | function(tint_target_set_output_name TARGET KIND OUTPUT_NAME) |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 593 | set(TARGET "${TARGET}${TINT_TARGET_SUFFIX}") # Apply suffix |
Ben Clayton | 3fe6761 | 2023-08-17 18:22:29 +0000 | [diff] [blame] | 594 | tint_check_target_is_enabled(IS_ENABLED ${KIND}) |
| 595 | if(NOT IS_ENABLED) |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 596 | return() # Target is disabled via build flags |
| 597 | endif() |
| 598 | |
| 599 | set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME}) |
| 600 | |
| 601 | # Create an alias target with the name OUTPUT_NAME to TARGET |
| 602 | if(${KIND} STREQUAL lib) |
| 603 | add_library(${OUTPUT_NAME} ALIAS ${TARGET}) |
| 604 | elseif(${KIND} STREQUAL test) |
| 605 | add_library(${OUTPUT_NAME} ALIAS ${TARGET}) |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 606 | elseif(${KIND} STREQUAL bench) |
| 607 | add_library(${OUTPUT_NAME} ALIAS ${TARGET}) |
| 608 | elseif(${KIND} STREQUAL fuzz) |
| 609 | add_library(${OUTPUT_NAME} ALIAS ${TARGET}) |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 610 | elseif(${KIND} STREQUAL cmd) |
| 611 | add_executable(${OUTPUT_NAME} ALIAS ${TARGET}) |
| 612 | elseif(${KIND} STREQUAL test_cmd) |
| 613 | add_executable(${OUTPUT_NAME} ALIAS ${TARGET}) |
| 614 | elseif(${KIND} STREQUAL bench_cmd) |
| 615 | add_executable(${OUTPUT_NAME} ALIAS ${TARGET}) |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 616 | elseif(${KIND} STREQUAL fuzz_cmd) |
| 617 | add_executable(${OUTPUT_NAME} ALIAS ${TARGET}) |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 618 | else() |
| 619 | message(FATAL_ERROR "unhandled target kind ${KIND}") |
| 620 | endif() |
| 621 | endfunction() |
| 622 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 623 | ################################################################################ |
| 624 | # Include the generated build files |
| 625 | ################################################################################ |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 626 | if(TINT_BUILD_FUZZERS) |
| 627 | if(NOT COMPILER_IS_CLANG) |
| 628 | message(FATAL_ERROR "TINT_BUILD_FUZZERS can only be enabled with the Clang toolchain") |
| 629 | endif() |
| 630 | |
| 631 | # Save the current build flags |
| 632 | set(SAVE_TINT_BUILD_CMD_TOOLS ${TINT_BUILD_CMD_TOOLS}) |
| 633 | set(SAVE_TINT_BUILD_TESTS ${TINT_BUILD_TESTS}) |
| 634 | set(SAVE_TINT_BUILD_BENCHMARKS ${TINT_BUILD_BENCHMARKS}) |
| 635 | set(SAVE_TINT_BUILD_FUZZERS ${TINT_BUILD_FUZZERS}) |
| 636 | set(SAVE_TINT_TARGET_SUFFIX ${TINT_TARGET_SUFFIX}) |
| 637 | |
| 638 | # Declare the targets with fuzzers disabled |
| 639 | set(TINT_BUILD_FUZZERS FALSE) |
| 640 | include("BUILD.cmake") |
| 641 | |
| 642 | # Now redeclare the fuzzers targets with a '_sanitize_fuzzer' target suffix |
| 643 | # Enabling TINT_BUILD_FUZZERS will enable the -fsanitize=fuzzer compilation flag for these |
| 644 | # targets. |
| 645 | set(TINT_TARGET_SUFFIX "_sanitize_fuzzer") |
| 646 | set(TINT_BUILD_FUZZERS TRUE) |
| 647 | set(TINT_BUILD_CMD_TOOLS FALSE) |
| 648 | set(TINT_BUILD_TESTS FALSE) |
| 649 | set(TINT_BUILD_BENCHMARKS FALSE) |
| 650 | include("BUILD.cmake") |
Ben Clayton | ffcb82a | 2023-09-28 16:26:52 +0000 | [diff] [blame] | 651 | |
| 652 | # Restore the build flags |
| 653 | set(TINT_BUILD_CMD_TOOLS ${SAVE_TINT_BUILD_CMD_TOOLS}) |
| 654 | set(TINT_BUILD_TESTS ${SAVE_TINT_BUILD_TESTS}) |
| 655 | set(TINT_BUILD_BENCHMARKS ${SAVE_TINT_BUILD_BENCHMARKS}) |
| 656 | set(TINT_BUILD_FUZZERS ${SAVE_TINT_BUILD_FUZZERS}) |
| 657 | set(TINT_TARGET_SUFFIX ${SAVE_TINT_TARGET_SUFFIX}) |
| 658 | else() |
| 659 | # Fuzzers not enabled. Just include BUILD.cmake with the current flags. |
| 660 | include("BUILD.cmake") |
| 661 | endif(TINT_BUILD_FUZZERS) |
| 662 | |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 663 | |
| 664 | ################################################################################ |
Ben Clayton | f2de7ea | 2023-11-16 15:34:12 +0000 | [diff] [blame] | 665 | # Generate protobuf sources |
| 666 | ################################################################################ |
dan sinclair | 0c27cf2 | 2024-06-11 12:31:38 +0000 | [diff] [blame] | 667 | if (DAWN_BUILD_PROTOBUF) |
| 668 | foreach(PROTO_TARGET ${TINT_PROTO_TARGETS}) |
| 669 | generate_protos( |
| 670 | TARGET ${PROTO_TARGET} |
| 671 | IMPORT_DIRS "${TINT_ROOT_SOURCE_DIR}" |
| 672 | PROTOC_OUT_DIR "${DAWN_BUILD_GEN_DIR}") |
| 673 | target_include_directories(${PROTO_TARGET} PRIVATE "${DAWN_BUILD_GEN_DIR}/src/tint/") |
| 674 | target_include_directories(${PROTO_TARGET} PUBLIC "${DAWN_BUILD_GEN_DIR}") |
Ryan Harrison | deec9b0 | 2024-06-14 00:19:12 +0000 | [diff] [blame] | 675 | target_link_libraries(${PROTO_TARGET} PUBLIC libprotobuf) |
dan sinclair | 0c27cf2 | 2024-06-11 12:31:38 +0000 | [diff] [blame] | 676 | endforeach() |
| 677 | endif() |
Ben Clayton | f2de7ea | 2023-11-16 15:34:12 +0000 | [diff] [blame] | 678 | |
| 679 | ################################################################################ |
Ben Clayton | f9a5b71 | 2024-03-13 17:37:33 +0000 | [diff] [blame] | 680 | # tintd (VSCode WGSL language server) |
| 681 | ################################################################################ |
Ben Clayton | 2f215d1 | 2024-03-23 10:18:00 +0000 | [diff] [blame] | 682 | if(TINT_BUILD_TINTD) |
| 683 | # Copy all the files out of cmd/tintd/vscode to {build}/vscode |
Ben Clayton | f9a5b71 | 2024-03-13 17:37:33 +0000 | [diff] [blame] | 684 | set(VSCODE_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmd/tintd/vscode") |
| 685 | set(VSCODE_DST_DIR "${DAWN_BUILD_GEN_DIR}/vscode") |
| 686 | |
| 687 | file(GLOB VSCODE_ASSETS RELATIVE "${VSCODE_SRC_DIR}" "${VSCODE_SRC_DIR}/*") |
| 688 | foreach(FILE ${VSCODE_ASSETS}) |
| 689 | configure_file("${VSCODE_SRC_DIR}/${FILE}" "${VSCODE_DST_DIR}/${FILE}" COPYONLY) |
| 690 | endforeach() |
| 691 | set_target_properties(tint_cmd_tintd_cmd PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${VSCODE_DST_DIR}") |
Ben Clayton | 2f215d1 | 2024-03-23 10:18:00 +0000 | [diff] [blame] | 692 | endif(TINT_BUILD_TINTD) |
Ben Clayton | f9a5b71 | 2024-03-13 17:37:33 +0000 | [diff] [blame] | 693 | |
| 694 | |
| 695 | ################################################################################ |
Antonio Maiorano | 18909c6 | 2023-09-07 23:44:32 +0000 | [diff] [blame] | 696 | # Bespoke target settings |
| 697 | ################################################################################ |
Ben Clayton | f9a5b71 | 2024-03-13 17:37:33 +0000 | [diff] [blame] | 698 | if(MSVC) |
Antonio Maiorano | 18909c6 | 2023-09-07 23:44:32 +0000 | [diff] [blame] | 699 | target_sources(tint_api PRIVATE tint.natvis) |
| 700 | endif() |
| 701 | |
Ben Clayton | f9a5b71 | 2024-03-13 17:37:33 +0000 | [diff] [blame] | 702 | |
Antonio Maiorano | 18909c6 | 2023-09-07 23:44:32 +0000 | [diff] [blame] | 703 | ################################################################################ |
Ben Clayton | 2468be5 | 2024-04-29 15:26:16 +0000 | [diff] [blame] | 704 | # Unit tests |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 705 | ################################################################################ |
| 706 | if(TINT_BUILD_TESTS) |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 707 | add_test(NAME tint_unittests COMMAND tint_cmd_test_test_cmd) |
| 708 | endif(TINT_BUILD_TESTS) |
| 709 | |
Ben Clayton | 2468be5 | 2024-04-29 15:26:16 +0000 | [diff] [blame] | 710 | |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 711 | ################################################################################ |
Ben Clayton | 5560934 | 2023-08-16 22:10:47 +0000 | [diff] [blame] | 712 | # Target aliases |
Ben Clayton | 3a3cb36 | 2023-08-16 01:05:21 +0000 | [diff] [blame] | 713 | ################################################################################ |
| 714 | add_library(libtint ALIAS tint_api) |
munoza | c511ffb | 2023-09-25 14:01:03 +0000 | [diff] [blame] | 715 | |
Ben Clayton | 2468be5 | 2024-04-29 15:26:16 +0000 | [diff] [blame] | 716 | |
| 717 | ################################################################################ |
| 718 | # Install rules |
| 719 | ################################################################################ |
munoza | c511ffb | 2023-09-25 14:01:03 +0000 | [diff] [blame] | 720 | if (TINT_ENABLE_INSTALL) |
| 721 | # We need to recurse all folders and include all headers because tint.h includes most headers from src/tint |
| 722 | file(GLOB TINT_HEADERS "${DAWN_INCLUDE_DIR}/tint/*.h") |
| 723 | |
| 724 | install(FILES ${TINT_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tint/) |
| 725 | |
amirsojoodi | a840d51 | 2024-01-23 17:03:44 +0000 | [diff] [blame] | 726 | file(GLOB_RECURSE TINT_SRC_HEADERS RELATIVE ${TINT_ROOT_SOURCE_DIR} "*.h") |
munoza | c511ffb | 2023-09-25 14:01:03 +0000 | [diff] [blame] | 727 | |
| 728 | foreach(TINT_HEADER_FILE ${TINT_SRC_HEADERS}) |
| 729 | get_filename_component(TINT_HEADER_DIR ${TINT_HEADER_FILE} DIRECTORY) |
amirsojoodi | a840d51 | 2024-01-23 17:03:44 +0000 | [diff] [blame] | 730 | install(FILES ${TINT_ROOT_SOURCE_DIR}/${TINT_HEADER_FILE} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/src/tint/${TINT_HEADER_DIR}) |
munoza | c511ffb | 2023-09-25 14:01:03 +0000 | [diff] [blame] | 731 | endforeach () |
| 732 | endif() |