summaryrefslogtreecommitdiff
path: root/Tests/QtAutogen
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2021-04-20 21:17:50 +0200
committerJoerg Bornemann <joerg.bornemann@qt.io>2021-04-23 10:49:07 +0200
commit5b0ea5874a3322e57156b329b340bf283673c207 (patch)
treeee25d305166e04e92251c847bf502846b69780e4 /Tests/QtAutogen
parent63ffe210365ce2d1dd67fcabcc67e20913f320a8 (diff)
downloadcmake-5b0ea5874a3322e57156b329b340bf283673c207.tar.gz
AutoGen: Retrieve Qt version from moc as fallback
Consider the case where the find_package call for QtCore is wrapped in a function call. Then AutoGen cannot determine the Qt version, because it only looks at variables and directory properties. The former don't leave the function scope and the latter are not set by default. As a fallback, locate the moc executable via its target and call it with the --version argument to determine the Qt version. Issue: #22028
Diffstat (limited to 'Tests/QtAutogen')
-rw-r--r--Tests/QtAutogen/Tests.cmake1
-rw-r--r--Tests/QtAutogen/WrappedFindPackage/CMakeLists.txt16
-rw-r--r--Tests/QtAutogen/WrappedFindPackage/main.cpp19
3 files changed, 36 insertions, 0 deletions
diff --git a/Tests/QtAutogen/Tests.cmake b/Tests/QtAutogen/Tests.cmake
index ab5686af65..a3c57a5871 100644
--- a/Tests/QtAutogen/Tests.cmake
+++ b/Tests/QtAutogen/Tests.cmake
@@ -49,6 +49,7 @@ if(QT_TEST_VERSION GREATER 4)
ADD_AUTOGEN_TEST(MocMacroName mocMacroName)
ADD_AUTOGEN_TEST(MocOsMacros)
ADD_AUTOGEN_TEST(RerunMocPlugin)
+ ADD_AUTOGEN_TEST(WrappedFindPackage)
if(APPLE)
ADD_AUTOGEN_TEST(MacOsFW)
endif()
diff --git a/Tests/QtAutogen/WrappedFindPackage/CMakeLists.txt b/Tests/QtAutogen/WrappedFindPackage/CMakeLists.txt
new file mode 100644
index 0000000000..e8f50d56e7
--- /dev/null
+++ b/Tests/QtAutogen/WrappedFindPackage/CMakeLists.txt
@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 3.20)
+project(WrappedFindPackage)
+
+# Wrap the find_package call in a function.
+# Test whether AutoMoc can retrieve the Qt version from the moc executable.
+function(find_qt_package)
+ include("../AutogenCoreTest.cmake")
+ set(QT_LIBRARIES "${QT_LIBRARIES}" PARENT_SCOPE)
+endfunction()
+
+find_qt_package()
+
+set(CMAKE_AUTOMOC ON)
+
+add_executable(wrappedFindPackage main.cpp)
+target_link_libraries(wrappedFindPackage PRIVATE ${QT_LIBRARIES})
diff --git a/Tests/QtAutogen/WrappedFindPackage/main.cpp b/Tests/QtAutogen/WrappedFindPackage/main.cpp
new file mode 100644
index 0000000000..1e2c63fab3
--- /dev/null
+++ b/Tests/QtAutogen/WrappedFindPackage/main.cpp
@@ -0,0 +1,19 @@
+#include <qobject.h>
+
+class MyObject : public QObject
+{
+ Q_OBJECT
+public:
+ MyObject(QObject* parent = 0)
+ : QObject(parent)
+ {
+ }
+};
+
+int main()
+{
+ MyObject obj;
+ return 0;
+}
+
+#include "main.moc"