diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-06-25 18:02:52 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-06-29 17:34:22 +0200 |
commit | f3c7d22dd04afe8d889585fb5d6426f3d4591e74 (patch) | |
tree | 68cfb3c9a36d7873304ec6d9947129ef36131128 /cmake/QtBuild.cmake | |
parent | 45c0f45e04f4c8431c2744dd52d334ee2e127019 (diff) |
CMake: Don't use libraries in /usr/local by default on macOS
qmake builds of Qt don't use libraries in /usr/local because the
path is not considered a system path. Only the SDK path should be
used as a source of system libraries.
We should do the same for the CMake builds, which involves a couple of
things.
Tell CMake not to consider /usr/local (and a bunch of other
paths) as system prefix paths.
Disable pkg-config usage which by default is not used in qmake
Windows and macOS builds.
If a user wishes to use libraries located in /usr/local on macOS, they
can explicitly enable the behavior via -DFEATURE_pkg_config=ON.
In addition to enabling pkg-config, that will also disable the system
prefix modification described above.
Implementation notes
To disable pkg-config usage, we set an empty path for
PKG_CONFIG_EXECUTABLE, because there is no other good way. The
downside to this is that a lot of warning messages will be printed
that the pkg-config package can not be found.
The pkg-config feature needs to be computed in QtBuildInternals before
qtbase/src/configure.cmake, because it's too late to do it in that
file where a few qt_find_package calls already exist.
The feature value is also saved to QtBuildInternalsExtra, to make sure
that pkg-config is disabled whenever building another repo.
System prefix adjustment is done by removing paths from
CMAKE_SYSTEM_PREFIX_PATH.
Ideally we would remove also /usr as a path, to match what qmake does,
but that breaks find_program() calls for perl, python, etc.
We have to make sure that qt_find_package does not look in
PATH when looking for packages, which is the default behavior, because
PATH on macOS most likely contains /usr/local.
One last curiosity for future generations is that CMake 3.18+ has
merged a change to prioritise SDK locations over regular /usr/lib.
Fixes: QTBUG-85261
Change-Id: I28fe5bae7997507a83b37b4eb1e0188e64062c57
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'cmake/QtBuild.cmake')
-rw-r--r-- | cmake/QtBuild.cmake | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 4ddb61aec3..9656fa293a 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -5246,6 +5246,12 @@ macro(qt_find_package) list(APPEND arg_UNPARSED_ARGUMENTS "COMPONENTS;${arg_COMPONENTS}") endif() + # Don't look for packages in PATH if requested to. + if(QT_NO_USE_FIND_PACKAGE_SYSTEM_ENVIRONMENT_PATH) + set(_qt_find_package_use_system_env_backup "${CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH}") + set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH "OFF") + endif() + if(NOT (arg_CONFIG OR arg_NO_MODULE OR arg_MODULE) AND NOT _qt_find_package_skip_find_package) # Try to find a config package first in quiet mode set(config_package_arg ${arg_UNPARSED_ARGUMENTS}) @@ -5291,6 +5297,14 @@ macro(qt_find_package) find_package(${arg_UNPARSED_ARGUMENTS}) endif() + if(QT_NO_USE_FIND_PACKAGE_SYSTEM_ENVIRONMENT_PATH) + if("${_qt_find_package_use_system_env_backup}" STREQUAL "") + unset(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH) + else() + set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH "${_qt_find_package_use_system_env_backup}") + endif() + endif() + if(${ARGV0}_FOUND AND arg_PROVIDED_TARGETS AND NOT _qt_find_package_skip_find_package) # If package was found, associate each target with its package name. This will be used # later when creating Config files for Qt libraries, to generate correct find_dependency() |