53 lines
2.2 KiB
CMake
53 lines
2.2 KiB
CMake
|
function(myx_cmake_format_sources target)
|
||
|
|
||
|
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()
|
||
|
if(NOT TARGET myx-cmake-check-format-sources)
|
||
|
add_custom_target(myx-cmake-check-format-sources)
|
||
|
endif()
|
||
|
if(NOT TARGET myx-cmake-add-doxygen-comments)
|
||
|
add_custom_target(myx-cmake-add-doxygen-comments)
|
||
|
endif()
|
||
|
|
||
|
find_program(UNCRUSTIFY_EXE NAMES uncrustify)
|
||
|
if(UNCRUSTIFY_EXE)
|
||
|
if(EXISTS ${CMAKE_SOURCE_DIR}/files/etc/uncrustify.cfg)
|
||
|
list(APPEND UNCRUSTIFY_OPTS -c ${CMAKE_SOURCE_DIR}/files/etc/uncrustify.cfg)
|
||
|
endif()
|
||
|
# cmake-format: off
|
||
|
add_custom_target(${target}-check-format-sources-uncrustify
|
||
|
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --check ${__sources})
|
||
|
list(APPEND UNCRUSTIFY_OPTS --replace --no-backup)
|
||
|
add_custom_target(${target}-format-sources-uncrustify
|
||
|
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --mtime ${__sources})
|
||
|
add_custom_target(${target}-add-doxygen-comments-uncrustify
|
||
|
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS}
|
||
|
--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
|
||
|
add_dependencies(myx-cmake-check-format-sources ${target}-check-format-sources-uncrustify)
|
||
|
add_dependencies(myx-cmake-format-sources ${target}-format-sources-uncrustify)
|
||
|
add_dependencies(myx-cmake-add-doxygen-comments ${target}-add-doxygen-comments-uncrustify)
|
||
|
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()
|
||
|
endfunction()
|