今天尝试了在 cmake 工程内部 添加cppcheck 进行 c++ 代码的静态检查。 记录一下实现的方案。
1. 安装cppcheck
apt install cppcheck
2. 命令行运行检查执行结果
先下载一份 rapidjson的代码 准备用来检查执行的结果
[root@jeason:~/temp]$ git clone https://gitee.com/Tencent/RapidJSON.git
Cloning into 'RapidJSON'...
remote: Enumerating objects: 24787, done.
remote: Counting objects: 100% (103/103), done.
remote: Compressing objects: 100% (50/50), done.
remote: Total 24787 (delta 51), reused 82 (delta 36), pack-reused 24684
Receiving objects: 100% (24787/24787), 26.60 MiB | 3.05 MiB/s, done.
Resolving deltas: 100% (19182/19182), done.
[root@jeason:~/temp]$
[root@jeason:~/temp]$ cd RapidJSON/ ## ------- 进入文件夹
[root@jeason:~/temp/RapidJSON → master]$ mkdir build ## ------- 创建目录
[root@jeason:~/temp/RapidJSON → master]$ cd build ## ------- 进入目录
[root@jeason:~/temp/RapidJSON/build → master]$ cmake .. ## ------- 生成makefile 文件
-- The CXX compiler identification is GNU 7.5.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- No Doxygen found. Documentation won't be built
-- Could NOT find GTestSrc (missing: GTEST_SOURCE_DIR GTEST_INCLUDE_DIR)
-- Configuring done
-- Generating done
-- Build files have been written to: /root/temp/RapidJSON/build
[root@jeason:~/temp/RapidJSON/build → master]$ make -j ## ------- 编译代码
Scanning dependencies of target pretty
Scanning dependencies of target capitalize
Scanning dependencies of target simplepullreader
Scanning dependencies of target parsebyparts
Scanning dependencies of target simplewriter
Scanning dependencies of target sortkeys
Scanning dependencies of target messagereader
Scanning dependencies of target lookaheadparser
Scanning dependencies of target condense
Scanning dependencies of target archivertest
Scanning dependencies of target filterkeydom
Scanning dependencies of target filterkey
Scanning dependencies of target simplereader
Scanning dependencies of target serialize
Scanning dependencies of target simpledom
Scanning dependencies of target prettyauto
Scanning dependencies of target schemavalidator
Scanning dependencies of target jsonx
[ 2%] Building CXX object example/CMakeFiles/simplewriter.dir/simplewriter/simplewriter.cpp.o
Scanning dependencies of target tutorial
[ 5%] Building CXX object example/CMakeFiles/messagereader.dir/messagereader/messagereader.cpp.o
[ 7%] Building CXX object example/CMakeFiles/pretty.dir/pretty/pretty.cpp.o
[ 10%] Building CXX object example/CMakeFiles/simplepullreader.dir/simplepullreader/simplepullreader.cpp.o
[ 12%] Building CXX object example/CMakeFiles/archivertest.dir/archiver/archiver.cpp.o
[ 20%] Building CXX object example/CMakeFiles/prettyauto.dir/prettyauto/prettyauto.cpp.o
[ 23%] Building CXX object example/CMakeFiles/sortkeys.dir/sortkeys/sortkeys.cpp.o
[ 15%] Building CXX object example/CMakeFiles/simplereader.dir/simplereader/simplereader.cpp.o
[ 25%] Building CXX object example/CMakeFiles/capitalize.dir/capitalize/capitalize.cpp.o
[ 17%] Building CXX object example/CMakeFiles/jsonx.dir/jsonx/jsonx.cpp.o
[ 28%] Building CXX object example/CMakeFiles/condense.dir/condense/condense.cpp.o
[ 30%] Building CXX object example/CMakeFiles/filterkeydom.dir/filterkeydom/filterkeydom.cpp.o
[ 33%] Building CXX object example/CMakeFiles/parsebyparts.dir/parsebyparts/parsebyparts.cpp.o
[ 35%] Building CXX object example/CMakeFiles/lookaheadparser.dir/lookaheadparser/lookaheadparser.cpp.o
[ 38%] Building CXX object example/CMakeFiles/archivertest.dir/archiver/archivertest.cpp.o
[ 41%] Building CXX object example/CMakeFiles/filterkey.dir/filterkey/filterkey.cpp.o
[ 43%] Building CXX object example/CMakeFiles/schemavalidator.dir/schemavalidator/schemavalidator.cpp.o
[ 46%] Building CXX object example/CMakeFiles/serialize.dir/serialize/serialize.cpp.o
[ 48%] Building CXX object example/CMakeFiles/simpledom.dir/simpledom/simpledom.cpp.o
[ 51%] Building CXX object example/CMakeFiles/tutorial.dir/tutorial/tutorial.cpp.o
[ 53%] Linking CXX executable ../bin/simplewriter
[ 56%] Linking CXX executable ../bin/simplereader
[ 56%] Built target simplewriter
[ 56%] Built target simplereader
[ 58%] Linking CXX executable ../bin/lookaheadparser
[ 61%] Linking CXX executable ../bin/messagereader
[ 61%] Built target lookaheadparser
[ 61%] Built target messagereader
[ 64%] Linking CXX executable ../bin/jsonx
[ 66%] Linking CXX executable ../bin/simplepullreader
[ 66%] Built target jsonx
[ 66%] Built target simplepullreader
[ 69%] Linking CXX executable ../bin/filterkey
[ 71%] Linking CXX executable ../bin/capitalize
[ 74%] Linking CXX executable ../bin/simpledom
[ 76%] Linking CXX executable ../bin/sortkeys
[ 76%] Built target capitalize
[ 76%] Built target filterkey
[ 79%] Linking CXX executable ../bin/serialize
[ 82%] Linking CXX executable ../bin/prettyauto
[ 82%] Built target simpledom
[ 84%] Linking CXX executable ../bin/condense
[ 84%] Built target serialize
[ 84%] Built target sortkeys
[ 84%] Built target prettyauto
[ 87%] Linking CXX executable ../bin/tutorial
[ 87%] Built target condense
[ 89%] Linking CXX executable ../bin/pretty
[ 92%] Linking CXX executable ../bin/filterkeydom
[ 92%] Built target tutorial
[ 94%] Linking CXX executable ../bin/archivertest
[ 94%] Built target pretty
[ 94%] Built target filterkeydom
[ 94%] Built target archivertest
[ 97%] Linking CXX executable ../bin/parsebyparts
[ 97%] Built target parsebyparts
[100%] Linking CXX executable ../bin/schemavalidator
[100%] Built target schemavalidator
Scanning dependencies of target examples
[100%] Built target examples
[root@jeason:~/temp/RapidJSON/build → master]$
可以看到 我们可以正常的编译 rapidjson 的代码。 接下来 使用命令行指令 手动的 进行cppcheck
执行结果如下:
[root@jeason:~/temp/RapidJSON/build → master]$ cppcheck ..
Checking ../build/CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp ...
Checking ../build/CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp: MPRAS;_MPRAS...
Checking ../build/CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp: SCO_SV;_SCO_SV;sco_sv...
Checking ../build/CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp: SIMULATE_VERSION_PATCH...
Checking ../build/CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp: SIMULATE_VERSION_PATCH;SIMULATE_VERSION_TWEAK...
Checking ../build/CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp: WIN32;_WIN32;__WIN32__...
Checking ../build/CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp: XENIX;_XENIX;__XENIX__...
Checking ../build/CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp: _AIX;__AIX;__AIX__;__aix;__aix__...
Checking ../build/CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp: _BEOS;__BEOS__;__BeOS...
Checking ../build/CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp: _COMPILER_VERSION;_SGI_COMPILER_VERSION...
Checking ../build/CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp: _COMPILER_VERSION;_SGI_COMPILER_VERSION;_SGI_COMPILER_VERSION...
Checking ../build/CMakeFiles/3.10.2/CompilerIdCXX/CMakeCXXCompilerId.cpp: _CRAYC...
1/57 files checked 1% done
Checking ../build/CMakeFiles/feature_tests.cxx ...
Checking ../build/CMakeFiles/feature_tests.cxx: __GXX_EXPERIMENTAL_CXX0X__...
2/57 files checked 3% done
Checking ../example/archiver/archiver.cpp ...
3/57 files checked 5% done
Checking ../example/archiver/archivertest.cpp ...
4/57 files checked 7% done
Checking ../example/capitalize/capitalize.cpp ...
5/57 files checked 8% done
Checking ../example/condense/condense.cpp ...
6/57 files checked 10% done
Checking ../example/filterkey/filterkey.cpp ...
7/57 files checked 12% done
Checking ../example/filterkeydom/filterkeydom.cpp ...
8/57 files checked 14% done
Checking ../example/jsonx/jsonx.cpp ...
9/57 files checked 15% done
Checking ../example/lookaheadparser/lookaheadparser.cpp ...
Checking ../example/lookaheadparser/lookaheadparser.cpp: __GNUC__...
10/57 files checked 17% done
Checking ../example/messagereader/messagereader.cpp ...
Checking ../example/messagereader/messagereader.cpp: __GNUC__...
Checking ../example/messagereader/messagereader.cpp: __clang__...
[../example/messagereader/messagereader.cpp:22]: (error) syntax error
11/57 files checked 19% done
Checking ../example/parsebyparts/parsebyparts.cpp ...
Checking ../example/parsebyparts/parsebyparts.cpp: _MSC_VER;__clang__...
12/57 files checked 21% done
Checking ../example/pretty/pretty.cpp ...
13/57 files checked 22% done
Checking ../example/prettyauto/prettyauto.cpp ...
Checking ../example/prettyauto/prettyauto.cpp: _WIN32...
14/57 files checked 24% done
Checking ../example/schemavalidator/schemavalidator.cpp ...
15/57 files checked 26% done
Checking ../example/serialize/serialize.cpp ...
Checking ../example/serialize/serialize.cpp: RAPIDJSON_HAS_STDSTRING...
16/57 files checked 28% done
Checking ../example/simpledom/simpledom.cpp ...
17/57 files checked 29% done
Checking ../example/simplepullreader/simplepullreader.cpp ...
18/57 files checked 31% done
Checking ../example/simplereader/simplereader.cpp ...
19/57 files checked 33% done
Checking ../example/simplewriter/simplewriter.cpp ...
20/57 files checked 35% done
Checking ../example/sortkeys/sortkeys.cpp ...
Checking ../example/sortkeys/sortkeys.cpp: _MSC_VER;__GLIBCXX__...
21/57 files checked 36% done
Checking ../example/traverseaspointer.cpp ...
22/57 files checked 38% done
Checking ../example/tutorial/tutorial.cpp ...
23/57 files checked 40% done
Checking ../test/perftest/misctest.cpp ...
Checking ../test/perftest/misctest.cpp: TEST_MISC...
Checking ../test/perftest/misctest.cpp: TEST_MISC;_M_IX86...
Checking ../test/perftest/misctest.cpp: TEST_MISC;_M_IX86;_M_X64...
Checking ../test/perftest/misctest.cpp: TEST_MISC;_M_X64...
Checking ../test/perftest/misctest.cpp: TEST_MISC;__GNUC__...
Checking ../test/perftest/misctest.cpp: TEST_MISC;__GNUC__;TEST_MISC;__GNUC__...
Checking ../test/perftest/misctest.cpp: _MSC_VER...
Checking ../test/perftest/misctest.cpp: __ARM_NEON...
Checking ../test/perftest/misctest.cpp: __GNUC__;__clang__...
Checking ../test/perftest/misctest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/perftest/misctest.cpp: __SSE2__...
24/57 files checked 42% done
Checking ../test/perftest/perftest.cpp ...
Checking ../test/perftest/perftest.cpp: _MSC_VER...
Checking ../test/perftest/perftest.cpp: __ARM_NEON...
Checking ../test/perftest/perftest.cpp: __GNUC__;__clang__...
Checking ../test/perftest/perftest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/perftest/perftest.cpp: __SSE2__...
Checking ../test/perftest/perftest.cpp: __SSE4_2__...
25/57 files checked 43% done
Checking ../test/perftest/platformtest.cpp ...
Checking ../test/perftest/platformtest.cpp: TEST_PLATFORM...
Checking ../test/perftest/platformtest.cpp: TEST_PLATFORM;_MSC_VER...
Checking ../test/perftest/platformtest.cpp: TEST_PLATFORM;_POSIX_MAPPED_FILES...
Checking ../test/perftest/platformtest.cpp: TEST_PLATFORM;_POSIX_MAPPED_FILES;__unix;__unix__;unix...
Checking ../test/perftest/platformtest.cpp: TEST_PLATFORM;_WIN32...
Checking ../test/perftest/platformtest.cpp: TEST_PLATFORM;__unix;__unix__;unix...
Checking ../test/perftest/platformtest.cpp: _MSC_VER...
Checking ../test/perftest/platformtest.cpp: __ARM_NEON...
Checking ../test/perftest/platformtest.cpp: __GNUC__;__clang__...
Checking ../test/perftest/platformtest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/perftest/platformtest.cpp: __SSE2__...
26/57 files checked 45% done
Checking ../test/perftest/rapidjsontest.cpp ...
Checking ../test/perftest/rapidjsontest.cpp: RAPIDJSON_HAS_STDSTRING;TEST_RAPIDJSON...
Checking ../test/perftest/rapidjsontest.cpp: RAPIDJSON_NEON;TEST_RAPIDJSON...
Checking ../test/perftest/rapidjsontest.cpp: RAPIDJSON_SSE2;TEST_RAPIDJSON...
Checking ../test/perftest/rapidjsontest.cpp: RAPIDJSON_SSE42;TEST_RAPIDJSON...
Checking ../test/perftest/rapidjsontest.cpp: TEST_RAPIDJSON...
Checking ../test/perftest/rapidjsontest.cpp: TEST_RAPIDJSON;__GNUC__...
Checking ../test/perftest/rapidjsontest.cpp: _MSC_VER...
Checking ../test/perftest/rapidjsontest.cpp: __ARM_NEON...
Checking ../test/perftest/rapidjsontest.cpp: __GNUC__;__clang__...
Checking ../test/perftest/rapidjsontest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/perftest/rapidjsontest.cpp: __SSE2__...
27/57 files checked 47% done
Checking ../test/perftest/schematest.cpp ...
[../test/perftest/schematest.cpp:19]: (error) syntax error
Checking ../test/perftest/schematest.cpp: TEST_RAPIDJSON...
Checking ../test/perftest/schematest.cpp: TEST_RAPIDJSON;__GNUC__...
Checking ../test/perftest/schematest.cpp: _MSC_VER...
Checking ../test/perftest/schematest.cpp: __ARM_NEON...
Checking ../test/perftest/schematest.cpp: __GNUC__;__clang__...
Checking ../test/perftest/schematest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/perftest/schematest.cpp: __SSE2__...
Checking ../test/perftest/schematest.cpp: __SSE4_2__...
28/57 files checked 49% done
Checking ../test/unittest/allocatorstest.cpp ...
Checking ../test/unittest/allocatorstest.cpp: RAPIDJSON_HAS_CXX11...
Checking ../test/unittest/allocatorstest.cpp: RAPIDJSON_HAS_CXX17...
Checking ../test/unittest/allocatorstest.cpp: _MSC_VER...
Checking ../test/unittest/allocatorstest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/allocatorstest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/allocatorstest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/allocatorstest.cpp: __clang__...
29/57 files checked 50% done
Checking ../test/unittest/bigintegertest.cpp ...
Checking ../test/unittest/bigintegertest.cpp: _MSC_VER...
Checking ../test/unittest/bigintegertest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/bigintegertest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/bigintegertest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/bigintegertest.cpp: __clang__...
30/57 files checked 52% done
Checking ../test/unittest/clzlltest.cpp ...
Checking ../test/unittest/clzlltest.cpp: _MSC_VER...
Checking ../test/unittest/clzlltest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/clzlltest.cpp: __GNUC__...
Checking ../test/unittest/clzlltest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/clzlltest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/clzlltest.cpp: __clang__...
31/57 files checked 54% done
Checking ../test/unittest/cursorstreamwrappertest.cpp ...
Checking ../test/unittest/cursorstreamwrappertest.cpp: _MSC_VER...
Checking ../test/unittest/cursorstreamwrappertest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/cursorstreamwrappertest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/cursorstreamwrappertest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/cursorstreamwrappertest.cpp: __clang__...
32/57 files checked 56% done
Checking ../test/unittest/documenttest.cpp ...
Checking ../test/unittest/documenttest.cpp: RAPIDJSON_HAS_CXX11_RVALUE_REFS...
Checking ../test/unittest/documenttest.cpp: RAPIDJSON_HAS_STDSTRING...
Checking ../test/unittest/documenttest.cpp: RAPIDJSON_HAS_STDSTRING;_MSC_VER...
Checking ../test/unittest/documenttest.cpp: _MSC_VER...
Checking ../test/unittest/documenttest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/documenttest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/documenttest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/documenttest.cpp: __clang__...
33/57 files checked 57% done
Checking ../test/unittest/dtoatest.cpp ...
Checking ../test/unittest/dtoatest.cpp: _MSC_VER...
Checking ../test/unittest/dtoatest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/dtoatest.cpp: __GNUC__...
Checking ../test/unittest/dtoatest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/dtoatest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/dtoatest.cpp: __clang__...
34/57 files checked 59% done
Checking ../test/unittest/encodedstreamtest.cpp ...
Checking ../test/unittest/encodedstreamtest.cpp: _MSC_VER...
Checking ../test/unittest/encodedstreamtest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/encodedstreamtest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/encodedstreamtest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/encodedstreamtest.cpp: __clang__...
35/57 files checked 61% done
Checking ../test/unittest/encodingstest.cpp ...
Checking ../test/unittest/encodingstest.cpp: _MSC_VER...
Checking ../test/unittest/encodingstest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/encodingstest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/encodingstest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/encodingstest.cpp: __clang__...
36/57 files checked 63% done
Checking ../test/unittest/filestreamtest.cpp ...
Checking ../test/unittest/filestreamtest.cpp: _MSC_VER...
Checking ../test/unittest/filestreamtest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/filestreamtest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/filestreamtest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/filestreamtest.cpp: __clang__...
37/57 files checked 64% done
Checking ../test/unittest/fwdtest.cpp ...
Checking ../test/unittest/fwdtest.cpp: _MSC_VER...
Checking ../test/unittest/fwdtest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/fwdtest.cpp: __GNUC__...
Checking ../test/unittest/fwdtest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/fwdtest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/fwdtest.cpp: __clang__...
38/57 files checked 66% done
Checking ../test/unittest/istreamwrappertest.cpp ...
Checking ../test/unittest/istreamwrappertest.cpp: _MSC_VER...
Checking ../test/unittest/istreamwrappertest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/istreamwrappertest.cpp: _MSC_VER;__clang__...
Checking ../test/unittest/istreamwrappertest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/istreamwrappertest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/istreamwrappertest.cpp: __clang__...
39/57 files checked 68% done
Checking ../test/unittest/itoatest.cpp ...
Checking ../test/unittest/itoatest.cpp: _MSC_VER...
Checking ../test/unittest/itoatest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/itoatest.cpp: __GNUC__...
Checking ../test/unittest/itoatest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/itoatest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/itoatest.cpp: __clang__...
40/57 files checked 70% done
Checking ../test/unittest/jsoncheckertest.cpp ...
Checking ../test/unittest/jsoncheckertest.cpp: _MSC_VER...
Checking ../test/unittest/jsoncheckertest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/jsoncheckertest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/jsoncheckertest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/jsoncheckertest.cpp: __clang__...
41/57 files checked 71% done
Checking ../test/unittest/namespacetest.cpp ...
Checking ../test/unittest/namespacetest.cpp: _MSC_VER...
Checking ../test/unittest/namespacetest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/namespacetest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/namespacetest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/namespacetest.cpp: __clang__...
42/57 files checked 73% done
Checking ../test/unittest/ostreamwrappertest.cpp ...
Checking ../test/unittest/ostreamwrappertest.cpp: _MSC_VER...
Checking ../test/unittest/ostreamwrappertest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/ostreamwrappertest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/ostreamwrappertest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/ostreamwrappertest.cpp: __clang__...
43/57 files checked 75% done
Checking ../test/unittest/platformtest.cpp ...
Checking ../test/unittest/platformtest.cpp: _MSC_VER...
Checking ../test/unittest/platformtest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/platformtest.cpp: _WIN32...
Checking ../test/unittest/platformtest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/platformtest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/platformtest.cpp: __clang__...
44/57 files checked 77% done
Checking ../test/unittest/pointertest.cpp ...
Checking ../test/unittest/pointertest.cpp: RAPIDJSON_HAS_STDSTRING...
Checking ../test/unittest/pointertest.cpp: _MSC_VER...
Checking ../test/unittest/pointertest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/pointertest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/pointertest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/pointertest.cpp: __clang__...
45/57 files checked 78% done
Checking ../test/unittest/prettywritertest.cpp ...
Checking ../test/unittest/prettywritertest.cpp: RAPIDJSON_HAS_CXX11_RVALUE_REFS...
Checking ../test/unittest/prettywritertest.cpp: RAPIDJSON_HAS_STDSTRING...
Checking ../test/unittest/prettywritertest.cpp: _MSC_VER...
Checking ../test/unittest/prettywritertest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/prettywritertest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/prettywritertest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/prettywritertest.cpp: __clang__...
46/57 files checked 80% done
Checking ../test/unittest/readertest.cpp ...
[../test/unittest/readertest.cpp:41]: (error) syntax error
Checking ../test/unittest/readertest.cpp: _MSC_VER...
Checking ../test/unittest/readertest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/readertest.cpp: __GNUC__...
Checking ../test/unittest/readertest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/readertest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/readertest.cpp: __clang__...
47/57 files checked 82% done
Checking ../test/unittest/regextest.cpp ...
Checking ../test/unittest/regextest.cpp: _MSC_VER...
Checking ../test/unittest/regextest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/regextest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/regextest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/regextest.cpp: __clang__...
48/57 files checked 84% done
Checking ../test/unittest/schematest.cpp ...
Checking ../test/unittest/schematest.cpp: RAPIDJSON_HAS_CXX11_RVALUE_REFS...
Checking ../test/unittest/schematest.cpp: RAPIDJSON_SCHEMA_HAS_REGEX...
Checking ../test/unittest/schematest.cpp: _MSC_VER...
Checking ../test/unittest/schematest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/schematest.cpp: _MSC_VER;__clang__...
Checking ../test/unittest/schematest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/schematest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/schematest.cpp: __clang__...
49/57 files checked 85% done
Checking ../test/unittest/simdtest.cpp ...
Checking ../test/unittest/simdtest.cpp: _MSC_VER...
Checking ../test/unittest/simdtest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/simdtest.cpp: __ARM_NEON...
Checking ../test/unittest/simdtest.cpp: __GNUC__...
Checking ../test/unittest/simdtest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/simdtest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/simdtest.cpp: __SSE2__...
Checking ../test/unittest/simdtest.cpp: __SSE4_2__...
Checking ../test/unittest/simdtest.cpp: __clang__...
50/57 files checked 87% done
Checking ../test/unittest/strfunctest.cpp ...
Checking ../test/unittest/strfunctest.cpp: _MSC_VER...
Checking ../test/unittest/strfunctest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/strfunctest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/strfunctest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/strfunctest.cpp: __clang__...
51/57 files checked 89% done
Checking ../test/unittest/stringbuffertest.cpp ...
Checking ../test/unittest/stringbuffertest.cpp: RAPIDJSON_HAS_CXX11_RVALUE_REFS...
Checking ../test/unittest/stringbuffertest.cpp: _MSC_VER...
Checking ../test/unittest/stringbuffertest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/stringbuffertest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/stringbuffertest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/stringbuffertest.cpp: __clang__...
52/57 files checked 91% done
Checking ../test/unittest/strtodtest.cpp ...
Checking ../test/unittest/strtodtest.cpp: _MSC_VER...
Checking ../test/unittest/strtodtest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/strtodtest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/strtodtest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/strtodtest.cpp: __clang__...
53/57 files checked 92% done
Checking ../test/unittest/unittest.cpp ...
Checking ../test/unittest/unittest.cpp: _MSC_VER...
Checking ../test/unittest/unittest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/unittest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/unittest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/unittest.cpp: __clang__...
54/57 files checked 94% done
Checking ../test/unittest/uritest.cpp ...
Checking ../test/unittest/uritest.cpp: _MSC_VER...
Checking ../test/unittest/uritest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/uritest.cpp: _MSC_VER;__clang__...
Checking ../test/unittest/uritest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/uritest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/uritest.cpp: __clang__...
55/57 files checked 96% done
Checking ../test/unittest/valuetest.cpp ...
Checking ../test/unittest/valuetest.cpp: RAPIDJSON_48BITPOINTER_OPTIMIZATION...
Checking ../test/unittest/valuetest.cpp: RAPIDJSON_64BIT...
Checking ../test/unittest/valuetest.cpp: RAPIDJSON_HAS_CXX11_RANGE_FOR...
Checking ../test/unittest/valuetest.cpp: RAPIDJSON_HAS_CXX11_RVALUE_REFS...
Checking ../test/unittest/valuetest.cpp: RAPIDJSON_HAS_STDSTRING...
Checking ../test/unittest/valuetest.cpp: _MSC_VER...
Checking ../test/unittest/valuetest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/valuetest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/valuetest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/valuetest.cpp: __clang__...
56/57 files checked 98% done
Checking ../test/unittest/writertest.cpp ...
Checking ../test/unittest/writertest.cpp: RAPIDJSON_HAS_CXX11_RVALUE_REFS...
Checking ../test/unittest/writertest.cpp: RAPIDJSON_HAS_STDSTRING...
Checking ../test/unittest/writertest.cpp: _MSC_VER...
Checking ../test/unittest/writertest.cpp: _MSC_VER;__WIN32__...
Checking ../test/unittest/writertest.cpp: __GNUC__;__clang__...
Checking ../test/unittest/writertest.cpp: __GNUC__;__clang__;__clang__...
Checking ../test/unittest/writertest.cpp: __clang__...
57/57 files checked 100% done
(information) Too many #ifdef configurations - cppcheck only checks 12 configurations. Use --force to check all configurations. For more details, use --enable=information.
[root@jeason:~/temp/RapidJSON/build → master]$
3. cmake + cppcheck
修改 默认的CMake 文件
添加的内容如下
# ....
find_program(CMAKE_C_CPPCHECK NAMES cppcheck)
if (CMAKE_C_CPPCHECK)
message("-- CppCheck found : ${CMAKE_C_CPPCHECK}")
message("-- current source dir : ${CMAKE_CURRENT_SOURCE_DIR}")
message("-- source dir : ${CMAKE_SOURCE_DIR}")
set(CMAKE_EXPORT_COMPILE_COMMANDS on)
set(CMAKE_CXX_CPPCHECK "cppcheck")
set(CMAKE_C_CPPCHECK "cppcheck")
list( APPEND CMAKE_C_CPPCHECK
"-j 4"
"--project=${CMAKE_SOURCE_DIR}/build/compile_commands.json"
"--force"
"--enable=all"
# "--quiet"
)
endif()
# ....
执行结果如下:
[root@jeason:~/temp/RapidJSON/build → master]$ rm -r ./* ; cmake .. && make -j 4
-- The CXX compiler identification is GNU 7.5.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CppCheck found : /usr/bin/cppcheck
-- current source dir : /root/temp/RapidJSON
-- source dir : /root/temp/RapidJSON
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- No Doxygen found. Documentation won't be built
-- Could NOT find GTestSrc (missing: GTEST_SOURCE_DIR GTEST_INCLUDE_DIR)
-- Configuring done
-- Generating done
-- Build files have been written to: /root/temp/RapidJSON/build
Scanning dependencies of target pretty
Scanning dependencies of target simplepullreader
Scanning dependencies of target tutorial
Scanning dependencies of target jsonx
[ 2%] Building CXX object example/CMakeFiles/simplepullreader.dir/simplepullreader/simplepullreader.cpp.o
[ 5%] Building CXX object example/CMakeFiles/pretty.dir/pretty/pretty.cpp.o
[ 7%] Building CXX object example/CMakeFiles/jsonx.dir/jsonx/jsonx.cpp.o
[ 10%] Building CXX object example/CMakeFiles/tutorial.dir/tutorial/tutorial.cpp.o
Checking /root/temp/RapidJSON/example/simplepullreader/simplepullreader.cpp ...
Checking /root/temp/RapidJSON/example/simplepullreader/simplepullreader.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
Checking /root/temp/RapidJSON/example/jsonx/jsonx.cpp ...
Checking /root/temp/RapidJSON/example/jsonx/jsonx.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
Checking /root/temp/RapidJSON/example/pretty/pretty.cpp ...
Checking /root/temp/RapidJSON/example/pretty/pretty.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
Checking /root/temp/RapidJSON/example/tutorial/tutorial.cpp ...
Checking /root/temp/RapidJSON/example/tutorial/tutorial.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
[ 12%] Linking CXX executable ../bin/simplepullreader
[ 12%] Built target simplepullreader
Scanning dependencies of target sortkeys
[ 15%] Building CXX object example/CMakeFiles/sortkeys.dir/sortkeys/sortkeys.cpp.o
Checking /root/temp/RapidJSON/example/sortkeys/sortkeys.cpp ...
Checking /root/temp/RapidJSON/example/sortkeys/sortkeys.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
[ 17%] Linking CXX executable ../bin/jsonx
[ 20%] Linking CXX executable ../bin/pretty
[ 20%] Built target jsonx
[ 23%] Linking CXX executable ../bin/tutorial
Scanning dependencies of target condense
[ 23%] Built target pretty
[ 25%] Building CXX object example/CMakeFiles/condense.dir/condense/condense.cpp.o
Scanning dependencies of target simpledom
[ 28%] Building CXX object example/CMakeFiles/simpledom.dir/simpledom/simpledom.cpp.o
[ 28%] Built target tutorial
Scanning dependencies of target messagereader
Checking /root/temp/RapidJSON/example/condense/condense.cpp ...
Checking /root/temp/RapidJSON/example/condense/condense.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
[ 30%] Building CXX object example/CMakeFiles/messagereader.dir/messagereader/messagereader.cpp.o
Checking /root/temp/RapidJSON/example/simpledom/simpledom.cpp ...
Checking /root/temp/RapidJSON/example/simpledom/simpledom.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
Checking /root/temp/RapidJSON/example/messagereader/messagereader.cpp ...
Checking /root/temp/RapidJSON/example/messagereader/messagereader.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
[ 33%] Linking CXX executable ../bin/sortkeys
[ 33%] Built target sortkeys
Scanning dependencies of target simplewriter
[ 35%] Building CXX object example/CMakeFiles/simplewriter.dir/simplewriter/simplewriter.cpp.o
Checking /root/temp/RapidJSON/example/simplewriter/simplewriter.cpp ...
Checking /root/temp/RapidJSON/example/simplewriter/simplewriter.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
[ 38%] Linking CXX executable ../bin/condense
[ 41%] Linking CXX executable ../bin/messagereader
[ 41%] Built target condense
Scanning dependencies of target filterkeydom
[ 43%] Building CXX object example/CMakeFiles/filterkeydom.dir/filterkeydom/filterkeydom.cpp.o
[ 46%] Linking CXX executable ../bin/simplewriter
[ 48%] Linking CXX executable ../bin/simpledom
[ 48%] Built target messagereader
Checking /root/temp/RapidJSON/example/filterkeydom/filterkeydom.cpp ...
Checking /root/temp/RapidJSON/example/filterkeydom/filterkeydom.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
Scanning dependencies of target filterkey
[ 51%] Building CXX object example/CMakeFiles/filterkey.dir/filterkey/filterkey.cpp.o
[ 51%] Built target simplewriter
Checking /root/temp/RapidJSON/example/filterkey/filterkey.cpp ...
Checking /root/temp/RapidJSON/example/filterkey/filterkey.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
Scanning dependencies of target lookaheadparser
[ 51%] Built target simpledom
[ 53%] Building CXX object example/CMakeFiles/lookaheadparser.dir/lookaheadparser/lookaheadparser.cpp.o
Scanning dependencies of target capitalize
[ 56%] Building CXX object example/CMakeFiles/capitalize.dir/capitalize/capitalize.cpp.o
Checking /root/temp/RapidJSON/example/lookaheadparser/lookaheadparser.cpp ...
Checking /root/temp/RapidJSON/example/lookaheadparser/lookaheadparser.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
Checking /root/temp/RapidJSON/example/capitalize/capitalize.cpp ...
Checking /root/temp/RapidJSON/example/capitalize/capitalize.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
[ 58%] Linking CXX executable ../bin/lookaheadparser
[ 58%] Built target lookaheadparser
Scanning dependencies of target parsebyparts
[ 61%] Building CXX object example/CMakeFiles/parsebyparts.dir/parsebyparts/parsebyparts.cpp.o
Checking /root/temp/RapidJSON/example/parsebyparts/parsebyparts.cpp ...
Checking /root/temp/RapidJSON/example/parsebyparts/parsebyparts.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
[ 64%] Linking CXX executable ../bin/filterkey
[ 64%] Built target filterkey
Scanning dependencies of target prettyauto
[ 66%] Building CXX object example/CMakeFiles/prettyauto.dir/prettyauto/prettyauto.cpp.o
[ 69%] Linking CXX executable ../bin/filterkeydom
Checking /root/temp/RapidJSON/example/prettyauto/prettyauto.cpp ...
Checking /root/temp/RapidJSON/example/prettyauto/prettyauto.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
[ 69%] Built target filterkeydom
Scanning dependencies of target schemavalidator
[ 71%] Building CXX object example/CMakeFiles/schemavalidator.dir/schemavalidator/schemavalidator.cpp.o
Checking /root/temp/RapidJSON/example/schemavalidator/schemavalidator.cpp ...
Checking /root/temp/RapidJSON/example/schemavalidator/schemavalidator.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
[ 74%] Linking CXX executable ../bin/capitalize
[ 74%] Built target capitalize
Scanning dependencies of target simplereader
[ 76%] Building CXX object example/CMakeFiles/simplereader.dir/simplereader/simplereader.cpp.o
Checking /root/temp/RapidJSON/example/simplereader/simplereader.cpp ...
Checking /root/temp/RapidJSON/example/simplereader/simplereader.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
[ 79%] Linking CXX executable ../bin/prettyauto
[ 82%] Linking CXX executable ../bin/simplereader
[ 82%] Built target prettyauto
Scanning dependencies of target serialize
[ 84%] Building CXX object example/CMakeFiles/serialize.dir/serialize/serialize.cpp.o
[ 84%] Built target simplereader
Checking /root/temp/RapidJSON/example/serialize/serialize.cpp ...
Checking /root/temp/RapidJSON/example/serialize/serialize.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
Scanning dependencies of target archivertest
[ 87%] Building CXX object example/CMakeFiles/archivertest.dir/archiver/archiver.cpp.o
Checking /root/temp/RapidJSON/example/archiver/archiver.cpp ...
Checking /root/temp/RapidJSON/example/archiver/archiver.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
Warning: cppcheck reported diagnostics:
[/root/temp/RapidJSON/include/rapidjson/rapidjson.h:280]: (error) #error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
[ 89%] Linking CXX executable ../bin/parsebyparts
[ 89%] Built target parsebyparts
[ 92%] Building CXX object example/CMakeFiles/archivertest.dir/archiver/archivertest.cpp.o
Checking /root/temp/RapidJSON/example/archiver/archivertest.cpp ...
Checking /root/temp/RapidJSON/example/archiver/archivertest.cpp: __STDC_FORMAT_MACROS=1;NDEBUG=1...
[ 94%] Linking CXX executable ../bin/serialize
[ 94%] Built target serialize
[ 97%] Linking CXX executable ../bin/archivertest
[ 97%] Built target archivertest
[100%] Linking CXX executable ../bin/schemavalidator
[100%] Built target schemavalidator
Scanning dependencies of target examples
[100%] Built target examples
[root@jeason:~/temp/RapidJSON/build → master]$
后续 看看有没有时间去补充一些其他的内容吧, 暂时就这些了, 可以在cmake 里面添加 直接运行 cppcheck 进行代码 的静态检查。