CMake: Fix usage of correct install prefix for standalone tests

Previously configuration of standalone tests might have failed
due to CMake trying to create files in the /usr/local default
prefix.
Make sure to use a fake prefix in the binary dir instead,
unless another prefix is explicitly specified.

Change-Id: Icfcb32285aa5596abf1a918396b26673880a8d27
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Alexandru Croitor 2020-04-28 11:45:44 +02:00
parent d2bb14253c
commit 39090ea15c

View File

@ -267,8 +267,21 @@ function(qt_restore_backed_up_install_prefix)
# Restore the CMAKE_INSTALL_PREFIX that was set before loading BuildInternals. # 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. # 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) 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) # If CMAKE_INSTALL_PREFIX was default initialized, that means it points to something
# like /usr/local which we don't want. Why? When metatype json files are created
# during standalone tests configuration, the folder creation might fail due to missing
# permissions in the /usr/local (which is the wrong place anyway).
# Instead specify a dummy install prefix in the current build dir.
# If the prefix was specified by the user at the command line, honor it, hoping that the
# user knows what they are doing.
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(new_install_prefix "${CMAKE_BINARY_DIR}/standalone_tests_fake_install_prefix")
else()
set(new_install_prefix "${QT_BACKUP_CMAKE_INSTALL_PREFIX_BEFORE_EXTRA_INCLUDE}")
endif()
set(CMAKE_INSTALL_PREFIX "${new_install_prefix}" CACHE STRING "${helpstring}" FORCE)
endfunction() endfunction()
macro(qt_examples_build_begin) macro(qt_examples_build_begin)