diff options
author | aqua <aqua@iserlohn-fortress.net> | 2024-04-28 10:50:04 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2024-04-28 10:50:04 +0300 |
commit | 0eb0cf57720943ad71857a4a4fc0a9f365581d2a (patch) | |
tree | e1f8234c4351ffbf37d26416b88ae5749a8ee881 /cmake | |
parent | Readded command line options (diff) | |
download | smolbote-0eb0cf57720943ad71857a4a4fc0a9f365581d2a.tar.xz |
Added compiler warnings for poi
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/CompilerOptions.cmake | 89 | ||||
-rw-r--r-- | cmake/CppCheck.cmake | 11 |
2 files changed, 100 insertions, 0 deletions
diff --git a/cmake/CompilerOptions.cmake b/cmake/CompilerOptions.cmake new file mode 100644 index 0000000..dbb37fd --- /dev/null +++ b/cmake/CompilerOptions.cmake @@ -0,0 +1,89 @@ +# ================================================================================== +# adapted from +# https://github.com/zhivkopetrov/cmake_helpers.git +# MIT License Copyright (c) 2020-2023 Zhivko Petrov +# +# some compiler warnings from +# https://lefticus.gitbooks.io/cpp-best-practices/content/02-Use_the_Tools_Available.html +# +# ================================================================================== +# target_enable_warnings + +function(target_enable_warnings target) + if(CMAKE_CXX_COMPILER_ID MATCHES MSVC) + target_compile_options( + ${target} + PRIVATE + /W4 + /WX + ) + endif() + + if((CMAKE_CXX_COMPILER_ID MATCHES GNU) OR + (CMAKE_CXX_COMPILER_ID MATCHES Clang)) + target_compile_options( + ${target} + PRIVATE + # compiler warnings + # generic + -Wall -Wextra # reasonable and standard + -Wpedantic # non-standard cpp is used + -Wmisleading-indentation + -Wlogical-op # logical op being used instead of bitwise + -Wundef + -Wuninitialized + -Weffc++ # disabled because it would require skeleton changes + # variables + -Wshadow # variable declaration shadows one from parent context + -Wunused # anything being unused + # casts + -Werror=old-style-cast # C-style casts + -Wcast-align # performance problem casts + -Wcast-qual + -Wuseless-cast # cast to same type + # conversion + #-Wconversion # type conversion may lose data + -Wsign-conversion # sign conversion + -Wdouble-promotion # implicit float to double + # functions + -Wunused-parameter + -Werror=missing-declarations # missing function declaration in header files + -Werror=redundant-decls + -Werror=return-type + -Werror=overloaded-virtual + # inheritance + -Wnon-virtual-dtor # class with virtual functions has non-virt dtor + -Woverloaded-virtual # overloaded (not override) virtual function + # branches + -Wduplicated-cond # if/else chain has duplicated conditions + -Wduplicated-branches # if/else chain has duplicated code + # pointers + -Wpointer-arith + -Wnull-dereference + # style + -Wformat=2 # security issues around printf + -Werror=date-time # usage of __DATE__ and __TIME__ macros + -Werror=missing-field-initializers + # logic + -Wlogical-op + -Wimplicit-fallthrough + -Wduplicated-cond + -Wduplicated-branches + + # other flags + -ffunction-sections # place each function into its own section + # better ASLR but larger executables + -fstack-protector-all # emit check for buffer overflows on all functions + -fstack-clash-protection # emit check for stack clash attacks + ) + endif() + + # add -Werror to release builds + if((${CMAKE_BUILD_TYPE} MATCHES Release) OR + (${CMAKE_BUILD_TYPE} MATCHES MinSizeRel)) + # currently disabled + #target_compile_options(${target} PRIVATE -Werror) + endif() + +endfunction() + diff --git a/cmake/CppCheck.cmake b/cmake/CppCheck.cmake new file mode 100644 index 0000000..d8a4559 --- /dev/null +++ b/cmake/CppCheck.cmake @@ -0,0 +1,11 @@ +find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck) + +if(CMAKE_CXX_CPPCHECK) + list(APPEND CMAKE_CXX_CPPCHECK + --std=c++20 + --enable=all + --inconclusive + --quiet + --suppressions-list=${PROJECT_SOURCE_DIR}/CppCheckSuppressions.txt + ) +endif() |