diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2017-08-16 16:24:44 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-08-30 14:23:46 (GMT) |
commit | 311b7b1a7095ec460fab950a6767571eb3b9652c (patch) | |
tree | 23843c9cd26d9d150e76fadda88a8fbf47d5f12c /Tests | |
parent | fff28e30cd01a88b2e5f67db2aaf4c068f1bfc89 (diff) | |
download | CMake-311b7b1a7095ec460fab950a6767571eb3b9652c.zip CMake-311b7b1a7095ec460fab950a6767571eb3b9652c.tar.gz CMake-311b7b1a7095ec460fab950a6767571eb3b9652c.tar.bz2 |
Add properties to run cppcheck along with the compiler
Create a `<LANG>_CPPCHECK` target property (initialized by a
`CMAKE_<LANG>_CPPCHECK` variable) to specify a `cppcheck` command line
to be run along with the compiler.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/RunCMake/CommandLine/E___run_iwyu-no-iwyu-stderr.txt | 2 | ||||
-rw-r--r-- | Tests/RunCMake/Cppcheck/C-Build-stdout.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/Cppcheck/C-launch-Build-stdout.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/Cppcheck/C-launch.cmake | 3 | ||||
-rw-r--r-- | Tests/RunCMake/Cppcheck/C.cmake | 4 | ||||
-rw-r--r-- | Tests/RunCMake/Cppcheck/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/Cppcheck/CXX-Build-stdout.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/Cppcheck/CXX-launch-Build-stdout.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/Cppcheck/CXX-launch.cmake | 3 | ||||
-rw-r--r-- | Tests/RunCMake/Cppcheck/CXX.cmake | 3 | ||||
-rw-r--r-- | Tests/RunCMake/Cppcheck/RunCMakeTest.cmake | 22 | ||||
-rw-r--r-- | Tests/RunCMake/Cppcheck/main.c | 4 | ||||
-rw-r--r-- | Tests/RunCMake/Cppcheck/main.cxx | 4 | ||||
-rw-r--r-- | Tests/RunCMake/pseudo_cppcheck.c | 21 |
15 files changed, 74 insertions, 1 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 13df4a8..88952e1 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -343,9 +343,11 @@ if("${CMAKE_GENERATOR}" MATCHES "Make|Ninja") add_executable(pseudo_tidy pseudo_tidy.c) add_executable(pseudo_iwyu pseudo_iwyu.c) add_executable(pseudo_cpplint pseudo_cpplint.c) + add_executable(pseudo_cppcheck pseudo_cppcheck.c) add_RunCMake_test(ClangTidy -DPSEUDO_TIDY=$<TARGET_FILE:pseudo_tidy>) add_RunCMake_test(IncludeWhatYouUse -DPSEUDO_IWYU=$<TARGET_FILE:pseudo_iwyu>) add_RunCMake_test(Cpplint -DPSEUDO_CPPLINT=$<TARGET_FILE:pseudo_cpplint>) + add_RunCMake_test(Cppcheck -DPSEUDO_CPPCHECK=$<TARGET_FILE:pseudo_cppcheck>) if(DEFINED CMake_TEST_CUDA) list(APPEND CompilerLauncher_ARGS -DCMake_TEST_CUDA=${CMake_TEST_CUDA}) endif() diff --git a/Tests/RunCMake/CommandLine/E___run_iwyu-no-iwyu-stderr.txt b/Tests/RunCMake/CommandLine/E___run_iwyu-no-iwyu-stderr.txt index 35f50b7..9db95f8 100644 --- a/Tests/RunCMake/CommandLine/E___run_iwyu-no-iwyu-stderr.txt +++ b/Tests/RunCMake/CommandLine/E___run_iwyu-no-iwyu-stderr.txt @@ -1 +1 @@ -^__run_iwyu missing --cpplint=, --iwyu=, --lwyu=, and/or --tidy=$ +^__run_iwyu missing --cpplint=, --iwyu=, --lwyu=, --cppcheck= and/or --tidy=$ diff --git a/Tests/RunCMake/Cppcheck/C-Build-stdout.txt b/Tests/RunCMake/Cppcheck/C-Build-stdout.txt new file mode 100644 index 0000000..26eded3 --- /dev/null +++ b/Tests/RunCMake/Cppcheck/C-Build-stdout.txt @@ -0,0 +1 @@ +.*Warning: cppcheck reported diagnostics.*error.*warning.*style.*performance.*information.* diff --git a/Tests/RunCMake/Cppcheck/C-launch-Build-stdout.txt b/Tests/RunCMake/Cppcheck/C-launch-Build-stdout.txt new file mode 100644 index 0000000..26eded3 --- /dev/null +++ b/Tests/RunCMake/Cppcheck/C-launch-Build-stdout.txt @@ -0,0 +1 @@ +.*Warning: cppcheck reported diagnostics.*error.*warning.*style.*performance.*information.* diff --git a/Tests/RunCMake/Cppcheck/C-launch.cmake b/Tests/RunCMake/Cppcheck/C-launch.cmake new file mode 100644 index 0000000..e66ca20 --- /dev/null +++ b/Tests/RunCMake/Cppcheck/C-launch.cmake @@ -0,0 +1,3 @@ +set(CTEST_USE_LAUNCHERS 1) +include(CTestUseLaunchers) +include(C.cmake) diff --git a/Tests/RunCMake/Cppcheck/C.cmake b/Tests/RunCMake/Cppcheck/C.cmake new file mode 100644 index 0000000..b1f5bf7 --- /dev/null +++ b/Tests/RunCMake/Cppcheck/C.cmake @@ -0,0 +1,4 @@ + +enable_language(C) +set(CMAKE_C_CPPCHECK "${PSEUDO_CPPCHECK}") +add_executable(main main.c) diff --git a/Tests/RunCMake/Cppcheck/CMakeLists.txt b/Tests/RunCMake/Cppcheck/CMakeLists.txt new file mode 100644 index 0000000..a640c56 --- /dev/null +++ b/Tests/RunCMake/Cppcheck/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.7) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/Cppcheck/CXX-Build-stdout.txt b/Tests/RunCMake/Cppcheck/CXX-Build-stdout.txt new file mode 100644 index 0000000..26eded3 --- /dev/null +++ b/Tests/RunCMake/Cppcheck/CXX-Build-stdout.txt @@ -0,0 +1 @@ +.*Warning: cppcheck reported diagnostics.*error.*warning.*style.*performance.*information.* diff --git a/Tests/RunCMake/Cppcheck/CXX-launch-Build-stdout.txt b/Tests/RunCMake/Cppcheck/CXX-launch-Build-stdout.txt new file mode 100644 index 0000000..26eded3 --- /dev/null +++ b/Tests/RunCMake/Cppcheck/CXX-launch-Build-stdout.txt @@ -0,0 +1 @@ +.*Warning: cppcheck reported diagnostics.*error.*warning.*style.*performance.*information.* diff --git a/Tests/RunCMake/Cppcheck/CXX-launch.cmake b/Tests/RunCMake/Cppcheck/CXX-launch.cmake new file mode 100644 index 0000000..3002c9d --- /dev/null +++ b/Tests/RunCMake/Cppcheck/CXX-launch.cmake @@ -0,0 +1,3 @@ +set(CTEST_USE_LAUNCHERS 1) +include(CTestUseLaunchers) +include(CXX.cmake) diff --git a/Tests/RunCMake/Cppcheck/CXX.cmake b/Tests/RunCMake/Cppcheck/CXX.cmake new file mode 100644 index 0000000..3b79471 --- /dev/null +++ b/Tests/RunCMake/Cppcheck/CXX.cmake @@ -0,0 +1,3 @@ +enable_language(CXX) +set(CMAKE_CXX_CPPCHECK "${PSEUDO_CPPCHECK}") +add_executable(main main.cxx) diff --git a/Tests/RunCMake/Cppcheck/RunCMakeTest.cmake b/Tests/RunCMake/Cppcheck/RunCMakeTest.cmake new file mode 100644 index 0000000..ae14f8c --- /dev/null +++ b/Tests/RunCMake/Cppcheck/RunCMakeTest.cmake @@ -0,0 +1,22 @@ +include(RunCMake) + +set(RunCMake_TEST_OPTIONS "-DPSEUDO_CPPCHECK=${PSEUDO_CPPCHECK}") + +function(run_cppcheck lang) + # Use a single build tree for tests without cleaning. + set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${lang}-build") + set(RunCMake_TEST_NO_CLEAN 1) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + run_cmake(${lang}) + set(RunCMake_TEST_OUTPUT_MERGE 1) + run_cmake_command(${lang}-Build ${CMAKE_COMMAND} --build .) +endfunction() + +run_cppcheck(C) +run_cppcheck(CXX) + +if(NOT RunCMake_GENERATOR STREQUAL "Watcom WMake") + run_cppcheck(C-launch) + run_cppcheck(CXX-launch) +endif() diff --git a/Tests/RunCMake/Cppcheck/main.c b/Tests/RunCMake/Cppcheck/main.c new file mode 100644 index 0000000..8488f4e --- /dev/null +++ b/Tests/RunCMake/Cppcheck/main.c @@ -0,0 +1,4 @@ +int main(void) +{ + return 0; +} diff --git a/Tests/RunCMake/Cppcheck/main.cxx b/Tests/RunCMake/Cppcheck/main.cxx new file mode 100644 index 0000000..f8b643a --- /dev/null +++ b/Tests/RunCMake/Cppcheck/main.cxx @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/Tests/RunCMake/pseudo_cppcheck.c b/Tests/RunCMake/pseudo_cppcheck.c new file mode 100644 index 0000000..32e6e28 --- /dev/null +++ b/Tests/RunCMake/pseudo_cppcheck.c @@ -0,0 +1,21 @@ +#include <stdio.h> + +int main(void) +{ + fprintf(stderr, + "[/foo/bar.c:2]: (error) Array 'abc[10]' accessed at index 12," + " which is out of bounds.\n"); + fprintf(stderr, "[/foo/bar.c:2]: (warning) Member variable 'foo::bar' is " + "not initialized in the constructor.\n"); + fprintf(stderr, "[/foo/bar.c:2]: (style) C-style pointer casting.\n"); + fprintf(stderr, "[/foo/bar.c:2]: (performance) Variable 'm_message' is " + "assigned in constructor body. Consider performing " + "initialization in initialization list.\n"); + fprintf(stderr, "[/foo/bar.c:2]: (portability) scanf without field width " + "limits can crash with huge input data on some versions of " + "libc\n"); + fprintf(stderr, "[/foo/bar.c:2]: (information) cannot find all the include " + "files (use --check-config for details)\n"); + // we allow this to return 1 as we ignore it + return 1; +} |