global_flags.compiler.gnu.cmake 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. set(_GNU_COMMON_C_CXX_FLAGS "\
  2. -fexceptions \
  3. -fno-common \
  4. -fcolor-diagnostics \
  5. -faligned-allocation \
  6. -fdebug-default-version=4 \
  7. -ffunction-sections \
  8. -fdata-sections \
  9. -Wall \
  10. -Wextra \
  11. -Wno-parentheses \
  12. -Wno-implicit-const-int-float-conversion \
  13. -Wno-unknown-warning-option \
  14. -pipe \
  15. -D_THREAD_SAFE \
  16. -D_PTHREADS \
  17. -D_REENTRANT \
  18. -D_LARGEFILE_SOURCE \
  19. -D__STDC_CONSTANT_MACROS \
  20. -D__STDC_FORMAT_MACROS \
  21. -D__LONG_LONG_SUPPORTED \
  22. ")
  23. if (CMAKE_SYSTEM_NAME MATCHES "^(Android|Linux)$")
  24. string(APPEND _GNU_COMMON_C_CXX_FLAGS " -D_GNU_SOURCE")
  25. endif()
  26. if (CMAKE_SYSTEM_NAME MATCHES "^(Darwin|Linux)$")
  27. string(APPEND _GNU_COMMON_C_CXX_FLAGS " -DLIBCXX_BUILDING_LIBCXXRT")
  28. endif()
  29. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  30. # Use .init_array instead of .ctors (default for old clang versions)
  31. # See: https://maskray.me/blog/2021-11-07-init-ctors-init-array
  32. string(APPEND _GNU_COMMON_C_CXX_FLAGS " -fuse-init-array")
  33. endif()
  34. if (ANDROID)
  35. include_directories(SYSTEM ${CMAKE_ANDROID_NDK}/sources/cxx-stl/llvm-libc++abi/include)
  36. # There is no usable _FILE_OFFSET_BITS=64 support in Androids until API 21. And it's incomplete until at least API 24.
  37. # https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md
  38. else()
  39. string(APPEND _GNU_COMMON_C_CXX_FLAGS " -D_FILE_OFFSET_BITS=64")
  40. endif()
  41. if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|aarch64|ppc64le)")
  42. string(APPEND _GNU_COMMON_C_CXX_FLAGS " -fsigned-char")
  43. endif()
  44. if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|x86_64|AMD64)$")
  45. if (CMAKE_SYSTEM_PROCESSOR STREQUAL "i686")
  46. string(APPEND _GNU_COMMON_C_CXX_FLAGS " -m32")
  47. elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$")
  48. string(APPEND _GNU_COMMON_C_CXX_FLAGS " -m64")
  49. endif()
  50. string(APPEND _GNU_COMMON_C_CXX_FLAGS "\
  51. -msse2 \
  52. -msse3 \
  53. -mssse3 \
  54. ")
  55. if ((CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$") OR (NOT ANDROID))
  56. string(APPEND _GNU_COMMON_C_CXX_FLAGS "\
  57. -msse4.1 \
  58. -msse4.2 \
  59. -mpopcnt \
  60. ")
  61. if (NOT ANDROID)
  62. # older clang versions did not support this feature on Android:
  63. # https://reviews.llvm.org/rGc32d307a49f5255602e7543e64e6c38a7f536abc
  64. string(APPEND _GNU_COMMON_C_CXX_FLAGS " -mcx16")
  65. endif()
  66. endif()
  67. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  68. string(APPEND _GNU_COMMON_C_CXX_FLAGS " -D_YNDX_LIBUNWIND_ENABLE_EXCEPTION_BACKTRACE")
  69. endif()
  70. elseif (ANDROID AND (CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a"))
  71. string(APPEND _GNU_COMMON_C_CXX_FLAGS " -mfloat-abi=softfp")
  72. endif()
  73. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_GNU_COMMON_C_CXX_FLAGS}")
  74. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_GNU_COMMON_C_CXX_FLAGS} \
  75. -Woverloaded-virtual \
  76. -Wimport-preprocessor-directive-pedantic \
  77. -Wno-undefined-var-template \
  78. -Wno-return-std-move \
  79. -Wno-defaulted-function-deleted \
  80. -Wno-pessimizing-move \
  81. -Wno-deprecated-anon-enum-enum-conversion \
  82. -Wno-deprecated-enum-enum-conversion \
  83. -Wno-deprecated-enum-float-conversion \
  84. -Wno-ambiguous-reversed-operator \
  85. -Wno-deprecated-volatile \
  86. ")