diff --git a/cmake/Qt3rdPartyLibraryHelpers.cmake b/cmake/Qt3rdPartyLibraryHelpers.cmake index 1eef71fe0f..dca360d074 100644 --- a/cmake/Qt3rdPartyLibraryHelpers.cmake +++ b/cmake/Qt3rdPartyLibraryHelpers.cmake @@ -50,12 +50,6 @@ function(qt_internal_add_common_qt_library_helper target) set(arg_MODULE STATIC) endif() - if(arg_NO_UNITY_BUILD) - set(arg_NO_UNITY_BUILD NO_UNITY_BUILD) - else() - set(arg_NO_UNITY_BUILD "") - endif() - _qt_internal_add_library(${target} ${arg_STATIC} ${arg_SHARED} ${arg_MODULE} ${arg_INTERFACE}) if(arg_NO_UNITY_BUILD) @@ -85,6 +79,7 @@ function(qt_internal_add_cmake_library target) "${multi_args}" ) _qt_internal_validate_all_args_are_parsed(arg) + _qt_internal_validate_no_unity_build(arg) qt_remove_args(library_helper_args ARGS_TO_REMOVE @@ -110,12 +105,6 @@ function(qt_internal_add_cmake_library target) ) endif() - if(arg_NO_UNITY_BUILD) - set(arg_NO_UNITY_BUILD NO_UNITY_BUILD) - else() - set(arg_NO_UNITY_BUILD "") - endif() - qt_internal_extend_target("${target}" SOURCES ${arg_SOURCES} INCLUDE_DIRECTORIES @@ -137,8 +126,7 @@ function(qt_internal_add_cmake_library target) MOC_OPTIONS ${arg_MOC_OPTIONS} ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS} DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS} - NO_UNITY_BUILD_SOURCES ${arg_NO_UNITY_BUILD_SOURCES} - ${arg_NO_UNITY_BUILD} + NO_UNITY_BUILD # Disabled by default ) endfunction() @@ -167,6 +155,7 @@ function(qt_internal_add_3rdparty_library target) "${multi_args}" ) _qt_internal_validate_all_args_are_parsed(arg) + _qt_internal_validate_no_unity_build(arg) qt_remove_args(library_helper_args ARGS_TO_REMOVE diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index bb067c3e92..2ac1db6daf 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -689,6 +689,8 @@ function(qt_internal_get_standalone_tests_config_file_name out_var) endfunction() macro(qt_build_tests) + set(CMAKE_UNITY_BUILD OFF) + if(QT_BUILD_STANDALONE_TESTS) # Find location of TestsConfig.cmake. These contain the modules that need to be # find_package'd when testing. @@ -759,6 +761,8 @@ macro(qt_build_tests) add_subdirectory(manual) endif() endif() + + set(CMAKE_UNITY_BUILD ${QT_UNITY_BUILD}) endmacro() function(qt_compute_relative_path_from_cmake_config_dir_to_prefix) @@ -973,6 +977,7 @@ macro(qt_examples_build_end) if(TARGET Qt::Widgets) qt_autogen_tools(${target} ENABLE_AUTOGEN_TOOLS "uic") endif() + set_target_properties(${target} PROPERTIES UNITY_BUILD OFF) endforeach() install(CODE " diff --git a/cmake/QtTargetHelpers.cmake b/cmake/QtTargetHelpers.cmake index 930fbc884f..b4cd5c81ae 100644 --- a/cmake/QtTargetHelpers.cmake +++ b/cmake/QtTargetHelpers.cmake @@ -212,11 +212,16 @@ function(qt_internal_extend_target target) DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS}) qt_update_precompiled_header("${target}" "${arg_PRECOMPILED_HEADER}") + ## Also exclude them from unity build qt_update_ignore_pch_source("${target}" "${arg_NO_PCH_SOURCES}") - qt_update_ignore_unity_build_sources("${target}" "${arg_NO_UNITY_BUILD_SOURCES}") ## Ignore objective-c files for PCH (not supported atm) qt_ignore_pch_obj_c_sources("${target}" "${arg_SOURCES}") + qt_update_ignore_unity_build_sources("${target}" "${arg_NO_UNITY_BUILD_SOURCES}") + if(arg_NO_UNITY_BUILD) + set_target_properties("${target}" PROPERTIES UNITY_BUILD OFF) + qt_update_ignore_unity_build_sources("${target}" "${arg_SOURCES}") + endif() else() if(QT_CMAKE_DEBUG_EXTEND_TARGET) message("qt_extend_target(${target} CONDITION ${arg_CONDITION} ...): Skipped") @@ -234,9 +239,6 @@ function(qt_internal_extend_target target) ${sources_property} "${arg_CONDITION_INDEPENDENT_SOURCES}") endif() - if(arg_NO_UNITY_BUILD) - set_target_properties(${target} PROPERTIES UNITY_BUILD OFF) - endif() endfunction() function(qt_is_imported_target target out_var) diff --git a/cmake/QtTestHelpers.cmake b/cmake/QtTestHelpers.cmake index 60b9687d2f..df477f53fe 100644 --- a/cmake/QtTestHelpers.cmake +++ b/cmake/QtTestHelpers.cmake @@ -15,6 +15,7 @@ function(qt_internal_add_benchmark target) "${__qt_internal_add_executable_multi_args}" ) _qt_internal_validate_all_args_are_parsed(arg) + _qt_internal_validate_no_unity_build(arg) qt_remove_args(exec_args ARGS_TO_REMOVE @@ -239,6 +240,8 @@ function(qt_internal_add_test_to_batch batch_name name) arg "${optional_args}" "${single_value_args}" "${multi_value_args}" ${ARGN}) qt_internal_prepare_test_target_flags(version_arg exceptions_text gui_text ${ARGN}) + _qt_internal_validate_no_unity_build(arg) + _qt_internal_test_batch_target_name(target) # Lazy-init the test batch @@ -324,6 +327,7 @@ function(qt_internal_add_test_to_batch batch_name name) ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS} DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS} NO_UNITY_BUILD # Tests should not be built using UNITY_BUILD + NO_UNITY_BUILD_SOURCES ${arg_SOURCES} ) foreach(source ${arg_SOURCES}) @@ -426,6 +430,7 @@ function(qt_internal_add_test name) "${multi_value_args}" ) _qt_internal_validate_all_args_are_parsed(arg) + _qt_internal_validate_no_unity_build(arg) set(batch_current_test FALSE) if(QT_BUILD_TESTS_BATCHED AND NOT arg_NO_BATCH AND NOT arg_QMLTEST AND NOT arg_MANUAL diff --git a/cmake/QtUnityBuildHelpers.cmake b/cmake/QtUnityBuildHelpers.cmake index 41062b027c..b66c6765ba 100644 --- a/cmake/QtUnityBuildHelpers.cmake +++ b/cmake/QtUnityBuildHelpers.cmake @@ -1,6 +1,15 @@ # Copyright (C) 2023 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause +# Check whether no unity build is requested where it is disabled by default. +function(_qt_internal_validate_no_unity_build prefix) + if(${prefix}_NO_UNITY_BUILD OR ${prefix}_NO_UNITY_BUILD_SOURCES) + message(WARNING + "Unity build is disabled by default for this target, and its sources. " + "You may remove the NO_UNITY_BUILD and/or NO_UNITY_BUILD_SOURCES arguments.") + endif() +endfunction() + function(qt_update_ignore_unity_build_sources target sources) if (sources) set_source_files_properties(${sources} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)