2021-12-24 11:44:34 +00:00
|
|
|
find_program(UNCRUSTIFY_EXE NAMES uncrustify)
|
|
|
|
|
|
|
|
if(UNCRUSTIFY_EXE)
|
|
|
|
if(NOT EXISTS ${CMAKE_BINARY_DIR}/uncrustify-classheader.txt)
|
|
|
|
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/uncrustify-classheader.txt CONTENT
|
|
|
|
"/**
|
|
|
|
* @class $(fclass)
|
|
|
|
* @brief TODO
|
|
|
|
* @details TODO
|
|
|
|
*/")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT EXISTS ${CMAKE_BINARY_DIR}/uncrustify-filefooter.txt)
|
|
|
|
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/uncrustify-filefooter.txt CONTENT
|
|
|
|
"// EOF $(filename)")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT EXISTS ${CMAKE_BINARY_DIR}/uncrustify-fileheader.txt)
|
|
|
|
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/uncrustify-fileheader.txt CONTENT
|
|
|
|
"/**
|
|
|
|
* @file $(filename)
|
|
|
|
* @brief TODO
|
|
|
|
* @details TODO
|
|
|
|
*/")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT EXISTS ${CMAKE_BINARY_DIR}/uncrustify-funcheader.txt)
|
|
|
|
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/uncrustify-funcheader.txt CONTENT
|
|
|
|
"/**
|
|
|
|
* @fn $(fclass)::$(function)
|
|
|
|
* $(javaparam)
|
|
|
|
* @details TODO
|
|
|
|
*/")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2021-12-08 11:32:04 +00:00
|
|
|
function(myx_cmake_format_sources target)
|
|
|
|
|
|
|
|
if(UNCRUSTIFY_EXE)
|
2021-12-12 16:44:29 +00:00
|
|
|
get_target_property(__sources ${target} SOURCES)
|
|
|
|
list(FILTER __sources EXCLUDE REGEX "qrc_.*\\.cpp$")
|
|
|
|
list(FILTER __sources EXCLUDE REGEX "moc_.*\\.cpp$")
|
|
|
|
list(FILTER __sources EXCLUDE REGEX "ui_.*\\.h$")
|
|
|
|
|
|
|
|
if(NOT TARGET myx-cmake-format-sources)
|
|
|
|
add_custom_target(myx-cmake-format-sources)
|
|
|
|
endif()
|
2021-12-24 04:18:29 +00:00
|
|
|
if(NOT TARGET myx-cmake-format-sources-check)
|
|
|
|
add_custom_target(myx-cmake-format-sources-check)
|
2021-12-12 16:44:29 +00:00
|
|
|
endif()
|
2021-12-24 04:18:29 +00:00
|
|
|
if(NOT TARGET myx-cmake-doc-doxygen-append-comments)
|
|
|
|
add_custom_target(myx-cmake-doc-doxygen-append-comments)
|
2021-12-12 16:44:29 +00:00
|
|
|
endif()
|
|
|
|
|
2021-12-10 13:18:27 +00:00
|
|
|
if(EXISTS ${CMAKE_SOURCE_DIR}/.uncrustify.cfg)
|
2021-12-22 07:33:24 +00:00
|
|
|
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/uncrustify.cfg
|
|
|
|
COMMAND ${UNCRUSTIFY_EXE} --update-config-with-doc
|
|
|
|
-c ${CMAKE_SOURCE_DIR}/.uncrustify.cfg
|
|
|
|
-o ${CMAKE_BINARY_DIR}/uncrustify.cfg)
|
2021-12-24 04:18:29 +00:00
|
|
|
list(APPEND UNCRUSTIFY_OPTS -c ${CMAKE_BINARY_DIR}/uncrustify.cfg)
|
2021-12-08 11:32:04 +00:00
|
|
|
endif()
|
|
|
|
# cmake-format: off
|
2021-12-24 04:18:29 +00:00
|
|
|
add_custom_target(${target}-format-sources-check-uncrustify
|
2021-12-22 07:33:24 +00:00
|
|
|
DEPENDS ${CMAKE_BINARY_DIR}/uncrustify.cfg
|
2021-12-08 11:32:04 +00:00
|
|
|
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --check ${__sources})
|
|
|
|
list(APPEND UNCRUSTIFY_OPTS --replace --no-backup)
|
|
|
|
add_custom_target(${target}-format-sources-uncrustify
|
2021-12-22 07:33:24 +00:00
|
|
|
DEPENDS ${CMAKE_BINARY_DIR}/uncrustify.cfg
|
2021-12-08 11:32:04 +00:00
|
|
|
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --mtime ${__sources})
|
2021-12-24 11:44:34 +00:00
|
|
|
|
2021-12-24 04:18:29 +00:00
|
|
|
add_custom_target(${target}-doc-doxygen-append-comments
|
2021-12-22 07:33:24 +00:00
|
|
|
DEPENDS ${CMAKE_BINARY_DIR}/uncrustify.cfg
|
2021-12-08 11:32:04 +00:00
|
|
|
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS}
|
2021-12-24 04:18:29 +00:00
|
|
|
--set cmt_insert_class_header=uncrustify-classheader.txt
|
|
|
|
--set cmt_insert_file_footer=uncrustify-filefooter.txt
|
|
|
|
--set cmt_insert_file_header=uncrustify-fileheader.txt
|
|
|
|
--set cmt_insert_func_header=uncrustify-funcheader.txt
|
2021-12-08 11:32:04 +00:00
|
|
|
--set cmt_insert_before_ctor_dtor=true ${__sources})
|
|
|
|
# cmake-format: on
|
|
|
|
add_dependencies(myx-cmake-format-sources ${target}-format-sources-uncrustify)
|
2021-12-24 04:18:29 +00:00
|
|
|
add_dependencies(myx-cmake-format-sources-check ${target}-format-sources-check-uncrustify)
|
|
|
|
add_dependencies(myx-cmake-doc-doxygen-append-comments ${target}-doc-doxygen-append-comments)
|
2021-12-08 11:32:04 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "MyxCMake: uncrustify executable is not found")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_program(DOS2UNIX_EXE NAMES dos2unix)
|
|
|
|
if(DOS2UNIX_EXE)
|
|
|
|
list(APPEND DOS2UNIX_OPTS -k -r)
|
|
|
|
add_custom_target(${target}-format-sources-dos2unix COMMAND ${DOS2UNIX_EXE} ${DOS2UNIX_OPTS} ${__sources})
|
|
|
|
add_dependencies(myx-cmake-format-sources ${target}-format-sources-dos2unix)
|
|
|
|
else()
|
|
|
|
message(STATUS "MyxCMake: dos2unix executable is not found")
|
|
|
|
endif()
|
2021-12-24 04:18:29 +00:00
|
|
|
|
|
|
|
if(UNIX)
|
|
|
|
add_custom_target(${target}-format-sources-unexec COMMAND chmod -x ${__sources})
|
|
|
|
add_dependencies(myx-cmake-format-sources ${target}-format-sources-unexec)
|
|
|
|
endif()
|
2021-12-08 11:32:04 +00:00
|
|
|
endfunction()
|