From 321e348e133f2f62dd51cd663fe30c7513ea53d8 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 24 Jan 2014 13:02:16 +0100 Subject: QtAutogen: Use Qt 4 IMPORTED targets to find executable locations. Avoid using the moc from Qt 5 with Qt 4 based targets. Moc generates a version check to ensure that such generated code does not compile. The Qt4And5Automoc unit test should have been testing this, but it was not because the test was broken. In that unit test, moc was run on trivial files which have no significant content, and in particular no Q_OBJECT macro. Therefore moc was generating empty files which do not even contain the version check. Fix this by generating files for input to moc at cmake time. --- Tests/Qt4And5Automoc/CMakeLists.txt | 15 +++++++++++++-- Tests/Qt4And5Automoc/main.cpp | 18 ------------------ Tests/Qt4And5Automoc/main.cpp.in | 18 ++++++++++++++++++ Tests/Qt4And5Automoc/main_qt4.cpp | 4 ---- Tests/Qt4And5Automoc/main_qt5.cpp | 4 ---- 5 files changed, 31 insertions(+), 28 deletions(-) delete mode 100644 Tests/Qt4And5Automoc/main.cpp create mode 100644 Tests/Qt4And5Automoc/main.cpp.in delete mode 100644 Tests/Qt4And5Automoc/main_qt4.cpp delete mode 100644 Tests/Qt4And5Automoc/main_qt5.cpp (limited to 'Tests/Qt4And5Automoc') diff --git a/Tests/Qt4And5Automoc/CMakeLists.txt b/Tests/Qt4And5Automoc/CMakeLists.txt index 0cc80fe73f..61d5743662 100644 --- a/Tests/Qt4And5Automoc/CMakeLists.txt +++ b/Tests/Qt4And5Automoc/CMakeLists.txt @@ -1,3 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12) project(Qt4And5Automoc) @@ -7,7 +8,17 @@ find_package(Qt5Core REQUIRED) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -add_executable(qt4_exe main_qt4.cpp) +macro(generate_main_file VERSION) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/main.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/main_qt${VERSION}.cpp" COPYONLY) + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/main_qt${VERSION}.cpp" + "#include \"main_qt${VERSION}.moc\"\n" + ) +endmacro() + +generate_main_file(4) +generate_main_file(5) + +add_executable(qt4_exe "${CMAKE_CURRENT_BINARY_DIR}/main_qt4.cpp") target_link_libraries(qt4_exe Qt4::QtCore) -add_executable(qt5_exe main_qt5.cpp) +add_executable(qt5_exe "${CMAKE_CURRENT_BINARY_DIR}/main_qt5.cpp") target_link_libraries(qt5_exe Qt5::Core) diff --git a/Tests/Qt4And5Automoc/main.cpp b/Tests/Qt4And5Automoc/main.cpp deleted file mode 100644 index 00fd641535..0000000000 --- a/Tests/Qt4And5Automoc/main.cpp +++ /dev/null @@ -1,18 +0,0 @@ - -#include - -class SomeObject : public QObject -{ - Q_OBJECT -public: - explicit SomeObject(QObject *parent = 0) - : QObject(parent) - { - - } -}; - -int main(int argc, char **argv) -{ - return 0; -} diff --git a/Tests/Qt4And5Automoc/main.cpp.in b/Tests/Qt4And5Automoc/main.cpp.in new file mode 100644 index 0000000000..00fd641535 --- /dev/null +++ b/Tests/Qt4And5Automoc/main.cpp.in @@ -0,0 +1,18 @@ + +#include + +class SomeObject : public QObject +{ + Q_OBJECT +public: + explicit SomeObject(QObject *parent = 0) + : QObject(parent) + { + + } +}; + +int main(int argc, char **argv) +{ + return 0; +} diff --git a/Tests/Qt4And5Automoc/main_qt4.cpp b/Tests/Qt4And5Automoc/main_qt4.cpp deleted file mode 100644 index a84ce897fd..0000000000 --- a/Tests/Qt4And5Automoc/main_qt4.cpp +++ /dev/null @@ -1,4 +0,0 @@ - -#include "main.cpp" - -#include "main_qt4.moc" diff --git a/Tests/Qt4And5Automoc/main_qt5.cpp b/Tests/Qt4And5Automoc/main_qt5.cpp deleted file mode 100644 index 287b261372..0000000000 --- a/Tests/Qt4And5Automoc/main_qt5.cpp +++ /dev/null @@ -1,4 +0,0 @@ - -#include "main.cpp" - -#include "main_qt5.moc" -- cgit v1.2.1