From d6272d774c7415186aa398e59f234d0073458072 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 16 Apr 2020 20:30:03 +0200 Subject: [PATCH] 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 Reviewed-by: Alexandru Croitor --- .../QtBuildInternalsConfig.cmake | 16 ++++++++++++++++ .../CMakeLists.txt | 3 +++ 2 files changed, 19 insertions(+) diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index a8c2cc6c65..d3a2a6012e 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -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. diff --git a/cmake/QtBuildInternals/QtStandaloneTestTemplateProject/CMakeLists.txt b/cmake/QtBuildInternals/QtStandaloneTestTemplateProject/CMakeLists.txt index a486d1a722..d77192d563 100644 --- a/cmake/QtBuildInternals/QtStandaloneTestTemplateProject/CMakeLists.txt +++ b/cmake/QtBuildInternals/QtStandaloneTestTemplateProject/CMakeLists.txt @@ -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