summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-07-06 17:55:30 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2021-08-04 16:03:08 +0200
commit9aa0d99e66b8be2be75d4f3b7fce2b94db9a1e32 (patch)
tree436a1e5f26939587caa21d1f0922b99640877113
parent07057188e3e42246cf006b43963d0bdcdaa159f5 (diff)
CMake: Bump min required CMake version for static Qt builds to 3.20
Building a static library Qt configuration will now require a minimum CMake version of 3.20. Qt builders and packagers can still opt out of the mentioned minimum required version by configuring Qt with QT_FORCE_MIN_CMAKE_VERSION. Such a Qt configuration is /NOT SUPPORTED/. To facilitate these changes, the minimum version check has been moved to happen after the BUILD_SHARED_LIBS option is computed by either QtAutoDetect.cmake or set by a user provided cmake toolchain file. Introduce a new QT_MIN_SUPPORTED_CMAKE_VERSION_FOR_STATIC_QT variable in .cmake.conf to mark the minimum version for a static Qt build. Pick-to: 6.2 Task-number: QTBUG-95018 Change-Id: Idc1875729f26a7c635b6bd26ac0c1be973917c13 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> Reviewed-by: Alexey Edelev <alexey.edelev@qt.io> Reviewed-by: Craig Scott <craig.scott@qt.io>
-rw-r--r--.cmake.conf1
-rw-r--r--CMakeLists.txt29
-rw-r--r--cmake/QtCMakeVersionHelpers.cmake40
3 files changed, 45 insertions, 25 deletions
diff --git a/.cmake.conf b/.cmake.conf
index 848faeb55d..ff95a9c186 100644
--- a/.cmake.conf
+++ b/.cmake.conf
@@ -3,6 +3,7 @@ set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "alpha1")
# Minimum requirement for building Qt
set(QT_MIN_SUPPORTED_CMAKE_VERSION "3.16")
+set(QT_MIN_SUPPORTED_CMAKE_VERSION_FOR_STATIC_QT "3.20")
# Policy settings for commands defined by qtbase. These will also be injected
# into the top level policy scope of each Qt module when building Qt so that
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 35ee14102e..c3dcc2f731 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,10 +28,6 @@ endif()
unset(build_dir_absolute)
unset(build_dir_realpath)
-# Early check to reduce chance of warning being lost in the output
-include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtCMakeVersionHelpers.cmake")
-qt_internal_check_for_suitable_cmake_version()
-
# 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
# auto-detection in a top-level build, because the top-level project file already includes it.
@@ -39,6 +35,7 @@ if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_SUPERBUILD)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtAutoDetect.cmake)
endif()
+# This call will load any provided cmake toolchain file.
project(QtBase
VERSION "${QT_REPO_MODULE_VERSION}"
DESCRIPTION "Qt Base Libraries"
@@ -46,6 +43,22 @@ project(QtBase
LANGUAGES CXX C ASM
)
+# Should this Qt be static or dynamically linked?
+option(BUILD_SHARED_LIBS "Build Qt statically or dynamically" ON)
+set(QT_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
+
+# This variable is also set in Qt6CoreConfigExtras.cmake, but it's not loaded when building
+# qtbase. Set it here so qt_add_plugin can compute the proper plugin flavor.
+set(QT6_IS_SHARED_LIBS_BUILD ${BUILD_SHARED_LIBS})
+
+# BUILD_SHARED_LIBS influences the minimum required CMake version. The value is set either by:
+# a cache variable provided on the configure command line
+# or set by QtAutoDetect.cmake depending on the platform
+# or specified via a toolchain file that is loaded by the project() call
+# or set by the option() call above
+include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtCMakeVersionHelpers.cmake")
+qt_internal_check_for_suitable_cmake_version()
+
if(NOT QT_BUILD_STANDALONE_TESTS)
## Add some paths to check for cmake modules:
list(PREPEND CMAKE_MODULE_PATH
@@ -77,14 +90,6 @@ endif()
qt_build_repo_begin()
if(NOT QT_BUILD_STANDALONE_TESTS)
- ## Should this Qt be static or dynamically linked?
- option(BUILD_SHARED_LIBS "Build Qt statically or dynamically" ON)
- set(QT_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
-
- # This variable is also set in Qt6CoreConfigExtras.cmake, but it's not loaded when building
- # qtbase. Set it here so qt_add_plugin can compute the proper plugin flavor.
- set(QT6_IS_SHARED_LIBS_BUILD ${BUILD_SHARED_LIBS})
-
## Should this Qt be built with Werror?
option(WARNINGS_ARE_ERRORS "Build Qt with warnings as errors" ${FEATURE_developer_build})
diff --git a/cmake/QtCMakeVersionHelpers.cmake b/cmake/QtCMakeVersionHelpers.cmake
index 4d4113bb43..31eb78b667 100644
--- a/cmake/QtCMakeVersionHelpers.cmake
+++ b/cmake/QtCMakeVersionHelpers.cmake
@@ -1,29 +1,40 @@
# 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)
+ if(NOT DEFINED BUILD_SHARED_LIBS)
+ message(FATAL_ERROR "BUILD_SHARED_LIBS is needed to decide the minimum CMake version. "
+ "It should have been set by this point.")
+ endif()
+
# QT_MIN_SUPPORTED_CMAKE_VERSION is set either in .cmake.conf or in QtBuildInternalsExtras.cmake
- # when building a child repo.
+ # when building a repo.
set(supported_version "${QT_MIN_SUPPORTED_CMAKE_VERSION}")
+
+ if(NOT BUILD_SHARED_LIBS)
+ set(supported_version "${QT_MIN_SUPPORTED_CMAKE_VERSION_FOR_STATIC_QT}")
+ endif()
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 in QtBuildInternalsExtras.cmake, which means it was already computed as part of qtbase
+ # configuration.
+ elseif(QT_COMPUTED_MIN_CMAKE_VERSION)
+ set(computed_min_version "${QT_COMPUTED_MIN_CMAKE_VERSION}")
+
+ # No override was given and the version was not computed before, thus initialize with the
+ # default minimum.
+ else()
+ qt_internal_get_qt_supported_minimum_cmake_version(min_supported_version)
+ set(computed_min_version "${min_supported_version}")
+ endif()
set(${out_var} "${computed_min_version}" PARENT_SCOPE)
endfunction()
@@ -64,7 +75,7 @@ function(qt_internal_check_for_suitable_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.
+# Function to be used in downstream repos like qtsvg to require a minimum CMake version.
#
# Such repos don't have the required version information at cmake_minimum_required() time, that's
# why we provide this function to be called at a time when the info is available.
@@ -73,8 +84,11 @@ function(qt_internal_require_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}")
+ message(FATAL_ERROR
+ "CMake ${computed_min_version} or higher is required. "
+ "You are running version ${CMAKE_VERSION} "
+ "\nQt requires newer CMake features to build correctly. You can lower the minimum "
+ "required version by passing a QT_FORCE_MIN_CMAKE_VERSION cache variable when configuring Qt.")
endif()
endfunction()