Skip to content

Commit 3da70c0

Browse files
authored
Use clang-tidy through cmake (#341)
1 parent d92c6fb commit 3da70c0

5 files changed

Lines changed: 24 additions & 24 deletions

File tree

.github/workflows/build_test.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,9 @@ jobs:
6767
env:
6868
CC: ${{ matrix.config.cc }}
6969
CXX: ${{ matrix.config.cxx }}
70-
run: |
71-
mkdir -p build
72-
cd build
73-
cmake -DCMAKE_BUILD_TYPE=Release ..
74-
- name: make
75-
run: |
76-
cd build
77-
cmake --build . --config Release # `config Release` somehow necessary by windows
70+
run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
71+
- name: build
72+
run: cmake --build build --config Release # `config Release` somehow necessary by windows
7873

7974
- name: upload binaries
8075
uses: actions/upload-artifact@v2

.github/workflows/format.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ jobs:
1111
runs-on: ubuntu-22.04
1212

1313
steps:
14-
- run: sudo apt install clang-format-15
15-
1614
- run: clang-format-15 --version
1715

1816
- name: checkout

.github/workflows/tidy.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ jobs:
1515
runs-on: ubuntu-22.04
1616

1717
steps:
18-
- name: ubuntu install clang-tidy
19-
run: |
20-
sudo apt install clang-tidy-12
21-
clang-tidy-12 --version
18+
- run: clang-tidy --version
2219

2320
- name: set up python 3.8
2421
uses: actions/setup-python@v2
@@ -31,12 +28,7 @@ jobs:
3128
uses: actions/checkout@v2
3229

3330
- name: cmake
34-
run: |
35-
mkdir -p build
36-
cd build
37-
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
31+
run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DODR_CLANG_TIDY=ON
3832

3933
- name: clang-tidy
40-
run: |
41-
FILES=$( find . -path ./build -prune -false -o -type f \( -iname \*.cpp \) )
42-
clang-tidy-12 -p build -header-filter '.*' $FILES
34+
run: cmake --build build

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
66
set(CMAKE_CXX_EXTENSIONS OFF)
77

88
option(ODR_TEST "enable tests" ON)
9+
option(ODR_CLANG_TIDY "Run clang-tidy static analysis" OFF)
910

1011
# TODO defining global compiler flags seems to be bad practice with conan
1112
# TODO consider using conan profiles
@@ -163,15 +164,15 @@ add_library(odr
163164

164165
"src/odr/internal/zip/zip_util.cpp"
165166
"src/odr/internal/zip/zip_archive.cpp"
166-
)
167+
)
167168
set_target_properties(odr PROPERTIES OUTPUT_NAME odr)
168169
if (EXISTS "${PROJECT_SOURCE_DIR}/.git")
169170
add_dependencies(odr check_git)
170171
endif ()
171172
target_include_directories(odr
172173
PUBLIC
173174
src
174-
)
175+
)
175176
target_link_libraries(odr
176177
PRIVATE
177178
pugixml::pugixml
@@ -180,14 +181,18 @@ target_link_libraries(odr
180181
nlohmann_json::nlohmann_json
181182
vincentlaucsb-csv-parser::vincentlaucsb-csv-parser
182183
uchardet::uchardet
183-
)
184+
)
184185

185186
add_subdirectory("cli")
186187

187188
if (ODR_TEST)
188189
add_subdirectory("test")
189190
endif ()
190191

192+
if (ODR_CLANG_TIDY)
193+
add_subdirectory("static_analysis/clang-tidy")
194+
endif ()
195+
191196
install(
192197
TARGETS
193198
odr
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
2+
3+
if (NOT CLANG_TIDY_COMMAND)
4+
message(ERROR "ACTS_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
5+
set(CMAKE_CXX_CLANG_TIDY "" CACHE STRING "" FORCE)
6+
endif ()
7+
8+
message(STATUS "Setting up clang-tidy run")
9+
10+
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")

0 commit comments

Comments
 (0)