From fe65d429f160ef63d2464485589f9ddd4f3d9c3b Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Sun, 30 Jul 2023 13:32:04 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BE=D0=B1=D1=89=D1=91=D0=BD?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D0=B2=D0=B5=D1=80=D1=81?= =?UTF-8?q?=D0=B8=D0=B9=20Qt=205=20=D0=B8=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MyxCMake/MyxCMakeConfig.cmake | 2 +- ...5TargetSetup.cmake => QtTargetSetup.cmake} | 66 ++++++++++++++----- 2 files changed, 50 insertions(+), 18 deletions(-) rename MyxCMake/lib/{Qt5TargetSetup.cmake => QtTargetSetup.cmake} (62%) diff --git a/MyxCMake/MyxCMakeConfig.cmake b/MyxCMake/MyxCMakeConfig.cmake index 43c3934..4179772 100644 --- a/MyxCMake/MyxCMakeConfig.cmake +++ b/MyxCMake/MyxCMakeConfig.cmake @@ -61,7 +61,7 @@ include(${MYX_CMAKE_LIB_DIR}/AddExecutable.cmake) include(${MYX_CMAKE_LIB_DIR}/AddInterfaceLibrary.cmake) include(${MYX_CMAKE_LIB_DIR}/AddObjectLibrary.cmake) include(${MYX_CMAKE_LIB_DIR}/TargetSetup.cmake) -include(${MYX_CMAKE_LIB_DIR}/Qt5TargetSetup.cmake) +include(${MYX_CMAKE_LIB_DIR}/QtTargetSetup.cmake) include(${MYX_CMAKE_LIB_DIR}/uncrustify/Uncrustify.cmake) include(${MYX_CMAKE_LIB_DIR}/doc/Doxygen.cmake) diff --git a/MyxCMake/lib/Qt5TargetSetup.cmake b/MyxCMake/lib/QtTargetSetup.cmake similarity index 62% rename from MyxCMake/lib/Qt5TargetSetup.cmake rename to MyxCMake/lib/QtTargetSetup.cmake index 23d0197..140afdd 100644 --- a/MyxCMake/lib/Qt5TargetSetup.cmake +++ b/MyxCMake/lib/QtTargetSetup.cmake @@ -1,43 +1,53 @@ include_guard(GLOBAL) -function(myx_qt5_target_setup TARGET_NAME) +function(myx_qt_target_setup TARGET_NAME) set(options) - set(oneValueArgs) + set(oneValueArgs VERSION) set(multiValueArgs COMPONENTS PRIVATE PUBLIC_MOC PRIVATE_MOC UI QRC LANGS) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + if(NOT ARG_VERSION) + set(ARG_VERSION "5") + endif() + + if(NOT (ARG_VERSION STREQUAL "5" OR ARG_VERSION STREQUAL "6")) + myx_message_fatal_error("Supported Qt versions are 5 and 6") + endif() + get_target_property(__target_type ${TARGET_NAME} TYPE) foreach(iter ${ARG_COMPONENTS}) + find_package(Qt${ARG_VERSION} COMPONENTS ${iter} REQUIRED) if(__target_type STREQUAL "INTERFACE_LIBRARY") - target_include_directories(${TARGET_NAME} INTERFACE ${Qt5${iter}_INCLUDE_DIRS}) + target_include_directories(${TARGET_NAME} INTERFACE ${Qt${ARG_VERSION}${iter}_INCLUDE_DIRS}) else() - target_include_directories(${TARGET_NAME} PRIVATE ${Qt5${iter}_INCLUDE_DIRS}) + target_include_directories(${TARGET_NAME} PRIVATE ${Qt${ARG_VERSION}${iter}_INCLUDE_DIRS}) endif() if(NOT iter STREQUAL "LinguistTools") if(__target_type STREQUAL "EXECUTABLE") - target_link_libraries(${TARGET_NAME} PRIVATE "Qt5::${iter}") + target_link_libraries(${TARGET_NAME} PRIVATE "Qt${ARG_VERSION}::${iter}") endif() if(__target_type STREQUAL "SHARED_LIBRARY") - target_link_libraries(${TARGET_NAME} PUBLIC "Qt5::${iter}") + target_link_libraries(${TARGET_NAME} PUBLIC "Qt${ARG_VERSION}::${iter}") endif() if((${CMAKE_VERSION} VERSION_GREATER "3.8.0") AND (__target_type STREQUAL "OBJECT_LIBRARY")) - target_link_libraries(${TARGET_NAME} PUBLIC "Qt5::${iter}") + target_link_libraries(${TARGET_NAME} PUBLIC "Qt${ARG_VERSION}::${iter}") endif() endif() endforeach() foreach(iter ${ARG_PRIVATE}) + find_package("Qt${ARG_VERSION}${iter}" COMPONENTS Private REQUIRED) if(__target_type STREQUAL "INTERFACE_LIBRARY") - target_include_directories(${TARGET_NAME} INTERFACE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS}) + target_include_directories(${TARGET_NAME} INTERFACE ${Qt${ARG_VERSION}${iter}_PRIVATE_INCLUDE_DIRS}) else() - target_include_directories(${TARGET_NAME} PRIVATE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS}) + target_include_directories(${TARGET_NAME} PRIVATE ${Qt${ARG_VERSION}${iter}_PRIVATE_INCLUDE_DIRS}) endif() endforeach() if(__target_type STREQUAL "EXECUTABLE") - target_compile_options(${TARGET_NAME} PRIVATE ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}) + target_compile_options(${TARGET_NAME} PRIVATE ${Qt${ARG_VERSION}Core_EXECUTABLE_COMPILE_FLAGS}) endif() if(ARG_PUBLIC_MOC) @@ -51,15 +61,27 @@ function(myx_qt5_target_setup TARGET_NAME) endif() if(ARG_PUBLIC_MOC OR ARG_PRIVATE_MOC) - qt5_wrap_cpp(moc_cpp ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC}) + if(ARG_VERSION STREQUAL "5") + qt5_wrap_cpp(moc_cpp ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC}) + else() + qt6_wrap_cpp(moc_cpp ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC}) + endif() endif() if(ARG_QRC) - qt5_add_resources(qrc_cpp ${ARG_QRC}) + if(ARG_VERSION STREQUAL "5") + qt5_add_resources(qrc_cpp ${ARG_QRC}) + else() + qt6_add_resources(qrc_cpp ${ARG_QRC}) + endif() endif() if(ARG_UI AND "Widgets" IN_LIST ARG_COMPONENTS) - qt5_wrap_ui(ui_h ${ARG_UI}) + if(ARG_VERSION STREQUAL "5") + qt5_wrap_ui(ui_h ${ARG_UI}) + else() + qt6_wrap_ui(ui_h ${ARG_UI}) + endif() set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_UI}) # TODO target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_BINARY_DIR}) @@ -79,9 +101,15 @@ function(myx_qt5_target_setup TARGET_NAME) foreach(iter ${ARG_LANGS}) # Создание или обновление файла переводов в каталоге ${PROJECT_SOURCE_DIR}/l10n # и его компиляция в каталог ${PROJECT_BINARY_DIR} - qt5_create_translation(qm ${tr} - "${PROJECT_SOURCE_DIR}/l10n/${TARGET_NAME}_${iter}.ts" - OPTIONS -I ${PROJECT_SOURCE_DIR}/include -I ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}) + if(ARG_VERSION STREQUAL "5") + qt5_create_translation(qm ${tr} + "${PROJECT_SOURCE_DIR}/l10n/${TARGET_NAME}_${iter}.ts" + OPTIONS -I ${PROJECT_SOURCE_DIR}/include -I ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}) + else() + qt6_create_translation(qm ${tr} + "${PROJECT_SOURCE_DIR}/l10n/${TARGET_NAME}_${iter}.ts" + OPTIONS -I ${PROJECT_SOURCE_DIR}/include -I ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}) + endif() # Добавление записи для скомпилированного файла переводов в ресурсный файл file(APPEND ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc "${TARGET_NAME}_${iter}.qm\n") @@ -91,7 +119,11 @@ function(myx_qt5_target_setup TARGET_NAME) # Окончание файла ресурсов file(APPEND ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc "\n") # Компиляция файла ресурсов с переводами - qt5_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc) + if(ARG_VERSION STREQUAL "5") + qt5_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc) + else() + qt6_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc) + endif() target_sources(${TARGET_NAME} PRIVATE ${qrc_l10n}) endif() unset(tr)