alecAbstraction Layer for Escape Codes |
git clone git://git.dimitrijedobrota.com/alec.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
lint.cmake (1337B)
0 cmake_minimum_required(VERSION 3.14)
2 macro(default name)
3 if(NOT DEFINED "${name}")
4 set("${name}" "${ARGN}")
5 endif()
6 endmacro()
8 default(FORMAT_COMMAND clang-format)
9 default(
10 PATTERNS
11 source/*.cpp source/*.hpp
12 include/*.hpp
13 test/*.cpp test/*.hpp
14 example/*.cpp example/*.hpp
15 )
16 default(FIX NO)
18 set(flag --output-replacements-xml)
19 set(args OUTPUT_VARIABLE output)
20 if(FIX)
21 set(flag -i)
22 set(args "")
23 endif()
25 file(GLOB_RECURSE files ${PATTERNS})
26 set(badly_formatted "")
27 set(output "")
28 string(LENGTH "${CMAKE_SOURCE_DIR}/" path_prefix_length)
30 foreach(file IN LISTS files)
31 execute_process(
32 COMMAND "${FORMAT_COMMAND}" --style=file "${flag}" "${file}"
33 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
34 RESULT_VARIABLE result
35 ${args}
36 )
37 if(NOT result EQUAL "0")
38 message(FATAL_ERROR "'${file}': formatter returned with ${result}")
39 endif()
40 if(NOT FIX AND output MATCHES "\n<replacement offset")
41 string(SUBSTRING "${file}" "${path_prefix_length}" -1 relative_file)
42 list(APPEND badly_formatted "${relative_file}")
43 endif()
44 set(output "")
45 endforeach()
47 if(NOT badly_formatted STREQUAL "")
48 list(JOIN badly_formatted "\n" bad_list)
49 message("The following files are badly formatted:\n\n${bad_list}\n")
50 message(FATAL_ERROR "Run again with FIX=YES to fix these files.")
51 endif()