2022-09-29 10:34:57 +00:00
|
|
|
|
include_guard(GLOBAL)
|
|
|
|
|
|
2022-09-29 14:20:02 +00:00
|
|
|
|
function(myx_qt5_target_setup NAME)
|
2022-09-29 10:34:57 +00:00
|
|
|
|
set(options)
|
|
|
|
|
set(oneValueArgs)
|
2022-10-02 13:22:43 +00:00
|
|
|
|
set(multiValueArgs COMPONENTS PRIVATE PUBLIC_MOC PRIVATE_MOC UI QRC LANGS)
|
2022-10-01 20:34:07 +00:00
|
|
|
|
|
2022-10-01 23:39:48 +00:00
|
|
|
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
2022-09-29 10:34:57 +00:00
|
|
|
|
|
2022-10-04 11:27:58 +00:00
|
|
|
|
get_target_property(target_type ${NAME} TYPE)
|
2022-10-01 20:34:07 +00:00
|
|
|
|
|
2022-10-04 03:08:31 +00:00
|
|
|
|
foreach(iter ${ARG_COMPONENTS})
|
2022-10-04 11:27:58 +00:00
|
|
|
|
if(target_type STREQUAL "INTERFACE_LIBRARY")
|
2022-10-04 05:08:30 +00:00
|
|
|
|
target_include_directories(${NAME} INTERFACE ${Qt5${iter}_INCLUDE_DIRS})
|
|
|
|
|
else()
|
|
|
|
|
target_include_directories(${NAME} PRIVATE ${Qt5${iter}_INCLUDE_DIRS})
|
|
|
|
|
endif()
|
2022-10-04 11:27:58 +00:00
|
|
|
|
if(target_type STREQUAL "EXECUTABLE" AND NOT iter STREQUAL "LinguistTools")
|
2022-10-04 03:08:31 +00:00
|
|
|
|
target_link_libraries(${NAME} PRIVATE "Qt5::${iter}")
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
2022-09-29 10:34:57 +00:00
|
|
|
|
|
2022-10-04 03:08:31 +00:00
|
|
|
|
foreach(iter ${ARG_PRIVATE})
|
2022-10-04 11:27:58 +00:00
|
|
|
|
if(target_type STREQUAL "INTERFACE_LIBRARY")
|
2022-10-04 05:08:30 +00:00
|
|
|
|
target_include_directories(${NAME} INTERFACE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS})
|
|
|
|
|
else()
|
|
|
|
|
target_include_directories(${NAME} PRIVATE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS})
|
|
|
|
|
endif()
|
2022-10-04 03:08:31 +00:00
|
|
|
|
endforeach()
|
2022-09-29 10:34:57 +00:00
|
|
|
|
|
2022-10-04 11:27:58 +00:00
|
|
|
|
if(target_type STREQUAL "EXECUTABLE")
|
2022-10-01 20:34:07 +00:00
|
|
|
|
target_compile_options(${NAME} PRIVATE ${Qt5Core_EXECUTABLE_COMPILE_FLAGS})
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-10-02 13:22:43 +00:00
|
|
|
|
if(ARG_PUBLIC_MOC)
|
|
|
|
|
set_property(TARGET ${NAME} APPEND PROPERTY PUBLIC_HEADER_FILES "${ARG_PUBLIC_MOC}")
|
2022-10-03 14:15:53 +00:00
|
|
|
|
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_PUBLIC_MOC})
|
2022-10-02 10:12:07 +00:00
|
|
|
|
endif()
|
|
|
|
|
|
2022-10-02 13:22:43 +00:00
|
|
|
|
if(ARG_PRIVATE_MOC)
|
2022-10-03 14:15:53 +00:00
|
|
|
|
set_property(TARGET ${NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PRIVATE_MOC}")
|
|
|
|
|
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_PRIVATE_MOC})
|
2022-10-02 10:12:07 +00:00
|
|
|
|
endif()
|
|
|
|
|
|
2022-10-02 13:22:43 +00:00
|
|
|
|
if(ARG_PUBLIC_MOC OR ARG_PRIVATE_MOC)
|
|
|
|
|
qt5_wrap_cpp(moc_cpp ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC})
|
2022-10-02 10:12:07 +00:00
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(ARG_QRC)
|
|
|
|
|
qt5_add_resources(qrc_cpp ${ARG_QRC})
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(ARG_UI AND "Widgets" IN_LIST ARG_COMPONENTS)
|
2022-10-01 20:34:07 +00:00
|
|
|
|
qt5_wrap_ui(ui_h ${ARG_UI})
|
2022-10-03 14:15:53 +00:00
|
|
|
|
set_property(TARGET ${NAME} APPEND PROPERTY TR_FILES ${ARG_UI})
|
|
|
|
|
# TODO
|
|
|
|
|
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_BINARY_DIR})
|
2022-10-01 20:34:07 +00:00
|
|
|
|
endif()
|
2022-09-29 10:34:57 +00:00
|
|
|
|
|
2022-10-04 09:58:19 +00:00
|
|
|
|
# Перечень файлов, подлежащих переводу
|
2022-10-08 14:23:13 +00:00
|
|
|
|
if(target_type STREQUAL "INTERFACE_LIBRARY")
|
|
|
|
|
get_target_property(tr ${NAME} INTERFACE_TR_FILES)
|
|
|
|
|
else()
|
|
|
|
|
get_target_property(tr ${NAME} TR_FILES)
|
|
|
|
|
endif()
|
2022-10-03 14:15:53 +00:00
|
|
|
|
# Формирование файла ресурсов с переводами
|
2022-10-04 09:58:19 +00:00
|
|
|
|
if("LinguistTools" IN_LIST ARG_COMPONENTS AND tr)
|
2022-10-03 14:15:53 +00:00
|
|
|
|
# Заглавие файла ресурсов
|
|
|
|
|
file(WRITE ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc "<RCC><qresource prefix=\"/qm\">\n")
|
|
|
|
|
# Для каждого языка, указанное в параметре LANGS
|
2022-10-01 20:34:07 +00:00
|
|
|
|
foreach(iter ${ARG_LANGS})
|
2022-10-03 14:15:53 +00:00
|
|
|
|
# Создание или обновление файла переводов в каталоге ${PROJECT_SOURCE_DIR}/l10n
|
|
|
|
|
# и его компиляция в каталог ${PROJECT_BINARY_DIR}
|
2022-10-08 14:23:13 +00:00
|
|
|
|
qt5_create_translation(qm ${tr}
|
2022-10-08 18:00:28 +00:00
|
|
|
|
"${PROJECT_SOURCE_DIR}/l10n/${NAME}_${iter}.ts"
|
2022-10-08 19:23:10 +00:00
|
|
|
|
OPTIONS -I ${PROJECT_SOURCE_DIR}/include -I ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME})
|
2022-10-03 14:15:53 +00:00
|
|
|
|
# Добавление записи для скомпилированного файла переводов в ресурсный файл
|
|
|
|
|
file(APPEND ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc
|
|
|
|
|
"<file alias=\"${NAME}_${iter}\">${NAME}_${iter}.qm</file>\n")
|
|
|
|
|
# Добавление скомпилированного файла переводов к списку зависимостей для цели
|
2022-10-01 23:39:48 +00:00
|
|
|
|
target_sources(${NAME} PRIVATE ${qm})
|
2022-09-29 10:34:57 +00:00
|
|
|
|
endforeach()
|
2022-10-03 14:15:53 +00:00
|
|
|
|
# Окончение файла ресурсов
|
|
|
|
|
file(APPEND ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc "</qresource></RCC>\n")
|
|
|
|
|
# Комплияция файла ресурсов с переводами
|
2022-10-04 03:08:31 +00:00
|
|
|
|
qt5_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${NAME}_l10n.qrc)
|
|
|
|
|
target_sources(${NAME} PRIVATE ${qrc_l10n})
|
2022-09-29 10:34:57 +00:00
|
|
|
|
endif()
|
2022-10-04 09:58:19 +00:00
|
|
|
|
unset(tr)
|
2022-10-04 03:08:31 +00:00
|
|
|
|
target_sources(${NAME} PRIVATE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
|
2022-10-01 20:34:07 +00:00
|
|
|
|
|
2022-10-02 13:22:43 +00:00
|
|
|
|
# Установка публичных заголовочных файлов
|
2022-10-02 13:33:14 +00:00
|
|
|
|
if(PROJECT_IS_TOP_LEVEL)
|
2022-10-08 22:01:31 +00:00
|
|
|
|
myx_install_relative(${PROJECT_SOURCE_DIR}
|
2022-10-02 13:33:14 +00:00
|
|
|
|
FILES ${ARG_PUBLIC_MOC}
|
|
|
|
|
DESTINATION ${CMAKE_INSTALL_PREFIX}
|
2022-10-09 01:23:55 +00:00
|
|
|
|
COMPONENT DEV
|
2022-10-02 13:33:14 +00:00
|
|
|
|
)
|
|
|
|
|
endif()
|
2022-09-29 10:34:57 +00:00
|
|
|
|
endfunction()
|