• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# nghttp2
2#
3# Copyright (c) 2023 nghttp2 contributors
4#
5# Permission is hereby granted, free of charge, to any person obtaining
6# a copy of this software and associated documentation files (the
7# "Software"), to deal in the Software without restriction, including
8# without limitation the rights to use, copy, modify, merge, publish,
9# distribute, sublicense, and/or sell copies of the Software, and to
10# permit persons to whom the Software is furnished to do so, subject to
11# the following conditions:
12#
13# The above copyright notice and this permission notice shall be
14# included in all copies or substantial portions of the Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24# C++
25
26include(CheckCXXCompilerFlag)
27
28if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
29
30  # https://clang.llvm.org/docs/DiagnosticsReference.html
31  # https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
32
33  # WPICKY_ENABLE = Options we want to enable as-is.
34  # WPICKY_DETECT = Options we want to test first and enable if available.
35
36  set(WPICKY_ENABLE "-Wall")
37
38  # ----------------------------------
39  # Add new options here, if in doubt:
40  # ----------------------------------
41  set(WPICKY_DETECT
42  )
43
44  # Assume these options always exist with both clang and gcc.
45  # Require clang 3.0 / gcc 2.95 or later.
46  list(APPEND WPICKY_ENABLE
47  )
48
49  # Always enable with clang, version dependent with gcc
50  set(WPICKY_COMMON_OLD
51    -Wformat-security                    # clang  3.0  gcc  4.1
52  )
53
54  set(WPICKY_COMMON
55  )
56
57  if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
58    list(APPEND WPICKY_ENABLE
59      ${WPICKY_COMMON_OLD}
60    )
61    # Enable based on compiler version
62    if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang"      AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6) OR
63       (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.3))
64      list(APPEND WPICKY_ENABLE
65        ${WPICKY_COMMON}
66      )
67    endif()
68    if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang"      AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.9) OR
69       (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.3))
70      list(APPEND WPICKY_ENABLE
71      )
72    endif()
73    if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang"      AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) OR
74       (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.4))
75      list(APPEND WPICKY_ENABLE
76      )
77    endif()
78    if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang"      AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) OR
79       (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.3))
80      list(APPEND WPICKY_ENABLE
81      )
82    endif()
83  else()  # gcc
84    list(APPEND WPICKY_DETECT
85      ${WPICKY_COMMON}
86    )
87    # Enable based on compiler version
88    if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3)
89      list(APPEND WPICKY_ENABLE
90        ${WPICKY_COMMON_OLD}
91      )
92    endif()
93  endif()
94
95  #
96
97  unset(_wpicky)
98
99  foreach(_CCOPT IN LISTS WPICKY_ENABLE)
100    set(_wpicky "${_wpicky} ${_CCOPT}")
101  endforeach()
102
103  foreach(_CCOPT IN LISTS WPICKY_DETECT)
104    # surprisingly, CHECK_CXX_COMPILER_FLAG needs a new variable to store each new
105    # test result in.
106    string(MAKE_C_IDENTIFIER "OPT${_CCOPT}" _optvarname)
107    # GCC only warns about unknown -Wno- options if there are also other diagnostic messages,
108    # so test for the positive form instead
109    string(REPLACE "-Wno-" "-W" _CCOPT_ON "${_CCOPT}")
110    check_cxx_compiler_flag(${_CCOPT_ON} ${_optvarname})
111    if(${_optvarname})
112      set(_wpicky "${_wpicky} ${_CCOPT}")
113    endif()
114  endforeach()
115
116  set(WARNCXXFLAGS "${WARNCXXFLAGS} ${_wpicky}")
117endif()
118