summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2019-06-04 12:07:20 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2019-06-04 10:14:39 +0000
commit5c954b89a9bd94b085a49d05dfa25644b2eda1c8 (patch)
tree4f7a392af74a9db67167a118c351c35f77cac330 /cmake
parentfae5691c7f78f8a0154c9cea28b6639327a90550 (diff)
Fix qFindTestData with cmake and ninja generator
In order for test lib to locate the file requested via QFINDTESTDATA, it needs the build directory of the test (for example $builddir/tests/auto/foo/bar) and __FILE__ expanding to a path to the source relative to this build directory. With ninja, __FILE__ is a path that is always relative to the top-level build directory, not the per-test case one. Therefore the path resolution in testlib fails. To accommodate this, add_qt_test() now always sets QT_TESTCASE_BUILDDIR as well as the newly introduced QT_TESTCASE_SOURCEDIR, which, as an absolute path, removes the need to use __FILE__. Change-Id: I16c2b0001e38162e6da9fdb1a61f4f8ce634fe46 Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtBuild.cmake5
1 files changed, 4 insertions, 1 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake
index 591c752f77..81b5298833 100644
--- a/cmake/QtBuild.cmake
+++ b/cmake/QtBuild.cmake
@@ -1565,7 +1565,10 @@ function(add_qt_test name)
"${CMAKE_CURRENT_BINARY_DIR}"
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
"${arg_INCLUDE_DIRECTORIES}"
- DEFINES "${arg_DEFINES}"
+ DEFINES
+ "${arg_DEFINES}"
+ QT_TESTCASE_BUILDDIR="${CMAKE_CURRENT_BINARY_DIR}"
+ QT_TESTCASE_SOURCEDIR="${CMAKE_CURRENT_SOURCE_DIR}"
PUBLIC_LIBRARIES ${QT_CMAKE_EXPORT_NAMESPACE}::Core ${QT_CMAKE_EXPORT_NAMESPACE}::Test
LIBRARIES ${arg_LIBRARIES}
COMPILE_OPTIONS ${arg_COMPILE_OPTIONS}