summaryrefslogtreecommitdiffstats
path: root/cmake/QtCMakePackageVersionFile.cmake.in
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 /cmake/QtCMakePackageVersionFile.cmake.in
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>
Diffstat (limited to 'cmake/QtCMakePackageVersionFile.cmake.in')
-rw-r--r--cmake/QtCMakePackageVersionFile.cmake.in55
1 files changed, 55 insertions, 0 deletions
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)