| 1 |
################################################################################ |
| 2 |
# |
| 3 |
# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved. |
| 4 |
# |
| 5 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 |
# of this software and associated documentation files (the "Software"), to deal |
| 7 |
# in the Software without restriction, including without limitation the rights |
| 8 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
# copies of the Software, and to permit persons to whom the Software is |
| 10 |
# furnished to do so, subject to the following conditions: |
| 11 |
# |
| 12 |
# The above copyright notice and this permission notice shall be included in |
| 13 |
# all copies or substantial portions of the Software. |
| 14 |
# |
| 15 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 |
# SOFTWARE. |
| 22 |
# |
| 23 |
################################################################################ |
| 24 |
|
| 25 |
# - Enable warning all for gcc/clang or use /W4 for visual studio |
| 26 |
|
| 27 |
## Strict warning level |
| 28 |
if (MSVC) |
| 29 |
# Use the highest warning level for visual studio. |
| 30 |
set(CMAKE_CXX_WARNING_LEVEL 4) |
| 31 |
if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") |
| 32 |
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 33 |
else () |
| 34 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") |
| 35 |
endif () |
| 36 |
|
| 37 |
set(CMAKE_C_WARNING_LEVEL 4) |
| 38 |
if (CMAKE_C_FLAGS MATCHES "/W[0-4]") |
| 39 |
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
| 40 |
else () |
| 41 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4") |
| 42 |
endif () |
| 43 |
|
| 44 |
# 4201 - nameless struct/union: used for complex.y, complex.y |
| 45 |
# 4100 - unused formal parameter: overriding functions don't have to use all parameters |
| 46 |
# 4715 - not all controll paths return a value: switch with returns where all enums handled |
| 47 |
# 4127 - conditional is constant: cpu algorithm uses if template for complex conjugate |
| 48 |
set (WARNINGS_TO_IGNORE "/wd4201 /wd4100 /wd4715 /wd4127") |
| 49 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNINGS_TO_IGNORE}") |
| 50 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNINGS_TO_IGNORE}") |
| 51 |
|
| 52 |
else() |
| 53 |
foreach(COMPILER C CXX) |
| 54 |
set(CMAKE_COMPILER_WARNINGS) |
| 55 |
# use -Wall for gcc and clang |
| 56 |
list(APPEND CMAKE_COMPILER_WARNINGS |
| 57 |
-Wall |
| 58 |
-Wextra |
| 59 |
-Wcomment |
| 60 |
-Wendif-labels |
| 61 |
-Wformat |
| 62 |
-Winit-self |
| 63 |
-Wreturn-type |
| 64 |
-Wsequence-point |
| 65 |
-Wshadow |
| 66 |
-Wswitch |
| 67 |
-Wtrigraphs |
| 68 |
-Wundef |
| 69 |
-Wuninitialized |
| 70 |
-Wunreachable-code |
| 71 |
-Wunused |
| 72 |
|
| 73 |
-Wno-sign-compare |
| 74 |
) |
| 75 |
if (CMAKE_${COMPILER}_COMPILER_ID MATCHES "Clang") |
| 76 |
list(APPEND CMAKE_COMPILER_WARNINGS |
| 77 |
-Wabi |
| 78 |
-Wabstract-final-class |
| 79 |
-Waddress |
| 80 |
-Waddress-of-array-temporary |
| 81 |
-Waddress-of-temporary |
| 82 |
-Waggregate-return |
| 83 |
-Wambiguous-macro |
| 84 |
-Wambiguous-member-template |
| 85 |
-Wanonymous-pack-parens |
| 86 |
-Warray-bounds |
| 87 |
-Warray-bounds-pointer-arithmetic |
| 88 |
-Wassign-enum |
| 89 |
-Watomic-properties |
| 90 |
-Wattributes |
| 91 |
-Wavailability |
| 92 |
-Wbackslash-newline-escape |
| 93 |
-Wbad-array-new-length |
| 94 |
-Wbad-function-cast |
| 95 |
-Wbind-to-temporary-copy |
| 96 |
-Wbuiltin-macro-redefined |
| 97 |
-Wbuiltin-requires-header |
| 98 |
-Wcast-align |
| 99 |
-Wcast-qual |
| 100 |
-Wchar-align |
| 101 |
-Wcomments |
| 102 |
-Wcompare-distinct-pointer-types |
| 103 |
-Wconditional-type-mismatch |
| 104 |
-Wconditional-uninitialized |
| 105 |
-Wconfig-macros |
| 106 |
-Wconstant-logical-operand |
| 107 |
-Wconstexpr-not-const |
| 108 |
-Wconversion-null |
| 109 |
-Wcovered-switch-default |
| 110 |
-Wctor-dtor-privacy |
| 111 |
-Wdangling-field |
| 112 |
-Wdangling-initializer-list |
| 113 |
-Wdelete-incomplete |
| 114 |
-Wdeprecated |
| 115 |
-Wdivision-by-zero |
| 116 |
-Wduplicate-decl-specifier |
| 117 |
-Wduplicate-enum |
| 118 |
-Wduplicate-method-arg |
| 119 |
-Wduplicate-method-match |
| 120 |
-Wdynamic-class-memaccess |
| 121 |
-Wempty-body |
| 122 |
-Wenum-compare |
| 123 |
-Wexplicit-ownership-type |
| 124 |
-Wextern-initializer |
| 125 |
-Wfloat-equal |
| 126 |
-Wgnu-array-member-paren-init |
| 127 |
-Wheader-guard |
| 128 |
-Wheader-hygiene |
| 129 |
-Widiomatic-parentheses |
| 130 |
-Wignored-attributes |
| 131 |
-Wimplicit-conversion-floating-point-to-bool |
| 132 |
-Wimplicit-exception-spec-mismatch |
| 133 |
-Wimplicit-fallthrough |
| 134 |
-Wincompatible-library-redeclaration |
| 135 |
-Wincompatible-pointer-types |
| 136 |
# -Winherited-variadic-ctor |
| 137 |
-Winline |
| 138 |
-Wint-conversions |
| 139 |
-Wint-to-pointer-cast |
| 140 |
-Winteger-overflow |
| 141 |
-Winvalid-constexpr |
| 142 |
-Winvalid-noreturn |
| 143 |
-Winvalid-offsetof |
| 144 |
-Winvalid-pch |
| 145 |
-Winvalid-pp-token |
| 146 |
-Winvalid-source-encoding |
| 147 |
-Winvalid-token-paste |
| 148 |
-Wloop-analysis |
| 149 |
-Wmain |
| 150 |
-Wmain-return-type |
| 151 |
-Wmalformed-warning-check |
| 152 |
-Wmethod-signatures |
| 153 |
-Wmismatched-parameter-types |
| 154 |
-Wmismatched-return-types |
| 155 |
-Wmissing-declarations |
| 156 |
-Wmissing-format-attribute |
| 157 |
-Wmissing-include-dirs |
| 158 |
-Wmissing-sysroot |
| 159 |
-Wmissing-variable-declarations |
| 160 |
-Wnarrowing |
| 161 |
-Wnested-externs |
| 162 |
-Wnewline-eof |
| 163 |
-Wnon-pod-varargs |
| 164 |
-Wnon-virtual-dtor |
| 165 |
-Wnull-arithmetic |
| 166 |
-Wnull-character |
| 167 |
-Wnull-dereference |
| 168 |
-Wodr |
| 169 |
-Wold-style-definition |
| 170 |
-Wout-of-line-declaration |
| 171 |
-Wover-aligned |
| 172 |
-Woverflow |
| 173 |
-Woverriding-method-mismatch |
| 174 |
-Wpacked |
| 175 |
-Wpointer-sign |
| 176 |
-Wpointer-to-int-cast |
| 177 |
-Wpointer-type-mismatch |
| 178 |
-Wpredefined-identifier-outside-function |
| 179 |
-Wredundant-decls |
| 180 |
-Wreinterpret-base-class |
| 181 |
-Wreserved-user-defined-literal |
| 182 |
-Wreturn-stack-address |
| 183 |
-Wsection |
| 184 |
-Wserialized-diagnostics |
| 185 |
-Wshift-count-negative |
| 186 |
-Wshift-count-overflow |
| 187 |
-Wshift-overflow |
| 188 |
-Wshift-sign-overflow |
| 189 |
# -Wsign-compare |
| 190 |
-Wsign-promo |
| 191 |
-Wsizeof-pointer-memaccess |
| 192 |
-Wstack-protector |
| 193 |
-Wstatic-float-init |
| 194 |
-Wstring-compare |
| 195 |
-Wstrlcpy-strlcat-size |
| 196 |
-Wstrncat-size |
| 197 |
-Wswitch-default |
| 198 |
-Wswitch-enum |
| 199 |
-Wsynth |
| 200 |
-Wtautological-compare |
| 201 |
-Wtentative-definition-incomplete-type |
| 202 |
-Wthread-safety |
| 203 |
-Wtype-limits |
| 204 |
-Wtype-safety |
| 205 |
-Wtypedef-redefinition |
| 206 |
-Wtypename-missing |
| 207 |
-Wundefined-inline |
| 208 |
-Wundefined-reinterpret-cast |
| 209 |
-Wunicode |
| 210 |
-Wunicode-whitespace |
| 211 |
-Wunused-exception-parameter |
| 212 |
-Wunused-macros |
| 213 |
-Wunused-member-function |
| 214 |
-Wunused-parameter |
| 215 |
-Wunused-volatile-lvalue |
| 216 |
-Wused-but-marked-unused |
| 217 |
-Wuser-defined-literals |
| 218 |
-Wvarargs |
| 219 |
-Wvector-conversions |
| 220 |
-Wvexing-parse |
| 221 |
-Wvisibility |
| 222 |
-Wvla |
| 223 |
-Wweak-template-vtables |
| 224 |
# -Wweak-vtables |
| 225 |
-Wwrite-strings |
| 226 |
) |
| 227 |
else() |
| 228 |
list(APPEND CMAKE_COMPILER_WARNINGS |
| 229 |
-Wno-missing-field-initializers |
| 230 |
) |
| 231 |
endif() |
| 232 |
|
| 233 |
foreach(FLAG ${CMAKE_COMPILER_WARNINGS}) |
| 234 |
if(NOT CMAKE_${COMPILER}_FLAGS MATCHES ${FLAG}) |
| 235 |
set(CMAKE_${COMPILER}_FLAGS "${CMAKE_${COMPILER}_FLAGS} ${FLAG}") |
| 236 |
endif() |
| 237 |
endforeach() |
| 238 |
endforeach() |
| 239 |
endif () |