Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame^] | 1 | """Abseil compiler options. |
| 2 | |
| 3 | This is the source of truth for Abseil compiler options. To modify Abseil |
| 4 | compilation options: |
| 5 | |
| 6 | (1) Edit the appropriate list in this file based on the platform the flag is |
| 7 | needed on. |
| 8 | (2) Run `<path_to_absl>/copts/generate_copts.py`. |
| 9 | |
| 10 | The generated copts are consumed by configure_copts.bzl and |
| 11 | AbseilConfigureCopts.cmake. |
| 12 | """ |
| 13 | |
| 14 | # /Wall with msvc includes unhelpful warnings such as C4711, C4710, ... |
| 15 | MSVC_BIG_WARNING_FLAGS = [ |
| 16 | "/W3", |
| 17 | ] |
| 18 | |
| 19 | LLVM_BIG_WARNING_FLAGS = [ |
| 20 | "-Wall", |
| 21 | "-Wextra", |
| 22 | "-Weverything", |
| 23 | ] |
| 24 | |
| 25 | # Docs on single flags is preceded by a comment. |
| 26 | # Docs on groups of flags is preceded by ###. |
| 27 | LLVM_DISABLE_WARNINGS_FLAGS = [ |
| 28 | # Abseil does not support C++98 |
| 29 | "-Wno-c++98-compat-pedantic", |
| 30 | # Turns off all implicit conversion warnings. Most are re-enabled below. |
| 31 | "-Wno-conversion", |
| 32 | "-Wno-covered-switch-default", |
| 33 | "-Wno-deprecated", |
| 34 | "-Wno-disabled-macro-expansion", |
| 35 | "-Wno-double-promotion", |
| 36 | ### |
| 37 | # Turned off as they include valid C++ code. |
| 38 | "-Wno-comma", |
| 39 | "-Wno-extra-semi", |
| 40 | "-Wno-extra-semi-stmt", |
| 41 | "-Wno-packed", |
| 42 | "-Wno-padded", |
| 43 | ### |
| 44 | # Google style does not use unsigned integers, though STL containers |
| 45 | # have unsigned types. |
| 46 | "-Wno-sign-compare", |
| 47 | ### |
| 48 | "-Wno-float-conversion", |
| 49 | "-Wno-float-equal", |
| 50 | "-Wno-format-nonliteral", |
| 51 | # Too aggressive: warns on Clang extensions enclosed in Clang-only |
| 52 | # compilation paths. |
| 53 | "-Wno-gcc-compat", |
| 54 | ### |
| 55 | # Some internal globals are necessary. Don't do this at home. |
| 56 | "-Wno-global-constructors", |
| 57 | "-Wno-exit-time-destructors", |
| 58 | ### |
| 59 | "-Wno-nested-anon-types", |
| 60 | "-Wno-non-modular-include-in-module", |
| 61 | "-Wno-old-style-cast", |
| 62 | # Warns on preferred usage of non-POD types such as string_view |
| 63 | "-Wno-range-loop-analysis", |
| 64 | "-Wno-reserved-id-macro", |
| 65 | "-Wno-shorten-64-to-32", |
| 66 | "-Wno-switch-enum", |
| 67 | "-Wno-thread-safety-negative", |
| 68 | "-Wno-unknown-warning-option", |
| 69 | "-Wno-unreachable-code", |
| 70 | # Causes warnings on include guards |
| 71 | "-Wno-unused-macros", |
| 72 | "-Wno-weak-vtables", |
| 73 | # Causes warnings on usage of types/compare.h comparison operators. |
| 74 | "-Wno-zero-as-null-pointer-constant", |
| 75 | ### |
| 76 | # Implicit conversion warnings turned off by -Wno-conversion |
| 77 | # which are re-enabled below. |
| 78 | "-Wbitfield-enum-conversion", |
| 79 | "-Wbool-conversion", |
| 80 | "-Wconstant-conversion", |
| 81 | "-Wenum-conversion", |
| 82 | "-Wint-conversion", |
| 83 | "-Wliteral-conversion", |
| 84 | "-Wnon-literal-null-conversion", |
| 85 | "-Wnull-conversion", |
| 86 | "-Wobjc-literal-conversion", |
| 87 | "-Wno-sign-conversion", |
| 88 | "-Wstring-conversion", |
| 89 | ] |
| 90 | |
| 91 | LLVM_TEST_DISABLE_WARNINGS_FLAGS = [ |
| 92 | "-Wno-c99-extensions", |
| 93 | "-Wno-deprecated-declarations", |
| 94 | "-Wno-missing-noreturn", |
| 95 | "-Wno-missing-prototypes", |
| 96 | "-Wno-missing-variable-declarations", |
| 97 | "-Wno-null-conversion", |
| 98 | "-Wno-shadow", |
| 99 | "-Wno-shift-sign-overflow", |
| 100 | "-Wno-sign-compare", |
| 101 | "-Wno-unused-function", |
| 102 | "-Wno-unused-member-function", |
| 103 | "-Wno-unused-parameter", |
| 104 | "-Wno-unused-private-field", |
| 105 | "-Wno-unused-template", |
| 106 | "-Wno-used-but-marked-unused", |
| 107 | "-Wno-zero-as-null-pointer-constant", |
| 108 | # gtest depends on this GNU extension being offered. |
| 109 | "-Wno-gnu-zero-variadic-macro-arguments", |
| 110 | ] |
| 111 | |
| 112 | MSVC_DEFINES = [ |
| 113 | "/DNOMINMAX", # Don't define min and max macros (windows.h) |
| 114 | # Don't bloat namespace with incompatible winsock versions. |
| 115 | "/DWIN32_LEAN_AND_MEAN", |
| 116 | # Don't warn about usage of insecure C functions. |
| 117 | "/D_CRT_SECURE_NO_WARNINGS", |
| 118 | "/D_SCL_SECURE_NO_WARNINGS", |
| 119 | # Introduced in VS 2017 15.8, allow overaligned types in aligned_storage |
| 120 | "/D_ENABLE_EXTENDED_ALIGNED_STORAGE", |
| 121 | ] |
| 122 | |
| 123 | COPT_VARS = { |
| 124 | "ABSL_GCC_FLAGS": [ |
| 125 | "-Wall", |
| 126 | "-Wextra", |
| 127 | "-Wcast-qual", |
| 128 | "-Wconversion-null", |
| 129 | "-Wmissing-declarations", |
| 130 | "-Woverlength-strings", |
| 131 | "-Wpointer-arith", |
| 132 | "-Wunused-local-typedefs", |
| 133 | "-Wunused-result", |
| 134 | "-Wvarargs", |
| 135 | "-Wvla", # variable-length array |
| 136 | "-Wwrite-strings", |
| 137 | # gcc-4.x has spurious missing field initializer warnings. |
| 138 | # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36750 |
| 139 | # Remove when gcc-4.x is no longer supported. |
| 140 | "-Wno-missing-field-initializers", |
| 141 | # Google style does not use unsigned integers, though STL containers |
| 142 | # have unsigned types. |
| 143 | "-Wno-sign-compare", |
| 144 | ], |
| 145 | "ABSL_GCC_TEST_FLAGS": [ |
| 146 | "-Wno-conversion-null", |
| 147 | "-Wno-deprecated-declarations", |
| 148 | "-Wno-missing-declarations", |
| 149 | "-Wno-sign-compare", |
| 150 | "-Wno-unused-function", |
| 151 | "-Wno-unused-parameter", |
| 152 | "-Wno-unused-private-field", |
| 153 | ], |
| 154 | "ABSL_LLVM_FLAGS": |
| 155 | LLVM_BIG_WARNING_FLAGS + LLVM_DISABLE_WARNINGS_FLAGS, |
| 156 | "ABSL_LLVM_TEST_FLAGS": |
| 157 | LLVM_TEST_DISABLE_WARNINGS_FLAGS, |
| 158 | "ABSL_CLANG_CL_FLAGS": |
| 159 | (MSVC_BIG_WARNING_FLAGS + LLVM_DISABLE_WARNINGS_FLAGS + MSVC_DEFINES), |
| 160 | "ABSL_CLANG_CL_TEST_FLAGS": |
| 161 | LLVM_TEST_DISABLE_WARNINGS_FLAGS, |
| 162 | "ABSL_MSVC_FLAGS": |
| 163 | MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + [ |
| 164 | # Increase the number of sections available in object files |
| 165 | "/bigobj", |
| 166 | "/wd4005", # macro-redefinition |
| 167 | "/wd4068", # unknown pragma |
| 168 | # qualifier applied to function type has no meaning; ignored |
| 169 | "/wd4180", |
| 170 | # conversion from 'type1' to 'type2', possible loss of data |
| 171 | "/wd4244", |
| 172 | # conversion from 'size_t' to 'type', possible loss of data |
| 173 | "/wd4267", |
| 174 | # The decorated name was longer than the compiler limit |
| 175 | "/wd4503", |
| 176 | # forcing value to bool 'true' or 'false' (performance warning) |
| 177 | "/wd4800", |
| 178 | ], |
| 179 | "ABSL_MSVC_TEST_FLAGS": [ |
| 180 | "/wd4018", # signed/unsigned mismatch |
| 181 | "/wd4101", # unreferenced local variable |
| 182 | "/wd4503", # decorated name length exceeded, name was truncated |
| 183 | "/wd4996", # use of deprecated symbol |
| 184 | "/DNOMINMAX", # disable the min() and max() macros from <windows.h> |
| 185 | ], |
| 186 | "ABSL_MSVC_LINKOPTS": [ |
| 187 | # Object file doesn't export any previously undefined symbols |
| 188 | "-ignore:4221", |
| 189 | ], |
| 190 | # "HWAES" is an abbreviation for "hardware AES" (AES - Advanced Encryption |
| 191 | # Standard). These flags are used for detecting whether or not the target |
| 192 | # architecture has hardware support for AES instructions which can be used |
| 193 | # to improve performance of some random bit generators. |
| 194 | "ABSL_RANDOM_HWAES_ARM64_FLAGS": ["-march=armv8-a+crypto"], |
| 195 | "ABSL_RANDOM_HWAES_ARM32_FLAGS": ["-mfpu=neon"], |
| 196 | "ABSL_RANDOM_HWAES_X64_FLAGS": [ |
| 197 | "-maes", |
| 198 | "-msse4.1", |
| 199 | ], |
| 200 | "ABSL_RANDOM_HWAES_MSVC_X64_FLAGS": [], |
| 201 | } |