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 <alexandru.croitor@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Assam Boudjelthia
2020-10-06 16:37:47 +03:00
parent 15db0bb173
commit 1f9124c976
2 changed files with 45 additions and 37 deletions

View File

@@ -34,23 +34,29 @@ 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
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()
if(ANDROID)
add_library(%{ProjectName} SHARED
${PROJECT_SOURCES}
)
else()
add_executable(%{ProjectName}
%{MainCppFileName}
qml.qrc
@if %{HasTranslation}
${TS_FILES}
@endif
${PROJECT_SOURCES}
)
endif()
endif()
target_compile_definitions(%{ProjectName}
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)

View File

@@ -34,8 +34,7 @@ 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
set(PROJECT_SOURCES
%{MainFileName}
%{SrcFileName}
%{HdrFileName}
@@ -46,19 +45,22 @@ if(ANDROID)
${TS_FILES}
@endif
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(%{ProjectName}
${PROJECT_SOURCES}
)
else()
if(ANDROID)
add_library(%{ProjectName} SHARED
${PROJECT_SOURCES}
)
else()
add_executable(%{ProjectName}
%{MainFileName}
%{SrcFileName}
%{HdrFileName}
@if %{GenerateForm}
%{FormFileName}
@endif
@if %{HasTranslation}
${TS_FILES}
@endif
${PROJECT_SOURCES}
)
endif()
endif()
target_link_libraries(%{ProjectName} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
@if %{HasTranslation}