Skip to content

Commit d1e0498

Browse files
committed
build(cmake): Add lint rule using clang-format
Origin: #136 Signed-off-by: Philippe Coval <[email protected]>
1 parent 575d305 commit d1e0498

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ if(BUILD_TESTING)
3030
include(cmake/include/unittest.cmake)
3131
endif()
3232

33+
include(cmake/include/clang-format.cmake)
3334
include(cmake/include/doxygen.cmake)
3435

3536
# ##############################################################################

cmake/include/clang-format.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-FileCopyrightText: Silicon Laboratories Inc. <https://www.silabs.com/>
2+
# SPDX-License-Identifier: ZLIB
3+
4+
file(GLOB_RECURSE sources_list *.c *.cpp *.h *.hpp)
5+
list(FILTER sources_list EXCLUDE REGEX ".git/.*")
6+
list(FILTER sources_list EXCLUDE REGEX "${CMAKE_BINARY_DIR}/.*")
7+
list(FILTER sources_list EXCLUDE REGEX ".*/ZW_classcmd.h")
8+
if(NOT ENV{uncrustify_args})
9+
set(uncrustify_args --replace)
10+
endif()
11+
12+
string(REPLACE ";" "\n" sources_list_text "${sources_list}" )
13+
file(WRITE "${CMAKE_BINARY_DIR}/sources.lst" ${sources_list_text})
14+
15+
add_custom_target(lint
16+
COMMAND clang-format -i --files="${CMAKE_BINARY_DIR}/sources.lst"
17+
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
18+
DEPENDS "${CMAKE_BINARY_DIR}/sources.lst"
19+
)

helper.mk

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export CMAKE_GENERATOR
3030

3131
build_dir?=build
3232
sudo?=sudo
33+
cmake?=cmake
3334

3435
debian_codename?=bookworm
3536

@@ -40,6 +41,7 @@ packages+=python3-defusedxml # For extract_get.py
4041
# TODO: remove for offline build
4142
packages+=curl wget python3-pip
4243
packages+=expect
44+
package+=clang-format
4345

4446
# For docs
4547
packages+=graphviz
@@ -231,6 +233,10 @@ all: ${build_dir}/CMakeCache.txt
231233
# cmake --build ${<D} \
232234
# || cat ${build_dir}/CMakeFiles/CMakeOutput.log
233235
cmake --build ${<D}
236+
237+
cmake/%: ${build_dir}/CMakeCache.txt
238+
${cmake} --build ${<D} --target=${@F}
239+
234240
.PHONY: all
235241

236242
${build_dir}/%: all
@@ -298,14 +304,17 @@ prepare: git/prepare
298304
git --version
299305
cmake --version
300306

301-
all/default: configure prepare all test dist
307+
all/default: lint configure prepare all test dist
302308
@date -u
303309

304310
run_args?=--help
305311
run:
306312
file -E ${run_file}
307313
${run_file} ${run_args}
308314

315+
lint: .clang-format cmake/lint
316+
git status
317+
309318
### @rootfs is faster than docker for env check
310319

311320
rootfs_dir?=/var/tmp/var/lib/machines/${project}

0 commit comments

Comments
 (0)