1"""Abseil compiler options. 2 3This is the source of truth for Abseil compiler options. To modify Abseil 4compilation 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 10The generated copts are consumed by configure_copts.bzl and 11AbseilConfigureCopts.cmake. 12""" 13 14# /Wall with msvc includes unhelpful warnings such as C4711, C4710, ... 15MSVC_BIG_WARNING_FLAGS = [ 16 "/W3", 17] 18 19LLVM_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 ###. 27LLVM_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-non-modular-include-in-module", 60 "-Wno-old-style-cast", 61 # Warns on preferred usage of non-POD types such as string_view 62 "-Wno-range-loop-analysis", 63 "-Wno-reserved-id-macro", 64 "-Wno-shorten-64-to-32", 65 "-Wno-switch-enum", 66 "-Wno-thread-safety-negative", 67 "-Wno-unknown-warning-option", 68 "-Wno-unreachable-code", 69 # Causes warnings on include guards 70 "-Wno-unused-macros", 71 "-Wno-weak-vtables", 72 # Causes warnings on usage of types/compare.h comparison operators. 73 "-Wno-zero-as-null-pointer-constant", 74 ### 75 # Implicit conversion warnings turned off by -Wno-conversion 76 # which are re-enabled below. 77 "-Wbitfield-enum-conversion", 78 "-Wbool-conversion", 79 "-Wconstant-conversion", 80 "-Wenum-conversion", 81 "-Wint-conversion", 82 "-Wliteral-conversion", 83 "-Wnon-literal-null-conversion", 84 "-Wnull-conversion", 85 "-Wobjc-literal-conversion", 86 "-Wno-sign-conversion", 87 "-Wstring-conversion", 88] 89 90LLVM_TEST_DISABLE_WARNINGS_FLAGS = [ 91 "-Wno-c99-extensions", 92 "-Wno-deprecated-declarations", 93 "-Wno-missing-noreturn", 94 "-Wno-missing-prototypes", 95 "-Wno-missing-variable-declarations", 96 "-Wno-null-conversion", 97 "-Wno-shadow", 98 "-Wno-shift-sign-overflow", 99 "-Wno-sign-compare", 100 "-Wno-unused-function", 101 "-Wno-unused-member-function", 102 "-Wno-unused-parameter", 103 "-Wno-unused-private-field", 104 "-Wno-unused-template", 105 "-Wno-used-but-marked-unused", 106 "-Wno-zero-as-null-pointer-constant", 107 # gtest depends on this GNU extension being offered. 108 "-Wno-gnu-zero-variadic-macro-arguments", 109] 110 111MSVC_DEFINES = [ 112 "/DNOMINMAX", # Don't define min and max macros (windows.h) 113 # Don't bloat namespace with incompatible winsock versions. 114 "/DWIN32_LEAN_AND_MEAN", 115 # Don't warn about usage of insecure C functions. 116 "/D_CRT_SECURE_NO_WARNINGS", 117 "/D_SCL_SECURE_NO_WARNINGS", 118 # Introduced in VS 2017 15.8, allow overaligned types in aligned_storage 119 "/D_ENABLE_EXTENDED_ALIGNED_STORAGE", 120] 121 122COPT_VARS = { 123 "ABSL_GCC_FLAGS": [ 124 "-Wall", 125 "-Wextra", 126 "-Wcast-qual", 127 "-Wconversion-null", 128 "-Wmissing-declarations", 129 "-Woverlength-strings", 130 "-Wpointer-arith", 131 "-Wundef", 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 # Don't define min and max macros (Build on Windows using gcc) 145 "-DNOMINMAX", 146 ], 147 "ABSL_GCC_TEST_FLAGS": [ 148 "-Wno-conversion-null", 149 "-Wno-deprecated-declarations", 150 "-Wno-missing-declarations", 151 "-Wno-sign-compare", 152 "-Wno-unused-function", 153 "-Wno-unused-parameter", 154 "-Wno-unused-private-field", 155 ], 156 "ABSL_LLVM_FLAGS": 157 LLVM_BIG_WARNING_FLAGS + LLVM_DISABLE_WARNINGS_FLAGS + [ 158 # Don't define min and max macros (Build on Windows using clang) 159 "-DNOMINMAX", 160 ], 161 "ABSL_LLVM_TEST_FLAGS": 162 LLVM_TEST_DISABLE_WARNINGS_FLAGS, 163 "ABSL_CLANG_CL_FLAGS": 164 (MSVC_BIG_WARNING_FLAGS + LLVM_DISABLE_WARNINGS_FLAGS + MSVC_DEFINES), 165 "ABSL_CLANG_CL_TEST_FLAGS": 166 LLVM_TEST_DISABLE_WARNINGS_FLAGS, 167 "ABSL_MSVC_FLAGS": 168 MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + [ 169 # Increase the number of sections available in object files 170 "/bigobj", 171 "/wd4005", # macro-redefinition 172 "/wd4068", # unknown pragma 173 # qualifier applied to function type has no meaning; ignored 174 "/wd4180", 175 # conversion from 'type1' to 'type2', possible loss of data 176 "/wd4244", 177 # conversion from 'size_t' to 'type', possible loss of data 178 "/wd4267", 179 # The decorated name was longer than the compiler limit 180 "/wd4503", 181 # forcing value to bool 'true' or 'false' (performance warning) 182 "/wd4800", 183 ], 184 "ABSL_MSVC_TEST_FLAGS": [ 185 "/wd4018", # signed/unsigned mismatch 186 "/wd4101", # unreferenced local variable 187 "/wd4503", # decorated name length exceeded, name was truncated 188 "/wd4996", # use of deprecated symbol 189 "/DNOMINMAX", # disable the min() and max() macros from <windows.h> 190 ], 191 "ABSL_MSVC_LINKOPTS": [ 192 # Object file doesn't export any previously undefined symbols 193 "-ignore:4221", 194 ], 195 # "HWAES" is an abbreviation for "hardware AES" (AES - Advanced Encryption 196 # Standard). These flags are used for detecting whether or not the target 197 # architecture has hardware support for AES instructions which can be used 198 # to improve performance of some random bit generators. 199 "ABSL_RANDOM_HWAES_ARM64_FLAGS": ["-march=armv8-a+crypto"], 200 "ABSL_RANDOM_HWAES_ARM32_FLAGS": ["-mfpu=neon"], 201 "ABSL_RANDOM_HWAES_X64_FLAGS": [ 202 "-maes", 203 "-msse4.1", 204 ], 205 "ABSL_RANDOM_HWAES_MSVC_X64_FLAGS": [], 206} 207