summaryrefslogtreecommitdiffstats
path: root/tests/auto/cmake
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 /tests/auto/cmake
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 'tests/auto/cmake')
-rw-r--r--tests/auto/cmake/CMakeLists.txt4
-rw-r--r--tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt2
-rw-r--r--tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/CMakeLists.txt20
-rw-r--r--tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/data/testdata.txt1
-rw-r--r--tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/main.cpp57
-rw-r--r--tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/testdata.txt1
6 files changed, 83 insertions, 2 deletions
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt
index 4fb6c24d8d..a94f1a51fe 100644
--- a/tests/auto/cmake/CMakeLists.txt
+++ b/tests/auto/cmake/CMakeLists.txt
@@ -112,6 +112,10 @@ if (CMAKE_GENERATOR STREQUAL Ninja AND UNIX AND NOT WIN32)
BINARY "tests/test_QFINDTESTDATA"
SIMULATE_IN_SOURCE
)
+ _qt_internal_test_expect_pass(test_QT_TESTCASE_BUILDDIR
+ BINARY "test_qt_testcase_builddir"
+ SIMULATE_IN_SOURCE
+ )
endif()
if (NOT NO_DBUS)
diff --git a/tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt b/tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt
index 6515aa8020..df91a7d84b 100644
--- a/tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt
+++ b/tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt
@@ -2,5 +2,3 @@
add_executable(test_QFINDTESTDATA WIN32 main.cpp)
target_link_libraries(test_QFINDTESTDATA Qt::Test)
-target_compile_definitions(test_QFINDTESTDATA PRIVATE QT_TESTCASE_BUILDDIR="${CMAKE_CURRENT_BINARY_DIR}")
-target_compile_definitions(test_QFINDTESTDATA PRIVATE QT_TESTCASE_SOURCEDIR="${CMAKE_CURRENT_SOURCE_DIR}")
diff --git a/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/CMakeLists.txt b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/CMakeLists.txt
new file mode 100644
index 0000000000..f6fe597def
--- /dev/null
+++ b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/CMakeLists.txt
@@ -0,0 +1,20 @@
+# The test is simply testing that manual specification of QT_TESTCASE_BUILDDIR works,
+# despite the weird paths.
+cmake_minimum_required(VERSION 3.14)
+
+project(test_qt_testcase_builddir)
+
+find_package(Qt6Test REQUIRED)
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+add_executable(test_qt_testcase_builddir WIN32 main.cpp)
+
+target_link_libraries(test_qt_testcase_builddir Qt::Test)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/testdata.txt"
+ "${CMAKE_CURRENT_BINARY_DIR}/level1/level2/testdata_build.txt"
+ COPYONLY
+)
+set_target_properties(test_qt_testcase_builddir PROPERTIES
+ QT_TESTCASE_BUILDDIR "${CMAKE_CURRENT_BINARY_DIR}/level1/level2"
+)
diff --git a/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/data/testdata.txt b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/data/testdata.txt
new file mode 100644
index 0000000000..e846386066
--- /dev/null
+++ b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/data/testdata.txt
@@ -0,0 +1 @@
+This is the test data found in QT_TESTCASE_SOURCEDIR.
diff --git a/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/main.cpp b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/main.cpp
new file mode 100644
index 0000000000..8965e0dac3
--- /dev/null
+++ b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QCoreApplication>
+#include <QtTest/QTest>
+#include <QDebug>
+
+class TestClass : public QObject
+{
+ Q_OBJECT
+public:
+ TestClass(QObject *parent = nullptr) { }
+
+private slots:
+ void doTest();
+};
+
+void TestClass::doTest()
+{
+ QFile fsrc(QFINDTESTDATA("data/testdata.txt"));
+ QVERIFY(fsrc.open(QFile::ReadOnly));
+ QCOMPARE(fsrc.readAll().trimmed(),
+ QByteArrayLiteral("This is the test data found in QT_TESTCASE_SOURCEDIR."));
+
+ QFile fbuild(QFINDTESTDATA("level2/testdata_build.txt"));
+ QVERIFY(fbuild.open(QFile::ReadOnly));
+ QCOMPARE(fbuild.readAll().trimmed(),
+ QByteArrayLiteral("This is the test data found in custom QT_TESTCASE_BUILDDIR."));
+}
+
+QTEST_MAIN(TestClass)
+#include "main.moc"
diff --git a/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/testdata.txt b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/testdata.txt
new file mode 100644
index 0000000000..96a369071b
--- /dev/null
+++ b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/testdata.txt
@@ -0,0 +1 @@
+This is the test data found in custom QT_TESTCASE_BUILDDIR.