|
| 1 | +include_guard(GLOBAL) |
| 2 | + |
| 3 | +# TiledArray internal warning-policy target. |
| 4 | +# |
| 5 | +# Owns an INTERFACE library `tiledarray_internal_warnings` that carries |
| 6 | +# the warning flags applied to TiledArray's own translation units. The |
| 7 | +# target is linked PRIVATE-ly to the `tiledarray` library and to |
| 8 | +# in-tree executables (via add_ta_executable). PRIVATE scope is |
| 9 | +# load-bearing: it keeps these flags out of INTERFACE_COMPILE_OPTIONS |
| 10 | +# on the installed/exported `tiledarray` target, so downstream |
| 11 | +# consumers (MPQC, ...) do not inherit -Werror through |
| 12 | +# find_package(tiledarray). |
| 13 | +# |
| 14 | +# The target is also NOT installed/exported, which keeps it out of the |
| 15 | +# package. |
| 16 | + |
| 17 | +add_library(tiledarray_internal_warnings INTERFACE) |
| 18 | + |
| 19 | +if (TA_WERROR) |
| 20 | + if (CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang|IntelLLVM)$") |
| 21 | + target_compile_options(tiledarray_internal_warnings INTERFACE |
| 22 | + $<$<OR:$<COMPILE_LANGUAGE:CXX>,$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:HIP>>:-Werror> |
| 23 | + # NVCC: forward -Werror to the host compiler, not to nvcc itself |
| 24 | + # (nvcc's own -Werror is a different switch with a different surface). |
| 25 | + $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=-Werror>) |
| 26 | + # gcc's interprocedural-after-inlining warnings have a long history of |
| 27 | + # false positives — particularly across template-heavy inlining and |
| 28 | + # idiomatic throw-on-assert patterns — that are repeatedly traded |
| 29 | + # across releases (gcc-12/13/14/15 all have outstanding upstream |
| 30 | + # bugzilla PRs in this family). Demote the noisiest of them to plain |
| 31 | + # warnings on gcc so they still surface in build logs but do not |
| 32 | + # gate CI. Clang does not exhibit these and stays under -Werror. |
| 33 | + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 34 | + set(_ta_gcc_ipa_warnings |
| 35 | + -Wno-error=nonnull |
| 36 | + -Wno-error=stringop-overflow |
| 37 | + -Wno-error=stringop-overread |
| 38 | + -Wno-error=array-bounds |
| 39 | + -Wno-error=dangling-pointer |
| 40 | + -Wno-error=use-after-free |
| 41 | + -Wno-error=restrict |
| 42 | + -Wno-error=maybe-uninitialized) |
| 43 | + foreach(_flag IN LISTS _ta_gcc_ipa_warnings) |
| 44 | + target_compile_options(tiledarray_internal_warnings INTERFACE |
| 45 | + $<$<OR:$<COMPILE_LANGUAGE:CXX>,$<COMPILE_LANGUAGE:C>>:${_flag}> |
| 46 | + $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=${_flag}>) |
| 47 | + endforeach() |
| 48 | + unset(_ta_gcc_ipa_warnings) |
| 49 | + endif() |
| 50 | + else() |
| 51 | + message(WARNING "TA_WERROR=ON but compiler '${CMAKE_CXX_COMPILER_ID}' is not in the supported set; ignoring.") |
| 52 | + endif() |
| 53 | +endif() |
0 commit comments