Introduce QT_SKIP_DEFAULT_TESTCASE_DIRS target property

The property allows skipping to set the QT_TESTCASE_BUILDDIR/SOURCEDIR
definitions. This might be helpful in certain uscases, to optimize the
build by avoiding the need to set the unused compilation flags.

Add the QT_SKIP_DEFAULT_TESTCASE_DIRS variable that is used as the
default value for the QT_SKIP_DEFAULT_TESTCASE_DIRS property.

Task-number: QTBUG-126729
Change-Id: I6fe5bed428175cdd30d21741c20b745d85f3917d
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Alexey Edelev 2024-06-27 17:18:40 +02:00
parent 13a04975fd
commit ecf8843720
4 changed files with 146 additions and 2 deletions

View File

@ -7,6 +7,8 @@ include(selfcover.cmake)
## Test Module:
#####################################################################
include("${CMAKE_CURRENT_SOURCE_DIR}/QtTestProperties.cmake")
qt_internal_add_module(Test
CONFIG_MODULE_NAME testlib
QMAKE_MODULE_CONFIG console testlib_defines
@ -80,6 +82,10 @@ qt_internal_add_module(Test
Qt::CorePrivate
ATTRIBUTION_FILE_DIR_PATHS
3rdparty
EXTRA_CMAKE_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/QtTestProperties.cmake"
EXTRA_CMAKE_INCLUDES
QtTestProperties.cmake
)
if(TARGET Gui)
@ -134,9 +140,15 @@ set(qt_bool_tc_build_dir "$<BOOL:${qt_tc_build_dir}>")
set(qt_tc_build_dir_def
"$<IF:${qt_bool_tc_build_dir},${qt_tc_build_dir},$<TARGET_PROPERTY:BINARY_DIR>>"
)
string(JOIN "" testcase_dirs_genex
"$<$<NOT:$<BOOL:$<TARGET_PROPERTY:QT_SKIP_DEFAULT_TESTCASE_DIRS>>>:"
"QT_TESTCASE_BUILDDIR=\"${qt_tc_build_dir_def}\"$<SEMICOLON>"
"QT_TESTCASE_SOURCEDIR=\"$<TARGET_PROPERTY:SOURCE_DIR>\""
">"
)
set_property(TARGET Test APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS
QT_TESTCASE_BUILDDIR="${qt_tc_build_dir_def}"
QT_TESTCASE_SOURCEDIR="$<TARGET_PROPERTY:SOURCE_DIR>"
${testcase_dirs_genex}
)
qt_internal_add_docs(Test

View File

@ -0,0 +1,27 @@
# Copyright (C) 2024 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
# This file contains the property definitions that are known by Qt Test
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.23")
set(qt_skip_default_testcase_dirs_extra_agrs
INITIALIZE_FROM_VARIABLE
QT_SKIP_DEFAULT_TESTCASE_DIRS
)
elseif(DEFINED QT_SKIP_DEFAULT_TESTCASE_DIRS)
message(WARNING "QT_SKIP_DEFAULT_TESTCASE_DIRS is set to ${QT_SKIP_DEFAULT_TESTCASE_DIRS},"
" but the variable is not supported by this CMake version. Please set the"
" QT_SKIP_DEFAULT_TESTCASE_DIRS target property where is required.")
endif()
define_property(TARGET
PROPERTY
QT_SKIP_DEFAULT_TESTCASE_DIRS
BRIEF_DOCS
"Disables the test case directory definitions for the Qt Test targets."
FULL_DOCS
"By default the definitions QT_TESTCASE_SOURCEDIR and QT_TESTCASE_BUILDDIR point to the
target source and build directories of the target accordingly. If
QT_SKIP_DEFAULT_TESTCASE_DIRS is set to TRUE the macros remain empty."
${qt_skip_default_testcase_dirs_extra_agrs}
)

View File

@ -0,0 +1,54 @@
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\group cmake-target-properties-qttest
\title CMake Target Properties in Qt6 Test
\brief Lists CMake target properties known to Qt6::Test.
\l{Qt Test} module knows about the following CMake target properties:
\sa{CMake Property Reference}
*/
/*!
\page cmake-target-property-qt-skip-default-testcase-dirs.html
\ingroup cmake-properties-qttest
\ingroup cmake-target-properties-qttest
\title QT_SKIP_DEFAULT_TESTCASE_DIRS
\target cmake-target-property-QT_SKIP_DEFAULT_TESTCASE_DIRS
\cmakepropertysince 6.9
\preliminarycmakeproperty
\brief Disables the test case directory definitions for targets that link
to the Test library.
The property disables the following compile-time definitions for the target:
\list
\li QT_TESTCASE_SOURCEDIR
\li QT_TESTCASE_BUILDDIR
\endlist
By default, these definitions point to the source and build directories
of the target. Since they are only defined for this target, they preclude
sharing precompiled headers with the compilation of other targets. If
\c QT_SKIP_DEFAULT_TESTCASE_DIRS is set to \c TRUE these definitions are
omitted, avoiding this limitation.
\badcode
qt_add_executable(mytest main.cpp)
set_property(TARGET mytest PROPERTY QT_SKIP_DEFAULT_TESTCASE_DIRS TRUE)
target_link_libraries(mytest PRIVATE Qt6::Test)
\endcode
The \c QT_TESTCASE_SOURCEDIR and \c QT_TESTCASE_BUILDDIR macros will remain
undefined when compiling \c mytest.
The value of the property defaults to the value of the
\l {cmake-variable-QT_SKIP_DEFAULT_TESTCASE_DIRS}{QT_SKIP_DEFAULT_TESTCASE_DIRS}
variable.
\sa QFINDTESTDATA,
{cmake-variable-QT_SKIP_DEFAULT_TESTCASE_DIRS}{QT_SKIP_DEFAULT_TESTCASE_DIRS}
*/

View File

@ -0,0 +1,51 @@
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\group cmake-variables-qttest
\title CMake Variables in Qt6 Test
\brief Lists CMake variables defined in Qt6::Test.
The following CMake variables are defined when Qt6::Test is loaded, for instance
with
\badcode
find_package(Qt6 REQUIRED COMPONENTS Test)
\endcode
\sa{CMake Variable Reference}
*/
/*!
\page cmake-variable-qt-skip-default-testcase-dirs.html
\ingroup cmake-variables-qttest
\title QT_SKIP_DEFAULT_TESTCASE_DIRS
\target cmake-variable-QT_SKIP_DEFAULT_TESTCASE_DIRS
\cmakevariablesince 6.9
\preliminarycmakevariable
\summary {Disables the test case directory definitions for the Qt Test targets.}
Controls the default value of the
\l {cmake-target-property-QT_SKIP_DEFAULT_TESTCASE_DIRS}{QT_SKIP_DEFAULT_TESTCASE_DIRS}
target property.
\note Supported by CMake versions >= 3.23.
\badcode
set(QT_SKIP_DEFAULT_TESTCASE_DIRS TRUE)
...
qt_add_executable(mytest1 main1.cpp)
target_link_libraries(mytest1 PRIVATE Qt6::Test)
...
qt_add_executable(mytest2 main2.cpp)
target_link_libraries(mytest2 PRIVATE Qt6::Test)
\endcode
The \c QT_TESTCASE_SOURCEDIR and \c QT_TESTCASE_BUILDDIR macros will remain
undefined when compiling \c mytest1 and \c mytest2.
\sa QFINDTESTDATA,
{cmake-target-property-QT_SKIP_DEFAULT_TESTCASE_DIRS}{QT_SKIP_DEFAULT_TESTCASE_DIRS}
*/