This commit is contained in:
Andrei Astafev 2022-10-15 10:14:08 +03:00
parent e87e190cd3
commit 8c4594fd71
13 changed files with 93 additions and 89 deletions

View File

@ -1,4 +1,4 @@
set(MYX_CMAKE_PACKAGE_VERSION "2.0.20")
set(MYX_CMAKE_PACKAGE_VERSION "2.0.21")
if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()

View File

@ -12,8 +12,8 @@ function(myx_create_packages TARGET_NAME)
# Общие настройки для пакета: организация, автор, версия
if(NOT ${PROJECT_NAME}_CONTACT)
if(${PROJECT_NAME}_AUTHOR AND ${PROJECT_NAME}_EMAIL)
set(CPACK_PACKAGE_CONTACT "${${PROJECT_NAME}_AUTHOR} <${${PROJECT_NAME}_EMAIL}>")
if(${PROJECT_NAME}_AUTHOR_NAME AND ${PROJECT_NAME}_AUTHOR_EMAIL)
set(CPACK_PACKAGE_CONTACT "${${PROJECT_NAME}_AUTHOR_NAME} <${${PROJECT_NAME}_AUTHOR_EMAIL}>")
else()
set(CPACK_PACKAGE_CONTACT "unknown maintainer <nonexistent@mailbox>")
myx_message_warning("\${PROJECT_NAME}_CONTACT variable is required for packaging but unset")
@ -23,8 +23,8 @@ function(myx_create_packages TARGET_NAME)
endif()
if(NOT ${PROJECT_NAME}_VENDOR)
if(${PROJECT_NAME}_AUTHOR)
set(CPACK_PACKAGE_VENDOR "${${PROJECT_NAME}_AUTHOR}")
if(${PROJECT_NAME}_AUTHOR_NAME)
set(CPACK_PACKAGE_VENDOR "${${PROJECT_NAME}_AUTHOR_NAME}")
else()
set(CPACK_PACKAGE_VENDOR "unknown vendor")
myx_message_warning("\${PROJECT_NAME}_VENDOR variable is required for packaging but unset")
@ -187,4 +187,4 @@ function(myx_create_packages TARGET_NAME)
# Подключение модуля, выполняющего сборку архивов и пакетов
include(CPack)
endfunction(myx_create_packages NAME)
endfunction(myx_create_packages TARGET_NAME)

View File

@ -24,7 +24,7 @@ include_guard(GLOBAL)
# Обязательно в глобальной области
find_package(Git)
function(FetchContent_Add NAME)
function(FetchContent_Add TARGET_NAME)
set(options "")
set(oneValueArgs GIT_REPOSITORY GIT_REMOTE GIT_PATH)
set(multiValueArgs "")
@ -45,12 +45,12 @@ function(FetchContent_Add NAME)
endif()
FetchContent_Declare(
${NAME}
${TARGET_NAME}
${ARG_UNPARSED_ARGUMENTS}
GIT_REPOSITORY ${ARG_GIT_REPOSITORY}
GIT_SHALLOW 1
)
set(FETCHCONTENT_QUIET off)
FetchContent_MakeAvailable(${NAME})
FetchContent_MakeAvailable(${TARGET_NAME})
endfunction()

View File

@ -1,45 +1,45 @@
include_guard(GLOBAL)
function(myx_qt5_target_setup NAME)
function(myx_qt5_target_setup TARGET_NAME)
set(options)
set(oneValueArgs)
set(multiValueArgs COMPONENTS PRIVATE PUBLIC_MOC PRIVATE_MOC UI QRC LANGS)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
get_target_property(target_type ${NAME} TYPE)
get_target_property(target_type ${TARGET_NAME} TYPE)
foreach(iter ${ARG_COMPONENTS})
if(target_type STREQUAL "INTERFACE_LIBRARY")
target_include_directories(${NAME} INTERFACE ${Qt5${iter}_INCLUDE_DIRS})
target_include_directories(${TARGET_NAME} INTERFACE ${Qt5${iter}_INCLUDE_DIRS})
else()
target_include_directories(${NAME} PRIVATE ${Qt5${iter}_INCLUDE_DIRS})
target_include_directories(${TARGET_NAME} PRIVATE ${Qt5${iter}_INCLUDE_DIRS})
endif()
if(target_type STREQUAL "EXECUTABLE" AND NOT iter STREQUAL "LinguistTools")
target_link_libraries(${NAME} PRIVATE "Qt5::${iter}")
target_link_libraries(${TARGET_NAME} PRIVATE "Qt5::${iter}")
endif()
endforeach()
foreach(iter ${ARG_PRIVATE})
if(target_type STREQUAL "INTERFACE_LIBRARY")
target_include_directories(${NAME} INTERFACE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS})
target_include_directories(${TARGET_NAME} INTERFACE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS})
else()
target_include_directories(${NAME} PRIVATE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS})
target_include_directories(${TARGET_NAME} PRIVATE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS})
endif()
endforeach()
if(target_type STREQUAL "EXECUTABLE")
target_compile_options(${NAME} PRIVATE ${Qt5Core_EXECUTABLE_COMPILE_FLAGS})
target_compile_options(${TARGET_NAME} PRIVATE ${Qt5Core_EXECUTABLE_COMPILE_FLAGS})
endif()
if(ARG_PUBLIC_MOC)
set_property(TARGET ${NAME} APPEND PROPERTY PUBLIC_HEADER_FILES "${ARG_PUBLIC_MOC}")
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_PUBLIC_MOC})
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PUBLIC_HEADER_FILES "${ARG_PUBLIC_MOC}")
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_PUBLIC_MOC})
endif()
if(ARG_PRIVATE_MOC)
set_property(TARGET ${NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PRIVATE_MOC}")
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_PRIVATE_MOC})
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PRIVATE_MOC}")
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_PRIVATE_MOC})
endif()
if(ARG_PUBLIC_MOC OR ARG_PRIVATE_MOC)
@ -52,42 +52,42 @@ function(myx_qt5_target_setup NAME)
if(ARG_UI AND "Widgets" IN_LIST ARG_COMPONENTS)
qt5_wrap_ui(ui_h ${ARG_UI})
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_UI})
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_UI})
# TODO
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_BINARY_DIR})
endif()
# Перечень файлов, подлежащих переводу
if(target_type STREQUAL "INTERFACE_LIBRARY")
get_target_property(tr ${NAME} INTERFACE_TR_FILES)
get_target_property(tr ${TARGET_NAME} INTERFACE_TR_FILES)
else()
get_target_property(tr ${NAME} TR_FILES)
get_target_property(tr ${TARGET_NAME} TR_FILES)
endif()
# Формирование файла ресурсов с переводами
if("LinguistTools" IN_LIST ARG_COMPONENTS AND tr)
# Заглавие файла ресурсов
file(WRITE ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc "<RCC><qresource prefix=\"/qm\">\n")
file(WRITE ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc "<RCC><qresource prefix=\"/qm\">\n")
# Для каждого языка, указанное в параметре LANGS
foreach(iter ${ARG_LANGS})
# Создание или обновление файла переводов в каталоге ${PROJECT_SOURCE_DIR}/l10n
# и его компиляция в каталог ${PROJECT_BINARY_DIR}
qt5_create_translation(qm ${tr}
"${PROJECT_SOURCE_DIR}/l10n/${NAME}_${iter}.ts"
"${PROJECT_SOURCE_DIR}/l10n/${TARGET_NAME}_${iter}.ts"
OPTIONS -I ${PROJECT_SOURCE_DIR}/include -I ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME})
# Добавление записи для скомпилированного файла переводов в ресурсный файл
file(APPEND ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc
"<file alias=\"${NAME}_${iter}\">${NAME}_${iter}.qm</file>\n")
file(APPEND ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc
"<file alias=\"${TARGET_NAME}_${iter}\">${TARGET_NAME}_${iter}.qm</file>\n")
# Добавление скомпилированного файла переводов к списку зависимостей для цели
target_sources(${NAME} PRIVATE ${qm})
target_sources(${TARGET_NAME} PRIVATE ${qm})
endforeach()
# Окончение файла ресурсов
file(APPEND ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc "</qresource></RCC>\n")
file(APPEND ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc "</qresource></RCC>\n")
# Комплияция файла ресурсов с переводами
qt5_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc)
target_sources(${NAME} PRIVATE ${qrc_l10n})
qt5_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc)
target_sources(${TARGET_NAME} PRIVATE ${qrc_l10n})
endif()
unset(tr)
target_sources(${NAME} PRIVATE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
target_sources(${TARGET_NAME} PRIVATE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
# Установка публичных заголовочных файлов
if(PROJECT_IS_TOP_LEVEL)

View File

@ -4,7 +4,7 @@ if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(MYX_CMAKE_LIB_DOC_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
endif()
function(myx_doc_doxygen NAME)
function(myx_doc_doxygen TARGET_NAME)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_DOC_DIR_BACKPORT})
endif()
@ -17,14 +17,14 @@ function(myx_doc_doxygen NAME)
set(DOXYGEN_FOUND OFF CACHE STRING "Doxygen documentation generator disabled" FORCE)
endif()
set(target "myx-doc-doxygen-${NAME}")
if(NOT DOXYGEN_FOUND)
add_custom_target(${target} VERBATIM COMMENT "Doxygen is not found. Skipping target ${target} build")
set(target myx-doc-doxygen-${TARGET_NAME})
if(TARGET ${target})
myx_message_warning("Target ${target} already defined")
return()
endif()
if(TARGET ${target})
myx_message_warning("Target ${target} already defined")
if(NOT DOXYGEN_FOUND)
add_custom_target(${target} VERBATIM COMMENT "Doxygen is not found. Skipping target ${target} build")
return()
endif()

View File

@ -5,12 +5,13 @@ myx_generate_git_info_header
Вспомогательная функция для автоматической генерации заголовочного
файла, содержащего информацию о текущем состоянии репозитория git::
myx_generate_git_info_header(TARGET BASE_FILENAME
myx_generate_git_info_header(TARGET_NAME BASE_FILENAME
[ PREFIX prefix ] )
Обязательные параметры: `TARGET` - имя цели, с которой связан заголовочный файл,
и `BASE_FILENAME` - имя генерируемого заголовочного файла. Дополнительный аргумент
`PREFIX` добавляет префикс к генерируемым именам переменных.
Обязательные параметры: `TARGET_NAME` - имя цели, с которой связан
заголовочный файл, и `BASE_FILENAME` - имя генерируемого заголовочного
файла. Дополнительный аргумент `PREFIX` добавляет префикс к генерируемым
именам переменных.
#]=======================================================================]
@ -20,7 +21,7 @@ if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
endif()
function(myx_generate_git_info_header target base_filename)
function(myx_generate_git_info_header TARGET_NAME BASE_FILENAME)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT})
endif()
@ -30,24 +31,25 @@ function(myx_generate_git_info_header target base_filename)
set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(filename "${PROJECT_BINARY_DIR}/include/${base_filename}")
set(__filename "${PROJECT_BINARY_DIR}/include/${BASE_FILENAME}")
write(APPEND ${__filename} "")
set(PREFIX "")
set(__prefix "")
if(ARG_PREFIX)
string(APPEND ARG_PREFIX "_")
string(REPLACE "-" "_" PREFIX ${ARG_PREFIX})
string(REPLACE "-" "_" __prefix ${ARG_PREFIX})
endif()
# cmake-format: off
if(NOT TARGET ${target}-git-info-header)
add_custom_target(${target}-git-info-header ALL
${CMAKE_COMMAND} -DGIT_INFO_FILE=${filename} -DPREFIX=${PREFIX}
if(NOT TARGET ${TARGET_NAME}-git-info-header)
add_custom_target(${TARGET_NAME}-git-info-header ALL
${CMAKE_COMMAND} -DGIT_INFO_FILE=${__filename} -DPREFIX=${__prefix}
-P ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/GitInfo.cmake
BYPRODUCTS ${filename}
BYPRODUCTS ${__filename}
WORKING_DIRECTORY ${CMAKE_CURRENT_FUNCTION_LIST_DIR})
endif()
# cmake-format: on
set_property(TARGET ${target} APPEND PROPERTY PRIVATE_HEADER_FILES ${filename})
target_sources(${target} PRIVATE ${filename})
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES ${__filename})
target_sources(${TARGET_NAME} PRIVATE ${__filename})
endfunction()

View File

@ -5,10 +5,10 @@ myx_generate_private_config_header
Вспомогательная функция для автоматической генерации заголовочного
файла, содержащего информацию о проекте::
myx_generate_private_config_header(TARGET BASE_FILENAME)
myx_generate_private_config_header(TARGET_NAME BASE_FILENAME)
Обязательные параметры: `TARGET` - имя цели, с которой связан заголовочный файл,
и `BASE_FILENAME` - имя генерируемого заголовочного файла.
Обязательные параметры: `TARGET_NAME` - имя цели, с которой связан
заголовочный файл, и `BASE_FILENAME` - имя генерируемого заголовочного файла.
#]=======================================================================]
@ -18,7 +18,7 @@ if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
endif()
function(myx_generate_private_config_header target base_filename)
function(myx_generate_private_config_header TARGET_NAME BASE_FILENAME)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT})
endif()
@ -27,9 +27,9 @@ function(myx_generate_private_config_header target base_filename)
myx_project_version_int()
get_property(PROJECT_VERSION_INT GLOBAL PROPERTY PROJECT_VERSION_INT)
set(filename "${PROJECT_BINARY_DIR}/include/${base_filename}")
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PrivateConfig.hpp.in" ${filename})
set(__filename "${PROJECT_BINARY_DIR}/include/${BASE_FILENAME}")
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PrivateConfig.hpp.in" ${__filename})
set_property(TARGET ${target} APPEND PROPERTY PRIVATE_HEADER_FILES ${filename})
target_sources(${target} PRIVATE ${filename})
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES ${__filename})
target_sources(${TARGET_NAME} PRIVATE ${__filename})
endfunction()

View File

@ -6,12 +6,12 @@ endif()
find_program(UNCRUSTIFY_EXE NAMES uncrustify)
function(myx_uncrustify NAME)
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()
myx_skip_external_target(${NAME})
myx_skip_external_target(${TARGET_NAME})
set(options)
set(oneValueArgs CONFIG)
@ -46,11 +46,11 @@ function(myx_uncrustify NAME)
endif()
# Динамически сгенерированные файлы исключаются
get_target_property(target_type ${NAME} TYPE)
get_target_property(target_type ${TARGET_NAME} TYPE)
if(${target_type} STREQUAL "INTERFACE_LIBRARY")
get_target_property(s ${NAME} INTERFACE_SOURCES)
get_target_property(s ${TARGET_NAME} INTERFACE_SOURCES)
else()
get_target_property(s ${NAME} SOURCES)
get_target_property(s ${TARGET_NAME} SOURCES)
endif()
foreach(iter ${s})
string(FIND ${iter} ${CMAKE_BINARY_DIR} pos)
@ -58,24 +58,26 @@ function(myx_uncrustify NAME)
list(APPEND src ${iter})
endif()
endforeach()
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.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-${NAME}.cfg)
list(APPEND UNCRUSTIFY_OPTS -c ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.cfg)
-c ${ARG_CONFIG} -o ${__fixed_config})
list(APPEND __options -c ${__fixed_config})
# cmake-format: off
add_custom_target(${NAME}-uncrustify-check
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.cfg
COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} --check ${src})
add_custom_target(${TARGET_NAME}-uncrustify-check
DEPENDS ${__fixed_config}
COMMAND ${UNCRUSTIFY_EXE} ${__options} --check ${src})
list(APPEND UNCRUSTIFY_OPTS --replace --no-backup)
add_custom_target(${NAME}-uncrustify
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.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 ${src})
add_custom_target(${NAME}-uncrustify-append-comments
DEPENDS ${PROJECT_BINARY_DIR}/uncrustify-${NAME}.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
@ -83,7 +85,7 @@ function(myx_uncrustify NAME)
--set cmt_insert_before_ctor_dtor=true --mtime ${src})
# cmake-format: on
add_dependencies(myx-uncrustify ${NAME}-uncrustify)
add_dependencies(myx-uncrustify-check ${NAME}-uncrustify-check)
add_dependencies(myx-uncrustify-append-comments ${NAME}-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()

View File

@ -3,7 +3,7 @@
## Установка
В корневом каталоге проекта создать каталог `cmake` и распаковать в него
[архив](../../../releases/download/2.0.20/myx-cmake-local-2.0.20.tar.xz ).
[архив](../../../releases/download/2.0.21/myx-cmake-local-2.0.21.tar.xz ).
## Использование

View File

@ -1 +1 @@
2.0.20
2.0.21

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
project(myx-cmake VERSION 2.0.20 LANGUAGES)
project(myx-cmake VERSION 2.0.21 LANGUAGES)
include(GNUInstallDirs)
file(WRITE ${CMAKE_SOURCE_DIR}/MyxCMake/MyxCMakeConfigVersion.cmake

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
myx-cmake (2.0.20) unstable; urgency=medium
myx-cmake (2.0.21) unstable; urgency=medium
* New version.

View File

@ -20,11 +20,11 @@ if(ENV{MYX_CMAKE_DIR})
set(MYX_CMAKE_DIR $ENV{MYX_CMAKE_DIR})
endif()
if(MYX_CMAKE_DIR)
find_package(MyxCMake 2.0.20 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH)
find_package(MyxCMake 2.0.21 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH)
myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===")
else()
if(MYX_CMAKE_USE_SYSTEM)
find_package(MyxCMake 2.0.20 REQUIRED)
find_package(MyxCMake 2.0.21 REQUIRED)
myx_message_notice("=== MyxCMake directory: ${MyxCMake_CONFIG} ===")
else()
include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)