diff --git a/cmake/Qt3rdPartyLibraryHelpers.cmake b/cmake/Qt3rdPartyLibraryHelpers.cmake index 1eef71fe0fc..dca360d0744 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 e83663fd28e..d2c15a26337 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -669,6 +669,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. @@ -739,6 +741,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) @@ -953,6 +957,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 c712731f117..ca4faf5f676 100644 --- a/cmake/QtTargetHelpers.cmake +++ b/cmake/QtTargetHelpers.cmake @@ -208,11 +208,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") @@ -230,9 +235,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 8812b005524..21a119dcf5a 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 @@ -322,6 +325,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}) @@ -396,6 +400,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) if (NOT arg_OUTPUT_DIRECTORY) set(arg_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/cmake/QtUnityBuildHelpers.cmake b/cmake/QtUnityBuildHelpers.cmake index 41062b027c7..b66c6765ba3 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)