global_flags.compiler.gnu.cmake 3.1 KB

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