Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
4.8KB

  1. # ===============================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_compiler_flags_cxxflags.html
  3. # ===============================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_COMPILER_FLAGS_CXXFLAGS([VARIABLE], [IS-RELEASE], [EXTRA-BASE-FLAGS], [EXTRA-YES-FLAGS])
  8. #
  9. # DESCRIPTION
  10. #
  11. # Add warning flags for the C++ compiler to VARIABLE, which defaults to
  12. # WARN_CXXFLAGS. VARIABLE is AC_SUBST-ed by this macro, but must be
  13. # manually added to the CXXFLAGS variable for each target in the code
  14. # base.
  15. #
  16. # This macro depends on the environment set up by AX_COMPILER_FLAGS.
  17. # Specifically, it uses the value of $ax_enable_compile_warnings to decide
  18. # which flags to enable.
  19. #
  20. # LICENSE
  21. #
  22. # Copyright (c) 2015 David King <amigadave@amigadave.com>
  23. #
  24. # Copying and distribution of this file, with or without modification, are
  25. # permitted in any medium without royalty provided the copyright notice
  26. # and this notice are preserved. This file is offered as-is, without any
  27. # warranty.
  28. #serial 10
  29. AC_DEFUN([AX_COMPILER_FLAGS_CXXFLAGS],[
  30. AC_REQUIRE([AC_PROG_SED])
  31. AX_REQUIRE_DEFINED([AX_APPEND_COMPILE_FLAGS])
  32. AX_REQUIRE_DEFINED([AX_APPEND_FLAG])
  33. AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
  34. # Variable names
  35. m4_define([ax_warn_cxxflags_variable],
  36. [m4_normalize(ifelse([$1],,[WARN_CXXFLAGS],[$1]))])
  37. AC_LANG_PUSH([C++])
  38. # Always pass -Werror=unknown-warning-option to get Clang to fail on bad
  39. # flags, otherwise they are always appended to the warn_cxxflags variable,
  40. # and Clang warns on them for every compilation unit.
  41. # If this is passed to GCC, it will explode, so the flag must be enabled
  42. # conditionally.
  43. AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option],[
  44. ax_compiler_flags_test="-Werror=unknown-warning-option"
  45. ],[
  46. ax_compiler_flags_test=""
  47. ])
  48. # Check that -Wno-suggest-attribute=format is supported
  49. AX_CHECK_COMPILE_FLAG([-Wno-suggest-attribute=format],[
  50. ax_compiler_no_suggest_attribute_flags="-Wno-suggest-attribute=format"
  51. ],[
  52. ax_compiler_no_suggest_attribute_flags=""
  53. ])
  54. # Base flags
  55. AX_APPEND_COMPILE_FLAGS([ dnl
  56. -fno-strict-aliasing dnl
  57. $3 dnl
  58. ],ax_warn_cxxflags_variable,[$ax_compiler_flags_test])
  59. AS_IF([test "$ax_enable_compile_warnings" != "no"],[
  60. # "yes" flags
  61. AX_APPEND_COMPILE_FLAGS([ dnl
  62. -Wall dnl
  63. -Wextra dnl
  64. -Wundef dnl
  65. -Wwrite-strings dnl
  66. -Wpointer-arith dnl
  67. -Wmissing-declarations dnl
  68. -Wredundant-decls dnl
  69. -Wno-unused-parameter dnl
  70. -Wno-missing-field-initializers dnl
  71. -Wformat=2 dnl
  72. -Wcast-align dnl
  73. -Wformat-nonliteral dnl
  74. -Wformat-security dnl
  75. -Wsign-compare dnl
  76. -Wstrict-aliasing dnl
  77. -Wshadow dnl
  78. -Winline dnl
  79. -Wpacked dnl
  80. -Wmissing-format-attribute dnl
  81. -Wmissing-noreturn dnl
  82. -Winit-self dnl
  83. -Wredundant-decls dnl
  84. -Wmissing-include-dirs dnl
  85. -Wunused-but-set-variable dnl
  86. -Warray-bounds dnl
  87. -Wreturn-type dnl
  88. -Wno-overloaded-virtual dnl
  89. -Wswitch-enum dnl
  90. -Wswitch-default dnl
  91. $4 dnl
  92. $5 dnl
  93. $6 dnl
  94. $7 dnl
  95. ],ax_warn_cxxflags_variable,[$ax_compiler_flags_test])
  96. ])
  97. AS_IF([test "$ax_enable_compile_warnings" = "error"],[
  98. # "error" flags; -Werror has to be appended unconditionally because
  99. # it's not possible to test for
  100. #
  101. # suggest-attribute=format is disabled because it gives too many false
  102. # positives
  103. AX_APPEND_FLAG([-Werror],ax_warn_cxxflags_variable)
  104. AX_APPEND_COMPILE_FLAGS([ dnl
  105. [$ax_compiler_no_suggest_attribute_flags] dnl
  106. ],ax_warn_cxxflags_variable,[$ax_compiler_flags_test])
  107. ])
  108. # In the flags below, when disabling specific flags, always add *both*
  109. # -Wno-foo and -Wno-error=foo. This fixes the situation where (for example)
  110. # we enable -Werror, disable a flag, and a build bot passes CXXFLAGS=-Wall,
  111. # which effectively turns that flag back on again as an error.
  112. for flag in $ax_warn_cxxflags_variable; do
  113. AS_CASE([$flag],
  114. [-Wno-*=*],[],
  115. [-Wno-*],[
  116. AX_APPEND_COMPILE_FLAGS([-Wno-error=$(AS_ECHO([$flag]) | $SED 's/^-Wno-//')],
  117. ax_warn_cxxflags_variable,
  118. [$ax_compiler_flags_test])
  119. ])
  120. done
  121. AC_LANG_POP([C++])
  122. # Substitute the variables
  123. AC_SUBST(ax_warn_cxxflags_variable)
  124. ])dnl AX_COMPILER_FLAGS_CXXFLAGS