Вызов dos2unix при форматировании исходников

This commit is contained in:
Andrei Astafev 2019-11-19 08:36:12 +03:00
parent 28e7c7ffa2
commit dbcf484006

View File

@ -1,24 +1,37 @@
function(add_uncrustify_format)
function(add_format_sources)
list(GET ARGN 0 _target)
set(_sources ${ARGN})
list(REMOVE_AT _sources 0)
if(NOT TARGET format-sources)
add_custom_target(format-sources)
endif()
find_program(UNCRUSTIFY_EXE NAMES uncrustify)
if(UNCRUSTIFY_EXE)
if(NOT TARGET uncrustify-format)
add_custom_target(uncrustify-format)
endif()
list(APPEND OPTS
list(APPEND UNCRUSTIFY_OPTS
-lCPP
--replace
--no-backup)
if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg)
list(APPEND OPTS -c ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg)
list(APPEND UNCRUSTIFY_OPTS -c ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg)
endif()
add_custom_target(uncrustify-format-${_target} COMMAND ${UNCRUSTIFY_EXE} ${OPTS} ${_sources})
add_dependencies(uncrustify-format uncrustify-format-${_target})
add_custom_target(format-sources-uncrustify-${_target} COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} ${_sources})
add_dependencies(format-sources format-sources-uncrustify-${_target})
else()
message(STATUS "CMLIB warning:")
message(STATUS " Uncrustify is not found")
message(STATUS " uncrustify executable is not found")
endif()
find_program(DOS2UNIX_EXE NAMES dos2unix)
if(DOS2UNIX_EXE)
list(APPEND DOS2UNIX_OPTS
-k
-r)
add_custom_target(format-sources-dos2unix-${_target} COMMAND ${DOS2UNIX_EXE} ${OPTS} ${_sources})
add_dependencies(format-sources format-sources-dos2unix-${_target})
else()
message(STATUS "CMLIB warning:")
message(STATUS " dos2unix executable is not found")
endif()
endfunction()