|
| 1 | + |
| 2 | +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") |
| 3 | + set(compile_options |
| 4 | + /bigobj |
| 5 | + /permissive- |
| 6 | + /WX # treat warnings as errors |
| 7 | + /W4 # Baseline reasonable warnings |
| 8 | + /we4242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data |
| 9 | + /we4244 # conversion from 'type1' to 'type_2', possible loss of data |
| 10 | + /we4254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data |
| 11 | + /we4263 # 'function': member function does not override any base class virtual member function |
| 12 | + /we4265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may not be destructed correctly |
| 13 | + /we4287 # 'operator': unsigned/negative constant mismatch |
| 14 | + /we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside the for-loop scope |
| 15 | + /we4296 # 'operator': expression is always 'boolean_value' |
| 16 | + /we4311 # 'variable': pointer truncation from 'type1' to 'type2' |
| 17 | + /we4545 # expression before comma evaluates to a function which is missing an argument list |
| 18 | + /we4546 # function call before comma missing argument list |
| 19 | + /we4547 # 'operator': operator before comma has no effect; expected operator with side-effect |
| 20 | + /we4549 # 'operator': operator before comma has no effect; did you intend 'operator'? |
| 21 | + /we4555 # expression has no effect; expected expression with side- effect |
| 22 | + /we4619 # pragma warning: there is no warning number 'number' |
| 23 | + /we4640 # Enable warning on thread un-safe static member initialization |
| 24 | + /we4826 # Conversion from 'type1' to 'type_2' is sign-extended. This may cause unexpected runtime behavior. |
| 25 | + /we4905 # wide string literal cast to 'LPSTR' |
| 26 | + /we4906 # string literal cast to 'LPWSTR' |
| 27 | + /we4928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied |
| 28 | + /we5038 # data member 'member1' will be initialized after data member 'member2' |
| 29 | + /Zc:__cplusplus |
| 30 | + PARENT_SCOPE) |
| 31 | +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 32 | + set(compile_options |
| 33 | + -Wall # reasonable and standard |
| 34 | + -Wcast-align # warn for potential performance problem casts |
| 35 | + -Wconversion # warn on type conversions that may lose data |
| 36 | + -Wdouble-promotion # warn if float is implicitly promoted to double |
| 37 | + -Werror # treat warnings as errors |
| 38 | + -Wextra |
| 39 | + -Wformat=2 # warn on security issues around functions that format output (i.e., printf) |
| 40 | + -Wimplicit-fallthrough # Warns when case statements fall-through. (Included with -Wextra in GCC, not in clang) |
| 41 | + -Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist |
| 42 | + -Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps catch hard to track down memory errors |
| 43 | + -Wnull-dereference # warn if a null dereference is detected |
| 44 | + -Wold-style-cast # warn for c-style casts |
| 45 | + -Woverloaded-virtual # warn if you overload (not override) a virtual function |
| 46 | + -Wshadow # warn the user if a variable declaration shadows one from a parent context |
| 47 | + -Wsign-conversion # warn on sign conversions |
| 48 | + -Wunused # warn on anything being unused |
| 49 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-c++98-compat> # do not warn on use of non-C++98 standard |
| 50 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-c++98-compat-pedantic> |
| 51 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-documentation> |
| 52 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-extra-semi-stmt> |
| 53 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-c++20-compat> |
| 54 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-pre-c++20-compat-pedantic> |
| 55 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-reserved-identifier> |
| 56 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-undef> |
| 57 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-switch-default> |
| 58 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-switch-enum> |
| 59 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-missing-prototypes> |
| 60 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-unused-template> |
| 61 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-unsafe-buffer-usage> |
| 62 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-documentation-unknown-command> |
| 63 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-float-equal> |
| 64 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-exit-time-destructors> |
| 65 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-global-constructors> |
| 66 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-newline-eof> |
| 67 | + $<$<CXX_COMPILER_ID:Clang>:-Wno-ctad-maybe-unsupported> |
| 68 | + $<$<CXX_COMPILER_ID:GNU>:-Wno-maybe-uninitialized> |
| 69 | + $<$<CXX_COMPILER_ID:GNU>:-Wno-array-bounds> |
| 70 | + $<$<CXX_COMPILER_ID:GNU>:-Wno-stringop-overread> |
| 71 | + $<$<CXX_COMPILER_ID:GNU>:-Wduplicated-branches> # warn if if / else branches have duplicated code |
| 72 | + $<$<CXX_COMPILER_ID:GNU>:-Wduplicated-cond> # warn if if / else chain has duplicated conditions |
| 73 | + $<$<CXX_COMPILER_ID:GNU>:-Wlogical-op> # warn about logical operations being used where bitwise were probably wanted |
| 74 | + $<$<CXX_COMPILER_ID:GNU>:-Wno-subobject-linkage> # suppress warnings about subobject linkage |
| 75 | + ) |
| 76 | + if (NOT "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") |
| 77 | + set(compile_options ${compile_options} -ftemplate-backtrace-limit=0 -pedantic) |
| 78 | + endif() |
| 79 | + |
| 80 | + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.3) |
| 81 | + set(compile_options ${compile_optoins} PRIVATE "-Wno-error=shift-negative-value") |
| 82 | + endif() |
| 83 | +endif() |
0 commit comments