File: EnableExtraCompilerWarnings.cmake

package info (click to toggle)
freespace2 25.0.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 47,232 kB
  • sloc: cpp: 657,500; ansic: 22,305; sh: 293; python: 200; makefile: 198; xml: 181
file content (125 lines) | stat: -rw-r--r-- 4,471 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# - Add flags to compile with extra warnings
#
#  enable_extra_compiler_warnings(<targetname>)
#  globally_enable_extra_compiler_warnings() - to modify CMAKE_CXX_FLAGS, etc
#    to change for all targets declared after the command, instead of per-command
#
#
# Original Author:
# 2010 Rylie Pavlik <rylie@ryliepavlik.com>
# https://ryliepavlik.com/
# Iowa State University - HCI Graduate Program/VRAC
#
# Additional Author:
# 2013 Kevin M. Godby <kevin@godby.org>
# http://kevin.godby.org/
# Iowa State University - HCI Graduate Program/VRAC
#
# Copyright 2009-2010, Iowa State University
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# SPDX-License-Identifier: BSL-1.0

if(__enable_extra_compiler_warnings)
	return()
endif()
set(__enable_extra_compiler_warnings YES)

macro(_check_warning_flag _flag _flags)
	include(CheckCXXCompilerFlag)
	string(REGEX REPLACE "[^A-Za-z0-9]" "" _flagvar "${_flag}")
	check_cxx_compiler_flag(${_flag} SUPPORTS_WARNING_${_flagvar})
	if(SUPPORTS_WARNING_${_flagvar})
		set(_flags "${_flags} ${_flag}")
	endif()
endmacro()

macro(_enable_extra_compiler_warnings_flags)
	set(_flags)
	if(MSVC)
		option(COMPILER_WARNINGS_EXTREME
			"Use compiler warnings that are probably overkill."
			off)
		mark_as_advanced(COMPILER_WARNINGS_EXTREME)
		set(_flags "/W4")
		if(COMPILER_WARNINGS_EXTREME)
			set(_flags "${_flags} /Wall /wd4619 /wd4668 /wd4820 /wd4571 /wd4710")
		endif()
	else()
		include(CheckCXXCompilerFlag)
		set(_flags)
		_check_warning_flag(-W "${_flags}")
		_check_warning_flag(-Wall "${_flags}")
		_check_warning_flag(-pedantic "${_flags}")
        _check_warning_flag(-Wbool-conversion "${_flags}")
		_check_warning_flag(-Wcast-align "${_flags}")
		_check_warning_flag(-Wchar-subscripts "${_flags}")
		_check_warning_flag(-Wconversion "${_flags}")
		_check_warning_flag(-Wdisabled-optimization "${_flags}")
		_check_warning_flag(-Wdocumentation "${_flags}")
		# _check_warning_flag(-Weffc++ "${_flags}")
		_check_warning_flag(-Wempty-body "${_flags}")
		_check_warning_flag(-Wfloat-equal "${_flags}")
		_check_warning_flag(-Wformat=2 "${_flags}")
		_check_warning_flag(-Wformat-security "${_flags}")
		_check_warning_flag(-Wheader-guard "${_flags}")
		_check_warning_flag(-Wimplicit-fallthrough "${_flags}")
		_check_warning_flag(-Winit-self "${_flags}")
		_check_warning_flag(-Winline "${_flags}")
		_check_warning_flag(-Winvalid-pch "${_flags}")
		_check_warning_flag(-Wlogical-not-parentheses "${_flags}")
		_check_warning_flag(-Wloop-analysis "${_flags}")
		_check_warning_flag(-Wmissing-format-attribute "${_flags}")
		_check_warning_flag(-Wmissing-include-dirs "${_flags}")
		_check_warning_flag(-Wno-long-long "${_flags}")
		_check_warning_flag(-Wnon-virtual-dtor "${_flags}")
		_check_warning_flag(-Wold-style-cast "${_flags}")
		_check_warning_flag(-Wpacked "${_flags}")
		_check_warning_flag(-Wpointer-arith "${_flags}")
		_check_warning_flag(-Wredundant-decls "${_flags}")
		_check_warning_flag(-Wshadow "${_flags}")
		_check_warning_flag(-Wsizeof-array-argument "${_flags}")
		_check_warning_flag(-Wstrict-overflow=4 "${_flags}")
		_check_warning_flag(-Wstring-conversion "${_flags}")
		_check_warning_flag(-Wsuggest-attribute=const "${_flags}")
		_check_warning_flag(-Wswitch-enum "${_flags}")
		_check_warning_flag(-Wswitch "${_flags}")
		_check_warning_flag(-Wtrigraphs "${_flags}")
		_check_warning_flag(-Wundef "${_flags}")
		_check_warning_flag(-Wunique-enum "${_flags}")
		_check_warning_flag(-Wuninitialized "${_flags}")
		_check_warning_flag(-Wunknown-pragmas "${_flags}")
		_check_warning_flag(-Wunused "${_flags}")
		_check_warning_flag(-Wunused-label "${_flags}")
		_check_warning_flag(-Wunused-parameter "${_flags}")
		_check_warning_flag(-Wwrite-strings "${_flags}")
	endif()
endmacro()

function(enable_extra_compiler_warnings _target)
	_enable_extra_compiler_warnings_flags()
	get_target_property(_origflags ${_target} COMPILE_FLAGS)
	if(_origflags)
		set_property(TARGET
			${_target}
			PROPERTY
			COMPILE_FLAGS
			"${_flags} ${_origflags}")
	else()
		set_property(TARGET
			${_target}
			PROPERTY
			COMPILE_FLAGS
			"${_flags}")
	endif()

endfunction()

function(globally_enable_extra_compiler_warnings)
	_enable_extra_compiler_warnings_flags()
	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flags}" PARENT_SCOPE)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flags}" PARENT_SCOPE)
endfunction()