• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
14ABSL_GCC_FLAGS = [
15    "-Wall",
16    "-Wextra",
17    "-Wcast-qual",
18    "-Wconversion-null",
19    "-Wformat-security",
20    "-Wmissing-declarations",
21    "-Wnon-virtual-dtor",
22    "-Woverlength-strings",
23    "-Wpointer-arith",
24    "-Wundef",
25    "-Wunused-local-typedefs",
26    "-Wunused-result",
27    "-Wvarargs",
28    "-Wvla",  # variable-length array
29    "-Wwrite-strings",
30    # Don't define min and max macros (Build on Windows using gcc)
31    "-DNOMINMAX",
32]
33
34ABSL_GCC_TEST_ADDITIONAL_FLAGS = [
35    "-Wno-deprecated-declarations",
36    "-Wno-missing-declarations",
37    "-Wno-self-move",
38    "-Wno-sign-compare",
39    "-Wno-unused-function",
40    "-Wno-unused-parameter",
41    "-Wno-unused-private-field",
42]
43
44ABSL_LLVM_FLAGS = [
45    "-Wall",
46    "-Wextra",
47    "-Wc++98-compat-extra-semi",
48    "-Wcast-qual",
49    "-Wconversion",
50    "-Wdeprecated-pragma",
51    "-Wfloat-overflow-conversion",
52    "-Wfloat-zero-conversion",
53    "-Wfor-loop-analysis",
54    "-Wformat-security",
55    "-Wgnu-redeclared-enum",
56    "-Winfinite-recursion",
57    "-Winvalid-constexpr",
58    "-Wliteral-conversion",
59    "-Wmissing-declarations",
60    "-Woverlength-strings",
61    "-Wpointer-arith",
62    "-Wself-assign",
63    "-Wshadow-all",
64    "-Wshorten-64-to-32",
65    "-Wsign-conversion",
66    "-Wstring-conversion",
67    "-Wtautological-overlap-compare",
68    "-Wtautological-unsigned-zero-compare",
69    "-Wundef",
70    "-Wuninitialized",
71    "-Wunreachable-code",
72    "-Wunused-comparison",
73    "-Wunused-local-typedefs",
74    "-Wunused-result",
75    "-Wvla",
76    "-Wwrite-strings",
77    # Warnings that are enabled by group warning flags like -Wall that we
78    # explicitly disable.
79    "-Wno-float-conversion",
80    "-Wno-implicit-float-conversion",
81    "-Wno-implicit-int-float-conversion",
82    # Disable warnings on unknown warning flags (when warning flags are
83    # unknown on older compiler versions)
84    "-Wno-unknown-warning-option",
85    # Don't define min and max macros (Build on Windows using clang)
86    "-DNOMINMAX",
87]
88
89ABSL_LLVM_TEST_ADDITIONAL_FLAGS = [
90    "-Wno-deprecated-declarations",
91    "-Wno-implicit-int-conversion",
92    "-Wno-missing-prototypes",
93    "-Wno-missing-variable-declarations",
94    "-Wno-shadow",
95    "-Wno-shorten-64-to-32",
96    "-Wno-sign-compare",
97    "-Wno-sign-conversion",
98    "-Wno-unreachable-code-loop-increment",
99    "-Wno-unused-function",
100    "-Wno-unused-member-function",
101    "-Wno-unused-parameter",
102    "-Wno-unused-private-field",
103    "-Wno-unused-template",
104    "-Wno-used-but-marked-unused",
105    # gtest depends on this GNU extension being offered.
106    "-Wno-gnu-zero-variadic-macro-arguments",
107]
108
109# /Wall with msvc includes unhelpful warnings such as C4711, C4710, ...
110MSVC_BIG_WARNING_FLAGS = [
111    "/W3",
112]
113
114MSVC_WARNING_FLAGS = [
115    # Increase the number of sections available in object files
116    "/bigobj",
117    "/wd4005",  # macro-redefinition
118    "/wd4068",  # unknown pragma
119    # qualifier applied to function type has no meaning; ignored
120    "/wd4180",
121    # The decorated name was longer than the compiler limit
122    "/wd4503",
123    # forcing value to bool 'true' or 'false' (performance warning)
124    "/wd4800",
125]
126
127MSVC_DEFINES = [
128    "/DNOMINMAX",  # Don't define min and max macros (windows.h)
129    # Don't bloat namespace with incompatible winsock versions.
130    "/DWIN32_LEAN_AND_MEAN",
131    # Don't warn about usage of insecure C functions.
132    "/D_CRT_SECURE_NO_WARNINGS",
133    "/D_SCL_SECURE_NO_WARNINGS",
134    # Introduced in VS 2017 15.8, allow overaligned types in aligned_storage
135    "/D_ENABLE_EXTENDED_ALIGNED_STORAGE",
136]
137
138
139def GccStyleFilterAndCombine(default_flags, test_flags):
140  """Merges default_flags and test_flags for GCC and LLVM.
141
142  Args:
143    default_flags: A list of default compiler flags
144    test_flags: A list of flags that are only used in tests
145
146  Returns:
147    A combined list of default_flags and test_flags, but with all flags of the
148    form '-Wwarning' removed if test_flags contains a flag of the form
149    '-Wno-warning'
150  """
151  remove = set(["-W" + f[5:] for f in test_flags if f[:5] == "-Wno-"])
152  return [f for f in default_flags if f not in remove] + test_flags
153
154COPT_VARS = {
155    "ABSL_GCC_FLAGS": ABSL_GCC_FLAGS,
156    "ABSL_GCC_TEST_FLAGS": GccStyleFilterAndCombine(
157        ABSL_GCC_FLAGS, ABSL_GCC_TEST_ADDITIONAL_FLAGS
158    ),
159    "ABSL_LLVM_FLAGS": ABSL_LLVM_FLAGS,
160    "ABSL_LLVM_TEST_FLAGS": GccStyleFilterAndCombine(
161        ABSL_LLVM_FLAGS, ABSL_LLVM_TEST_ADDITIONAL_FLAGS
162    ),
163    "ABSL_CLANG_CL_FLAGS": MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES,
164    "ABSL_CLANG_CL_TEST_FLAGS": (
165        MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + ABSL_LLVM_TEST_ADDITIONAL_FLAGS
166    ),
167    "ABSL_MSVC_FLAGS": (
168        MSVC_BIG_WARNING_FLAGS + MSVC_WARNING_FLAGS + MSVC_DEFINES
169    ),
170    "ABSL_MSVC_TEST_FLAGS": (
171        MSVC_BIG_WARNING_FLAGS
172        + MSVC_WARNING_FLAGS
173        + MSVC_DEFINES
174        + [
175            "/wd4018",  # signed/unsigned mismatch
176            "/wd4101",  # unreferenced local variable
177            "/wd4244",  # shortening conversion
178            "/wd4267",  # shortening conversion
179            "/wd4503",  # decorated name length exceeded, name was truncated
180            "/wd4996",  # use of deprecated symbol
181            "/DNOMINMAX",  # disable the min() and max() macros from <windows.h>
182        ]
183    ),
184    "ABSL_MSVC_LINKOPTS": [
185        # Object file doesn't export any previously undefined symbols
186        "-ignore:4221",
187    ],
188}
189