Improve the internal handling of unity build
- Removed the NO_UNITY_BUILD argument from commands that disable it by default. - Add a warning in case NO_UNITY_BUILD or NO_UNITY_BUILD_SOURCES is being used where it is already disabled, e.g., qt_internal_add_test - Exclude all sources of a target from unity build if NO_UNITY_BUILD is set on the target. This sounds a bit harsh, but I have noticed that sometimes the same source file can be included somewhere else, and some unexpected collision may occur. - qt_examples_build_end excludes all its examples from the unity build. - qt_build_test now sets the CMAKE_UNITY_BUILD to OFF before configuring the tests, and restore its value when done. Task-number: QTBUG-109394 Change-Id: Ia42e7dd5a5bfb151db241deb639325720fd91eec Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> (cherry picked from commit 360293623094a31586981206e59c92aa6235163d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
40a948ade1
commit
1ea96d8675
@ -50,12 +50,6 @@ 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)
|
if(arg_NO_UNITY_BUILD)
|
||||||
@ -85,6 +79,7 @@ function(qt_internal_add_cmake_library target)
|
|||||||
"${multi_args}"
|
"${multi_args}"
|
||||||
)
|
)
|
||||||
_qt_internal_validate_all_args_are_parsed(arg)
|
_qt_internal_validate_all_args_are_parsed(arg)
|
||||||
|
_qt_internal_validate_no_unity_build(arg)
|
||||||
|
|
||||||
qt_remove_args(library_helper_args
|
qt_remove_args(library_helper_args
|
||||||
ARGS_TO_REMOVE
|
ARGS_TO_REMOVE
|
||||||
@ -110,12 +105,6 @@ 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
|
||||||
@ -137,8 +126,7 @@ 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}
|
NO_UNITY_BUILD # Disabled by default
|
||||||
${arg_NO_UNITY_BUILD}
|
|
||||||
)
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
@ -167,6 +155,7 @@ function(qt_internal_add_3rdparty_library target)
|
|||||||
"${multi_args}"
|
"${multi_args}"
|
||||||
)
|
)
|
||||||
_qt_internal_validate_all_args_are_parsed(arg)
|
_qt_internal_validate_all_args_are_parsed(arg)
|
||||||
|
_qt_internal_validate_no_unity_build(arg)
|
||||||
|
|
||||||
qt_remove_args(library_helper_args
|
qt_remove_args(library_helper_args
|
||||||
ARGS_TO_REMOVE
|
ARGS_TO_REMOVE
|
||||||
|
@ -669,6 +669,8 @@ function(qt_internal_get_standalone_tests_config_file_name out_var)
|
|||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
macro(qt_build_tests)
|
macro(qt_build_tests)
|
||||||
|
set(CMAKE_UNITY_BUILD OFF)
|
||||||
|
|
||||||
if(QT_BUILD_STANDALONE_TESTS)
|
if(QT_BUILD_STANDALONE_TESTS)
|
||||||
# Find location of TestsConfig.cmake. These contain the modules that need to be
|
# Find location of TestsConfig.cmake. These contain the modules that need to be
|
||||||
# find_package'd when testing.
|
# find_package'd when testing.
|
||||||
@ -739,6 +741,8 @@ macro(qt_build_tests)
|
|||||||
add_subdirectory(manual)
|
add_subdirectory(manual)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_UNITY_BUILD ${QT_UNITY_BUILD})
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
function(qt_compute_relative_path_from_cmake_config_dir_to_prefix)
|
function(qt_compute_relative_path_from_cmake_config_dir_to_prefix)
|
||||||
@ -953,6 +957,7 @@ macro(qt_examples_build_end)
|
|||||||
if(TARGET Qt::Widgets)
|
if(TARGET Qt::Widgets)
|
||||||
qt_autogen_tools(${target} ENABLE_AUTOGEN_TOOLS "uic")
|
qt_autogen_tools(${target} ENABLE_AUTOGEN_TOOLS "uic")
|
||||||
endif()
|
endif()
|
||||||
|
set_target_properties(${target} PROPERTIES UNITY_BUILD OFF)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
install(CODE "
|
install(CODE "
|
||||||
|
@ -208,11 +208,16 @@ function(qt_internal_extend_target target)
|
|||||||
DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS})
|
DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS})
|
||||||
|
|
||||||
qt_update_precompiled_header("${target}" "${arg_PRECOMPILED_HEADER}")
|
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_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}")
|
||||||
|
|
||||||
|
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()
|
else()
|
||||||
if(QT_CMAKE_DEBUG_EXTEND_TARGET)
|
if(QT_CMAKE_DEBUG_EXTEND_TARGET)
|
||||||
message("qt_extend_target(${target} CONDITION ${arg_CONDITION} ...): Skipped")
|
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}")
|
${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)
|
||||||
|
@ -15,6 +15,7 @@ function(qt_internal_add_benchmark target)
|
|||||||
"${__qt_internal_add_executable_multi_args}"
|
"${__qt_internal_add_executable_multi_args}"
|
||||||
)
|
)
|
||||||
_qt_internal_validate_all_args_are_parsed(arg)
|
_qt_internal_validate_all_args_are_parsed(arg)
|
||||||
|
_qt_internal_validate_no_unity_build(arg)
|
||||||
|
|
||||||
qt_remove_args(exec_args
|
qt_remove_args(exec_args
|
||||||
ARGS_TO_REMOVE
|
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})
|
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_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)
|
_qt_internal_test_batch_target_name(target)
|
||||||
|
|
||||||
# Lazy-init the test batch
|
# 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}
|
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
|
NO_UNITY_BUILD # Tests should not be built using UNITY_BUILD
|
||||||
|
NO_UNITY_BUILD_SOURCES ${arg_SOURCES}
|
||||||
)
|
)
|
||||||
|
|
||||||
foreach(source ${arg_SOURCES})
|
foreach(source ${arg_SOURCES})
|
||||||
@ -396,6 +400,7 @@ function(qt_internal_add_test name)
|
|||||||
"${multi_value_args}"
|
"${multi_value_args}"
|
||||||
)
|
)
|
||||||
_qt_internal_validate_all_args_are_parsed(arg)
|
_qt_internal_validate_all_args_are_parsed(arg)
|
||||||
|
_qt_internal_validate_no_unity_build(arg)
|
||||||
|
|
||||||
if (NOT arg_OUTPUT_DIRECTORY)
|
if (NOT arg_OUTPUT_DIRECTORY)
|
||||||
set(arg_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
|
set(arg_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
# Copyright (C) 2023 The Qt Company Ltd.
|
# Copyright (C) 2023 The Qt Company Ltd.
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# 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)
|
function(qt_update_ignore_unity_build_sources target sources)
|
||||||
if (sources)
|
if (sources)
|
||||||
set_source_files_properties(${sources} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
|
set_source_files_properties(${sources} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user