diff --git a/cmake/QtBuildInternalsExtra.cmake.in b/cmake/QtBuildInternalsExtra.cmake.in index 49d929b6662..2dc906b6c61 100644 --- a/cmake/QtBuildInternalsExtra.cmake.in +++ b/cmake/QtBuildInternalsExtra.cmake.in @@ -103,6 +103,10 @@ set(QT_BUILD_EXAMPLES_AS_EXTERNAL "@QT_BUILD_EXAMPLES_AS_EXTERNAL@" CACHE BOOL # Propagate usage of ccache. set(QT_USE_CCACHE @QT_USE_CCACHE@ CACHE BOOL "Enable the use of ccache") +# Propagate usage of unity build. +set(QT_UNITY_BUILD @QT_UNITY_BUILD@ CACHE BOOL "Enable unity (jumbo) build") +set(QT_UNITY_BUILD_BATCH_SIZE "@QT_UNITY_BUILD_BATCH_SIZE@" CACHE STRING "Unity build batch size") + # Propragate the value of WARNINGS_ARE_ERRORS. set(WARNINGS_ARE_ERRORS "@WARNINGS_ARE_ERRORS@" CACHE BOOL "Build Qt with warnings as errors") diff --git a/cmake/QtProcessConfigureArgs.cmake b/cmake/QtProcessConfigureArgs.cmake index e5b4b36d49c..0572fbbd5b8 100644 --- a/cmake/QtProcessConfigureArgs.cmake +++ b/cmake/QtProcessConfigureArgs.cmake @@ -135,6 +135,13 @@ while(NOT "${configure_args}" STREQUAL "") list(POP_FRONT configure_args version) is_valid_qt_hex_version("${arg}" "${version}") push("-DQT_DISABLE_DEPRECATED_UP_TO=${version}") + elseif(arg STREQUAL "-unity-build") + push("-DQT_UNITY_BUILD=ON") + # QT_UNITY_BUILD_BATCH_SIZE will be set to 8, CMake's default. + elseif(arg STREQUAL "-unity-build-batch-size") + list(POP_FRONT configure_args unity_build_batch_size) + is_non_empty_valid_arg("${arg}" "${unity_build_batch_size}") + push("-DQT_UNITY_BUILD_BATCH_SIZE=${unity_build_batch_size}") elseif(arg STREQUAL "--") # Everything after this argument will be passed to CMake verbatim. list(APPEND cmake_args "${configure_args}") diff --git a/cmake/QtSetup.cmake b/cmake/QtSetup.cmake index 7c5cfe90c96..a961baa9483 100644 --- a/cmake/QtSetup.cmake +++ b/cmake/QtSetup.cmake @@ -331,6 +331,13 @@ if(QT_USE_CCACHE) endif() endif() +option(QT_UNITY_BUILD "Enable unity (jumbo) build") +set(QT_UNITY_BUILD_BATCH_SIZE "8" CACHE STRING "Unity build batch size") +if(QT_UNITY_BUILD) + set(CMAKE_UNITY_BUILD ON) + set(CMAKE_UNITY_BUILD_BATCH_SIZE "${QT_UNITY_BUILD_BATCH_SIZE}") +endif() + # We need to clean up QT_FEATURE_*, but only once per configuration cycle get_property(qt_feature_clean GLOBAL PROPERTY _qt_feature_clean) if(NOT qt_feature_clean) diff --git a/cmake/configure-cmake-mapping.md b/cmake/configure-cmake-mapping.md index d4a9ede75ff..796c30c01cf 100644 --- a/cmake/configure-cmake-mapping.md +++ b/cmake/configure-cmake-mapping.md @@ -73,6 +73,8 @@ The following table describes the mapping of configure options to CMake argument | | | custom build steps for moc, uic, and rcc. | | | | This lacks support in CMake. | | -ccache | -DQT_USE_CCACHE=ON | | +| -unity-build | -DQT_UNITY_BUILD=ON | | +| -unity-build-batch-size | -DQT_UNITY_BUILD_BATCH_SIZE= | | | -make-tool | n/a | | | -mp | n/a | | | -warnings-are-errors | -DWARNINGS_ARE_ERRORS=ON | | diff --git a/config_help.txt b/config_help.txt index 9fc0b380424..c0b0b79b476 100644 --- a/config_help.txt +++ b/config_help.txt @@ -140,6 +140,10 @@ Build options: Force use of the GNU ld, GNU gold, LLVM/LLD or mold linker instead of default one (GCC and clang only) -ccache .............. Use the ccache compiler cache [no] (Unix only) + -unity-build ......... Enable Unity (Jumbo) build + -unity-build-batch-size + Maximum number of source files used by the unity build + to create unity source files [8] -warnings-are-errors . Treat warnings as errors [no; yes if -developer-build]