Static code analysis using CMake
Unit tests, sanitizers, and coverage reports all depend on the code being actually run to detect possible errors. Static code analysis analyzes the code without running it. The good thing about that is that all code that is compiled can be analyzed, not just the parts that are covered by tests. This, of course, also means that different kinds of glitches can be found. A downside of static code analysis is that it can take a very long time to run the tests.
CMake supports several tools for static code analysis that are enabled either by setting a property or a global variable. All of the tools, except link what you use, are external programs that need to be installed and found in the path of the system. Link what you use uses the linker of the system, so no further installation is necessary. The tools supported by CMake are the following:
- Clang-Tidy is a C++ linter tool covering a wide array of errors, including style violations and interface...