From 9d268e1d169320375bec1cfee4e0e35ff2e1fdf5 Mon Sep 17 00:00:00 2001 From: Martin Gerhardy Date: Sat, 13 Oct 2018 11:59:13 +0200 Subject: [PATCH] CMAKE: added sanitizers --- .clang-tidy | 4 ++++ CMakeLists.txt | 29 +++++++++++++++++++++++++++++ contrib/.clang-tidy | 6 ++++++ src/tools/glslang/.clang-tidy | 6 ++++++ 4 files changed, 45 insertions(+) create mode 100644 .clang-tidy create mode 100644 contrib/.clang-tidy create mode 100644 src/tools/glslang/.clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000..3b47c1bda --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,4 @@ +--- +Checks: 'clang-diagnostic-*,clang-analyzer-*,modernizer*,-clang-analyzer-alpha*' +... + diff --git a/CMakeLists.txt b/CMakeLists.txt index 594b009f1..461c23222 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,9 @@ option(USE_CCACHE "Use ccache" ON) option(USE_GPROF "Use gprof - will become slow" OFF) option(USE_GCOV "Use gcov - will become slow" OFF) option(USE_DOXYGEN_CHECK "Use -Wdocumentation if available" OFF) +option(USE_LINK_WHAT_YOU_USE "Enable link-what-you-use" OFF) +option(USE_CPPCHECK "Enable cppcheck" OFF) +option(USE_CLANG_TIDY "Enable Clang Tidy" OFF) set(DEBUGGER "gdb" CACHE STRING "Which debugger should be used") set_property(CACHE DEBUGGER PROPERTY STRINGS gdb lldb) set(SERVER_HOST "localhost" CACHE STRING "Host where the server is running on") @@ -104,11 +107,37 @@ if (CCACHE) message(STATUS "Using ccache") set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE}) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE}) + if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") + set(ENV{CCACHE_CPP2} "yes") + add_compile_options(-Qunused-arguments) + endif() endif() else() message(STATUS "ccache not found") endif() +if (USE_LINK_WHAT_YOU_USE) + set(CMAKE_LINK_WHAT_YOU_USE ON) +endif() + +if (USE_CLANG_TIDY) + find_host_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy clang-tidy-3.8) + if (CLANG_TIDY_EXECUTABLE) + set(CLANG_TIDY_OPTS ${CLANG_TIDY_EXECUTABLE}) + set(CMAKE_C_CLANG_TIDY "${CLANG_TIDY_OPTS}") + set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_OPTS}") + endif() +endif() + +if (USE_CPPCHECK) + find_host_program(CPPCHECK_EXECUTABLE NAMES cppcheck) + if (CPPCHECK_EXECUTABLE) + set(CPPCHECK_OPTS ${CPPCHECK_EXECUTABLE} "--enable=all") + set(CMAKE_C_CPPCHECK "${CLANG_TIDY_OPTS}") + set(CMAKE_CXX_CPPCHECK "${CLANG_TIDY_OPTS}") + endif() +endif() + find_host_program(GDB_EXECUTABLE NAMES ${GDB_BINARY} gdb) find_host_program(LLDB_EXECUTABLE NAMES ${LLDB_BINARY} lldb) find_host_program(GIT_EXECUTABLE NAMES ${GIT_BINARY} git) diff --git a/contrib/.clang-tidy b/contrib/.clang-tidy new file mode 100644 index 000000000..381a0f45a --- /dev/null +++ b/contrib/.clang-tidy @@ -0,0 +1,6 @@ +--- +# We want to disable all checks for 3rd party code. However, clang-tidy will +# assume we did not configure it correctly. Just add one check that will never +# be found. +Checks: '-*,llvm-twine-local' +... diff --git a/src/tools/glslang/.clang-tidy b/src/tools/glslang/.clang-tidy new file mode 100644 index 000000000..381a0f45a --- /dev/null +++ b/src/tools/glslang/.clang-tidy @@ -0,0 +1,6 @@ +--- +# We want to disable all checks for 3rd party code. However, clang-tidy will +# assume we did not configure it correctly. Just add one check that will never +# be found. +Checks: '-*,llvm-twine-local' +...