diff options
author | Mikolaj Boc <mikolaj.boc@qt.io> | 2022-07-12 18:15:24 +0200 |
---|---|---|
committer | Mikolaj Boc <mikolaj.boc@qt.io> | 2022-08-24 02:46:37 +0200 |
commit | 8d728a0ed9c1fb366c64babc1f753b5ea77c2cdf (patch) | |
tree | c6c73b5bfa6ee2068707989500221064c1488fe9 /cmake/QtTargetHelpers.cmake | |
parent | 8446655f24c38d2d52f56d0369182895b6306026 (diff) |
Implement the batch_tests feature
An approach of test batching (joining multiple tests into a single
binary) has been taken, due to long linking times/binary size on certain
platforms, including WASM. This change adds a new feature
'batch_test_support' in Qt testlib. Based on the value of the feature,
test batching may become enabled with the -batch-tests switch.
Batching works for every target added via qt_internal_add_test. When
first such target is being processed, a new combined target for all of
the future test sources is created under the name of 'test_batch'.
CMake attempts to merge the parameters of each of the tests, and some
basic checks are run for parameter differences that are impossible to
reconcile.
On the C++ level, convenience macros instantiating the tests are
redefined when batch_tests is on. The new, changed behavior triggered
by the changes in the macros registers the tests in a central test
registry, where they are available for execution based solely on their
test name. The test name is interoperable with the names CMake is aware
of, so CTest is able to run the tests one by one in the combined binary.
Task-number: QTBUG-105273
Change-Id: I2b6071d58be16979bd967eab2d405249f5a4e658
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'cmake/QtTargetHelpers.cmake')
-rw-r--r-- | cmake/QtTargetHelpers.cmake | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/cmake/QtTargetHelpers.cmake b/cmake/QtTargetHelpers.cmake index cfeb969ca9..4a51849c78 100644 --- a/cmake/QtTargetHelpers.cmake +++ b/cmake/QtTargetHelpers.cmake @@ -4,15 +4,20 @@ # This function can be used to add sources/libraries/etc. to the specified CMake target # if the provided CONDITION evaluates to true. function(qt_internal_extend_target target) + if(NOT TARGET "${target}") + qt_internal_is_in_test_batch(in_batch ${target}) + if(NOT in_batch) + message(FATAL_ERROR "Trying to extend a non-existing target \"${target}\".") + endif() + qt_internal_test_batch_target_name(target) + endif() + # Don't try to extend_target when cross compiling an imported host target (like a tool). qt_is_imported_target("${target}" is_imported) if(is_imported) return() endif() - if (NOT TARGET "${target}") - message(FATAL_ERROR "Trying to extend non-existing target \"${target}\".") - endif() qt_parse_all_arguments(arg "qt_extend_target" "" "PRECOMPILED_HEADER" "CONDITION;${__default_public_args};${__default_private_args};${__default_private_module_args};COMPILE_FLAGS;NO_PCH_SOURCES" ${ARGN}) if ("x${arg_CONDITION}" STREQUAL x) @@ -884,7 +889,11 @@ endfunction() # qt_internal_add_global_definition function for a specific 'target'. function(qt_internal_undefine_global_definition target) if(NOT TARGET ${target}) - message(FATAL_ERROR "${target} is not a target.") + qt_internal_is_in_test_batch(in_batch ${target}) + if(NOT ${in_batch}) + message(FATAL_ERROR "${target} is not a target.") + endif() + qt_internal_test_batch_target_name(target) endif() if("${ARGN}" STREQUAL "") |