5
5
6
6
# warnings that are valid for gcc and clang
7
7
function (commonwarn target )
8
- target_compile_options (${target} PUBLIC -Wall -Wextra -pedantic -pedantic-errors )
8
+ target_compile_options (${target} PRIVATE -Wall -Wextra -pedantic -pedantic-errors )
9
9
10
10
# see https://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Warning-Options.html for more details
11
11
12
- target_compile_options (${target} PUBLIC -Wnull-dereference )
13
- target_compile_options (${target} PUBLIC -Wold-style-cast )
14
- target_compile_options (${target} PUBLIC -Wdouble-promotion )
15
- target_compile_options (${target} PUBLIC -Wformat=2 )
16
- target_compile_options (${target} PUBLIC -Winit-self )
17
- target_compile_options (${target} PUBLIC -Wsequence-point )
18
- target_compile_options (${target} PUBLIC -Wswitch-default )
19
- target_compile_options (${target} PUBLIC -Wswitch-enum -Wno-error=switch-enum )
20
- target_compile_options (${target} PUBLIC -Wconversion )
21
- target_compile_options (${target} PUBLIC -Wcast-align )
22
- target_compile_options (${target} PUBLIC -Wfloat-equal )
23
- target_compile_options (${target} PUBLIC -Wundef )
24
- target_compile_options (${target} PUBLIC -Wcast-qual )
12
+ target_compile_options (${target} PRIVATE -Wnull-dereference )
13
+ target_compile_options (${target} PRIVATE -Wold-style-cast )
14
+ target_compile_options (${target} PRIVATE -Wdouble-promotion )
15
+ target_compile_options (${target} PRIVATE -Wformat=2 )
16
+ target_compile_options (${target} PRIVATE -Winit-self )
17
+ target_compile_options (${target} PRIVATE -Wsequence-point )
18
+ target_compile_options (${target} PRIVATE -Wswitch-default )
19
+ target_compile_options (${target} PRIVATE -Wswitch-enum -Wno-error=switch-enum )
20
+ target_compile_options (${target} PRIVATE -Wconversion )
21
+ target_compile_options (${target} PRIVATE -Wcast-align )
22
+ target_compile_options (${target} PRIVATE -Wfloat-equal )
23
+ target_compile_options (${target} PRIVATE -Wundef )
24
+ target_compile_options (${target} PRIVATE -Wcast-qual )
25
25
endfunction ()
26
26
27
27
# gcc specific warnings
28
28
function (gccwarn target )
29
29
# see https://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Warning-Options.html for more details
30
30
31
- target_compile_options (${target} PUBLIC -Wduplicated-cond )
32
- target_compile_options (${target} PUBLIC -Wduplicated-branches )
33
- target_compile_options (${target} PUBLIC -Wlogical-op )
34
- target_compile_options (${target} PUBLIC -Wrestrict )
35
- target_compile_options (${target} PUBLIC -Wuseless-cast -Wno-error=useless-cast )
36
- target_compile_options (${target} PUBLIC -Wshadow=local -Wno-error=shadow )
31
+ target_compile_options (${target} PRIVATE -Wduplicated-cond )
32
+ target_compile_options (${target} PRIVATE -Wduplicated-branches )
33
+ target_compile_options (${target} PRIVATE -Wlogical-op )
34
+ target_compile_options (${target} PRIVATE -Wrestrict )
35
+ target_compile_options (${target} PRIVATE -Wuseless-cast -Wno-error=useless-cast )
36
+ target_compile_options (${target} PRIVATE -Wshadow=local -Wno-error=shadow )
37
37
38
- target_compile_options (${target} PUBLIC -Wno-error=switch-default )
39
- target_compile_options (${target} PUBLIC -Wno-error=attributes )
38
+ target_compile_options (${target} PRIVATE -Wno-error=switch-default )
39
+ target_compile_options (${target} PRIVATE -Wno-error=attributes )
40
40
endfunction ()
41
41
42
42
# clang specific warnings
43
43
function (clangwarn target )
44
44
# enable all
45
- target_compile_options (${target} PUBLIC -Weverything )
45
+ target_compile_options (${target} PRIVATE -Weverything )
46
46
47
47
# and remove "useless" ones
48
- target_compile_options (${target} PUBLIC -Wno-c++98-compat )
49
- target_compile_options (${target} PUBLIC -Wno-c++98-c++11-c++14-compat )
50
- target_compile_options (${target} PUBLIC -Wno-c++98-compat-pedantic )
51
- target_compile_options (${target} PUBLIC -Wno-error=covered-switch-default )
52
- target_compile_options (${target} PUBLIC -Wno-shadow-field-in-constructor )
53
- target_compile_options (${target} PUBLIC -Wno-padded )
54
- target_compile_options (${target} PUBLIC -Wno-shadow-field )
55
- target_compile_options (${target} PUBLIC -Wno-weak-vtables )
56
- target_compile_options (${target} PUBLIC -Wno-exit-time-destructors )
57
- target_compile_options (${target} PUBLIC -Wno-global-constructors )
58
- target_compile_options (${target} PUBLIC -Wno-error=unreachable-code-return )
59
- target_compile_options (${target} PUBLIC -Wno-error=unreachable-code )
60
- target_compile_options (${target} PUBLIC -Wno-error=documentation )
61
- target_compile_options (${target} PUBLIC -Wno-error=unused-exception-parameter )
62
- target_compile_options (${target} PUBLIC -Wno-nested-anon-types )
63
- target_compile_options (${target} PUBLIC -Wno-gnu-anonymous-struct )
64
- target_compile_options (${target} PUBLIC -Wno-source-uses-openmp )
48
+ target_compile_options (${target} PRIVATE -Wno-c++98-compat )
49
+ target_compile_options (${target} PRIVATE -Wno-c++98-c++11-c++14-compat )
50
+ target_compile_options (${target} PRIVATE -Wno-c++98-compat-pedantic )
51
+ target_compile_options (${target} PRIVATE -Wno-error=covered-switch-default )
52
+ target_compile_options (${target} PRIVATE -Wno-shadow-field-in-constructor )
53
+ target_compile_options (${target} PRIVATE -Wno-padded )
54
+ target_compile_options (${target} PRIVATE -Wno-shadow-field )
55
+ target_compile_options (${target} PRIVATE -Wno-weak-vtables )
56
+ target_compile_options (${target} PRIVATE -Wno-exit-time-destructors )
57
+ target_compile_options (${target} PRIVATE -Wno-global-constructors )
58
+ target_compile_options (${target} PRIVATE -Wno-error=unreachable-code-return )
59
+ target_compile_options (${target} PRIVATE -Wno-error=unreachable-code )
60
+ target_compile_options (${target} PRIVATE -Wno-error=documentation )
61
+ target_compile_options (${target} PRIVATE -Wno-error=unused-exception-parameter )
62
+ target_compile_options (${target} PRIVATE -Wno-nested-anon-types )
63
+ target_compile_options (${target} PRIVATE -Wno-gnu-anonymous-struct )
64
+ target_compile_options (${target} PRIVATE -Wno-source-uses-openmp )
65
+ target_compile_options (${target} PRIVATE -Wno-disabled-macro-expansion )
65
66
66
67
endfunction ()
67
68
@@ -73,10 +74,10 @@ function(enable_warnings target)
73
74
commonwarn (${target} )
74
75
clangwarn (${target} )
75
76
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
76
- target_compile_options (${target} PUBLIC /Wall /WX )
77
+ target_compile_options (${target} PRIVATE /Wall /WX )
77
78
endif ()
78
79
endfunction ()
79
80
80
81
function (disable_warnings target )
81
- target_compile_options (${target} PUBLIC -w )
82
+ target_compile_options (${target} PRIVATE -w )
82
83
endfunction ()
0 commit comments