summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorAlexey Edelev <alexey.edelev@qt.io>2021-03-24 12:58:08 +0100
committerAlexey Edelev <alexey.edelev@qt.io>2021-04-08 13:16:41 +0200
commit70464b355ec1c7007e0b1291f733e2540ba1825f (patch)
tree36113b6e6c9fa80804c7a34c2d3cb90e7956cbb4 /src/testlib
parent1999e2adc12a66488b241ff0e00c8716bd217c0a (diff)
Specify QT_TESTCASE_BUILDDIR for Qt::Test users implicitly
QT_TESTCASE_BUILDDIR was implicitly defined by Qt::Test target for library users in Qt5. By default, this definition will point to CMAKE_CURRENT_BINARY_DIR. This logic works similarly to qmake logic. From user's perspective it might be useful to not rely on standard search paths, but specify own. This can be done by setting the QT_TESTCASE_BUILDDIR property for the user's target. CMake will substute the value of the QT_TESTCASE_BUILDDIR property into the QT_TESTCASE_BUILDDIR definition. The implicit QT_TESTCASE_SOURCEDIR also seems to be useful. According to the current logic, it points to CMAKE_CURRENT_SOURCE_DIR. Fixes: QTBUG-92079 Change-Id: I8a9065f08e859c713b3c8cc08142a9ced0677770 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/CMakeLists.txt10
-rw-r--r--src/testlib/qtestcase.qdoc4
2 files changed, 14 insertions, 0 deletions
diff --git a/src/testlib/CMakeLists.txt b/src/testlib/CMakeLists.txt
index a2307045e7..da53bb8b68 100644
--- a/src/testlib/CMakeLists.txt
+++ b/src/testlib/CMakeLists.txt
@@ -110,6 +110,16 @@ qt_internal_extend_target(Test CONDITION MACOS
${FWIOKit}
)
+set(qt_tc_build_dir "$<TARGET_PROPERTY:QT_TESTCASE_BUILDDIR>")
+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>>"
+)
+set_property(TARGET Test PROPERTY INTERFACE_COMPILE_DEFINITIONS
+ QT_TESTCASE_BUILDDIR="${qt_tc_build_dir_def}"
+ QT_TESTCASE_SOURCEDIR="$<TARGET_PROPERTY:SOURCE_DIR>"
+)
+
# special case begin
# Do not bother with disabled stuff:
# qt_internal_extend_target(Test CONDITION (MACOS) AND (OFF AND NOT lessThan(QMAKE_XCODE_VERSION, "6.0")) ...
diff --git a/src/testlib/qtestcase.qdoc b/src/testlib/qtestcase.qdoc
index 08f111b43e..2a480fb349 100644
--- a/src/testlib/qtestcase.qdoc
+++ b/src/testlib/qtestcase.qdoc
@@ -522,6 +522,10 @@
absolute paths to the source files are passed to the compiler. Otherwise, the
absolute path of the source directory cannot be determined.
+ \note The \c{QT_TESTCASE_BUILDDIR} macro is also implicitly defined if CMake is used
+ and the QtTest module is linked to the target. You can change the default
+ \c{QT_TESTCASE_BUILDDIR} by setting the QT_TESTCASE_BUILDDIR property on the target.
+
\note For tests that use the \l QTEST_APPLESS_MAIN() macro to generate a
\c{main()} function, \c{QFINDTESTDATA} will not attempt to find test data
relative to QCoreApplication::applicationDirPath(). In practice, this means that