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