myx update

This commit is contained in:
2022-10-20 12:53:06 +03:00
parent 56ca4c3a1c
commit 1f5536f696
21 changed files with 761 additions and 402 deletions

View File

@@ -1,16 +1,18 @@
include_guard(GLOBAL)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(MYX_CMAKE_LIB_UNCRUSTIFY_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
endif()
find_program(UNCRUSTIFY_EXE NAMES uncrustify)
function(myx_uncrustify target)
function(myx_uncrustify TARGET_NAME)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_UNCRUSTIFY_DIR_BACKPORT})
endif()
if(NOT ${PROJECT_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
return()
endif()
set(options)
set(oneValueArgs CONFIG)
set(multiValueArgs)
@@ -33,8 +35,6 @@ function(myx_uncrustify target)
return()
endif()
if(NOT TARGET myx-uncrustify)
add_custom_target(myx-uncrustify)
endif()
@@ -46,39 +46,53 @@ function(myx_uncrustify target)
endif()
# Динамически сгенерированные файлы исключаются
get_target_property(s ${target} SOURCES)
foreach(iter ${s})
get_target_property(__target_type ${TARGET_NAME} TYPE)
if(${__target_type} STREQUAL "INTERFACE_LIBRARY")
get_target_property(__s1 ${TARGET_NAME} INTERFACE_SOURCES)
if(__s1)
list(APPEND __all_sources ${__s1})
endif()
else()
get_target_property(__s2 ${TARGET_NAME} SOURCES)
if(__s2)
list(APPEND __all_sources ${__s2})
endif()
endif()
foreach(iter ${__all_sources})
string(FIND ${iter} ${CMAKE_BINARY_DIR} pos)
if(pos EQUAL -1)
list(APPEND src ${iter})
list(APPEND __sources ${iter})
endif()
endforeach()
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg
set(__fixed_config ${PROJECT_BINARY_DIR}/uncrustify-${TARGET_NAME}.cfg)
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/uncrustify-${TARGET_NAME}.cfg
COMMAND ${UNCRUSTIFY_EXE} --update-config-with-doc
-c ${ARG_CONFIG}
-o ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg)
list(APPEND UNCRUSTIFY_OPTS -c ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg)
-c ${ARG_CONFIG} -o ${__fixed_config})
list(APPEND __options -c ${__fixed_config})
# cmake-format: off
add_custom_target(${target}-uncrustify-check
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --check ${src})
add_custom_target(${TARGET_NAME}-uncrustify-check
DEPENDS ${__fixed_config}
COMMAND ${UNCRUSTIFY_EXE} ${__options} --check ${__sources})
list(APPEND UNCRUSTIFY_OPTS --replace --no-backup)
add_custom_target(${target}-uncrustify
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --mtime ${src})
list(APPEND __options --replace --no-backup)
add_custom_target(${TARGET_NAME}-uncrustify
DEPENDS ${__fixed_config}
COMMAND ${UNCRUSTIFY_EXE} ${__options} --mtime ${__sources})
add_custom_target(${target}-uncrustify-append-comments
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${target}.cfg
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS}
add_custom_target(${TARGET_NAME}-uncrustify-append-comments
DEPENDS ${__fixed_config}
COMMAND ${UNCRUSTIFY_EXE} ${__options}
--set cmt_insert_class_header=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/classheader.txt
--set cmt_insert_file_footer=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/filefooter.txt
--set cmt_insert_file_header=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/fileheader.txt
--set cmt_insert_func_header=${CMAKE_CURRENT_FUNCTION_LIST_DIR}/funcheader.txt
--set cmt_insert_before_ctor_dtor=true --mtime ${src})
--set cmt_insert_before_ctor_dtor=true --mtime ${__sources})
# cmake-format: on
add_dependencies(myx-uncrustify ${target}-uncrustify)
add_dependencies(myx-uncrustify-check ${target}-uncrustify-check)
add_dependencies(myx-uncrustify-append-comments ${target}-uncrustify-append-comments)
add_dependencies(myx-uncrustify ${TARGET_NAME}-uncrustify)
add_dependencies(myx-uncrustify-check ${TARGET_NAME}-uncrustify-check)
add_dependencies(myx-uncrustify-append-comments ${TARGET_NAME}-uncrustify-append-comments)
endfunction()