From f7ae1d8ad6d0db2b6656ed77f7de12189badf05c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 24 Jan 2014 17:01:59 +0100 Subject: QtAutogen: Short-circut some logic when moc is not available. This is the case when AUTOMOC is false. This prevents creating rules to moc the files in the absense of moc. --- Source/cmQtAutoGenerators.cxx | 17 ++++++++++++++--- Tests/QtAutogen/CMakeLists.txt | 14 ++++++++++++++ Tests/QtAutogen/uiconly.cpp | 13 +++++++++++++ Tests/QtAutogen/uiconly.h | 20 ++++++++++++++++++++ Tests/QtAutogen/uiconly.ui | 24 ++++++++++++++++++++++++ 5 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 Tests/QtAutogen/uiconly.cpp create mode 100644 Tests/QtAutogen/uiconly.h create mode 100644 Tests/QtAutogen/uiconly.ui diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 758466b..cab59fe 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -1444,6 +1444,12 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename, << std::endl; return; } + this->ParseForUic(absFilename, contentsString, includedUis); + if (this->MocExecutable.empty()) + { + return; + } + const std::string absPath = cmsys::SystemTools::GetFilenamePath( cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/'; const std::string scannedFileBasename = cmsys::SystemTools:: @@ -1572,7 +1578,6 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename, matchOffset += mocIncludeRegExp.end(); } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset)); } - this->ParseForUic(absFilename, contentsString, includedUis); // In this case, check whether the scanned file itself contains a Q_OBJECT. // If this is the case, the moc_foo.cpp should probably be generated from @@ -1627,6 +1632,12 @@ void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename, << std::endl; return; } + this->ParseForUic(absFilename, contentsString, includedUis); + if (this->MocExecutable.empty()) + { + return; + } + const std::string absPath = cmsys::SystemTools::GetFilenamePath( cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/'; const std::string scannedFileBasename = cmsys::SystemTools:: @@ -1705,7 +1716,6 @@ void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename, matchOffset += mocIncludeRegExp.end(); } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset)); } - this->ParseForUic(absFilename, contentsString, includedUis); // In this case, check whether the scanned file itself contains a Q_OBJECT. // If this is the case, the moc_foo.cpp should probably be generated from @@ -1830,7 +1840,8 @@ void cmQtAutoGenerators::ParseHeaders(const std::set& absHeaders, const std::string& headerName = *hIt; const std::string contents = ReadAll(headerName); - if (includedMocs.find(headerName) == includedMocs.end()) + if (!this->MocExecutable.empty() + && includedMocs.find(headerName) == includedMocs.end()) { if (this->Verbose) { diff --git a/Tests/QtAutogen/CMakeLists.txt b/Tests/QtAutogen/CMakeLists.txt index 7b99395..515bf5b 100644 --- a/Tests/QtAutogen/CMakeLists.txt +++ b/Tests/QtAutogen/CMakeLists.txt @@ -11,6 +11,11 @@ if (QT_TEST_VERSION STREQUAL 4) include(UseQt4) set(QT_QTCORE_TARGET Qt4::QtCore) + + macro(qtx_wrap_cpp) + qt4_wrap_cpp(${ARGN}) + endmacro() + else() if (NOT QT_TEST_VERSION STREQUAL 5) message(SEND_ERROR "Invalid Qt version specified.") @@ -25,6 +30,11 @@ else() if(Qt5_POSITION_INDEPENDENT_CODE) set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif() + + macro(qtx_wrap_cpp) + qt5_wrap_cpp(${ARGN}) + endmacro() + endif() @@ -77,3 +87,7 @@ set_target_properties(empty PROPERTIES AUTOMOC TRUE) target_link_libraries(empty no_link_language) add_library(no_link_language STATIC empty.h) set_target_properties(no_link_language PROPERTIES AUTOMOC TRUE) + +qtx_wrap_cpp(uicOnlyMoc uiconly.h) +add_executable(uiconly uiconly.cpp ${uicOnlyMoc}) +target_link_libraries(uiconly ${QT_LIBRARIES}) diff --git a/Tests/QtAutogen/uiconly.cpp b/Tests/QtAutogen/uiconly.cpp new file mode 100644 index 0000000..cdb3318 --- /dev/null +++ b/Tests/QtAutogen/uiconly.cpp @@ -0,0 +1,13 @@ + +#include "uiconly.h" + +UicOnly::UicOnly(QWidget *parent) + : QWidget(parent), ui(new Ui::UicOnly) +{ + +} + +int main() +{ + return 0; +} diff --git a/Tests/QtAutogen/uiconly.h b/Tests/QtAutogen/uiconly.h new file mode 100644 index 0000000..9e21f82 --- /dev/null +++ b/Tests/QtAutogen/uiconly.h @@ -0,0 +1,20 @@ + +#ifndef UIC_ONLY_H +#define UIC_ONLY_H + +#include +#include + +#include "ui_uiconly.h" + +class UicOnly : public QWidget +{ + Q_OBJECT +public: + explicit UicOnly(QWidget *parent = 0); + +private: + const std::auto_ptr ui; +}; + +#endif diff --git a/Tests/QtAutogen/uiconly.ui b/Tests/QtAutogen/uiconly.ui new file mode 100644 index 0000000..13fb832 --- /dev/null +++ b/Tests/QtAutogen/uiconly.ui @@ -0,0 +1,24 @@ + + + UicOnly + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + + -- cgit v0.12