copts.py 5.6 KB

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