compiler_flags.cmake 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. set_property(GLOBAL PROPERTY CSTD gnu99)
  2. # List the warnings that are not supported for C++ compilations
  3. list(APPEND CXX_EXCLUDED_OPTIONS
  4. -Werror=implicit-int
  5. -Wold-style-definition
  6. )
  7. ###################################################
  8. # Setting compiler properties for MWDT compilers. #
  9. ###################################################
  10. #####################################################
  11. # This section covers flags related to optimization #
  12. #####################################################
  13. set_compiler_property(PROPERTY no_optimization -O0)
  14. set_compiler_property(PROPERTY optimization_debug -O0)
  15. set_compiler_property(PROPERTY optimization_speed -O2)
  16. set_compiler_property(PROPERTY optimization_size -Os)
  17. #######################################################
  18. # This section covers flags related to warning levels #
  19. #######################################################
  20. # options for warnings
  21. # base options
  22. set_compiler_property(PROPERTY warning_base
  23. -Wformat
  24. -Wformat-security
  25. -Wno-format-zero-length
  26. -Wno-main-return-type
  27. -Wno-unaligned-pointer-conversion
  28. -Wno-incompatible-pointer-types-discards-qualifiers
  29. -Wno-typedef-redefinition
  30. )
  31. check_set_compiler_property(APPEND PROPERTY warning_base -Wno-pointer-sign)
  32. # Prohibit void pointer arithmetic. Illegal in C99
  33. check_set_compiler_property(APPEND PROPERTY warning_base -Wpointer-arith)
  34. # level 1 warning options
  35. set_compiler_property(PROPERTY warning_dw_1
  36. -Wextra
  37. -Wunused
  38. -Wno-unused-parameter
  39. -Wmissing-declarations
  40. -Wmissing-format-attribute
  41. )
  42. check_set_compiler_property(APPEND PROPERTY warning_dw_1
  43. -Wold-style-definition
  44. -Wmissing-prototypes
  45. -Wmissing-include-dirs
  46. -Wunused-but-set-variable
  47. -Wno-missing-field-initializers
  48. )
  49. # level 2 warning options
  50. set_compiler_property(PROPERTY warning_dw_2
  51. -Waggregate-return
  52. -Wcast-align
  53. -Wdisabled-optimization
  54. -Wnested-externs
  55. -Wshadow
  56. )
  57. check_set_compiler_property(APPEND PROPERTY warning_dw_2
  58. -Wlogical-op
  59. -Wmissing-field-initializers
  60. )
  61. # level 3 warning options
  62. set_compiler_property(PROPERTY warning_dw_3
  63. -Wbad-function-cast
  64. -Wcast-qual
  65. -Wconversion
  66. -Wpacked
  67. -Wpadded
  68. -Wpointer-arith
  69. -Wredundant-decls
  70. -Wswitch-default
  71. )
  72. check_set_compiler_property(APPEND PROPERTY warning_dw_3
  73. -Wpacked-bitfield-compat
  74. -Wvla
  75. )
  76. # extended warning options
  77. check_set_compiler_property(PROPERTY warning_extended
  78. -Wno-sometimes-uninitialized
  79. -Wno-shift-overflow
  80. -Wno-missing-braces
  81. -Wno-self-assign
  82. -Wno-address-of-packed-member
  83. -Wno-unused-function
  84. -Wno-initializer-overrides
  85. -Wno-section
  86. -Wno-unknown-warning-option
  87. -Wno-unused-variable
  88. -Wno-format-invalid-specifier
  89. -Wno-gnu
  90. # comparison of unsigned expression < 0 is always false
  91. -Wno-tautological-compare
  92. )
  93. check_set_compiler_property(PROPERTY warning_error_implicit_int -Werror=implicit-int)
  94. set_compiler_property(PROPERTY warning_error_misra_sane -Werror=vla)
  95. ###########################################################################
  96. # This section covers flags related to C or C++ standards / standard libs #
  97. ###########################################################################
  98. set_compiler_property(PROPERTY cstd -std=)
  99. if (NOT CONFIG_ARCMWDT_LIBC)
  100. set_compiler_property(PROPERTY nostdinc -Hno_default_include -Hnoarcexlib)
  101. endif()
  102. set_compiler_property(APPEND PROPERTY nostdinc_include ${NOSTDINC})
  103. # C++ std options
  104. set_property(TARGET compiler-cpp PROPERTY dialect_cpp98 "-std=c++98")
  105. set_property(TARGET compiler-cpp PROPERTY dialect_cpp11 "-std=c++11")
  106. set_property(TARGET compiler-cpp PROPERTY dialect_cpp14 "-std=c++14")
  107. set_property(TARGET compiler-cpp PROPERTY dialect_cpp17 "-std=c++17")
  108. #no support of C++2a, C++20, C++2b
  109. set_property(TARGET compiler-cpp PROPERTY dialect_cpp2a "")
  110. set_property(TARGET compiler-cpp PROPERTY dialect_cpp20 "")
  111. set_property(TARGET compiler-cpp PROPERTY dialect_cpp2b "")
  112. # Disable exeptions flag in C++
  113. set_property(TARGET compiler-cpp PROPERTY no_exceptions "-fno-exceptions")
  114. # Disable rtti in C++
  115. set_property(TARGET compiler-cpp PROPERTY no_rtti "-fno-rtti")
  116. ###################################################
  117. # This section covers all remaining C / C++ flags #
  118. ###################################################
  119. # mwdt flag for a freestanding application
  120. # do not link in supplied run-time startup files
  121. set_compiler_property(PROPERTY freestanding -Hnocrt)
  122. # Flag to enable debugging
  123. set_compiler_property(PROPERTY debug -g)
  124. # compile common globals like normal definitions
  125. set_compiler_property(PROPERTY no_common -fno-common)
  126. # mwdt's coverage mechanism is different with gnu
  127. # at present, zephyr only support gnu coverage
  128. set_compiler_property(PROPERTY coverage "")
  129. # mwdt compiler flags for imacros. The specific header must be appended by user.
  130. set_compiler_property(PROPERTY imacros -imacros)
  131. #no support of -fsanitize=address and -lasan
  132. set_compiler_property(PROPERTY sanitize_address "")
  133. set_compiler_property(PROPERTY sanitize_undefined "")
  134. # Security canaries.
  135. #no support of -mstack-protector-guard=global"
  136. set_compiler_property(PROPERTY security_canaries -fstack-protector-all)
  137. #no support of _FORTIFY_SOURCE"
  138. set_compiler_property(PROPERTY security_fortify "")
  139. # Required C++ flags when using mwdt
  140. set_property(TARGET compiler-cpp PROPERTY required "-Hcplus" "-Hoff=Stackcheck_alloca")
  141. # Compiler flag for turning off thread-safe initialization of local statics
  142. set_property(TARGET compiler-cpp PROPERTY no_threadsafe_statics "-fno-threadsafe-statics")
  143. #################################
  144. # This section covers asm flags #
  145. #################################
  146. # Required ASM flags when using mwdt
  147. set_property(TARGET asm PROPERTY required "-Hasmcpp")