Команда для проверки форматирования кода

This commit is contained in:
Andrei Astafev 2021-02-19 11:04:50 +03:00
parent b725122c89
commit 1bff4d2a0d

View File

@ -4,20 +4,26 @@ function(add_format_sources target)
if(NOT TARGET format-sources) if(NOT TARGET format-sources)
add_custom_target(format-sources) add_custom_target(format-sources)
endif() endif()
if(NOT TARGET check-format-sources)
add_custom_target(check-format-sources)
endif()
if(NOT TARGET doc-add-comments) if(NOT TARGET doc-add-comments)
add_custom_target(doc-add-comments) add_custom_target(doc-add-comments)
endif() endif()
find_program(UNCRUSTIFY_EXE NAMES uncrustify) find_program(UNCRUSTIFY_EXE NAMES uncrustify)
if(UNCRUSTIFY_EXE) if(UNCRUSTIFY_EXE)
list(APPEND UNCRUSTIFY_OPTS --replace --no-backup)
if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg) if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg)
list(APPEND UNCRUSTIFY_OPTS -c ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg) list(APPEND UNCRUSTIFY_OPTS -c ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg)
endif() endif()
# cmake-format: off # cmake-format: off
add_custom_target(format-sources-uncrustify-${target} COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} add_custom_target(check-format-sources-uncrustify-${target} COMMAND ${UNCRUSTIFY_EXE}
--mtime ${_sources}) ${UNCRUSTIFY_OPTS} --check ${_sources})
add_custom_target(doc-add-comments-uncrustify-${target} COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} list(APPEND UNCRUSTIFY_OPTS --replace --no-backup)
add_custom_target(format-sources-uncrustify-${target} COMMAND ${UNCRUSTIFY_EXE}
${UNCRUSTIFY_OPTS} --mtime ${_sources})
add_custom_target(doc-add-comments-uncrustify-${target} COMMAND ${UNCRUSTIFY_EXE}
${UNCRUSTIFY_OPTS}
--set cmt_insert_file_header=fileheader.txt --set cmt_insert_file_header=fileheader.txt
--set cmt_insert_file_footer=filefooter.txt --set cmt_insert_file_footer=filefooter.txt
--set cmt_insert_func_header=funcheader.txt --set cmt_insert_func_header=funcheader.txt
@ -25,6 +31,7 @@ function(add_format_sources target)
--set cmt_insert_before_ctor_dtor=true ${_sources}) --set cmt_insert_before_ctor_dtor=true ${_sources})
# cmake-format: on # cmake-format: on
add_dependencies(format-sources format-sources-uncrustify-${target}) add_dependencies(format-sources format-sources-uncrustify-${target})
add_dependencies(check-format-sources check-format-sources-uncrustify-${target})
add_dependencies(doc-add-comments doc-add-comments-uncrustify-${target}) add_dependencies(doc-add-comments doc-add-comments-uncrustify-${target})
else() else()
message(STATUS "CMLIB warning:") message(STATUS "CMLIB warning:")