forked from qt-creator/qt-creator
CMake: Add Android Multi ABI support
Change-Id: Ia5b3fcda29705fefca85833ebc28b4154defba5f Reviewed-by: Cristian Adam <cristian.adam@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
committed by
BogDan Vatra
parent
afd22a75c1
commit
e3904f3b13
@@ -11,6 +11,19 @@ set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
|
||||
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
|
||||
# They need to be set before the find_package(Qt5 ...) call.
|
||||
|
||||
#if(ANDROID)
|
||||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
|
||||
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
|
||||
# set(ANDROID_EXTRA_LIBS
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
|
||||
# endif()
|
||||
#endif()
|
||||
|
||||
@if %{HasTranslation}
|
||||
find_package(Qt5 COMPONENTS Core Quick LinguistTools REQUIRED)
|
||||
|
||||
@@ -20,8 +33,7 @@ find_package(Qt5 COMPONENTS Core Quick REQUIRED)
|
||||
@endif
|
||||
|
||||
if(ANDROID)
|
||||
set(TARGET %{ProjectName}_${ANDROID_ABI})
|
||||
add_library(${TARGET} SHARED
|
||||
add_library(%{ProjectName} SHARED
|
||||
%{MainCppFileName}
|
||||
qml.qrc
|
||||
@if %{HasTranslation}
|
||||
@@ -29,8 +41,7 @@ if(ANDROID)
|
||||
@endif
|
||||
)
|
||||
else()
|
||||
set(TARGET %{ProjectName})
|
||||
add_executable(${TARGET}
|
||||
add_executable(%{ProjectName}
|
||||
%{MainCppFileName}
|
||||
qml.qrc
|
||||
@if %{HasTranslation}
|
||||
@@ -39,22 +50,11 @@ else()
|
||||
)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(${TARGET}
|
||||
target_compile_definitions(%{ProjectName}
|
||||
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
|
||||
target_link_libraries(${TARGET}
|
||||
target_link_libraries(%{ProjectName}
|
||||
PRIVATE Qt5::Core Qt5::Quick)
|
||||
@if %{HasTranslation}
|
||||
|
||||
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
|
||||
@endif
|
||||
|
||||
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
|
||||
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
|
||||
# These variables must use CACHE, otherwise QtCreator won't see them.
|
||||
|
||||
#if(ANDROID)
|
||||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android" CACHE INTERNAL "")
|
||||
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
|
||||
# set(ANDROID_EXTRA_LIBS ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so CACHE INTERNAL "")
|
||||
# endif()
|
||||
#endif()
|
||||
|
@@ -11,6 +11,19 @@ set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
|
||||
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
|
||||
# They need to be set before the find_package(Qt5 ...) call.
|
||||
|
||||
#if(ANDROID)
|
||||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
|
||||
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
|
||||
# set(ANDROID_EXTRA_LIBS
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
|
||||
# endif()
|
||||
#endif()
|
||||
|
||||
@if %{HasTranslation}
|
||||
find_package(Qt5 COMPONENTS Widgets LinguistTools REQUIRED)
|
||||
|
||||
@@ -19,17 +32,31 @@ set(TS_FILES %{TsFileName})
|
||||
find_package(Qt5 COMPONENTS Widgets REQUIRED)
|
||||
@endif
|
||||
|
||||
add_executable(%{ProjectName}
|
||||
%{MainFileName}
|
||||
%{SrcFileName}
|
||||
%{HdrFileName}
|
||||
@if %{GenerateForm}
|
||||
%{FormFileName}
|
||||
@endif
|
||||
@if %{HasTranslation}
|
||||
${TS_FILES}
|
||||
@endif
|
||||
)
|
||||
if(ANDROID)
|
||||
add_library(%{ProjectName} SHARED
|
||||
%{MainFileName}
|
||||
%{SrcFileName}
|
||||
%{HdrFileName}
|
||||
@if %{GenerateForm}
|
||||
%{FormFileName}
|
||||
@endif
|
||||
@if %{HasTranslation}
|
||||
${TS_FILES}
|
||||
@endif
|
||||
)
|
||||
else()
|
||||
add_executable(%{ProjectName}
|
||||
%{MainFileName}
|
||||
%{SrcFileName}
|
||||
%{HdrFileName}
|
||||
@if %{GenerateForm}
|
||||
%{FormFileName}
|
||||
@endif
|
||||
@if %{HasTranslation}
|
||||
${TS_FILES}
|
||||
@endif
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(%{ProjectName} PRIVATE Qt5::Widgets)
|
||||
@if %{HasTranslation}
|
||||
|
@@ -393,6 +393,10 @@ void AndroidBuildApkStep::doRun()
|
||||
if (!node)
|
||||
return false;
|
||||
|
||||
FilePath deploymentSettingsFile = FilePath::fromString(node->data(Android::Constants::AndroidDeploySettingsFile).toString());
|
||||
if (deploymentSettingsFile.exists())
|
||||
return true; // cmake creates this file for us
|
||||
|
||||
auto targets = node->data(Android::Constants::AndroidTargets).toStringList();
|
||||
if (targets.isEmpty())
|
||||
return true; // qmake does this job for us
|
||||
@@ -449,7 +453,7 @@ void AndroidBuildApkStep::doRun()
|
||||
qmlRootPath = target()->project()->rootProjectDirectory().toString();
|
||||
deploySettings["qml-root-path"] = qmlRootPath;
|
||||
|
||||
QFile f{bc->buildDirectory().pathAppended("android_deployment_settings.json").toString()};
|
||||
QFile f{deploymentSettingsFile.toString()};
|
||||
if (!f.open(QIODevice::WriteOnly))
|
||||
return false;
|
||||
f.write(QJsonDocument{deploySettings}.toJson());
|
||||
@@ -518,6 +522,8 @@ QVariant AndroidBuildApkStep::data(Core::Id id) const
|
||||
return AndroidConfigurations::currentConfig().bestNdkPlatformMatch(AndroidManager::minimumSDK(target())).mid(8);
|
||||
if (id == Constants::NdkLocation)
|
||||
return QVariant::fromValue(AndroidConfigurations::currentConfig().ndkLocation());
|
||||
if (id == Constants::SdkLocation)
|
||||
return QVariant::fromValue(AndroidConfigurations::currentConfig().sdkLocation());
|
||||
if (id == Constants::AndroidABIs)
|
||||
return AndroidManager::applicationAbis(target());
|
||||
|
||||
|
@@ -82,6 +82,7 @@ const char AndroidManifest[] = "Android.Manifest"; // QStringList
|
||||
|
||||
const char AndroidNdkPlatform[] = "AndroidNdkPlatform"; //QString
|
||||
const char NdkLocation[] = "NdkLocation"; // FileName
|
||||
const char SdkLocation[] = "SdkLocation"; // FileName
|
||||
const char AndroidABIs[] = "AndroidABIs"; // QString
|
||||
|
||||
} // namespace Constants;
|
||||
|
@@ -48,6 +48,7 @@
|
||||
#include <projectexplorer/projectmacroexpander.h>
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
#include <qtsupport/baseqtversion.h>
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
@@ -199,11 +200,13 @@ void CMakeBuildConfiguration::initialize()
|
||||
m_initialConfiguration.prepend(CMakeProjectManager::CMakeConfigItem{"ANDROID_NDK",
|
||||
CMakeProjectManager::CMakeConfigItem::Type::PATH,
|
||||
"Android NDK PATH",
|
||||
ndkLocation.toUserOutput().toUtf8()});
|
||||
ndkLocation.toString().toUtf8()});
|
||||
|
||||
m_initialConfiguration.prepend(CMakeProjectManager::CMakeConfigItem{"CMAKE_TOOLCHAIN_FILE",
|
||||
CMakeProjectManager::CMakeConfigItem::Type::PATH,
|
||||
"Android CMake toolchain file",
|
||||
ndkLocation.pathAppended("build/cmake/android.toolchain.cmake").toUserOutput().toUtf8()});
|
||||
ndkLocation.pathAppended("build/cmake/android.toolchain.cmake").toString().toUtf8()});
|
||||
|
||||
auto androidAbis = bs->data(Android::Constants::AndroidABIs).toStringList();
|
||||
QString preferredAbi;
|
||||
if (androidAbis.contains("arm64-v8a")) {
|
||||
@@ -219,14 +222,23 @@ void CMakeBuildConfiguration::initialize()
|
||||
"Android ABI",
|
||||
preferredAbi.toLatin1(),
|
||||
androidAbis});
|
||||
|
||||
QtSupport::BaseQtVersion *qt = QtSupport::QtKitAspect::qtVersion(target()->kit());
|
||||
if (qt->qtVersion() >= QtSupport::QtVersionNumber{5, 14, 0}) {
|
||||
auto sdkLocation = bs->data(Android::Constants::SdkLocation).value<FilePath>();
|
||||
m_initialConfiguration.prepend(CMakeProjectManager::CMakeConfigItem{"ANDROID_SDK",
|
||||
CMakeProjectManager::CMakeConfigItem::Type::PATH,
|
||||
"Android SDK PATH",
|
||||
sdkLocation.toString().toUtf8()});
|
||||
|
||||
}
|
||||
|
||||
m_initialConfiguration.prepend(CMakeProjectManager::CMakeConfigItem{"ANDROID_STL",
|
||||
CMakeProjectManager::CMakeConfigItem::Type::STRING,
|
||||
"Android STL",
|
||||
"c++_shared"});
|
||||
m_initialConfiguration.prepend(CMakeProjectManager::CMakeConfigItem{"CMAKE_FIND_ROOT_PATH_MODE_PROGRAM", "BOTH"});
|
||||
m_initialConfiguration.prepend(CMakeProjectManager::CMakeConfigItem{"CMAKE_FIND_ROOT_PATH_MODE_LIBRARY", "BOTH"});
|
||||
m_initialConfiguration.prepend(CMakeProjectManager::CMakeConfigItem{"CMAKE_FIND_ROOT_PATH_MODE_INCLUDE", "BOTH"});
|
||||
m_initialConfiguration.prepend(CMakeProjectManager::CMakeConfigItem{"CMAKE_FIND_ROOT_PATH_MODE_PACKAGE", "BOTH"});
|
||||
|
||||
m_initialConfiguration.prepend(CMakeProjectManager::CMakeConfigItem{"CMAKE_FIND_ROOT_PATH", "%{Qt:QT_INSTALL_PREFIX}"});
|
||||
}
|
||||
|
||||
BuildStepList *cleanSteps = stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
|
||||
@@ -434,6 +446,16 @@ void CMakeBuildConfiguration::setConfigurationForCMake(const QList<ConfigModel::
|
||||
|
||||
const CMakeConfig config = configurationForCMake() + newConfig;
|
||||
setConfigurationForCMake(config);
|
||||
|
||||
if (Utils::indexOf(newConfig, [](const CMakeConfigItem &item){
|
||||
return item.key.startsWith("ANDROID_BUILD_ABI_");
|
||||
}) != -1) {
|
||||
// We always need to clean when we change the ANDROID_BUILD_ABI_ variables
|
||||
QList<ProjectExplorer::BuildStepList *> stepLists;
|
||||
const Core::Id clean = ProjectExplorer::Constants::BUILDSTEPS_CLEAN;
|
||||
stepLists << stepList(clean);
|
||||
BuildManager::buildLists(stepLists, QStringList() << ProjectExplorerPlugin::displayNameForStepId(clean));
|
||||
}
|
||||
}
|
||||
|
||||
void CMakeBuildConfiguration::clearError(ForceEnabledChanged fec)
|
||||
@@ -471,7 +493,8 @@ void CMakeBuildConfiguration::setConfigurationForCMake(const CMakeConfig &config
|
||||
{
|
||||
auto configs = removeDuplicates(config);
|
||||
if (m_configurationForCMake.isEmpty())
|
||||
m_configurationForCMake = removeDuplicates(configs + m_initialConfiguration);
|
||||
m_configurationForCMake = removeDuplicates(m_initialConfiguration +
|
||||
CMakeConfigurationKitAspect::configuration(target()->kit()) + configs);
|
||||
else
|
||||
m_configurationForCMake = configs;
|
||||
|
||||
|
Reference in New Issue
Block a user