Skip to content

🏰 Example C++11 CMake project that incorporates awesome Clang tooling 🐉

Notifications You must be signed in to change notification settings

johnthagen/clang-blueprint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clang-blueprint

Build Status
Travis Travis Build Status

Example CMake project that incorporates awesome Clang tooling.

Current status: Work in progress.

Requirements

Ubuntu 18.04

$ sudo apt install gcc g++ clang clang-tidy cmake cppcheck doxygen graphviz

Build

Use -DCMAKE_BUILD_TYPE=Release or -DCMAKE_BUILD_TYPE=Debug to specify release or debug builds.

GCC

$ cd build
$ cmake ..
$ make

Clang

$ cd build
$ cmake -DCMAKE_CXX_COMPILER=clang++ ..
$ make

Run

Navigate into the build directory.

Application

$ ./clang-blueprint

Unit tests

$ ./unit-test

Build Docs

$ cd docs
$ doxygen
$ firefox html/index.html

Clang Tools

Navigate into the build directory.

Clang-Tidy

Clang-Tidy is configured using the .clang-format 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.
...

Clang-Format

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;

Cppcheck

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.
...

References

  • Clang - Compiler Framework
  • CMake - Cross Platform Build System
  • Catch2 - Unit Testing
  • Doxygen - Documentation Generation