summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-10-22 13:38:00 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2021-10-27 16:41:26 +0200
commit5ffc744b791a114a3180a425dd26e298f7399955 (patch)
tree49138e472b350deb6bdae0d3c4cfa5a944daaef8
parent9beae46b599be011aab9f44efc92d49309b72da3 (diff)
CMake: Allow disabling package version check
When building Qt repos, all find_package(Qt6) calls request a PROJECT_VERSION version which is set in .cmake.conf via QT_REPO_MODULE_VERSION. This means trying to configure qtsvg from a 6.3 branch using a 6.2 qtbase won't work, because qtsvg will call find_package(Qt6 6.3) and no such Qt6 package version exists. There are certain scenarios where it might be useful to try to do that though. One of them is doing Qt development while locally mixing branches. Another is building a 6.4 QtWebEngine against a 6.2 Qt. Allow to opt out of the version check by configuring each Qt repo with -DQT_NO_PACKAGE_VERSION_CHECK=TRUE. This setting is not recorded and will have to be set again when configuring another repo. The version check will also be disabled by default when configuring with the -developer-build feature. This will be recorded and embedded into each ConfigVersion file. If the version check is disabled, a warning will be shown mentioning the incompatible version of a package that was found but that package will still be accepted. The warning will show both when building Qt or using Qt in a user project. The warnings can be disabled by passing -DQT_NO_PACKAGE_VERSION_INCOMPATIBLE_WARNING=TRUE Furthermore when building a Qt repo, another warning will show when an incompatible package version is detected, to suggest to the Qt builder whether they want to use the incompatible version by disabling the version check. Note that there are no compatibility promises when using mixed non-matching versions. Things might not work. These options are only provided for convenience and their users know what they are doing. Pick-to: 6.2 Fixes: QTBUG-96458 Change-Id: I1a42e0b2a00b73513d776d89a76102ffd9136422 Reviewed-by: Craig Scott <craig.scott@qt.io>
-rw-r--r--cmake/Qt3rdPartyLibraryHelpers.cmake7
-rw-r--r--cmake/QtBaseGlobalTargets.cmake15
-rw-r--r--cmake/QtCMakeHelpers.cmake22
-rw-r--r--cmake/QtCMakePackageVersionFile.cmake.in55
-rw-r--r--cmake/QtModuleHelpers.cmake7
-rw-r--r--cmake/QtPluginHelpers.cmake7
-rw-r--r--cmake/QtToolHelpers.cmake7
7 files changed, 114 insertions, 6 deletions
diff --git a/cmake/Qt3rdPartyLibraryHelpers.cmake b/cmake/Qt3rdPartyLibraryHelpers.cmake
index f2b3882fc7..1cc5ebea44 100644
--- a/cmake/Qt3rdPartyLibraryHelpers.cmake
+++ b/cmake/Qt3rdPartyLibraryHelpers.cmake
@@ -241,14 +241,19 @@ function(qt_internal_add_3rdparty_library target)
)
write_basic_package_version_file(
- "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake"
+ "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersionImpl.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
+ qt_internal_write_qt_package_version_file(
+ "${INSTALL_CMAKE_NAMESPACE}${target}"
+ "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake"
+ )
qt_install(FILES
"${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}Config.cmake"
"${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake"
+ "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersionImpl.cmake"
DESTINATION "${config_install_dir}"
COMPONENT Devel
)
diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake
index 0c7d73375e..38fe49f6d6 100644
--- a/cmake/QtBaseGlobalTargets.cmake
+++ b/cmake/QtBaseGlobalTargets.cmake
@@ -35,14 +35,19 @@ configure_file(
)
write_basic_package_version_file(
- "${__build_internals_build_dir}/${INSTALL_CMAKE_NAMESPACE}BuildInternalsConfigVersion.cmake"
+ "${__build_internals_build_dir}/${INSTALL_CMAKE_NAMESPACE}BuildInternalsConfigVersionImpl.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
+qt_internal_write_qt_package_version_file(
+ "${INSTALL_CMAKE_NAMESPACE}BuildInternals"
+ "${__build_internals_build_dir}/${INSTALL_CMAKE_NAMESPACE}BuildInternalsConfigVersion.cmake"
+)
qt_install(FILES
"${__build_internals_build_dir}/${INSTALL_CMAKE_NAMESPACE}BuildInternalsConfig.cmake"
"${__build_internals_build_dir}/${INSTALL_CMAKE_NAMESPACE}BuildInternalsConfigVersion.cmake"
+ "${__build_internals_build_dir}/${INSTALL_CMAKE_NAMESPACE}BuildInternalsConfigVersionImpl.cmake"
"${__build_internals_build_dir}/QtBuildInternalsExtra.cmake"
DESTINATION "${__build_internals_install_dir}"
COMPONENT Devel
@@ -172,15 +177,20 @@ configure_file(
)
write_basic_package_version_file(
- "${__GlobalConfig_build_dir}/${INSTALL_CMAKE_NAMESPACE}ConfigVersion.cmake"
+ "${__GlobalConfig_build_dir}/${INSTALL_CMAKE_NAMESPACE}ConfigVersionImpl.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
+qt_internal_write_qt_package_version_file(
+ "${INSTALL_CMAKE_NAMESPACE}"
+ "${__GlobalConfig_build_dir}/${INSTALL_CMAKE_NAMESPACE}ConfigVersion.cmake"
+)
qt_install(FILES
"${__GlobalConfig_build_dir}/${INSTALL_CMAKE_NAMESPACE}Config.cmake"
"${__GlobalConfig_build_dir}/${INSTALL_CMAKE_NAMESPACE}ConfigExtras.cmake"
"${__GlobalConfig_build_dir}/${INSTALL_CMAKE_NAMESPACE}ConfigVersion.cmake"
+ "${__GlobalConfig_build_dir}/${INSTALL_CMAKE_NAMESPACE}ConfigVersionImpl.cmake"
DESTINATION "${__GlobalConfig_install_dir}"
COMPONENT Devel
)
@@ -199,6 +209,7 @@ qt_copy_or_install(FILES
cmake/QtBuildInformation.cmake
cmake/QtCMakeHelpers.cmake
cmake/QtCMakeVersionHelpers.cmake
+ cmake/QtCMakePackageVersionFile.cmake.in
cmake/QtCompilerFlags.cmake
cmake/QtCompilerOptimization.cmake
cmake/QtConfigDependencies.cmake.in
diff --git a/cmake/QtCMakeHelpers.cmake b/cmake/QtCMakeHelpers.cmake
index e47d9878e1..d1d4fb9054 100644
--- a/cmake/QtCMakeHelpers.cmake
+++ b/cmake/QtCMakeHelpers.cmake
@@ -184,3 +184,25 @@ function(qt_internal_get_target_property out_var target property)
endif()
set(${out_var} "${result}" PARENT_SCOPE)
endfunction()
+
+# Creates a wrapper ConfigVersion.cmake file to be loaded by find_package when checking for
+# compatible versions. It expects a ConfigVersionImpl.cmake file in the same directory which will
+# be included to do the regular version checks.
+# The version check result might be overridden by the wrapper.
+# package_name is used by the content of the wrapper file to include the basic package version file.
+# example: Qt6Gui
+# out_path should be the build path where the write the file.
+function(qt_internal_write_qt_package_version_file package_name out_path)
+ set(extra_code "")
+
+ # Need to check for FEATURE_developer_build as well, because QT_FEATURE_developer_build is not
+ # yet available when configuring the file for the BuildInternals package.
+ if(FEATURE_developer_build OR QT_FEATURE_developer_build)
+ string(APPEND extra_code "
+# Disabling version check because Qt was configured with -developer-build.
+set(__qt_disable_package_version_check TRUE)
+set(__qt_disable_package_version_check_due_to_developer_build TRUE)")
+ endif()
+
+ configure_file("${QT_CMAKE_DIR}/QtCMakePackageVersionFile.cmake.in" "${out_path}" @ONLY)
+endfunction()
diff --git a/cmake/QtCMakePackageVersionFile.cmake.in b/cmake/QtCMakePackageVersionFile.cmake.in
new file mode 100644
index 0000000000..f668e614c5
--- /dev/null
+++ b/cmake/QtCMakePackageVersionFile.cmake.in
@@ -0,0 +1,55 @@
+# Include the basic version config file to get results of regular version checking.
+include("${CMAKE_CURRENT_LIST_DIR}/@package_name@ConfigVersionImpl.cmake")
+
+set(__qt_disable_package_version_check FALSE)
+
+# Allow to opt out of the version check.
+if(QT_NO_PACKAGE_VERSION_CHECK)
+ set(__qt_disable_package_version_check TRUE)
+endif()
+
+@extra_code@
+
+if((NOT PACKAGE_VERSION_COMPATIBLE) OR PACKAGE_VERSION_UNSUITABLE)
+ set(__qt_package_version_incompatible TRUE)
+else()
+ set(__qt_package_version_incompatible FALSE)
+endif()
+
+if(__qt_disable_package_version_check)
+ # Warn if version check is disabled regardless if it's a Qt repo build or user project build.
+ # Allow to opt out of warning.
+ if(__qt_package_version_incompatible AND NOT QT_NO_PACKAGE_VERSION_INCOMPATIBLE_WARNING)
+ message(WARNING
+ "Package ${PACKAGE_FIND_NAME} with version ${PACKAGE_VERSION} was accepted as "
+ "compatible because QT_NO_PACKAGE_VERSION_CHECK was set to TRUE. There is no guarantee "
+ "the build will succeed. You can silence this warning by passing "
+ "-DQT_NO_PACKAGE_VERSION_INCOMPATIBLE_WARNING=TRUE")
+ endif()
+
+ # Mark version as compatible. This is how we disable the version check.
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ unset(PACKAGE_VERSION_UNSUITABLE)
+
+# If QT_REPO_MODULE_VERSION is set, that means we are building a Qt repo. Show message that one can
+# disable the check if they need to.
+elseif(QT_REPO_MODULE_VERSION AND __qt_package_version_incompatible)
+ if(PACKAGE_FIND_VERSION_RANGE)
+ set(__qt_package_version_message_prefix "Version range ${PACKAGE_FIND_VERSION_RANGE}")
+ else()
+ set(__qt_package_version_message_prefix "Version ${PACKAGE_FIND_VERSION}")
+ endif()
+
+ message(WARNING
+ "${__qt_package_version_message_prefix} of package ${PACKAGE_FIND_NAME} was requested but "
+ "an incompatible version was found: ${PACKAGE_VERSION}. You can pass "
+ "-DQT_NO_PACKAGE_VERSION_CHECK=TRUE to disable the version check and force the "
+ "incompatible version to be used. There is no guarantee the build will succeed. "
+ "Use at your own risk. "
+ "You can silence this warning by passing -DQT_NO_PACKAGE_VERSION_INCOMPATIBLE_WARNING=TRUE")
+endif()
+
+unset(__qt_disable_package_version_check)
+unset(__qt_disable_package_version_check_due_to_developer_build)
+unset(__qt_package_version_message_prefix)
+unset(__qt_package_version_incompatible)
diff --git a/cmake/QtModuleHelpers.cmake b/cmake/QtModuleHelpers.cmake
index dba0b27e98..85ee910c9d 100644
--- a/cmake/QtModuleHelpers.cmake
+++ b/cmake/QtModuleHelpers.cmake
@@ -649,13 +649,18 @@ set(QT_LIBINFIX \"${QT_LIBINFIX}\")")
endif()
write_basic_package_version_file(
- "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake"
+ "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersionImpl.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
+ qt_internal_write_qt_package_version_file(
+ "${INSTALL_CMAKE_NAMESPACE}${target}"
+ "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake"
+ )
qt_install(FILES
"${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}Config.cmake"
"${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake"
+ "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersionImpl.cmake"
${extra_cmake_files}
DESTINATION "${config_install_dir}"
COMPONENT Devel
diff --git a/cmake/QtPluginHelpers.cmake b/cmake/QtPluginHelpers.cmake
index e8b5a38f41..fe90a33b85 100644
--- a/cmake/QtPluginHelpers.cmake
+++ b/cmake/QtPluginHelpers.cmake
@@ -382,14 +382,19 @@ function(qt_internal_add_plugin target)
INSTALL_DESTINATION "${config_install_dir}"
)
write_basic_package_version_file(
- "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake"
+ "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersionImpl.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
+ qt_internal_write_qt_package_version_file(
+ "${INSTALL_CMAKE_NAMESPACE}${target}"
+ "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake"
+ )
qt_install(FILES
"${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}Config.cmake"
"${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake"
+ "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersionImpl.cmake"
DESTINATION "${config_install_dir}"
COMPONENT Devel
)
diff --git a/cmake/QtToolHelpers.cmake b/cmake/QtToolHelpers.cmake
index f28b2d27a4..c42209a83d 100644
--- a/cmake/QtToolHelpers.cmake
+++ b/cmake/QtToolHelpers.cmake
@@ -370,15 +370,20 @@ endif()
INSTALL_DESTINATION "${config_install_dir}"
)
write_basic_package_version_file(
- "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake"
+ "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersionImpl.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
ARCH_INDEPENDENT
)
+ qt_internal_write_qt_package_version_file(
+ "${INSTALL_CMAKE_NAMESPACE}${target}"
+ "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake"
+ )
qt_install(FILES
"${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}Config.cmake"
"${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake"
+ "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersionImpl.cmake"
DESTINATION "${config_install_dir}"
COMPONENT Devel
)