summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2020-04-16 20:30:03 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-04-17 15:59:33 +0200
commitd6272d774c7415186aa398e59f234d0073458072 (patch)
tree5c052e54d31f48f1f58dfd0eb96a4a6b1fe2b684
parentf4cd66ff0a4da3a9d8a54bc33ecf8bff4002497e (diff)
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>
-rw-r--r--cmake/QtBuildInternals/QtBuildInternalsConfig.cmake16
-rw-r--r--cmake/QtBuildInternals/QtStandaloneTestTemplateProject/CMakeLists.txt3
2 files changed, 19 insertions, 0 deletions
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