Skip to content

Commit e92e156

Browse files
committed
Add clang-tidy
1 parent c409e5e commit e92e156

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,16 @@ matrix:
141141
after_success:
142142
- coveralls --gcov gcov-7 --gcov-options '\-lp' --exclude src
143143

144+
- compiler: clang
145+
addons:
146+
apt:
147+
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0']
148+
packages: ['clang-5.0', 'clang-tidy-5.0']
149+
env:
150+
- CXX=clang++-5.0
151+
- CLANG_TIDY=clang-tidy-5.0
152+
script:
153+
- make -kj3 clang-tidy
154+
144155
script:
145156
make -j3

Makefile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,26 @@ endif
2929
CPPFLAGS ?= -pedantic
3030
CXXFLAGS ?= -Wall -Wextra -Wshadow -Werror -O3
3131

32-
.PHONY: all clean
32+
CLANG_TIDY ?= clang-tidy
3333

34+
HEADERS := $(shell find include -name '*.hpp')
3435
SOURCES := $(shell find src -name '*.cpp')
3536
DEPENDS := $(SOURCES:%.cpp=build/%.d)
3637
BINARIES := $(SOURCES:%.cpp=build/%)
3738

3839
UNIT_TESTS := $(filter build/src/test/%,$(BINARIES))
3940

40-
all: $(BINARIES)
41+
.PHONY: all
42+
all: compile check
43+
44+
.PHONY: compile
45+
compile: $(BINARIES)
46+
47+
.PHONY: check
48+
check: $(UNIT_TESTS)
4149
@set -e; for T in $(UNIT_TESTS); do echo $$T; $$T > /dev/null; done
4250

51+
.PHONY: clean
4352
clean:
4453
@rm -rf build
4554
@find . -name '*~' -delete
@@ -51,6 +60,15 @@ build/%.d: %.cpp Makefile
5160
build/%: %.cpp build/%.d
5261
$(CXX) $(CXXSTD) -Iinclude $(CPPFLAGS) $(CXXFLAGS) $< -o $@
5362

63+
build/%.clang-tidy: %
64+
$(CLANG_TIDY) -extra-arg "-Iinclude" -extra-arg "-std=c++11" -checks=*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-misc-macro-parentheses -warnings-as-errors=* $< 2>/dev/null
65+
@mkdir -p $(@D)
66+
@touch $@
67+
68+
.PHONY: clang-tidy
69+
clang-tidy: $(HEADERS:%=build/%.clang-tidy) $(SOURCES:%=build/%.clang-tidy)
70+
@echo "All $(words $(HEADERS) $(SOURCES)) clang-tidy tests passed."
71+
5472
ifeq ($(findstring $(MAKECMDGOALS),clean),)
5573
-include $(DEPENDS)
5674
endif

0 commit comments

Comments
 (0)