From 1f9124c976b6463e1814bdc094f6fbf194c84bd4 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Tue, 6 Oct 2020 16:37:47 +0300 Subject: [PATCH] CMake: update project templates to work with Android for Qt 6 Qt 6 introduces qt_add_executable() function, which for Android make sure to call few Android specific functions like: * qt_android_generate_deployment_settings() * qt_android_add_apk_target() * qt_android_apply_arch_suffix() Using add_library() only the user would otherwise need to reimplement what's already implemented in add_qt_gui_executable(). Task-number: QTCREATORBUG-24681 Change-Id: Iec3984139844fe1cbac2d9a583b3c40bdaa308a0 Reviewed-by: Alexandru Croitor Reviewed-by: Alessandro Portale --- .../qtquickapplication/CMakeLists.txt | 34 +++++++------ .../qtwidgetsapplication/CMakeLists.txt | 48 ++++++++++--------- 2 files changed, 45 insertions(+), 37 deletions(-) diff --git a/share/qtcreator/templates/wizards/projects/qtquickapplication/CMakeLists.txt b/share/qtcreator/templates/wizards/projects/qtquickapplication/CMakeLists.txt index 3b479a595c4..95426d9498c 100644 --- a/share/qtcreator/templates/wizards/projects/qtquickapplication/CMakeLists.txt +++ b/share/qtcreator/templates/wizards/projects/qtquickapplication/CMakeLists.txt @@ -34,22 +34,28 @@ find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick REQUIRED) @endif -if(ANDROID) - add_library(%{ProjectName} SHARED - %{MainCppFileName} - qml.qrc -@if %{HasTranslation} - ${TS_FILES} -@endif +set(PROJECT_SOURCES + %{MainCppFileName} + qml.qrc + @if %{HasTranslation} + ${TS_FILES} + @endif +) + +if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) + qt_add_executable(%{ProjectName} + ${PROJECT_SOURCES} ) else() - add_executable(%{ProjectName} - %{MainCppFileName} - qml.qrc -@if %{HasTranslation} - ${TS_FILES} -@endif - ) + if(ANDROID) + add_library(%{ProjectName} SHARED + ${PROJECT_SOURCES} + ) + else() + add_executable(%{ProjectName} + ${PROJECT_SOURCES} + ) + endif() endif() target_compile_definitions(%{ProjectName} diff --git a/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/CMakeLists.txt b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/CMakeLists.txt index 21fec5e47b8..391da140528 100644 --- a/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/CMakeLists.txt +++ b/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/CMakeLists.txt @@ -34,30 +34,32 @@ find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) @endif -if(ANDROID) - add_library(%{ProjectName} SHARED - %{MainFileName} - %{SrcFileName} - %{HdrFileName} - @if %{GenerateForm} - %{FormFileName} - @endif - @if %{HasTranslation} - ${TS_FILES} - @endif - ) +set(PROJECT_SOURCES + %{MainFileName} + %{SrcFileName} + %{HdrFileName} + @if %{GenerateForm} + %{FormFileName} + @endif + @if %{HasTranslation} + ${TS_FILES} + @endif +) + +if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) + qt_add_executable(%{ProjectName} + ${PROJECT_SOURCES} + ) else() - add_executable(%{ProjectName} - %{MainFileName} - %{SrcFileName} - %{HdrFileName} - @if %{GenerateForm} - %{FormFileName} - @endif - @if %{HasTranslation} - ${TS_FILES} - @endif - ) + if(ANDROID) + add_library(%{ProjectName} SHARED + ${PROJECT_SOURCES} + ) + else() + add_executable(%{ProjectName} + ${PROJECT_SOURCES} + ) + endif() endif() target_link_libraries(%{ProjectName} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)