function(add_format_sources target) set(_sources ${ARGN}) if(NOT TARGET format-sources) add_custom_target(format-sources) endif() find_program(UNCRUSTIFY_EXE NAMES uncrustify) if(UNCRUSTIFY_EXE) list( APPEND UNCRUSTIFY_OPTS -lCPP --replace --no-backup) if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/comments.cfg) if(NOT TARGET doc-add-comments) add_custom_target(doc-add-comments) endif() set(COMMENTS_OPTS ${UNCRUSTIFY_OPTS} -c ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/comments.cfg) add_custom_target(doc-add-comments-uncrustify-${target} COMMAND ${UNCRUSTIFY_EXE} ${COMMENTS_OPTS} ${_sources}) add_dependencies(doc-add-comments doc-add-comments-uncrustify-${target}) endif() if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg) list(APPEND UNCRUSTIFY_OPTS --mtime -c ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg) endif() 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 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} ${DOS2UNIX_OPTS} ${_sources}) add_dependencies(format-sources format-sources-dos2unix-${target}) else() message(STATUS "CMLIB warning:") message(STATUS " dos2unix executable is not found") endif() endfunction()