diff options
Diffstat (limited to 'cmake/QtPublicCMakeVersionHelpers.cmake')
-rw-r--r-- | cmake/QtPublicCMakeVersionHelpers.cmake | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/cmake/QtPublicCMakeVersionHelpers.cmake b/cmake/QtPublicCMakeVersionHelpers.cmake index 2b3c697f4c..638c9edc2d 100644 --- a/cmake/QtPublicCMakeVersionHelpers.cmake +++ b/cmake/QtPublicCMakeVersionHelpers.cmake @@ -4,6 +4,12 @@ function(__qt_internal_get_supported_min_cmake_version_for_using_qt out_var) set(${out_var} "${supported_version}" PARENT_SCOPE) endfunction() +function(__qt_internal_get_supported_min_cmake_version_for_using_qt_in_cmake_min_required out_var) + # This is recorded in Qt6ConfigExtras.cmake + set(supported_version "${QT_SUPPORTED_MIN_CMAKE_VERSION_FOR_USING_QT_IN_CMAKE_MIN_REQUIRED}") + set(${out_var} "${supported_version}" PARENT_SCOPE) +endfunction() + function(__qt_internal_get_computed_min_cmake_version_for_using_qt out_var) # Allow override when configuring user project. if(QT_FORCE_MIN_CMAKE_VERSION_FOR_USING_QT) @@ -20,6 +26,23 @@ function(__qt_internal_get_computed_min_cmake_version_for_using_qt out_var) set(${out_var} "${computed_min_version}" PARENT_SCOPE) endfunction() +function(__qt_internal_get_computed_min_cmake_version_for_using_qt_in_cmake_min_required out_var) + # Allow override when configuring user project. + if(QT_FORCE_MIN_CMAKE_VERSION_FOR_USING_QT_IN_CMAKE_MIN_REQUIRED) + set(computed_min_version "${QT_FORCE_MIN_CMAKE_VERSION_FOR_USING_QT_IN_CMAKE_MIN_REQUIRED}") + + # Set in QtConfigExtras.cmake. + elseif(QT_COMPUTED_MIN_CMAKE_VERSION_FOR_USING_QT_IN_CMAKE_MIN_REQUIRED) + set(computed_min_version + "${QT_COMPUTED_MIN_CMAKE_VERSION_FOR_USING_QT_IN_CMAKE_MIN_REQUIRED}") + else() + message(FATAL_ERROR + "Qt Developer error: Can't compute the version that should appear in cmake_minimum_required to use this Qt.") + endif() + + set(${out_var} "${computed_min_version}" PARENT_SCOPE) +endfunction() + function(__qt_internal_warn_if_min_cmake_version_not_met) __qt_internal_get_supported_min_cmake_version_for_using_qt(min_supported_version) __qt_internal_get_computed_min_cmake_version_for_using_qt(computed_min_version) @@ -34,6 +57,22 @@ function(__qt_internal_warn_if_min_cmake_version_not_met) endif() endfunction() +function(__qt_internal_warn_if_project_min_cmake_version_is_not_met) + __qt_internal_get_supported_min_cmake_version_for_using_qt_in_cmake_min_required( + min_supported_version) + __qt_internal_get_computed_min_cmake_version_for_using_qt_in_cmake_min_required( + computed_min_version) + + if(computed_min_version VERSION_LESS min_supported_version) + message(WARNING + "To use this Qt, the minimum CMake version that should appear in the project's " + "cmake_minimum_required() call should be: '${min_supported_version}'. " + "You have explicitly chosen to require a lower version: '${computed_min_version}'. " + "Using Qt with this version is not officially supported. Use at your own risk." + ) + endif() +endfunction() + function(__qt_internal_require_suitable_cmake_version_for_using_qt) # Skip the public project check if we're building a Qt repo because it's too early to do # it at find_package(Qt6) time. @@ -66,4 +105,23 @@ function(__qt_internal_require_suitable_cmake_version_for_using_qt) "project. Using Qt with this CMake version is not officially supported. " "Use at your own risk.") endif() + + + # Check that the project has a supported version specified in the last cmake_minimum_required + # call before the Qt6 package was found. + __qt_internal_warn_if_project_min_cmake_version_is_not_met() + __qt_internal_get_computed_min_cmake_version_for_using_qt_in_cmake_min_required( + computed_min_version) + + if(_qt_project_last_cmake_minimum_required_version VERSION_LESS computed_min_version) + message(FATAL_ERROR + "The last cmake_minimum_required() call before the Qt package was found had the " + "following version specified: '${_qt_project_last_cmake_minimum_required_version}' but " + "it needs to be ${computed_min_version} or higher to use Qt. " + "You can reduce the error into a warning by passing " + "-DQT_FORCE_MIN_CMAKE_VERSION_FOR_USING_QT_IN_CMAKE_MIN_REQUIRED=${_qt_project_last_cmake_minimum_required_version} " + "when configuring the project, but you do so at your own risk (it is not an officially " + "supported way of building Qt projects)." + ) + endif() endfunction() |