From 112cba927abfd54e72d12831dc668148c1465446 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 5 Mar 2014 13:43:50 +0100 Subject: [PATCH] QtAutogen: Fix AUTOGEN depends on custom command output with VS. Visual Studio is handled as a special case for autogen depends. However, the special handling works only for target dependencies, not file dependencies output by a custom command. Use a PRE_BUILD step only if all depends are targets. --- Source/cmQtAutoGenerators.cxx | 12 ++++++++++++ Tests/QtAutogen/CMakeLists.txt | 8 +++++++- Tests/QtAutogen/generated.h | 5 +++-- Tests/QtAutogen/myotherinterface.h.in | 14 ++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 Tests/QtAutogen/myotherinterface.h.in diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index dfb310e54..2c5dd450d 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -260,6 +260,18 @@ bool cmQtAutoGenerators::InitializeAutogenTarget(cmTarget* target) // This also works around a VS 11 bug that may skip updating the target: // https://connect.microsoft.com/VisualStudio/feedback/details/769495 usePRE_BUILD = vslg->GetVersion() >= cmLocalVisualStudioGenerator::VS7; + if(usePRE_BUILD) + { + for (std::vector::iterator it = depends.begin(); + it != depends.end(); ++it) + { + if(!makefile->FindTargetToUse(it->c_str())) + { + usePRE_BUILD = false; + break; + } + } + } } if(usePRE_BUILD) { diff --git a/Tests/QtAutogen/CMakeLists.txt b/Tests/QtAutogen/CMakeLists.txt index 4da125f8a..0821b454d 100644 --- a/Tests/QtAutogen/CMakeLists.txt +++ b/Tests/QtAutogen/CMakeLists.txt @@ -58,11 +58,17 @@ add_custom_target(generate_moc_input COMMAND ${CMAKE_COMMAND} -E rename "${CMAKE_CURRENT_BINARY_DIR}/myinterface.h.in" "${CMAKE_CURRENT_BINARY_DIR}/myinterface.h" ) +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/myotherinterface.h" + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/myotherinterface.h.in" "${CMAKE_CURRENT_BINARY_DIR}/myotherinterface.h" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/myotherinterface.h.in" +) + add_executable(QtAutogen main.cpp calwidget.cpp foo.cpp blub.cpp bar.cpp abc.cpp xyz.cpp yaf.cpp gadget.cpp $ test.qrc resourcetester.cpp generated.cpp ) -set_property(TARGET QtAutogen APPEND PROPERTY AUTOGEN_TARGET_DEPENDS generate_moc_input) +set_property(TARGET QtAutogen APPEND PROPERTY AUTOGEN_TARGET_DEPENDS generate_moc_input "${CMAKE_CURRENT_BINARY_DIR}/myotherinterface.h") set_target_properties(QtAutogen codeeditorLib privateSlot PROPERTIES AUTOMOC TRUE) diff --git a/Tests/QtAutogen/generated.h b/Tests/QtAutogen/generated.h index dd22489b1..b6c271115 100644 --- a/Tests/QtAutogen/generated.h +++ b/Tests/QtAutogen/generated.h @@ -5,11 +5,12 @@ #include #include "myinterface.h" +#include "myotherinterface.h" -class Generated : public QObject, MyInterface +class Generated : public QObject, MyInterface, MyOtherInterface { Q_OBJECT - Q_INTERFACES(MyInterface) + Q_INTERFACES(MyInterface MyOtherInterface) public: explicit Generated(QObject *parent = 0); }; diff --git a/Tests/QtAutogen/myotherinterface.h.in b/Tests/QtAutogen/myotherinterface.h.in new file mode 100644 index 000000000..d21e7af7c --- /dev/null +++ b/Tests/QtAutogen/myotherinterface.h.in @@ -0,0 +1,14 @@ + +#ifndef MYOTHERINTERFACE_H +#define MYOTHERINTERFACE_H + +#include + +class MyOtherInterface +{ + +}; + +Q_DECLARE_INTERFACE(MyOtherInterface, "org.cmake.example.MyOtherInterface") + +#endif