Some very basic modules for clang-tidy. The modules which come with clang-tidy are very good, but I am missing some very basic checks for the code I have to work with. So I have read this perfect introduction and started to write some modules just for my very own needs.
You need some parts of the llvm sources:
cd
git clone http://llvm.org/git/llvm.git
cd llvm/tools/
git clone http://llvm.org/git/clang.git
cd clang/tools/
git clone http://llvm.org/git/clang-tools-extra.git extra
Now check if you are able to build these modules:
cd
mkdir llvm-build && cd llvm-build/
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
make check-clang-tools
If you have problems compiling the beast, just checkout the llvm docs.
Now it is time to integrate these modules:
cd
cd llvm/tools/clang/tools/extra/clang-tidy
git clone https://github.com/valpo/clang-tidy-modules.git valpo
valpo/integrate_module.sh
The last line applies a patch to clang tidy which integrates the valpo module. Basically it changes the following files in llvm/tools/clang/tools/extra/clang-tidy:
- CMakeList.txt: add a line
add_subdirectory(valpo)
just below the lineadd_subdirectory(utils)
- plugin/CMakeLists.txt: add a line
clangTidyValpoModule
just belowclangTidyMiscModule
- clang-tidy/tool/CMakeLists.txt: add a line
clangTidyValpoModule
just belowclangTidyMiscModule
- clang-tidy/tool/ClangTidyMain.cpp: add the lines
// This anchor is used to force the linker to link the ValpoModule.
extern volatile int ValpoModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ValpoModuleAnchorDestination =
ValpoModuleAnchorSource;
just below the line GoogleModuleAnchorSource;
Recompile clang-tidy:
cd
mkdir llvm-build && cd llvm-build/
make check-clang-tools
Now check if our new modules are there:
bin/clang-tidy -list-checks --checks "-*,valpo*"
should print out some checks.