2020-04-13 16:44:42 +00:00
|
|
|
function(add_format_sources target)
|
2019-07-19 07:55:17 +00:00
|
|
|
set(_sources ${ARGN})
|
|
|
|
|
2019-11-19 05:36:12 +00:00
|
|
|
if(NOT TARGET format-sources)
|
|
|
|
add_custom_target(format-sources)
|
|
|
|
endif()
|
2021-02-19 08:04:50 +00:00
|
|
|
if(NOT TARGET check-format-sources)
|
|
|
|
add_custom_target(check-format-sources)
|
|
|
|
endif()
|
2020-04-22 10:12:33 +00:00
|
|
|
if(NOT TARGET doc-add-comments)
|
|
|
|
add_custom_target(doc-add-comments)
|
|
|
|
endif()
|
2019-11-19 05:36:12 +00:00
|
|
|
|
2019-07-19 07:55:17 +00:00
|
|
|
find_program(UNCRUSTIFY_EXE NAMES uncrustify)
|
|
|
|
if(UNCRUSTIFY_EXE)
|
2019-07-20 08:39:42 +00:00
|
|
|
if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg)
|
2020-04-22 10:12:33 +00:00
|
|
|
list(APPEND UNCRUSTIFY_OPTS -c ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg)
|
2019-07-20 08:39:42 +00:00
|
|
|
endif()
|
2020-04-22 10:12:33 +00:00
|
|
|
# cmake-format: off
|
2021-02-19 08:04:50 +00:00
|
|
|
add_custom_target(check-format-sources-uncrustify-${target} COMMAND ${UNCRUSTIFY_EXE}
|
|
|
|
${UNCRUSTIFY_OPTS} --check ${_sources})
|
|
|
|
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}
|
2020-04-22 10:12:33 +00:00
|
|
|
--set cmt_insert_file_header=fileheader.txt
|
|
|
|
--set cmt_insert_file_footer=filefooter.txt
|
|
|
|
--set cmt_insert_func_header=funcheader.txt
|
|
|
|
--set cmt_insert_class_header=classheader.txt
|
|
|
|
--set cmt_insert_before_ctor_dtor=true ${_sources})
|
|
|
|
# cmake-format: on
|
2020-04-13 16:44:42 +00:00
|
|
|
add_dependencies(format-sources format-sources-uncrustify-${target})
|
2021-02-19 08:04:50 +00:00
|
|
|
add_dependencies(check-format-sources check-format-sources-uncrustify-${target})
|
2020-04-22 10:12:33 +00:00
|
|
|
add_dependencies(doc-add-comments doc-add-comments-uncrustify-${target})
|
2019-11-19 05:36:12 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "CMLIB warning:")
|
|
|
|
message(STATUS " uncrustify executable is not found")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_program(DOS2UNIX_EXE NAMES dos2unix)
|
|
|
|
if(DOS2UNIX_EXE)
|
2019-12-03 16:23:14 +00:00
|
|
|
list(APPEND DOS2UNIX_OPTS -k -r)
|
2020-04-13 16:44:42 +00:00
|
|
|
add_custom_target(format-sources-dos2unix-${target} COMMAND ${DOS2UNIX_EXE} ${DOS2UNIX_OPTS} ${_sources})
|
|
|
|
add_dependencies(format-sources format-sources-dos2unix-${target})
|
2019-07-19 07:55:17 +00:00
|
|
|
else()
|
2019-08-10 07:30:01 +00:00
|
|
|
message(STATUS "CMLIB warning:")
|
2019-11-19 05:36:12 +00:00
|
|
|
message(STATUS " dos2unix executable is not found")
|
2019-07-19 07:55:17 +00:00
|
|
|
endif()
|
|
|
|
endfunction()
|