From 39090ea15c41eded8a233ec2633c0c657280297c Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 28 Apr 2020 11:45:44 +0200 Subject: [PATCH] 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 --- .../QtBuildInternalsConfig.cmake | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index 5966695da44..1743f1fc021 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -267,8 +267,21 @@ 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) + + # 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() macro(qt_examples_build_begin)