CMake: Make sure not to use the Qt prefix for standalone tests

We don't want people accidentally installing tests into the
Qt prefix.

Change-Id: Ic99492559875f753897a83af162253cac846a8a5
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Alexandru Croitor 2020-04-16 20:30:03 +02:00
parent f4cd66ff0a
commit d6272d774c
2 changed files with 19 additions and 0 deletions

View File

@ -8,6 +8,8 @@ endif()
#
######################################
set(QT_BACKUP_CMAKE_INSTALL_PREFIX_BEFORE_EXTRA_INCLUDE "${CMAKE_INSTALL_PREFIX}")
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/QtBuildInternalsExtra.cmake")
include(${CMAKE_CURRENT_LIST_DIR}/QtBuildInternalsExtra.cmake)
endif()
@ -234,6 +236,12 @@ macro(qt_build_tests)
# feature variables are available, and the call in QtSetup is too early when building
# standalone tests, because Core was not find_package()'d yet.
qt_set_language_standards()
if(NOT QT_SUPERBUILD)
# Restore original install prefix. For super builds it needs to be done in
# qt5/CMakeLists.txt.
qt_restore_backed_up_install_prefix()
endif()
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/auto/CMakeLists.txt")
@ -247,6 +255,14 @@ macro(qt_build_tests)
endif()
endmacro()
function(qt_restore_backed_up_install_prefix)
# Restore the CMAKE_INSTALL_PREFIX that was set before loading BuildInternals.
# Useful for standalone tests, we don't want to accidentally install a test into the Qt prefix.
get_property(helpstring CACHE CMAKE_INSTALL_PREFIX PROPERTY HELPSTRING)
set(CMAKE_INSTALL_PREFIX "${QT_BACKUP_CMAKE_INSTALL_PREFIX_BEFORE_EXTRA_INCLUDE}"
CACHE STRING "${helpstring}" FORCE)
endfunction()
macro(qt_examples_build_begin)
# Examples that are built as part of the Qt build need to use the CMake config files from the
# build dir, because they are not installed yet in a prefix build.

View File

@ -6,6 +6,9 @@ find_package(Qt6 REQUIRED COMPONENTS BuildInternals)
# Includes QtSetup and friends for private CMake API.
qt_build_internals_set_up_private_api()
# Restore original install prefix.
qt_restore_backed_up_install_prefix()
# Find all StandaloneTestsConfig.cmake files, and include them
# This will find all Qt packages that are required for standalone tests.
# It will find more packages that needed for a certain test, but will ensure any test can