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,22 +34,28 @@ find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick REQUIRED)
@endif @endif
if(ANDROID) set(PROJECT_SOURCES
add_library(%{ProjectName} SHARED %{MainCppFileName}
%{MainCppFileName} qml.qrc
qml.qrc @if %{HasTranslation}
@if %{HasTranslation} ${TS_FILES}
${TS_FILES} @endif
@endif )
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(%{ProjectName}
${PROJECT_SOURCES}
) )
else() else()
add_executable(%{ProjectName} if(ANDROID)
%{MainCppFileName} add_library(%{ProjectName} SHARED
qml.qrc ${PROJECT_SOURCES}
@if %{HasTranslation} )
${TS_FILES} else()
@endif add_executable(%{ProjectName}
) ${PROJECT_SOURCES}
)
endif()
endif() endif()
target_compile_definitions(%{ProjectName} target_compile_definitions(%{ProjectName}

View File

@@ -34,30 +34,32 @@ find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
@endif @endif
if(ANDROID) set(PROJECT_SOURCES
add_library(%{ProjectName} SHARED %{MainFileName}
%{MainFileName} %{SrcFileName}
%{SrcFileName} %{HdrFileName}
%{HdrFileName} @if %{GenerateForm}
@if %{GenerateForm} %{FormFileName}
%{FormFileName} @endif
@endif @if %{HasTranslation}
@if %{HasTranslation} ${TS_FILES}
${TS_FILES} @endif
@endif )
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(%{ProjectName}
${PROJECT_SOURCES}
)
else() else()
add_executable(%{ProjectName} if(ANDROID)
%{MainFileName} add_library(%{ProjectName} SHARED
%{SrcFileName} ${PROJECT_SOURCES}
%{HdrFileName} )
@if %{GenerateForm} else()
%{FormFileName} add_executable(%{ProjectName}
@endif ${PROJECT_SOURCES}
@if %{HasTranslation} )
${TS_FILES} endif()
@endif
)
endif() endif()
target_link_libraries(%{ProjectName} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) target_link_libraries(%{ProjectName} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)