|
| 1 | +function(set_compiler_warnings target) |
| 2 | + if(MSVC) |
| 3 | + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 4 | + set(PROJECT_WARNINGS |
| 5 | + -Wall |
| 6 | + -Wextra |
| 7 | + -Wshadow |
| 8 | + -Wpedantic |
| 9 | + -Wunused |
| 10 | + -Wformat=2 |
| 11 | + -Wnull-dereference |
| 12 | + -Wnon-virtual-dtor |
| 13 | + -Woverloaded-virtual |
| 14 | + -Wold-style-cast |
| 15 | + -Wno-missing-prototypes |
| 16 | + -Wno-switch-enum |
| 17 | + -Wno-c++98-compat |
| 18 | + -Wno-c++98-compat-pedantic |
| 19 | + /EHsc) |
| 20 | + else() |
| 21 | + # Note that all the flags after /W4 are required for MSVC to conform to the language standard |
| 22 | + set(PROJECT_WARNINGS |
| 23 | + /guard:cf |
| 24 | + /utf-8 |
| 25 | + /diagnostics:caret |
| 26 | + /sdl |
| 27 | + /W4 |
| 28 | + /w14165 # 'HRESULT' is being converted to 'bool'; are you sure this is what you want? |
| 29 | + /w44242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data |
| 30 | + /w44254 # 'operator': conversion from 'type1':'field_bits' to 'type2':'field_bits', possible loss of data |
| 31 | + /w44263 # 'function' : member function does not override any base class virtual member function |
| 32 | + /w34265 # 'classname': class has virtual functions, but its non-trivial destructor is not virtual; instances of this class may not be destructed correctly |
| 33 | + /w34287 # 'operator' : unsigned/negative constant mismatch |
| 34 | + /w44296 # 'operator' : expression is always false |
| 35 | + /w44388 # 'token' : signed/unsigned mismatch |
| 36 | + /w44464 # relative include path contains '..' |
| 37 | + /w14545 # expression before comma evaluates to a function which is missing an argument list |
| 38 | + /w14546 # function call before comma missing argument list |
| 39 | + /w14547 # 'operator' : operator before comma has no effect; expected operator with side-effect |
| 40 | + /w14549 # 'operator' : operator before comma has no effect; did you intend 'operator'? |
| 41 | + /w14555 # expression has no effect; expected expression with side-effect |
| 42 | + /w34619 # #pragma warning : there is no warning number 'number' |
| 43 | + /w34640 # 'instance' : construction of local static object is not thread-safe |
| 44 | + /w24826 # Conversion from 'type' to 'type' is sign-extended. This may cause unexpected runtime behavior. |
| 45 | + /w14905 # wide string literal cast to 'LPSTR' |
| 46 | + /w14906 # string literal cast to 'LPWSTR' |
| 47 | + /w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied |
| 48 | + /w45038 # data member 'member1' will be initialized after data member 'member2', data member 'member' will be initialized after base class 'base_class' |
| 49 | + /permissive- |
| 50 | + /volatile:iso |
| 51 | + /Zc:inline |
| 52 | + /Zc:preprocessor |
| 53 | + /Zc:enumTypes |
| 54 | + /Zc:lambda |
| 55 | + /Zc:__cplusplus |
| 56 | + /Zc:externConstexpr |
| 57 | + /Zc:throwingNew |
| 58 | + /EHsc) |
| 59 | + endif() |
| 60 | + elseif(APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 61 | + set(PROJECT_WARNINGS |
| 62 | + -fstack-protector-strong |
| 63 | + -Wall |
| 64 | + -Wextra |
| 65 | + -Wpedantic |
| 66 | + -Wconversion |
| 67 | + -Wsign-conversion |
| 68 | + -Wcast-qual |
| 69 | + -Wformat=2 |
| 70 | + -Wundef |
| 71 | + -Werror=float-equal |
| 72 | + -Wshadow |
| 73 | + -Wcast-align |
| 74 | + -Wunused |
| 75 | + -Wnull-dereference |
| 76 | + -Wdouble-promotion |
| 77 | + -Wimplicit-fallthrough |
| 78 | + -Wextra-semi |
| 79 | + -Woverloaded-virtual |
| 80 | + -Wnon-virtual-dtor |
| 81 | + -Wold-style-cast |
| 82 | + ) |
| 83 | + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 84 | + set(PROJECT_WARNINGS |
| 85 | + -U_FORTIFY_SOURCE |
| 86 | + -D_FORTIFY_SOURCE=3 |
| 87 | + -D_GLIBCXX_ASSERTIONS=1 |
| 88 | + -fstack-protector-strong |
| 89 | + -fcf-protection=full |
| 90 | + -fstack-clash-protection |
| 91 | + -Wall |
| 92 | + -Wextra |
| 93 | + -Wpedantic |
| 94 | + -Wconversion |
| 95 | + -Wsign-conversion |
| 96 | + -Wcast-qual |
| 97 | + -Wformat=2 |
| 98 | + -Wundef |
| 99 | + -Werror=float-equal |
| 100 | + -Wshadow |
| 101 | + -Wcast-align |
| 102 | + -Wunused |
| 103 | + -Wnull-dereference |
| 104 | + -Wdouble-promotion |
| 105 | + -Wimplicit-fallthrough |
| 106 | + -Wextra-semi |
| 107 | + -Woverloaded-virtual |
| 108 | + -Wnon-virtual-dtor |
| 109 | + -Wold-style-cast |
| 110 | + ) |
| 111 | + else() |
| 112 | + message(AUTHOR_WARNING "No compiler warnings set for CXX compiler: '${CMAKE_CXX_COMPILER_ID}'") |
| 113 | + endif() |
| 114 | + |
| 115 | + target_compile_options(${target} PRIVATE ${PROJECT_WARNINGS}) |
| 116 | +endfunction() |
0 commit comments