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.

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:

cmake_minimum_required(VERSION 3.18)

project(MyProject LANGUAGES CXX)

find_package(Qt6 REQUIRED COMPONENTS Core)

qt_add_executable(MyApp main.cpp)

    target_sources(MyApp PRIVATE sourcefile1.cpp)
    target_sources(MyApp PRIVATE sourcefile2.cpp)

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> \

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)

Setting the variable in this way allows you 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().

© 2023 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.