657525965b
Qt6Config.cmake calls cmake_minimum_required to ensure a recent enough
CMake version is used in projects.
That call does not set policies in the calling subdirectory scope,
because find_package introduces a new policy scope.
If a project using Qt has a 'cmake_minimum_required(VERSION 3.1)'
call and is configured with a recent CMake, many policies will
still be set to OLD.
One such policy is CMP0071 (Run AUTOMOC on GENERATED files). The
policy value is queried at generation time rather than at target
definition time, which means we can't influence the policy value
(e.g. inside the implementation of qt_add_executable for example)
The inability to influence the policy value for targets created by our
own CMake functions is unfortunate and can lead to issues (in the case
of the above policy to compilation / linker issues).
Record the version of the last cmake_minimum_required call before
the Qt packages are found and error out if the version is lower than
the minimum supported one.
A project can reduce the error into a warning by specifying a
-DQT_FORCE_MIN_CMAKE_VERSION_FOR_USING_QT_IN_CMAKE_MIN_REQUIRED=3.xyz
option when configuring the project.
If the option is used and build issues arise, no official support is
given.
All the CMake example projects shipped with Qt specify a minimum
version of 3.16 already (which is the minimum for shared Qt builds),
so it shouldn't be an issue to require that in other user projects as
well.
Implementation wise, we follow the existing pattern to record
what the minimum and computed versions for static and shared Qt
builds are at qtbase configure time.
These are then checked before the Qt6 or QtFoo packages are
find_package'd.
Amends 6518bcc167
Pick-to: 6.2
Task-number: QTBUG-95018
Task-number: QTBUG-95832
Change-Id: I1a1d06d82f566c92192a699045127943604c8353
Reviewed-by: Craig Scott <craig.scott@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
227 lines
10 KiB
CMake
227 lines
10 KiB
CMake
@PACKAGE_INIT@
|
|
|
|
# Used by __qt_internal_warn_if_project_min_cmake_version_is_not_met
|
|
if(NOT _qt_project_last_cmake_minimum_required_version)
|
|
set(_qt_project_last_cmake_minimum_required_version "${CMAKE_MINIMUM_REQUIRED_VERSION}")
|
|
endif()
|
|
cmake_minimum_required(VERSION @min_new_policy_version@...@max_new_policy_version@)
|
|
|
|
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@ConfigExtras.cmake")
|
|
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicCMakeVersionHelpers.cmake")
|
|
__qt_internal_require_suitable_cmake_version_for_using_qt()
|
|
|
|
get_filename_component(_qt_cmake_dir "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
|
|
set(_qt_@PROJECT_VERSION_MAJOR@_config_cmake_dir "${CMAKE_CURRENT_LIST_DIR}")
|
|
|
|
if (NOT QT_NO_CREATE_TARGETS)
|
|
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@Targets.cmake")
|
|
if(NOT QT_NO_CREATE_VERSIONLESS_TARGETS)
|
|
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@VersionlessTargets.cmake")
|
|
endif()
|
|
else()
|
|
# For examples using `find_package(...)` inside their CMakeLists.txt files:
|
|
# Make CMake's AUTOGEN detect this Qt version properly
|
|
set_directory_properties(PROPERTIES
|
|
QT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
|
|
QT_VERSION_MINOR @PROJECT_VERSION_MINOR@
|
|
QT_VERSION_PATCH @PROJECT_VERSION_PATCH@)
|
|
endif()
|
|
|
|
if(NOT "${QT_HOST_PATH}" STREQUAL "")
|
|
find_package(Qt@PROJECT_VERSION_MAJOR@HostInfo
|
|
CONFIG
|
|
REQUIRED
|
|
PATHS "${QT_HOST_PATH}"
|
|
"${QT_HOST_PATH_CMAKE_DIR}"
|
|
NO_CMAKE_FIND_ROOT_PATH
|
|
NO_DEFAULT_PATH)
|
|
endif()
|
|
|
|
get_filename_component(_qt_import_prefix "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
|
get_filename_component(_qt_import_prefix "${_qt_import_prefix}" REALPATH)
|
|
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}")
|
|
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}/3rdparty/extra-cmake-modules/find-modules")
|
|
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}/3rdparty/kwin")
|
|
|
|
if(APPLE AND (NOT CMAKE_SYSTEM_NAME OR CMAKE_SYSTEM_NAME STREQUAL "Darwin"))
|
|
# Add module directory to pick up custom Info.plist template for macOS
|
|
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}/macos")
|
|
elseif(APPLE AND CMAKE_SYSTEM_NAME STREQUAL "iOS")
|
|
# Add module directory to pick up custom Info.plist template for iOS
|
|
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}/ios")
|
|
endif()
|
|
|
|
set(QT_ADDITIONAL_PACKAGES_PREFIX_PATH "" CACHE STRING
|
|
"Additional directories where find(Qt6 ...) components are searched")
|
|
|
|
# Collect additional package prefix paths to look for Qt packages, both from command line and the
|
|
# env variable.
|
|
if(NOT DEFINED _qt_additional_packages_prefix_paths)
|
|
set(_qt_additional_packages_prefix_paths "")
|
|
|
|
set(_qt_additional_packages_prefixes "")
|
|
if(QT_ADDITIONAL_PACKAGES_PREFIX_PATH)
|
|
list(APPEND _qt_additional_packages_prefixes ${QT_ADDITIONAL_PACKAGES_PREFIX_PATH})
|
|
endif()
|
|
if(DEFINED ENV{QT_ADDITIONAL_PACKAGES_PREFIX_PATH}
|
|
AND NOT "$ENV{QT_ADDITIONAL_PACKAGES_PREFIX_PATH}" STREQUAL "")
|
|
list(APPEND _qt_additional_packages_prefixes $ENV{QT_ADDITIONAL_PACKAGES_PREFIX_PATH})
|
|
endif()
|
|
|
|
foreach(_qt_additional_path IN LISTS _qt_additional_packages_prefixes)
|
|
file(TO_CMAKE_PATH "${_qt_additional_path}" _qt_additional_path)
|
|
|
|
# The prefix paths need to end with lib/cmake to ensure the packages are found when
|
|
# cross compiling. Search for REROOT_PATH_ISSUE_MARKER in the qt.toolchain.cmake file for
|
|
# details.
|
|
# We must pass the values via the PATHS options because the main find_package call uses
|
|
# NO_DEFAULT_PATH, and thus CMAKE_PREFIX_PATH values are discarded.
|
|
# CMAKE_FIND_ROOT_PATH values are not discarded and togegher with the PATHS option, it
|
|
# ensures packages from additional prefixes are found.
|
|
if(NOT _qt_additional_path MATCHES "/lib/cmake$")
|
|
string(APPEND _qt_additional_path "/lib/cmake")
|
|
endif()
|
|
list(APPEND _qt_additional_packages_prefix_paths "${_qt_additional_path}")
|
|
endforeach()
|
|
unset(_qt_additional_path)
|
|
unset(_qt_additional_packages_prefixes)
|
|
endif()
|
|
|
|
# Public helpers available to all Qt packages.
|
|
include("${CMAKE_CURRENT_LIST_DIR}/QtFeature.cmake")
|
|
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicFinalizerHelpers.cmake")
|
|
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicPluginHelpers.cmake")
|
|
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicTargetHelpers.cmake")
|
|
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicWalkLibsHelpers.cmake")
|
|
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicFindPackageHelpers.cmake")
|
|
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicDependencyHelpers.cmake")
|
|
|
|
if(NOT DEFINED QT_CMAKE_EXPORT_NAMESPACE)
|
|
set(QT_CMAKE_EXPORT_NAMESPACE @QT_CMAKE_EXPORT_NAMESPACE@)
|
|
endif()
|
|
|
|
# Propagate sanitizer flags to both internal Qt builds and user projects.
|
|
# Allow opt-out in case if downstream projects handle it in a different way.
|
|
set(QT_CONFIGURED_SANITIZER_OPTIONS "@ECM_ENABLE_SANITIZERS@")
|
|
|
|
if(QT_CONFIGURED_SANITIZER_OPTIONS
|
|
AND NOT __qt_sanitizer_options_set
|
|
AND NOT QT_NO_ADD_SANITIZER_OPTIONS)
|
|
set(ECM_ENABLE_SANITIZERS "${QT_CONFIGURED_SANITIZER_OPTIONS}")
|
|
include(
|
|
"${CMAKE_CURRENT_LIST_DIR}/3rdparty/extra-cmake-modules/modules/ECMEnableSanitizers.cmake")
|
|
endif()
|
|
# Mark that the current directory scope has its sanitizer flags set.
|
|
set(__qt_sanitizer_options_set TRUE)
|
|
|
|
# Find required dependencies, if any.
|
|
include(CMakeFindDependencyMacro)
|
|
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@Dependencies.cmake")
|
|
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@Dependencies.cmake")
|
|
if(NOT @INSTALL_CMAKE_NAMESPACE@_DEPENDENCIES_FOUND)
|
|
set(@INSTALL_CMAKE_NAMESPACE@_FOUND FALSE)
|
|
message(FATAL_ERROR "Failed to find Qt Platform dependency: "
|
|
"${@INSTALL_CMAKE_NAMESPACE@_DEPENDENCY_NOT_FOUND_MESSAGE}")
|
|
endif()
|
|
endif()
|
|
|
|
set(_@INSTALL_CMAKE_NAMESPACE@_FIND_PARTS_QUIET)
|
|
if(@INSTALL_CMAKE_NAMESPACE@_FIND_QUIETLY)
|
|
set(_@INSTALL_CMAKE_NAMESPACE@_FIND_PARTS_QUIET QUIET)
|
|
endif()
|
|
|
|
set(__qt_use_no_default_path_for_qt_packages "NO_DEFAULT_PATH")
|
|
if(QT_DISABLE_NO_DEFAULT_PATH_IN_QT_PACKAGES)
|
|
set(__qt_use_no_default_path_for_qt_packages "")
|
|
endif()
|
|
|
|
foreach(module ${@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS})
|
|
if(NOT "${QT_HOST_PATH}" STREQUAL ""
|
|
AND "${module}" MATCHES "Tools$"
|
|
AND NOT "${module}" MATCHES "ShaderTools$"
|
|
AND NOT "${module}" MATCHES "^Tools$"
|
|
AND NOT QT_NO_FIND_HOST_TOOLS_PATH_MANIPULATION)
|
|
# Make sure that a Qt*Tools package is also looked up in QT_HOST_PATH.
|
|
# But don't match QtShaderTools and QtTools which are cross-compiled target package names.
|
|
# Allow opt out just in case.
|
|
# TODO: Handle a hypothetical QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH
|
|
# See QTBUG-94524
|
|
set(__qt_find_package_host_qt_path "${QT_HOST_PATH}/lib/cmake")
|
|
set(__qt_backup_cmake_prefix_path "${CMAKE_PREFIX_PATH}")
|
|
set(__qt_backup_cmake_find_root_path "${CMAKE_FIND_ROOT_PATH}")
|
|
list(PREPEND CMAKE_PREFIX_PATH "${__qt_find_package_host_qt_path}")
|
|
list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}")
|
|
endif()
|
|
|
|
find_package(@INSTALL_CMAKE_NAMESPACE@${module}
|
|
${@INSTALL_CMAKE_NAMESPACE@_FIND_VERSION}
|
|
${_@INSTALL_CMAKE_NAMESPACE@_FIND_PARTS_QUIET}
|
|
PATHS
|
|
${_qt_cmake_dir}
|
|
${_qt_additional_packages_prefix_paths}
|
|
${QT_EXAMPLES_CMAKE_PREFIX_PATH}
|
|
${__qt_find_package_host_qt_path}
|
|
${__qt_use_no_default_path_for_qt_packages}
|
|
)
|
|
|
|
if(NOT "${__qt_find_package_host_qt_path}" STREQUAL "")
|
|
set(CMAKE_PREFIX_PATH "${__qt_backup_cmake_prefix_path}")
|
|
set(CMAKE_FIND_ROOT_PATH "${__qt_backup_cmake_find_root_path}")
|
|
unset(__qt_backup_cmake_prefix_path)
|
|
unset(__qt_backup_cmake_find_root_path)
|
|
unset(__qt_find_package_host_qt_path)
|
|
endif()
|
|
|
|
if (NOT @INSTALL_CMAKE_NAMESPACE@${module}_FOUND)
|
|
set(_qt_expected_component_config_path
|
|
"${_qt_cmake_dir}/@INSTALL_CMAKE_NAMESPACE@${module}/@INSTALL_CMAKE_NAMESPACE@${module}Config.cmake")
|
|
get_filename_component(
|
|
_qt_expected_component_dir_path "${_qt_expected_component_config_path}" DIRECTORY)
|
|
|
|
set(_qt_component_not_found_msg
|
|
"\nExpected Config file at \"${_qt_expected_component_config_path}\"")
|
|
|
|
if(EXISTS "${_qt_expected_component_config_path}")
|
|
string(APPEND _qt_component_not_found_msg " exists \n")
|
|
else()
|
|
string(APPEND _qt_component_not_found_msg " does NOT exist\n")
|
|
endif()
|
|
|
|
set(_qt_candidate_component_dir_path "${@INSTALL_CMAKE_NAMESPACE@${module}_DIR}")
|
|
|
|
if(_qt_candidate_component_dir_path AND
|
|
NOT _qt_expected_component_dir_path STREQUAL _qt_candidate_component_dir_path)
|
|
string(APPEND _qt_component_not_found_msg
|
|
"\n@INSTALL_CMAKE_NAMESPACE@${module}_DIR was computed by CMake or specified on the "
|
|
"command line by the user: \"${_qt_candidate_component_dir_path}\" "
|
|
"\nThe expected and computed paths are different, which might be the reason for "
|
|
"the package not to be found.")
|
|
endif()
|
|
|
|
if(@INSTALL_CMAKE_NAMESPACE@_FIND_REQUIRED_${module})
|
|
set(_Qt_NOTFOUND_MESSAGE
|
|
"${_Qt_NOTFOUND_MESSAGE}Failed to find Qt component \"${module}\". ${_qt_component_not_found_msg}")
|
|
elseif(NOT @INSTALL_CMAKE_NAMESPACE@_FIND_QUIETLY)
|
|
message(WARNING
|
|
"Failed to find Qt component \"${module}\". ${_qt_component_not_found_msg}")
|
|
endif()
|
|
|
|
unset(_qt_expected_component_config_path)
|
|
unset(_qt_expected_component_dir_path)
|
|
unset(_qt_candidate_component_dir_path)
|
|
unset(_qt_component_not_found_msg)
|
|
endif()
|
|
endforeach()
|
|
|
|
if(@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS AND _Qt_NOTFOUND_MESSAGE)
|
|
set(@INSTALL_CMAKE_NAMESPACE@_NOT_FOUND_MESSAGE "${_Qt_NOTFOUND_MESSAGE}")
|
|
set(@INSTALL_CMAKE_NAMESPACE@_FOUND False)
|
|
unset(_Qt_NOTFOUND_MESSAGE)
|
|
endif()
|
|
|
|
__qt_internal_defer_promote_targets_in_dir_scope_to_global()
|
|
if(CMAKE_VERSION VERSION_LESS 3.21)
|
|
__qt_internal_check_link_order_matters()
|
|
__qt_internal_check_cmp0099_available()
|
|
endif()
|