CMake: Don't set QT_BUILDING_QT for single standalone tests

Standalone test projects have the following condition in the
beginning of their project:

 if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
     find_package(Qt6BuildInternals COMPONENT STANDALONE_TEST)
 endif()

When configuring the project the first time, QT_BUILDING_QT is not
set, find_package is called, configuration succeeds.
But because standalone projects implicitly include QtSetup.cmake,
that file sets the QT_BUILDING_QT cache var to true, and upon test
reconfiguration, cmake errors out with:
 Unknown CMake command "qt_internal_add_test"
or similar.

This happens because QT_BUILDING_QT is true on the second
reconfiguration and the find_package mentioned above is not executed
anymore, leading to unknown internal command errors.

Set a new QT_INTERNAL_IS_STANDALONE_TEST variable when we detect
a standalone test and check for its value in QtSetup so we don't
set QT_BUILDING_QT to TRUE anymore.

Adjust a few code locations where QT_BUILDING_QT being false might
trigger different behavior for standalone tests.

 6.5 resolved conflicts:
	src/corelib/Qt6AndroidMacros.cmake

Task-number: QTBUG-93020
Change-Id: I5413b9f37653225175a1006f7626e023045b5979
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
(cherry picked from commit b9b5ed3aa6)
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Alexandru Croitor 2023-07-04 17:47:14 +02:00
parent 64edf3181f
commit c7bd7ddfb6
3 changed files with 12 additions and 5 deletions

View File

@ -2,6 +2,7 @@
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# Includes QtSetup and friends for private CMake API. # Includes QtSetup and friends for private CMake API.
set(QT_INTERNAL_IS_STANDALONE_TEST TRUE)
qt_internal_project_setup() qt_internal_project_setup()
qt_build_internals_set_up_private_api() qt_build_internals_set_up_private_api()

View File

@ -3,10 +3,16 @@
## Set a default build type if none was specified ## Set a default build type if none was specified
# Set the QT_IS_BUILDING_QT variable so we can verify whether we are building # Set the QT_BUILDING_QT variable so we can verify whether we are building
# Qt from source # Qt from source.
# Make sure not to set it when building a standalone test, otherwise
# upon reconfiguration we get an error about qt_internal_add_test
# not being found due the if(NOT QT_BUILDING_QT) check we have
# in each standalone test.
if(NOT QT_INTERNAL_IS_STANDALONE_TEST)
set(QT_BUILDING_QT TRUE CACHE BOOL set(QT_BUILDING_QT TRUE CACHE BOOL
"When this is present and set to true, it signals that we are building Qt from source.") "When this is present and set to true, it signals that we are building Qt from source.")
endif()
# Pre-calculate the developer_build feature if it's set by the user via the INPUT_developer_build # Pre-calculate the developer_build feature if it's set by the user via the INPUT_developer_build
# variable when using the configure script. When not using configure, don't take the INPUT variable # variable when using the configure script. When not using configure, don't take the INPUT variable

View File

@ -877,7 +877,7 @@ endfunction()
# It doesn't overwrite public properties, but instead writes formatted values to internal # It doesn't overwrite public properties, but instead writes formatted values to internal
# properties. # properties.
function(_qt_internal_android_format_deployment_paths target) function(_qt_internal_android_format_deployment_paths target)
if(QT_BUILD_STANDALONE_TESTS OR QT_BUILDING_QT) if(QT_BUILD_STANDALONE_TESTS OR QT_BUILDING_QT OR QT_INTERNAL_IS_STANDALONE_TEST)
# When building standalone tests or Qt itself we obligate developers to not use # When building standalone tests or Qt itself we obligate developers to not use
# windows paths when setting QT_* properties below, so their values are used as is when # windows paths when setting QT_* properties below, so their values are used as is when
# generating deployment settings. # generating deployment settings.
@ -977,7 +977,7 @@ function(_qt_internal_get_android_abi_cmake_dir_path out_path abi)
else() else()
_qt_internal_get_android_abi_prefix_path(prefix_path ${abi}) _qt_internal_get_android_abi_prefix_path(prefix_path ${abi})
if((PROJECT_NAME STREQUAL "QtBase" OR QT_SUPERBUILD) AND QT_BUILDING_QT AND if((PROJECT_NAME STREQUAL "QtBase" OR QT_SUPERBUILD) AND QT_BUILDING_QT AND
NOT QT_BUILD_STANDALONE_TESTS) NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_INTERNAL_IS_STANDALONE_TEST)
set(cmake_dir "${QT_CONFIG_BUILD_DIR}") set(cmake_dir "${QT_CONFIG_BUILD_DIR}")
else() else()
set(cmake_dir "${prefix_path}/${QT6_INSTALL_LIBS}/cmake") set(cmake_dir "${prefix_path}/${QT6_INSTALL_LIBS}/cmake")