compiler_flags.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # First step is to inherit all properties from gcc, as clang is compatible with most flags.
  2. include(${ZEPHYR_BASE}/cmake/compiler/gcc/compiler_flags.cmake)
  3. # Now, let's overwrite the flags that are different in clang.
  4. # No property flag, clang doesn't understand fortify at all
  5. set_compiler_property(PROPERTY security_fortify)
  6. # No property flag, this is used by the native_posix, clang has problems
  7. # compiling the native_posix with -fno-freestanding.
  8. check_set_compiler_property(PROPERTY hosted)
  9. # clang flags for coverage generation
  10. set_property(TARGET compiler PROPERTY coverage --coverage -fno-inline)
  11. # clang flag for colourful diagnostic messages
  12. set_compiler_property(PROPERTY diagnostic -fcolor-diagnostics)
  13. #######################################################
  14. # This section covers flags related to warning levels #
  15. #######################################################
  16. # clang option standard warning base in Zephyr
  17. set_compiler_property(PROPERTY warning_base
  18. -Wall
  19. -Wformat
  20. -Wformat-security
  21. -Wno-format-zero-length
  22. -Wno-main
  23. -Wno-typedef-redefinition
  24. )
  25. check_set_compiler_property(APPEND PROPERTY warning_base -Wno-pointer-sign)
  26. # Prohibit void pointer arithmetic. Illegal in C99
  27. check_set_compiler_property(APPEND PROPERTY warning_base -Wpointer-arith)
  28. # clang options for warning levels 1, 2, 3, when using `-DW=[1|2|3]`
  29. set_compiler_property(PROPERTY warning_dw_1
  30. -Wextra
  31. -Wunused
  32. -Wno-unused-parameter
  33. -Wmissing-declarations
  34. -Wmissing-format-attribute
  35. )
  36. check_set_compiler_property(APPEND PROPERTY warning_dw_1
  37. -Wold-style-definition
  38. -Wmissing-prototypes
  39. -Wmissing-include-dirs
  40. -Wunused-but-set-variable
  41. -Wno-missing-field-initializers
  42. )
  43. set_compiler_property(PROPERTY warning_dw_2
  44. -Waggregate-return
  45. -Wcast-align
  46. -Wdisabled-optimization
  47. -Wnested-externs
  48. -Wshadow
  49. )
  50. check_set_compiler_property(APPEND PROPERTY warning_dw_2
  51. -Wlogical-op
  52. -Wmissing-field-initializers
  53. )
  54. set_compiler_property(PROPERTY warning_dw_3
  55. -Wbad-function-cast
  56. -Wcast-qual
  57. -Wconversion
  58. -Wpacked
  59. -Wpadded
  60. -Wpointer-arith
  61. -Wredundant-decls
  62. -Wswitch-default
  63. )
  64. check_set_compiler_property(APPEND PROPERTY warning_dw_3
  65. -Wpacked-bitfield-compat
  66. -Wvla
  67. )
  68. check_set_compiler_property(PROPERTY warning_extended
  69. #FIXME: need to fix all of those
  70. -Wno-sometimes-uninitialized
  71. -Wno-shift-overflow
  72. -Wno-missing-braces
  73. -Wno-self-assign
  74. -Wno-address-of-packed-member
  75. -Wno-unused-function
  76. -Wno-initializer-overrides
  77. -Wno-section
  78. -Wno-unknown-warning-option
  79. -Wno-unused-variable
  80. -Wno-format-invalid-specifier
  81. -Wno-gnu
  82. # comparison of unsigned expression < 0 is always false
  83. -Wno-tautological-compare
  84. )
  85. set_compiler_property(PROPERTY warning_error_coding_guideline
  86. -Werror=vla
  87. -Wimplicit-fallthrough
  88. -Wconversion
  89. -Woverride-init
  90. )