Skip to content

Commit a4f3c07

Browse files
committed
[infra] add check_format and reformat targets
1 parent b9b68a5 commit a4f3c07

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/CMakeLists.txt

+27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
cmake_minimum_required (VERSION 3.8)
22

3+
###############################################################################
4+
# App tests
5+
###############################################################################
6+
37
# Set directories for test output files, input data and binaries.
48
file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/output)
59
add_definitions (-DOUTPUTDIR=\"${CMAKE_CURRENT_BINARY_DIR}/output/\")
@@ -83,3 +87,26 @@ else ()
8387
endif ()
8488

8589
message (STATUS "${FontBold}You can run `make cli-test` to build the tests and `make test` to run them.${FontReset}")
90+
91+
###############################################################################
92+
# Clang format
93+
###############################################################################
94+
95+
find_program(CLANG_FORMAT "clang-format-14")
96+
97+
if (CLANG_FORMAT STREQUAL "CLANG_FORMAT-NOTFOUND")
98+
find_program(CLANG_FORMAT "clang-format")
99+
endif()
100+
101+
if (NOT CLANG_FORMAT STREQUAL "CLANG_FORMAT-NOTFOUND")
102+
add_custom_target (check_format ALL "find" "${CMAKE_CURRENT_SOURCE_DIR}/../src" "-name" "'*.[ch]pp'" "-exec"
103+
${CLANG_FORMAT} "-style=file" "-n" "-Werror" "{}" "+"
104+
COMMENT "Checking the source-code with clang-format.")
105+
106+
107+
add_custom_target (reformat "find" "${CMAKE_CURRENT_SOURCE_DIR}/../src" "-name" "'*.[ch]pp'" "-exec"
108+
${CLANG_FORMAT} "-style=file" "-i" "{}" "+"
109+
COMMENT "Reformatting the source-code with clang-format.")
110+
else ()
111+
message(STATUS "clang_format not found; not adding the 'check_format' and 'reformat' targets.")
112+
endif()

0 commit comments

Comments
 (0)