Add some utilities for UNITY_BUILD

- The following commands accepts NO_UNITY_BUILD, and
  NO_UNITY_BUILD_SOURCES arguments to opt out of the unity build, and
  to exclude some source files from unity build, respectively.
  - qt_internal_add_executable
  - qt_internal_add_module
  - qt_internal_add_plugin
  - qt_internal_add_tool
  - qt_internal_extend_target
  - qt_internal_add_common_qt_library_helper
  - qt_internal_add_cmake_library
  - qt_internal_add_simd_part
- Unity build is disabled by default in these:
  - qt_internal_add_test
  - qt_internal_add_test_helper
  - qt_internal_add_benchmark
  - qt_internal_add_3rdparty_library
- qt_update_ignore_pch_source also excludes the files from unity_build

Pick-to: 6.5
Task-number: QTBUG-109394
Change-Id: I5d0e7df633738310a015142a6c73fbb78b6c3467
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Amir Masoud Abdol 2023-01-31 14:05:16 +01:00
parent 66a1a71f1f
commit 31518f1a4e
12 changed files with 96 additions and 6 deletions

View File

@ -4,6 +4,7 @@ macro(qt_internal_get_add_library_option_args option_args)
STATIC STATIC
MODULE MODULE
INTERFACE INTERFACE
NO_UNITY_BUILD
) )
endmacro() endmacro()
@ -49,7 +50,18 @@ function(qt_internal_add_common_qt_library_helper target)
set(arg_MODULE STATIC) set(arg_MODULE STATIC)
endif() 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}) _qt_internal_add_library(${target} ${arg_STATIC} ${arg_SHARED} ${arg_MODULE} ${arg_INTERFACE})
if(arg_NO_UNITY_BUILD)
set_property(TARGET "${target}" PROPERTY UNITY_BUILD OFF)
endif()
qt_internal_mark_as_internal_library(${target}) qt_internal_mark_as_internal_library(${target})
endfunction() endfunction()
@ -98,6 +110,12 @@ function(qt_internal_add_cmake_library target)
) )
endif() 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}" qt_internal_extend_target("${target}"
SOURCES ${arg_SOURCES} SOURCES ${arg_SOURCES}
INCLUDE_DIRECTORIES INCLUDE_DIRECTORIES
@ -119,6 +137,8 @@ function(qt_internal_add_cmake_library target)
MOC_OPTIONS ${arg_MOC_OPTIONS} MOC_OPTIONS ${arg_MOC_OPTIONS}
ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS} ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS}
DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS} DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS}
NO_UNITY_BUILD_SOURCES ${arg_NO_UNITY_BUILD_SOURCES}
${arg_NO_UNITY_BUILD}
) )
endfunction() endfunction()
@ -240,6 +260,7 @@ function(qt_internal_add_3rdparty_library target)
MOC_OPTIONS ${arg_MOC_OPTIONS} MOC_OPTIONS ${arg_MOC_OPTIONS}
ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS} ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS}
DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS} DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS}
NO_UNITY_BUILD
) )
if(NOT BUILD_SHARED_LIBS OR arg_INSTALL) if(NOT BUILD_SHARED_LIBS OR arg_INSTALL)

View File

@ -263,6 +263,7 @@ qt_copy_or_install(FILES
cmake/QtPostProcess.cmake cmake/QtPostProcess.cmake
cmake/QtPostProcessHelpers.cmake cmake/QtPostProcessHelpers.cmake
cmake/QtPrecompiledHeadersHelpers.cmake cmake/QtPrecompiledHeadersHelpers.cmake
cmake/QtUnityBuildHelpers.cmake
cmake/QtPriHelpers.cmake cmake/QtPriHelpers.cmake
cmake/QtPrlHelpers.cmake cmake/QtPrlHelpers.cmake
cmake/QtPlatformTargetHelpers.cmake cmake/QtPlatformTargetHelpers.cmake

View File

@ -459,6 +459,7 @@ set(__default_private_args
DISABLE_AUTOGEN_TOOLS DISABLE_AUTOGEN_TOOLS
ENABLE_AUTOGEN_TOOLS ENABLE_AUTOGEN_TOOLS
PLUGIN_TYPES PLUGIN_TYPES
NO_UNITY_BUILD_SOURCES
) )
set(__default_public_args set(__default_public_args
PUBLIC_LIBRARIES PUBLIC_LIBRARIES
@ -487,6 +488,7 @@ set(__qt_internal_add_executable_optional_args
DELAY_RC DELAY_RC
DELAY_TARGET_INFO DELAY_TARGET_INFO
QT_APP QT_APP
NO_UNITY_BUILD
) )
set(__qt_internal_add_executable_single_args set(__qt_internal_add_executable_single_args
CORE_LIBRARY CORE_LIBRARY
@ -520,6 +522,7 @@ include(QtModuleHelpers)
include(QtNoLinkTargetHelpers) include(QtNoLinkTargetHelpers)
include(QtPluginHelpers) include(QtPluginHelpers)
include(QtPrecompiledHeadersHelpers) include(QtPrecompiledHeadersHelpers)
include(QtUnityBuildHelpers)
include(QtPkgConfigHelpers) include(QtPkgConfigHelpers)
include(QtPriHelpers) include(QtPriHelpers)
include(QtPrlHelpers) include(QtPrlHelpers)

View File

@ -110,6 +110,12 @@ function(qt_internal_add_executable name)
"removed in a future Qt version. Use the LIBRARIES option instead.") "removed in a future Qt version. Use the LIBRARIES option instead.")
endif() 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("${name}" qt_internal_extend_target("${name}"
SOURCES ${arg_SOURCES} SOURCES ${arg_SOURCES}
INCLUDE_DIRECTORIES ${private_includes} INCLUDE_DIRECTORIES ${private_includes}
@ -128,6 +134,8 @@ function(qt_internal_add_executable name)
MOC_OPTIONS ${arg_MOC_OPTIONS} MOC_OPTIONS ${arg_MOC_OPTIONS}
ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS} ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS}
DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS} DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS}
NO_UNITY_BUILD_SOURCES ${arg_NO_UNITY_BUILD_SOURCES}
${arg_NO_UNITY_BUILD}
) )
set_target_properties("${name}" PROPERTIES set_target_properties("${name}" PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${arg_OUTPUT_DIRECTORY}" RUNTIME_OUTPUT_DIRECTORY "${arg_OUTPUT_DIRECTORY}"

View File

@ -18,6 +18,7 @@ macro(qt_internal_get_internal_add_module_keywords option_args single_args multi
NO_HEADERSCLEAN_CHECK NO_HEADERSCLEAN_CHECK
GENERATE_CPP_EXPORTS GENERATE_CPP_EXPORTS
GENERATE_PRIVATE_CPP_EXPORTS GENERATE_PRIVATE_CPP_EXPORTS
NO_UNITY_BUILD
) )
set(${single_args} set(${single_args}
MODULE_INCLUDE_NAME MODULE_INCLUDE_NAME
@ -572,6 +573,12 @@ function(qt_internal_add_module target)
qt_internal_add_repo_local_defines("${target}") qt_internal_add_repo_local_defines("${target}")
if(arg_NO_UNITY_BUILD)
set(arg_NO_UNITY_BUILD NO_UNITY_BUILD)
else()
set(arg_NO_UNITY_BUILD "")
endif()
if(NOT arg_EXTERNAL_HEADERS) if(NOT arg_EXTERNAL_HEADERS)
set(arg_EXTERNAL_HEADERS "") set(arg_EXTERNAL_HEADERS "")
endif() endif()
@ -607,6 +614,8 @@ function(qt_internal_add_module target)
DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS} DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS}
PRECOMPILED_HEADER ${arg_PRECOMPILED_HEADER} PRECOMPILED_HEADER ${arg_PRECOMPILED_HEADER}
NO_PCH_SOURCES ${arg_NO_PCH_SOURCES} NO_PCH_SOURCES ${arg_NO_PCH_SOURCES}
NO_UNITY_BUILD_SOURCES ${arg_NO_UNITY_BUILD_SOURCES}
${arg_NO_UNITY_BUILD}
) )
# The public module define is not meant to be used when building the module itself, # The public module define is not meant to be used when building the module itself,

View File

@ -8,6 +8,7 @@ macro(qt_internal_get_internal_add_plugin_keywords option_args single_args multi
EXCEPTIONS EXCEPTIONS
ALLOW_UNDEFINED_SYMBOLS ALLOW_UNDEFINED_SYMBOLS
SKIP_INSTALL SKIP_INSTALL
NO_UNITY_BUILD
) )
set(${single_args} set(${single_args}
OUTPUT_DIRECTORY OUTPUT_DIRECTORY
@ -305,6 +306,12 @@ function(qt_internal_add_plugin target)
endif() endif()
endif() endif()
if(arg_NO_UNITY_BUILD)
set(arg_NO_UNITY_BUILD NO_UNITY_BUILD)
else()
set(arg_NO_UNITY_BUILD "")
endif()
set_property(TARGET "${target}" PROPERTY QT_DEFAULT_PLUGIN "${_default_plugin}") set_property(TARGET "${target}" PROPERTY QT_DEFAULT_PLUGIN "${_default_plugin}")
set_property(TARGET "${target}" APPEND PROPERTY EXPORT_PROPERTIES "QT_PLUGIN_CLASS_NAME;QT_PLUGIN_TYPE;QT_MODULE;QT_DEFAULT_PLUGIN") set_property(TARGET "${target}" APPEND PROPERTY EXPORT_PROPERTIES "QT_PLUGIN_CLASS_NAME;QT_PLUGIN_TYPE;QT_MODULE;QT_DEFAULT_PLUGIN")
@ -347,6 +354,8 @@ function(qt_internal_add_plugin target)
MOC_OPTIONS ${arg_MOC_OPTIONS} MOC_OPTIONS ${arg_MOC_OPTIONS}
ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS} ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS}
DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS} DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS}
NO_UNITY_BUILD_SOURCES ${arg_NO_UNITY_BUILD_SOURCES}
${arg_NO_UNITY_BUILD}
) )
qt_internal_add_repo_local_defines("${target}") qt_internal_add_repo_local_defines("${target}")

View File

@ -19,7 +19,9 @@ endfunction()
function(qt_update_ignore_pch_source target sources) function(qt_update_ignore_pch_source target sources)
if (sources) if (sources)
set_source_files_properties(${sources} PROPERTIES SKIP_PRECOMPILE_HEADERS ON) set_source_files_properties(${sources} PROPERTIES
SKIP_PRECOMPILE_HEADERS ON
SKIP_UNITY_BUILD_INCLUSION ON)
endif() endif()
endfunction() endfunction()

View File

@ -98,7 +98,9 @@ function(qt_internal_add_simd_part target)
${arg_COMPILE_FLAGS} ${arg_COMPILE_FLAGS}
) )
endforeach() endforeach()
set_source_files_properties(${arg_SOURCES} PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE) set_source_files_properties(${arg_SOURCES} PROPERTIES
SKIP_PRECOMPILE_HEADERS TRUE
SKIP_UNITY_BUILD_INCLUSION TRUE)
target_sources(${target} PRIVATE ${arg_SOURCES}) target_sources(${target} PRIVATE ${arg_SOURCES})
else() else()
if(QT_CMAKE_DEBUG_EXTEND_TARGET) if(QT_CMAKE_DEBUG_EXTEND_TARGET)

View File

@ -35,7 +35,9 @@ function(qt_internal_extend_target target)
return() return()
endif() endif()
set(option_args "") set(option_args
NO_UNITY_BUILD
)
set(single_args set(single_args
PRECOMPILED_HEADER PRECOMPILED_HEADER
) )
@ -211,6 +213,7 @@ function(qt_internal_extend_target target)
qt_update_precompiled_header("${target}" "${arg_PRECOMPILED_HEADER}") qt_update_precompiled_header("${target}" "${arg_PRECOMPILED_HEADER}")
qt_update_ignore_pch_source("${target}" "${arg_NO_PCH_SOURCES}") 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) ## Ignore objective-c files for PCH (not supported atm)
qt_ignore_pch_obj_c_sources("${target}" "${arg_SOURCES}") qt_ignore_pch_obj_c_sources("${target}" "${arg_SOURCES}")
@ -230,6 +233,10 @@ function(qt_internal_extend_target target)
set_property(TARGET ${target} APPEND PROPERTY set_property(TARGET ${target} APPEND PROPERTY
${sources_property} "${arg_CONDITION_INDEPENDENT_SOURCES}") ${sources_property} "${arg_CONDITION_INDEPENDENT_SOURCES}")
endif() endif()
if(arg_NO_UNITY_BUILD)
set_target_properties(${target} PROPERTIES UNITY_BUILD OFF)
endif()
endfunction() endfunction()
function(qt_is_imported_target target out_var) function(qt_is_imported_target target out_var)

View File

@ -37,6 +37,7 @@ function(qt_internal_add_benchmark target)
qt_internal_add_executable(${target} qt_internal_add_executable(${target}
NO_INSTALL # we don't install benchmarks NO_INSTALL # we don't install benchmarks
NO_UNITY_BUILD # excluded by default
OUTPUT_DIRECTORY "${arg_OUTPUT_DIRECTORY}" # avoid polluting bin directory OUTPUT_DIRECTORY "${arg_OUTPUT_DIRECTORY}" # avoid polluting bin directory
${exec_args} ${exec_args}
) )
@ -121,6 +122,7 @@ function(qt_internal_add_manual_test target)
qt_internal_add_executable(${target} qt_internal_add_executable(${target}
NO_INSTALL # we don't install benchmarks NO_INSTALL # we don't install benchmarks
NO_UNITY_BUILD
OUTPUT_DIRECTORY "${arg_OUTPUT_DIRECTORY}" # avoid polluting bin directory OUTPUT_DIRECTORY "${arg_OUTPUT_DIRECTORY}" # avoid polluting bin directory
${exec_args} ${exec_args}
) )
@ -362,7 +364,9 @@ function(qt_internal_add_test_to_batch batch_name name)
LINK_OPTIONS ${arg_LINK_OPTIONS} LINK_OPTIONS ${arg_LINK_OPTIONS}
MOC_OPTIONS ${arg_MOC_OPTIONS} MOC_OPTIONS ${arg_MOC_OPTIONS}
ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS} ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS}
DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS}) DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS}
NO_UNITY_BUILD # Tests should not be built using UNITY_BUILD
)
foreach(source ${arg_SOURCES}) foreach(source ${arg_SOURCES})
# We define the test name which is later used to launch this test using # We define the test name which is later used to launch this test using
@ -527,6 +531,7 @@ function(qt_internal_add_test name)
MOC_OPTIONS ${arg_MOC_OPTIONS} MOC_OPTIONS ${arg_MOC_OPTIONS}
ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS} ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS}
DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS} DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS}
NO_UNITY_BUILD # Tests should not be built using UNITY_BUILD
) )
qt_internal_add_repo_local_defines(${name}) qt_internal_add_repo_local_defines(${name})
@ -908,7 +913,9 @@ function(qt_internal_add_test_helper name)
endif() endif()
endif() endif()
qt_internal_add_executable("${name}" NO_INSTALL ${extra_args_to_pass} ${forward_args}) qt_internal_add_executable("${name}" NO_INSTALL
NO_UNITY_BUILD # excluded by default
${extra_args_to_pass} ${forward_args})
# Disable the QT_NO_NARROWING_CONVERSIONS_IN_CONNECT define for test helpers # Disable the QT_NO_NARROWING_CONVERSIONS_IN_CONNECT define for test helpers
qt_internal_undefine_global_definition(${name} QT_NO_NARROWING_CONVERSIONS_IN_CONNECT) qt_internal_undefine_global_definition(${name} QT_NO_NARROWING_CONVERSIONS_IN_CONNECT)

View File

@ -37,7 +37,12 @@
# linked to the executable target by default. # linked to the executable target by default.
function(qt_internal_add_tool target_name) function(qt_internal_add_tool target_name)
qt_tool_target_to_name(name ${target_name}) qt_tool_target_to_name(name ${target_name})
set(option_keywords NO_INSTALL USER_FACING INSTALL_VERSIONED_LINK EXCEPTIONS) set(option_keywords
NO_INSTALL
USER_FACING
INSTALL_VERSIONED_LINK
EXCEPTIONS
NO_UNITY_BUILD)
set(one_value_keywords set(one_value_keywords
TOOLS_TARGET TOOLS_TARGET
INSTALL_DIR INSTALL_DIR
@ -88,6 +93,12 @@ function(qt_internal_add_tool target_name)
qt_internal_library_deprecation_level(deprecation_define) qt_internal_library_deprecation_level(deprecation_define)
if(arg_NO_UNITY_BUILD)
set(arg_NO_UNITY_BUILD NO_UNITY_BUILD)
else()
set(arg_NO_UNITY_BUILD "")
endif()
qt_internal_add_executable("${target_name}" qt_internal_add_executable("${target_name}"
OUTPUT_DIRECTORY "${output_dir}" OUTPUT_DIRECTORY "${output_dir}"
${exceptions} ${exceptions}
@ -113,6 +124,8 @@ function(qt_internal_add_tool target_name)
TARGET_DESCRIPTION "${arg_TARGET_DESCRIPTION}" TARGET_DESCRIPTION "${arg_TARGET_DESCRIPTION}"
TARGET_COMPANY "${arg_TARGET_COMPANY}" TARGET_COMPANY "${arg_TARGET_COMPANY}"
TARGET_COPYRIGHT "${arg_TARGET_COPYRIGHT}" TARGET_COPYRIGHT "${arg_TARGET_COPYRIGHT}"
NO_UNITY_BUILD_SOURCES "${arg_NO_UNITY_BUILD_SOURCES}"
${arg_NO_UNITY_BUILD}
) )
qt_internal_add_target_aliases("${target_name}") qt_internal_add_target_aliases("${target_name}")
_qt_internal_apply_strict_cpp("${target_name}") _qt_internal_apply_strict_cpp("${target_name}")

View File

@ -0,0 +1,8 @@
# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
function(qt_update_ignore_unity_build_sources target sources)
if (sources)
set_source_files_properties(${sources} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
endif()
endfunction()