Don't use libs in /usr/local for configure tests by default on macOS

Since commit f3c7d22dd0 we do not use
libraries from /usr/local and other non-system locations on macOS.  But
our configure tests still did.  This led to discrepancies between
find_package calls in configure tests and the Qt project itself.

Mentioned commit removed /usr/local and friends from
CMAKE_SYSTEM_PREFIX_PATH.  But we can't pass this variable to the
configure tests, because CMake sets it up and overwrites our value.

Pass CMAKE_SYSTEM_PREFIX_PATH and CMAKE_SYSTEM_FRAMEWORK_PATH as
QT_CONFIGURE_TEST_CMAKE_SYSTEM_{PREFIX|FRAMEWORK}_PATH variables to
tests.

Tests with separate project files that call find_package() must add code
like this after the project() command:

if(DEFINED QT_CONFIGURE_TEST_CMAKE_SYSTEM_PREFIX_PATH)
    set(CMAKE_SYSTEM_PREFIX_PATH
        "${QT_CONFIGURE_TEST_CMAKE_SYSTEM_PREFIX_PATH}")
endif()
if(DEFINED QT_CONFIGURE_TEST_CMAKE_SYSTEM_FRAMEWORK_PATH)
    set(CMAKE_SYSTEM_FRAMEWORK_PATH
        "${QT_CONFIGURE_TEST_CMAKE_SYSTEM_FRAMEWORK_PATH}")
endif()

Adjust pro2cmake accordingly.

Task-number: QTBUG-97076
Change-Id: Iac1622768d1200e6ea63be569eef12b7eada6c76
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2021-10-05 11:09:07 +02:00
parent e5183c49dd
commit f19668ce65
2 changed files with 22 additions and 0 deletions

View File

@ -875,6 +875,18 @@ function(qt_config_compile_test name)
endif()
endif()
# Pass override values for CMAKE_SYSTEM_{PREFIX|FRAMEWORK}_PATH.
if(DEFINED QT_CMAKE_SYSTEM_PREFIX_PATH_BACKUP)
set(path_list ${CMAKE_SYSTEM_PREFIX_PATH})
string(REPLACE ";" "\\;" path_list "${path_list}")
list(APPEND flags "-DQT_CONFIG_COMPILE_TEST_CMAKE_SYSTEM_PREFIX_PATH=${path_list}")
endif()
if(DEFINED QT_CMAKE_SYSTEM_FRAMEWORK_PATH_BACKUP)
set(path_list ${CMAKE_SYSTEM_FRAMEWORK_PATH})
string(REPLACE ";" "\\;" path_list "${path_list}")
list(APPEND flags "-DQT_CONFIG_COMPILE_TEST_CMAKE_SYSTEM_FRAMEWORK_PATH=${path_list}")
endif()
if(NOT arg_CMAKE_FLAGS)
set(arg_CMAKE_FLAGS "")
endif()
@ -1016,6 +1028,9 @@ function(qt_get_platform_try_compile_vars out_var)
list(APPEND flags_cmd_line "-DCMAKE_OSX_SYSROOT:STRING=${QT_UIKIT_SDK}")
endif()
endif()
if(QT_NO_USE_FIND_PACKAGE_SYSTEM_ENVIRONMENT_PATH)
list(APPEND flags_cmd_line "-DCMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH:BOOL=OFF")
endif()
set("${out_var}" "${flags_cmd_line}" PARENT_SCOPE)
endfunction()

View File

@ -4507,6 +4507,13 @@ def handle_config_test_project(scope: Scope, cm_fh: IO[str]):
f"cmake_minimum_required(VERSION 3.16)\n"
f"project(config_test_{project_name} LANGUAGES C CXX)\n"
"""
if(DEFINED QT_CONFIG_COMPILE_TEST_CMAKE_SYSTEM_PREFIX_PATH)
set(CMAKE_SYSTEM_PREFIX_PATH "${QT_CONFIG_COMPILE_TEST_CMAKE_SYSTEM_PREFIX_PATH}")
endif()
if(DEFINED QT_CONFIG_COMPILE_TEST_CMAKE_SYSTEM_FRAMEWORK_PATH)
set(CMAKE_SYSTEM_FRAMEWORK_PATH "${QT_CONFIG_COMPILE_TEST_CMAKE_SYSTEM_FRAMEWORK_PATH}")
endif()
foreach(p ${QT_CONFIG_COMPILE_TEST_PACKAGES})
find_package(${p})
endforeach()