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 | |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 19 | LLVM_TEST_DISABLE_WARNINGS_FLAGS = [ |
| 20 | "-Wno-c99-extensions", |
| 21 | "-Wno-deprecated-declarations", |
| 22 | "-Wno-missing-noreturn", |
| 23 | "-Wno-missing-prototypes", |
| 24 | "-Wno-missing-variable-declarations", |
| 25 | "-Wno-null-conversion", |
| 26 | "-Wno-shadow", |
| 27 | "-Wno-shift-sign-overflow", |
| 28 | "-Wno-sign-compare", |
| 29 | "-Wno-unused-function", |
| 30 | "-Wno-unused-member-function", |
| 31 | "-Wno-unused-parameter", |
| 32 | "-Wno-unused-private-field", |
| 33 | "-Wno-unused-template", |
| 34 | "-Wno-used-but-marked-unused", |
| 35 | "-Wno-zero-as-null-pointer-constant", |
| 36 | # gtest depends on this GNU extension being offered. |
| 37 | "-Wno-gnu-zero-variadic-macro-arguments", |
| 38 | ] |
| 39 | |
| 40 | MSVC_DEFINES = [ |
| 41 | "/DNOMINMAX", # Don't define min and max macros (windows.h) |
| 42 | # Don't bloat namespace with incompatible winsock versions. |
| 43 | "/DWIN32_LEAN_AND_MEAN", |
| 44 | # Don't warn about usage of insecure C functions. |
| 45 | "/D_CRT_SECURE_NO_WARNINGS", |
| 46 | "/D_SCL_SECURE_NO_WARNINGS", |
| 47 | # Introduced in VS 2017 15.8, allow overaligned types in aligned_storage |
| 48 | "/D_ENABLE_EXTENDED_ALIGNED_STORAGE", |
| 49 | ] |
| 50 | |
| 51 | COPT_VARS = { |
| 52 | "ABSL_GCC_FLAGS": [ |
| 53 | "-Wall", |
| 54 | "-Wextra", |
| 55 | "-Wcast-qual", |
| 56 | "-Wconversion-null", |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 57 | "-Wformat-security", |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 58 | "-Wmissing-declarations", |
| 59 | "-Woverlength-strings", |
| 60 | "-Wpointer-arith", |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 61 | "-Wundef", |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 62 | "-Wunused-local-typedefs", |
| 63 | "-Wunused-result", |
| 64 | "-Wvarargs", |
| 65 | "-Wvla", # variable-length array |
| 66 | "-Wwrite-strings", |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 67 | # Don't define min and max macros (Build on Windows using gcc) |
| 68 | "-DNOMINMAX", |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 69 | ], |
| 70 | "ABSL_GCC_TEST_FLAGS": [ |
| 71 | "-Wno-conversion-null", |
| 72 | "-Wno-deprecated-declarations", |
| 73 | "-Wno-missing-declarations", |
| 74 | "-Wno-sign-compare", |
| 75 | "-Wno-unused-function", |
| 76 | "-Wno-unused-parameter", |
| 77 | "-Wno-unused-private-field", |
| 78 | ], |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 79 | "ABSL_LLVM_FLAGS": [ |
| 80 | "-Wall", |
| 81 | "-Wextra", |
| 82 | "-Wcast-qual", |
| 83 | "-Wconversion", |
| 84 | "-Wfloat-overflow-conversion", |
| 85 | "-Wfloat-zero-conversion", |
| 86 | "-Wfor-loop-analysis", |
| 87 | "-Wformat-security", |
| 88 | "-Wgnu-redeclared-enum", |
| 89 | "-Winfinite-recursion", |
| 90 | "-Wliteral-conversion", |
| 91 | "-Wmissing-declarations", |
| 92 | "-Woverlength-strings", |
| 93 | "-Wpointer-arith", |
| 94 | "-Wself-assign", |
| 95 | "-Wshadow", |
| 96 | "-Wstring-conversion", |
| 97 | "-Wtautological-overlap-compare", |
| 98 | "-Wundef", |
| 99 | "-Wuninitialized", |
| 100 | "-Wunreachable-code", |
| 101 | "-Wunused-comparison", |
| 102 | "-Wunused-local-typedefs", |
| 103 | "-Wunused-result", |
| 104 | "-Wvla", |
| 105 | "-Wwrite-strings", |
| 106 | # Warnings that are enabled by group warning flags like -Wall that we |
| 107 | # explicitly disable. |
| 108 | "-Wno-float-conversion", |
| 109 | "-Wno-implicit-float-conversion", |
| 110 | "-Wno-implicit-int-float-conversion", |
| 111 | "-Wno-implicit-int-conversion", |
| 112 | "-Wno-shorten-64-to-32", |
| 113 | "-Wno-sign-conversion", |
| 114 | # Don't define min and max macros (Build on Windows using clang) |
| 115 | "-DNOMINMAX", |
| 116 | ], |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 117 | "ABSL_LLVM_TEST_FLAGS": |
| 118 | LLVM_TEST_DISABLE_WARNINGS_FLAGS, |
| 119 | "ABSL_CLANG_CL_FLAGS": |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 120 | (MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES), |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 121 | "ABSL_CLANG_CL_TEST_FLAGS": |
| 122 | LLVM_TEST_DISABLE_WARNINGS_FLAGS, |
| 123 | "ABSL_MSVC_FLAGS": |
| 124 | MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + [ |
| 125 | # Increase the number of sections available in object files |
| 126 | "/bigobj", |
| 127 | "/wd4005", # macro-redefinition |
| 128 | "/wd4068", # unknown pragma |
| 129 | # qualifier applied to function type has no meaning; ignored |
| 130 | "/wd4180", |
| 131 | # conversion from 'type1' to 'type2', possible loss of data |
| 132 | "/wd4244", |
| 133 | # conversion from 'size_t' to 'type', possible loss of data |
| 134 | "/wd4267", |
| 135 | # The decorated name was longer than the compiler limit |
| 136 | "/wd4503", |
| 137 | # forcing value to bool 'true' or 'false' (performance warning) |
| 138 | "/wd4800", |
| 139 | ], |
| 140 | "ABSL_MSVC_TEST_FLAGS": [ |
| 141 | "/wd4018", # signed/unsigned mismatch |
| 142 | "/wd4101", # unreferenced local variable |
| 143 | "/wd4503", # decorated name length exceeded, name was truncated |
| 144 | "/wd4996", # use of deprecated symbol |
| 145 | "/DNOMINMAX", # disable the min() and max() macros from <windows.h> |
| 146 | ], |
| 147 | "ABSL_MSVC_LINKOPTS": [ |
| 148 | # Object file doesn't export any previously undefined symbols |
| 149 | "-ignore:4221", |
| 150 | ], |
| 151 | # "HWAES" is an abbreviation for "hardware AES" (AES - Advanced Encryption |
| 152 | # Standard). These flags are used for detecting whether or not the target |
| 153 | # architecture has hardware support for AES instructions which can be used |
| 154 | # to improve performance of some random bit generators. |
| 155 | "ABSL_RANDOM_HWAES_ARM64_FLAGS": ["-march=armv8-a+crypto"], |
| 156 | "ABSL_RANDOM_HWAES_ARM32_FLAGS": ["-mfpu=neon"], |
| 157 | "ABSL_RANDOM_HWAES_X64_FLAGS": [ |
| 158 | "-maes", |
| 159 | "-msse4.1", |
| 160 | ], |
| 161 | "ABSL_RANDOM_HWAES_MSVC_X64_FLAGS": [], |
| 162 | } |