summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2020-10-30 17:42:34 +0100
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-11-03 13:06:14 +0100
commit72aab8b4875dc3b14ef4a72a881047f4ef619f3d (patch)
tree1f2269799daa7ccfaad64657cf1259780c96895d
parentaaabdf8457705be82fd368bb2320264a538d1161 (diff)
CMake: Bump the minimum required CMake version to build Qt to 3.18
Add a new function that returns the minimum CMake version required to build Qt. Pass that value to cmake_minimum_required() when building qtbase and its standalone tests. The minimum supported CMake version is read from qtbase/.cmake.conf and its value should be updated when the need arises. It's the main source of truth for all repos. Provide a way to lower the minimum CMake version at configure time by passing a value via QT_FORCE_MIN_CMAKE_VERSION. This is not an officially supported way of building Qt. If the specified version is lower than Qt's supported minimum, show a warning. Nevertheless the option is useful for testing how Qt builds with a different minimum CMake version due to different policies being enabled by default. Issue warnings for CMake versions that are higher than the minimum version but are known to cause issues when building Qt. A counterpart change is needed in qt5 to ensure the minimum CMake version is set at the proper time for top-level builds. Ideally we would use the same 'check the CMake minimum version` code in all our repositories, but that will cause lots of duplication because we can't really find_package() the code and doing something like include(../qtbase/foo.cmake) hardcodes assumptions about repo locations. So for now we don't bump the minimum version in child repo cmake_minimum_required calls (qtsvg, qtdeclarative, etc). Instead we record both the minimum supported version and the computed minimum version (in case a different version was forced) in QtBuildInternalsExtra.cmake. Then we require qtbase's computed min version in qt_build_repo_begin(). This won't set policies as cmake_minimum_required would, but at least it propagates what minimum CMake version should be used for child repos. We might still have to bump the versions in child repos at some point. Task-number: QTBUG-88086 Change-Id: Ida1c0d5d3e0fbb15d2aee9b68abab7a1648774b9 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Adam <cristian.adam@qt.io>
-rw-r--r--.cmake.conf1
-rw-r--r--CMakeLists.txt12
-rw-r--r--cmake/QtBaseConfigureTests.cmake1
-rw-r--r--cmake/QtBaseGlobalTargets.cmake1
-rw-r--r--cmake/QtBuildInternals/QtBuildInternalsConfig.cmake4
-rw-r--r--cmake/QtCMakeVersionHelpers.cmake102
-rw-r--r--cmake/QtPostProcessHelpers.cmake9
7 files changed, 128 insertions, 2 deletions
diff --git a/.cmake.conf b/.cmake.conf
index 9305480451..b8e9ae6735 100644
--- a/.cmake.conf
+++ b/.cmake.conf
@@ -1 +1,2 @@
set(QT_REPO_MODULE_VERSION "6.0.0")
+set(QT_MIN_SUPPORTED_CMAKE_VERSION "3.18")
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f900ef2abc..9cdfd96f5e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,14 @@
# special case skip regeneration
-cmake_minimum_required(VERSION 3.15.0)
+
+# Get the repo version and the minimum CMake version.
+include("${CMAKE_CURRENT_SOURCE_DIR}/.cmake.conf")
+
+if(NOT QT_SUPER_BUILD)
+ include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtCMakeVersionHelpers.cmake")
+ qt_internal_check_for_suitable_cmake_version()
+ qt_internal_get_computed_minimum_cmake_version(__qt_minimum_cmake_version)
+ cmake_minimum_required(VERSION ${__qt_minimum_cmake_version})
+endif()
# Run auto detection routines, but not when doing standalone tests. In that case, the detection
# results are taken from either QtBuildInternals or the qt.toolchain.cmake file. Also, inhibit
@@ -8,7 +17,6 @@ if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_SUPER_BUILD)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtAutoDetect.cmake)
endif()
-include(".cmake.conf")
project(QtBase
VERSION "${QT_REPO_MODULE_VERSION}"
DESCRIPTION "Qt Base Libraries"
diff --git a/cmake/QtBaseConfigureTests.cmake b/cmake/QtBaseConfigureTests.cmake
index c1aba357c2..50fc0c4fc0 100644
--- a/cmake/QtBaseConfigureTests.cmake
+++ b/cmake/QtBaseConfigureTests.cmake
@@ -149,6 +149,7 @@ endfunction()
qt_internal_print_cmake_darwin_info()
function(qt_internal_print_cmake_host_and_target_info)
+ message(STATUS "CMAKE_VERSION: \"${CMAKE_VERSION}\"")
message(STATUS "CMAKE_HOST_SYSTEM: \"${CMAKE_HOST_SYSTEM}\"")
message(STATUS "CMAKE_HOST_SYSTEM_NAME: \"${CMAKE_HOST_SYSTEM_NAME}\"")
message(STATUS "CMAKE_HOST_SYSTEM_VERSION: \"${CMAKE_HOST_SYSTEM_VERSION}\"")
diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake
index 2fd8b260a9..b6efee7ad6 100644
--- a/cmake/QtBaseGlobalTargets.cmake
+++ b/cmake/QtBaseGlobalTargets.cmake
@@ -154,6 +154,7 @@ qt_copy_or_install(FILES
cmake/QtBuild.cmake
cmake/QtBuildInformation.cmake
cmake/QtCMakeHelpers.cmake
+ cmake/QtCMakeVersionHelpers.cmake
cmake/QtCompatibilityHelpers.cmake
cmake/QtCompilerFlags.cmake
cmake/QtCompilerOptimization.cmake
diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
index 56e7e99d63..5bf4f4a567 100644
--- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
+++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
@@ -165,6 +165,10 @@ if(NOT QT_BUILD_INTERNALS_SKIP_SYSTEM_PREFIX_ADJUSTMENT)
endif()
macro(qt_build_internals_set_up_private_api)
+ # Check for the minimum CMake version.
+ include(QtCMakeVersionHelpers)
+ qt_internal_require_suitable_cmake_version()
+
# Qt specific setup common for all modules:
include(QtSetup)
include(FeatureSummary)
diff --git a/cmake/QtCMakeVersionHelpers.cmake b/cmake/QtCMakeVersionHelpers.cmake
new file mode 100644
index 0000000000..274af52cd1
--- /dev/null
+++ b/cmake/QtCMakeVersionHelpers.cmake
@@ -0,0 +1,102 @@
+# Returns the minimum supported CMake version required to build Qt as originally advertised by Qt.
+function(qt_internal_get_qt_supported_minimum_cmake_version out_var)
+ # QT_MIN_SUPPORTED_CMAKE_VERSION is set either in .cmake.conf or in QtBuildInternalsExtras.cmake
+ # when building a child repo.
+ set(supported_version "${QT_MIN_SUPPORTED_CMAKE_VERSION}")
+ set(${out_var} "${supported_version}" PARENT_SCOPE)
+endfunction()
+
+# Returns the computed minimum supported CMake version required to build Qt.
+function(qt_internal_get_computed_minimum_cmake_version out_var)
+ qt_internal_get_qt_supported_minimum_cmake_version(min_supported_version)
+ set(computed_min_version "${min_supported_version}")
+
+ # Set in QtBuildInternalsExtras.cmake.
+ if(QT_COMPUTED_MIN_CMAKE_VERSION)
+ set(computed_min_version "${QT_COMPUTED_MIN_CMAKE_VERSION}")
+ endif()
+
+ # An explicit override for those that take it upon themselves to fix the build system
+ # when using a CMake version lower than the one officially supported.
+ # Also useful for build testing locally with different minimum versions to observe different
+ # policy behaviors.
+ if(QT_FORCE_MIN_CMAKE_VERSION)
+ set(computed_min_version "${QT_FORCE_MIN_CMAKE_VERSION}")
+ endif()
+
+ set(${out_var} "${computed_min_version}" PARENT_SCOPE)
+endfunction()
+
+function(qt_internal_check_for_suitable_cmake_version)
+ # Implementation note.
+ # The very first cmake_required_version() call can't be placed in an include()d file.
+ # It causes CMake to fail to configure with 'No cmake_minimum_required command is present.'
+ # The first cmake_required_version() must be called directly in the top-level CMakeLists.txt
+ # file.
+ # That's why this function only handles output of warnings, and doesn't try to set the required
+ # version.
+ qt_internal_check_minimum_cmake_version()
+ qt_internal_warn_about_unsuitable_cmake_versions()
+endfunction()
+
+# Function to be used in child repos like qtsvg to require a minimum CMake version.
+#
+# Such repos don't have the required version information at cmake_required_version() time, that's
+# why we provide this function to be called at a time when the info is available.
+function(qt_internal_require_suitable_cmake_version)
+ qt_internal_check_for_suitable_cmake_version()
+ qt_internal_get_computed_minimum_cmake_version(computed_min_version)
+
+ if(CMAKE_VERSION VERSION_LESS computed_min_version)
+ message(FATAL_ERROR "CMake ${computed_min_version} or higher is required. "
+ "You are running version ${CMAKE_VERSION}")
+ endif()
+endfunction()
+
+function(qt_internal_check_minimum_cmake_version)
+ qt_internal_get_qt_supported_minimum_cmake_version(min_supported_version)
+ qt_internal_get_computed_minimum_cmake_version(computed_min_version)
+
+ if(NOT min_supported_version STREQUAL computed_min_version
+ AND computed_min_version VERSION_LESS min_supported_version)
+ message(WARNING
+ "The minimum required CMake version to build Qt is '${min_supported_version}'. "
+ "You have explicitly chosen to require a lower minimum CMake version, namely '${computed_min_version}'. "
+ "Building Qt with such a CMake version is not officially supported. Use at your own risk.")
+ endif()
+endfunction()
+
+function(qt_internal_warn_about_unsuitable_cmake_versions)
+ set(unsuitable_versions "")
+
+ # Touching a library's source file causes unnecessary rebuilding of unrelated targets.
+ # https://gitlab.kitware.com/cmake/cmake/-/issues/21020
+ list(APPEND unsuitable_versions "3.18.0")
+
+ # Ninja Multi-Config race condition overrides response files of different configurations
+ # https://gitlab.kitware.com/cmake/cmake/-/issues/20961
+ # https://gitlab.kitware.com/cmake/cmake/-/issues/21050 (follow up issue)
+ list(APPEND unsuitable_versions "3.18.1")
+
+ # AUTOMOC dependencies are not properly created when using Ninja Multi-Config.
+ # https://gitlab.kitware.com/cmake/cmake/-/issues/21118
+ #
+ # Also until 3.18.2 inclusive, AUTOMOC dependencies are out-of-date if a previously header
+ # disappears (for example when upgrading a compiler)
+ # https://gitlab.kitware.com/cmake/cmake/-/issues/21136
+ #
+ # Also multi-arch PCH doesn't work on iOS. Can't quite find the original upstream CMake issue
+ # but the Qt one was detected at https://codereview.qt-project.org/c/qt/qt5/+/310947
+ # And a follow up issue regarding PCH and -fembed-bitcode failing.
+ # https://gitlab.kitware.com/cmake/cmake/-/issues/21163
+ list(APPEND unsuitable_versions "3.18.2")
+
+ foreach(unsuitable_version ${unsuitable_versions})
+ if(CMAKE_VERSION VERSION_EQUAL unsuitable_version)
+ message(WARNING
+ "The CMake version you are using is known to cause issues when building Qt. "
+ "Please upgrade to a newer version. "
+ "CMake version used: '${unsuitable_version}'")
+ endif()
+ endforeach()
+endfunction()
diff --git a/cmake/QtPostProcessHelpers.cmake b/cmake/QtPostProcessHelpers.cmake
index dbcb33b62f..ae6610ec67 100644
--- a/cmake/QtPostProcessHelpers.cmake
+++ b/cmake/QtPostProcessHelpers.cmake
@@ -543,6 +543,15 @@ endif()\n")
"set(QT_QPA_DEFAULT_PLATFORM \"${QT_QPA_DEFAULT_PLATFORM}\" CACHE STRING \"\")\n")
endif()
+ # Save the supported and computed minimum CMake versions to ensure the same minimum is
+ # checked for when building other child repos (qtsvg, etc).
+ qt_internal_get_qt_supported_minimum_cmake_version(min_supported_version)
+ qt_internal_get_computed_minimum_cmake_version(computed_min_version)
+ string(APPEND QT_EXTRA_BUILD_INTERNALS_VARS
+ "set(QT_MIN_SUPPORTED_CMAKE_VERSION \"${min_supported_version}\" CACHE STRING \"Minimum supported CMake version required to build Qt\")\n")
+ string(APPEND QT_EXTRA_BUILD_INTERNALS_VARS
+ "set(QT_COMPUTED_MIN_CMAKE_VERSION \"${computed_min_version}\" CACHE STRING \"Computed minimum CMake version required to build Qt\")\n")
+
# Rpath related things that need to be re-used when building other repos.
string(APPEND QT_EXTRA_BUILD_INTERNALS_VARS
"set(CMAKE_INSTALL_RPATH \"${CMAKE_INSTALL_RPATH}\" CACHE STRING \"\")\n")