From a876ff1283d997795a421f7e0a49e0ad3c2f2ad5 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 30 Apr 2020 17:00:13 +0200 Subject: [PATCH] CMake: Fix failing standalone tests on Windows Due to the install prefix being changed for standalone tests, the correct $qt_prefix/bin folder was not added to the PATH environment variable when running tests. Make sure to always include the the original qt install prefix, even if a different install prefix is specified when configuring standalone tests. Amends 39090ea15c41eded8a233ec2633c0c657280297c Change-Id: I22aab732bb2bb679074a811d28d8209e1d535df3 Reviewed-by: Joerg Bornemann --- cmake/QtBuild.cmake | 25 +++++++++++++++++++++---- cmake/QtBuildInternalsExtra.cmake.in | 8 ++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 6375ffdca7..933fc367a6 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -3310,17 +3310,34 @@ function(qt_add_test name) if (arg_TIMEOUT) set_tests_properties(${name} PROPERTIES TIMEOUT ${arg_TIMEOUT}) endif() - # Get path to qtbase/bin, then prepend this path containing the shared libraries to PATH - set(INSTALL_PREFIX_BIN "${CMAKE_INSTALL_PREFIX}/${INSTALL_BINDIR}") - set(test_env_path "PATH=${CMAKE_CURRENT_BINARY_DIR}${QT_PATH_SEPARATOR}${INSTALL_PREFIX_BIN}${QT_PATH_SEPARATOR}$ENV{PATH}") + + # Get path to /bin, as well as CMAKE_INSTALL_PREFIX/bin, then + # prepend them to the PATH environment variable. + # It's needed on Windows to find the shared libraries and plugins. + # original_qtbase_install_prefix is the CMAKE_INSTALL_PREFIX specified when building qtbase. + # The regular CMAKE_INSTALL_PREFIX can be different for example when building standalone tests. + # Latest CMAKE_INSTALL_PREFIX takes priority for the PATH environment variable. + set(install_prefixes "${CMAKE_INSTALL_PREFIX}") + if(QT_BUILD_INTERNALS_ORIGINAL_INSTALL_PREFIX) + list(APPEND install_prefixes "${QT_BUILD_INTERNALS_ORIGINAL_INSTALL_PREFIX}") + endif() + + set(test_env_path "PATH=${CMAKE_CURRENT_BINARY_DIR}") + foreach(install_prefix ${install_prefixes}) + set(test_env_path "${test_env_path}${QT_PATH_SEPARATOR}${install_prefix}/${INSTALL_BINDIR}") + endforeach() + set(test_env_path "${test_env_path}${QT_PATH_SEPARATOR}$ENV{PATH}") string(REPLACE ";" "\;" test_env_path "${test_env_path}") set_property(TEST "${name}" APPEND PROPERTY ENVIRONMENT "${test_env_path}") set_property(TEST "${name}" APPEND PROPERTY ENVIRONMENT "QT_TEST_RUNNING_IN_CTEST=1") # Add the install prefix to list of plugin paths when doing a prefix build if(NOT QT_INSTALL_DIR) - list(APPEND plugin_paths "${CMAKE_INSTALL_PREFIX}/${INSTALL_PLUGINSDIR}") + foreach(install_prefix ${install_prefixes}) + list(APPEND plugin_paths "${install_prefix}/${INSTALL_PLUGINSDIR}") + endforeach() endif() + #TODO: Collect all paths from known repositories when performing a super # build. list(APPEND plugin_paths "${PROJECT_BINARY_DIR}/${INSTALL_PLUGINSDIR}") diff --git a/cmake/QtBuildInternalsExtra.cmake.in b/cmake/QtBuildInternalsExtra.cmake.in index 5278890337..ea945a913d 100644 --- a/cmake/QtBuildInternalsExtra.cmake.in +++ b/cmake/QtBuildInternalsExtra.cmake.in @@ -10,6 +10,14 @@ set(QT_BUILD_INTERNALS_PATH "${CMAKE_CURRENT_LIST_DIR}") set(CMAKE_INSTALL_PREFIX @CMAKE_INSTALL_PREFIX@ CACHE PATH "Install path prefix, prepended onto install directories." FORCE) +# Save the original install prefix in an additional variable. +# While CMAKE_INSTALL_PREFIX may be overridden in certain cases (like for standalone tests building +# or for singular qt-cmake-standalone-test usage), we still need the original qtbase install prefix +# to know where the shared libraries are located to inject them into PATH when running tests via +# ctest. +set(QT_BUILD_INTERNALS_ORIGINAL_INSTALL_PREFIX @CMAKE_INSTALL_PREFIX@ CACHE PATH + "Original install prefix specified when building qtbase." FORCE) + # Propagate developer builds to other modules via BuildInternals package. if(@FEATURE_developer_build@) set(FEATURE_developer_build ON CACHE BOOL "Developer build." FORCE)