|
8 | 8 |
|
9 | 9 | include(CheckCXXCompilerFlag)
|
10 | 10 | function(add_cxx_flag_if_supported_to_targets flagname targets)
|
11 |
| - string(MAKE_C_IDENTIFIER ${flagname} flag_identifier ) |
12 |
| - check_cxx_compiler_flag("${flagname}" HAVE_FLAG_${flag_identifier}) |
| 11 | + string(MAKE_C_IDENTIFIER ${flagname} flag_identifier) |
| 12 | + check_cxx_compiler_flag("${flagname}" HAVE_FLAG_${flag_identifier}) |
13 | 13 |
|
14 |
| - if (HAVE_FLAG_${flag_identifier}) |
15 |
| - foreach(target ${targets}) |
16 |
| - target_compile_options(${target} PRIVATE ${flagname}) |
17 |
| - endforeach() |
18 |
| - endif() |
| 14 | + if(HAVE_FLAG_${flag_identifier}) |
| 15 | + foreach(target ${targets}) |
| 16 | + target_compile_options(${target} PRIVATE ${flagname}) |
| 17 | + endforeach() |
| 18 | + endif() |
19 | 19 | endfunction()
|
20 | 20 |
|
21 | 21 | # Assumes that it is only called for development builds, where warnings
|
22 | 22 | # and Werror is desired, so it also enables Werror.
|
23 | 23 | function(add_warnings_to_targets targets)
|
24 |
| - LIST(LENGTH targets TARGETS_LEN) |
25 |
| - # For now we just assume 2 possibilities: msvc and msvc-like compilers, |
26 |
| - # and other. |
27 |
| - if (MSVC) |
28 |
| - foreach(target ${targets}) |
29 |
| - # Force MSVC to consider everything as encoded in utf-8 |
30 |
| - target_compile_options( ${target} PRIVATE /utf-8 ) |
31 |
| - # Enable Werror equivalent |
32 |
| - if (CATCH_ENABLE_WERROR) |
33 |
| - target_compile_options( ${target} PRIVATE /WX ) |
34 |
| - endif() |
35 |
| - |
36 |
| - # MSVC is currently handled specially |
37 |
| - if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" ) |
38 |
| - STRING(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # override default warning level |
39 |
| - target_compile_options( ${target} PRIVATE /w44265 /w44061 /w44062 /w45038 ) |
40 |
| - endif() |
41 |
| - endforeach() |
| 24 | + LIST(LENGTH targets TARGETS_LEN) |
| 25 | + # For now we just assume 2 possibilities: msvc and msvc-like compilers, |
| 26 | + # and other. |
| 27 | + if(MSVC) |
| 28 | + foreach(target ${targets}) |
| 29 | + # Force MSVC to consider everything as encoded in utf-8 |
| 30 | + target_compile_options(${target} PRIVATE /utf-8) |
| 31 | + # Enable Werror equivalent |
| 32 | + if(CATCH_ENABLE_WERROR) |
| 33 | + target_compile_options(${target} PRIVATE /WX) |
| 34 | + endif() |
42 | 35 |
|
43 |
| - endif() |
| 36 | + # MSVC is currently handled specially |
| 37 | + if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") |
| 38 | + STRING(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # override default warning level |
| 39 | + target_compile_options(${target} PRIVATE /w44265 /w44061 /w44062 /w45038) |
| 40 | + endif() |
| 41 | + endforeach() |
| 42 | + endif() |
44 | 43 |
|
45 |
| - if (NOT MSVC) |
46 |
| - set(CHECKED_WARNING_FLAGS |
47 |
| - "-Wabsolute-value" |
48 |
| - "-Wall" |
49 |
| - "-Wcall-to-pure-virtual-from-ctor-dtor" |
50 |
| - "-Wcast-align" |
51 |
| - "-Wcatch-value" |
52 |
| - "-Wdangling" |
53 |
| - "-Wdeprecated" |
54 |
| - "-Wdeprecated-register" |
55 |
| - "-Wexceptions" |
56 |
| - "-Wexit-time-destructors" |
57 |
| - "-Wextra" |
58 |
| - "-Wextra-semi" |
59 |
| - "-Wfloat-equal" |
60 |
| - "-Wglobal-constructors" |
61 |
| - "-Winit-self" |
62 |
| - "-Wmisleading-indentation" |
63 |
| - "-Wmismatched-new-delete" |
64 |
| - "-Wmismatched-return-types" |
65 |
| - "-Wmismatched-tags" |
66 |
| - "-Wmissing-braces" |
67 |
| - "-Wmissing-declarations" |
68 |
| - "-Wmissing-noreturn" |
69 |
| - "-Wmissing-prototypes" |
70 |
| - "-Wmissing-variable-declarations" |
71 |
| - "-Wnon-virtual-dtor" |
72 |
| - "-Wnull-dereference" |
73 |
| - "-Wold-style-cast" |
74 |
| - "-Woverloaded-virtual" |
75 |
| - "-Wparentheses" |
76 |
| - "-Wpedantic" |
77 |
| - "-Wredundant-decls" |
78 |
| - "-Wreorder" |
79 |
| - "-Wreturn-std-move" |
80 |
| - "-Wshadow" |
81 |
| - "-Wstrict-aliasing" |
82 |
| - "-Wsubobject-linkage" |
83 |
| - "-Wsuggest-destructor-override" |
84 |
| - "-Wsuggest-override" |
85 |
| - "-Wundef" |
86 |
| - "-Wuninitialized" |
87 |
| - "-Wunneeded-internal-declaration" |
88 |
| - "-Wunreachable-code-aggressive" |
89 |
| - "-Wunused" |
90 |
| - "-Wunused-function" |
91 |
| - "-Wunused-parameter" |
92 |
| - "-Wvla" |
93 |
| - "-Wweak-vtables" |
| 44 | + if(NOT MSVC) |
| 45 | + set(CHECKED_WARNING_FLAGS |
| 46 | + "-Wabsolute-value" |
| 47 | + "-Wall" |
| 48 | + "-Wcall-to-pure-virtual-from-ctor-dtor" |
| 49 | + "-Wcast-align" |
| 50 | + "-Wcatch-value" |
| 51 | + "-Wdangling" |
| 52 | + "-Wdeprecated" |
| 53 | + "-Wdeprecated-register" |
| 54 | + "-Wexceptions" |
| 55 | + "-Wexit-time-destructors" |
| 56 | + "-Wextra" |
| 57 | + "-Wextra-semi" |
| 58 | + "-Wfloat-equal" |
| 59 | + "-Wglobal-constructors" |
| 60 | + "-Winit-self" |
| 61 | + "-Wmisleading-indentation" |
| 62 | + "-Wmismatched-new-delete" |
| 63 | + "-Wmismatched-return-types" |
| 64 | + "-Wmismatched-tags" |
| 65 | + "-Wmissing-braces" |
| 66 | + "-Wmissing-declarations" |
| 67 | + "-Wmissing-noreturn" |
| 68 | + "-Wmissing-prototypes" |
| 69 | + "-Wmissing-variable-declarations" |
| 70 | + "-Wnon-virtual-dtor" |
| 71 | + "-Wnull-dereference" |
| 72 | + "-Wold-style-cast" |
| 73 | + "-Woverloaded-virtual" |
| 74 | + "-Wparentheses" |
| 75 | + "-Wpedantic" |
| 76 | + "-Wredundant-decls" |
| 77 | + "-Wreorder" |
| 78 | + "-Wreturn-std-move" |
| 79 | + "-Wshadow" |
| 80 | + "-Wstrict-aliasing" |
| 81 | + "-Wsubobject-linkage" |
| 82 | + "-Wsuggest-destructor-override" |
| 83 | + "-Wsuggest-override" |
| 84 | + "-Wundef" |
| 85 | + "-Wuninitialized" |
| 86 | + "-Wunneeded-internal-declaration" |
| 87 | + "-Wunreachable-code-aggressive" |
| 88 | + "-Wunused" |
| 89 | + "-Wunused-function" |
| 90 | + "-Wunused-parameter" |
| 91 | + "-Wvla" |
| 92 | + "-Wweak-vtables" |
94 | 93 |
|
95 |
| - # This is a useful warning, but our tests sometimes rely on |
96 |
| - # functions being present, but not picked (e.g. various checks |
97 |
| - # for stringification implementation ordering). |
98 |
| - # Ergo, we should use it every now and then, but we cannot |
99 |
| - # enable it by default. |
100 |
| - # "-Wunused-member-function" |
101 |
| - ) |
102 |
| - foreach(warning ${CHECKED_WARNING_FLAGS}) |
103 |
| - add_cxx_flag_if_supported_to_targets(${warning} "${targets}") |
104 |
| - endforeach() |
| 94 | + # This is a useful warning, but our tests sometimes rely on |
| 95 | + # functions being present, but not picked (e.g. various checks |
| 96 | + # for stringification implementation ordering). |
| 97 | + # Ergo, we should use it every now and then, but we cannot |
| 98 | + # enable it by default. |
| 99 | + # "-Wunused-member-function" |
| 100 | + ) |
| 101 | + foreach(warning ${CHECKED_WARNING_FLAGS}) |
| 102 | + add_cxx_flag_if_supported_to_targets(${warning} "${targets}") |
| 103 | + endforeach() |
105 | 104 |
|
106 |
| - if (CATCH_ENABLE_WERROR) |
107 |
| - foreach(target ${targets}) |
108 |
| - # Enable Werror equivalent |
109 |
| - target_compile_options( ${target} PRIVATE -Werror ) |
110 |
| - endforeach() |
111 |
| - endif() |
| 105 | + if(CATCH_ENABLE_WERROR) |
| 106 | + foreach(target ${targets}) |
| 107 | + # Enable Werror equivalent |
| 108 | + target_compile_options(${target} PRIVATE -Werror) |
| 109 | + endforeach() |
112 | 110 | endif()
|
| 111 | + endif() |
113 | 112 | endfunction()
|
114 | 113 |
|
115 | 114 | # Adds flags required for reproducible build to the target
|
|
0 commit comments