- Qt 6.9
- Qt Core
- CMake Variables in Qt6 Core
- QT_ANDROID_MULTI_ABI_FORWARD_VARS
- Qt 6.9.3 Reference Documentation

# QT_ANDROID_MULTI_ABI_FORWARD_VARS

Allows to share CMake variables in multi-ABI builds.

This variable was introduced in Qt 6.4.2.

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

Note: This variable is used only if targeting the Android platform.

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:

     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:

     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:

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

Set the variable in this way to have a predefined set of variables that will always be forwarded to ABI-specific projects.

Note: 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 qt_finalize_target() and qt_add_executable().