global_flags.compiler.gnu.cmake 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. include(global_flags.compiler.gnu.march)
  45. string(APPEND _GNU_COMMON_C_CXX_FLAGS " ${_GNU_MARCH_C_CXX_FLAGS}")
  46. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_GNU_COMMON_C_CXX_FLAGS}")
  47. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_GNU_COMMON_C_CXX_FLAGS} \
  48. -Woverloaded-virtual \
  49. -Wimport-preprocessor-directive-pedantic \
  50. -Wno-undefined-var-template \
  51. -Wno-return-std-move \
  52. -Wno-defaulted-function-deleted \
  53. -Wno-pessimizing-move \
  54. -Wno-deprecated-anon-enum-enum-conversion \
  55. -Wno-deprecated-enum-enum-conversion \
  56. -Wno-deprecated-enum-float-conversion \
  57. -Wno-ambiguous-reversed-operator \
  58. -Wno-deprecated-volatile \
  59. ")