IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QT_ANDROID_MULTI_ABI_FORWARD_VARS

Allows to share CMake variables in multi-ABI builds.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QT_ANDROID_MULTI_ABI_FORWARD_VARS

Allows to share CMake variables in multi-ABI builds

This variable was introduced in Qt 6.4.2.

This variable is in technology preview and may change in future releases.

This variable is used only if targeting the Android platform.

The QT_ANDROID_MULTI_ABI_FORWARD_VARS variable allows specifying the list of CMake variables that need to be forwarded from the main ABI project to ABI-specific subprojects. Due to the specifics of the Multi-ABI project build process, there is no generic way to forward the CMake cache variables that are specified either in the command line or in another similar way.

A typical use case for the variable is propagating CMake cache variables specified in the command line. For example, a project has two variables PROJECT_WIDE_VARIABLE1 and PROJECT_WIDE_VARIABLE2 that affect the project configuration:

 
Sélectionnez
cmake_minimum_required(VERSION 3.18)

project(MyProject LANGUAGES CXX)

find_package(Qt6 REQUIRED COMPONENTS Core)

qt_add_executable(MyApp main.cpp)

if(PROJECT_WIDE_VARIABLE1)
    target_sources(MyApp PRIVATE sourcefile1.cpp)
endif()
if(PROJECT_WIDE_VARIABLE2)
    target_sources(MyApp PRIVATE sourcefile2.cpp)
endif()

The above contents of CMakeLists.txt enable you to control how MyApp is built by setting the corresponding CMake variables from the command line:

 
Sélectionnez
qt-cmake -S<source directory> -B<build directory> \
    -DPROJECT_WIDE_VARIABLE1=ON \
    -DPROJECT_WIDE_VARIABLE2=ON \
    -DQT_ANDROID_MULTI_ABI_FORWARD_VARS="PROJECT_WIDE_VARIABLE1;PROJECT_WIDE_VARIABLE2"

When configuring the application for desktop, PROJECT_WIDE_VARIABLE1 and PROJECT_WIDE_VARIABLE2 are visible in CMake listings and scripts as global cache variables. This doesn't work for Android Multi-ABI builds because ABI-specific subprojects do not inherit the cache variables from the main-ABI project. This issue can be solved by passing the list of required variables to the QT_ANDROID_MULTI_ABI_FORWARD_VARS variable, so both PROJECT_WIDE_VARIABLE1 and PROJECT_WIDE_VARIABLE2 values will be propagated to the ABI-specific builds.

The variable can be also defined in the project's CMakeLists.txt:

 
Sélectionnez
...
qt_add_executable(MyApp main.cpp)
...
if(ANDROID)
    set(QT_ANDROID_MULTI_ABI_FORWARD_VARS "PROJECT_WIDE_VARIABLE1;PROJECT_WIDE_VARIABLE2")
endif()
...

Setting the variable in this way allows you to have a predefined set of variables that will always be forwarded to abi-specific projects.

The forwarding is done in the target finalizer, which is implicitly called when qt_add_executable() is used. The finalization occurs automatically when using CMake 3.19 or later.

See Also

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+