Build Status | |
---|---|
Travis |
Example CMake project that incorporates awesome Clang tooling.
Current status: Work in progress.
$ sudo apt install gcc g++ clang clang-tidy cmake cppcheck doxygen graphviz
Use -DCMAKE_BUILD_TYPE=Release
or -DCMAKE_BUILD_TYPE=Debug
to specify release or debug builds.
$ cd build
$ cmake ..
$ make
$ cd build
$ cmake -DCMAKE_CXX_COMPILER=clang++ ..
$ make
Navigate into the build
directory.
$ ./clang-blueprint
Unit tests are written using the Catch2 unit testing framework.
$ ./unit-test
Documentation is built using Doxygen. To configure how the docs are built,
modify docs/Doxyfile
.
$ cd docs
$ doxygen
$ firefox html/index.html
Navigate into the build
directory.
Clang-Tidy is configured using the .clang-tidy
configuration file. Modify this file to control which checks should be run and configure parameters for certain checks.
$ cmake ..
$ make clang-tidy
Scanning dependencies of target clang-tidy
95 warnings generated.
7477 warnings generated.
/home/user/GitHub/clang-blueprint/src/main.cpp:10:28: warning: parameter 'argc' is unused [misc-unused-parameters]
int32_t main(const int32_t argc, const char* argv[]) {
^~~~~
/*argc*/
/home/user/GitHub/clang-blueprint/src/main.
...
$ cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=clang++ -DADDRESS_SANITIZER=On ..
$ make
$ ./unit_test
==25797==ERROR: AddressSanitizer: heap-use-after-free on address 0x61400000024c at pc 0x000000616ecf bp 0x7ffd7aab4b30
sp 0x7ffd7aab4b28
...
Clang-Format is configured using the .clang-format
configuration file. Modify this file to control how source files should be formatted.
To demonstrate clang-format
in action, first modify src/main.cpp
from
return EXIT_SUCCESS;
To
return EXIT_SUCCESS;
Next, run clang-format
on the project.
$ cmake ..
$ make clang-format
main.cpp will be reformatted properly to
return EXIT_SUCCESS;
To run Cppcheck on the project
$ cmake ..
$ make cppcheck
[/home/user/GitHub/clang-blueprint/src/main.cpp:14]: (error) Array 'a[2]' accessed at index 3, which is out of bounds.
...