From 76d1ffc5301e17c1bcd5e23c79aeaf028a075302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Hunold?= Date: Thu, 25 Aug 2011 18:09:59 +0000 Subject: [PATCH] Fix #5802: Add response file support for moc. [SVN r74058] --- v2/test/qt4/jamroot.jam | 29 +++++++++++--------- v2/test/qt4/mock.cpp | 26 ++++++++++++++++++ v2/test/qt4/mock.h | 21 +++++++++++++++ v2/test/qt4/qttest.cpp | 8 ++++-- v2/tools/qt4.jam | 60 ++++++++++++++++++++++------------------- 5 files changed, 101 insertions(+), 43 deletions(-) create mode 100644 v2/test/qt4/mock.cpp create mode 100644 v2/test/qt4/mock.h diff --git a/v2/test/qt4/jamroot.jam b/v2/test/qt4/jamroot.jam index c089ecccc..eeddc586f 100644 --- a/v2/test/qt4/jamroot.jam +++ b/v2/test/qt4/jamroot.jam @@ -1,35 +1,35 @@ # (c) Copyright Juergen Hunold 2008 -# Use, modification, and distribution are subject to the -# Boost Software License, Version 1.0. (See accompanying file +# Use, modification, and distribution are subject to the +# Boost Software License, Version 1.0. (See accompanying file # LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) import qt4 ; -import testing ; +import testing ; import cast ; - + if [ qt4.initialized ] { use-project /boost : ../../../../.. ; - project qttest - : requirements + project qttest + : requirements /boost/test//boost_unit_test_framework ; - + alias qt-tests : # Check for explicit libraries, /qt should not link any lib [ link-fail qtcorefail.cpp : /qt ] - + [ run qtcore.cpp /qt//QtCore ] [ run qtsql.cpp /qt//QtSql ] - [ run qtxml.cpp /qt//QtXml ] + [ run qtxml.cpp /qt//QtXml ] [ run qtnetwork.cpp /qt//QtNetwork ] [ run qtscript.cpp /qt//QtScript ] [ run qtscripttools.cpp /qt//QtScriptTools ] [ run qtxmlpatterns.cpp /qt//QtXmlPatterns ] - + # ToDo: runable example code [ link qtsvg.cpp /qt//QtSvg ] [ link qtgui.cpp /qt//QtGui ] @@ -39,7 +39,7 @@ if [ qt4.initialized ] [ link phonon.cpp /qt//phonon ] [ link qtmultimedia.cpp /qt//QtMultimedia ] - # QML + # QML [ link qtdeclarative.cpp /qt//QtDeclarative ] # Help systems. @@ -52,12 +52,15 @@ if [ qt4.initialized ] # Testing using QtTest. Simple sample # ToDo: better support for "automoc" aka '#include "qttest.moc"' - [ run qttest.cpp [ cast _ moccable-cpp : qttest.cpp ] /qt//QtTest ] + [ run qttest.cpp [ cast _ moccable-cpp : qttest.cpp ] /qt//QtTest : : : TEST_MOCK ] + + # Test moc rule + [ run mock.cpp mock.h /qt//QtCore : : : TEST_MOCK ] : # requirements : # default-build : # usage-requirements - ; + ; } # QtAssistant is removed from Qt >= 4.6 diff --git a/v2/test/qt4/mock.cpp b/v2/test/qt4/mock.cpp new file mode 100644 index 000000000..8f7a35c2d --- /dev/null +++ b/v2/test/qt4/mock.cpp @@ -0,0 +1,26 @@ +// (c) Copyright Juergen Hunold 2011 +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_TEST_MODULE QtMoc + +#include "mock.h" + +#include + +Mock::Mock() +{ +} + +/*! + Check that the compiler get the correct #defines. + The logic to test the moc is in the header file "mock.h" + */ +BOOST_AUTO_TEST_CASE(construct_mock) +{ + delete new Mock(); + + BOOST_CHECK_EQUAL(BOOST_IS_DEFINED(QT_CORE_LIB), true); + BOOST_CHECK_EQUAL(BOOST_IS_DEFINED(TEST_MOCK), true); +} diff --git a/v2/test/qt4/mock.h b/v2/test/qt4/mock.h new file mode 100644 index 000000000..1cc95b057 --- /dev/null +++ b/v2/test/qt4/mock.h @@ -0,0 +1,21 @@ +// (c) Copyright Juergen Hunold 2011 +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include + +class Mock : public QObject +{ + /*! + Test that the moc gets the necessary #defines + Else the moc will not see the Q_OBJECT macro, issue a warning + and linking will fail due to missing vtable symbols. + */ +#if defined(TEST_MOCK) + Q_OBJECT +#endif + public: + + Mock(); +}; diff --git a/v2/test/qt4/qttest.cpp b/v2/test/qt4/qttest.cpp index c46af7004..a2744cdc7 100644 --- a/v2/test/qt4/qttest.cpp +++ b/v2/test/qt4/qttest.cpp @@ -1,4 +1,4 @@ -// (c) Copyright Juergen Hunold 2008 +// (c) Copyright Juergen Hunold 2008-2011 // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -7,11 +7,15 @@ class QtTest: public QObject { + /*! + Test if the moc gets the #define + */ +#if defined(TEST_MOCK) Q_OBJECT +#endif private Q_SLOTS: void toUpper(); - }; void diff --git a/v2/tools/qt4.jam b/v2/tools/qt4.jam index b1d34b72d..93924b7d3 100644 --- a/v2/tools/qt4.jam +++ b/v2/tools/qt4.jam @@ -68,7 +68,7 @@ feature.feature qt3support : off on : propagated link-incompatible ; # The Qt version used for requirements # Valid are 4.4 or 4.5.0 -# Auto-detection via qmake sets 'major.minor.patch' +# Auto-detection via qmake sets 'major.minor.patch' feature.feature qt : : propagated ; project.initialize $(__name__) ; @@ -110,7 +110,7 @@ local rule read-output ( content ) # Capture Qt version from qmake local rule check-version ( bin_prefix ) { - full-cmd = $(bin_prefix)"/qmake -v" ; + full-cmd = $(bin_prefix)"/qmake -v" ; debug-message Running '$(full-cmd)' ; local output = [ SHELL $(full-cmd) ] ; for line in [ read-output $(output) ] @@ -120,7 +120,7 @@ local rule check-version ( bin_prefix ) { # Skip first line of output } - else + else { temp = [ MATCH "([0-9]*)\\.([0-9]*)\\.([0-9]*)" : $(line) ] ; } @@ -144,14 +144,14 @@ local rule split-version ( version ) return $(major-minor[1]) $(major-minor[2]) ; } -# Initialize the QT support module. +# Initialize the QT support module. # Parameters: # - 'prefix' parameter tells where Qt is installed. # - 'full_bin' optional full path to Qt binaries (qmake,moc,uic,rcc) # - 'full_inc' optional full path to Qt top-level include directory # - 'full_lib' optional full path to Qt library directory # - 'version' optional version of Qt, else autodetected via 'qmake -v' -# - 'condition' optional requirements +# - 'condition' optional requirements rule init ( prefix : full_bin ? : full_inc ? : full_lib ? : version ? : condition * ) { project.push-current $(.project) ; @@ -172,7 +172,7 @@ rule init ( prefix : full_bin ? : full_inc ? : full_lib ? : version ? : conditio local inc_prefix lib_prefix bin_prefix ; if $(full_inc) { - inc_prefix = $(full_inc) ; + inc_prefix = $(full_inc) ; } else { @@ -236,7 +236,7 @@ rule init ( prefix : full_bin ? : full_inc ? : full_lib ? : version ? : conditio version = $(major-minor:J=.) ; } else - { + { version = [ check-version $(bin_prefix) ] ; if $(version) { @@ -259,7 +259,7 @@ rule init ( prefix : full_bin ? : full_inc ? : full_lib ? : version ? : conditio local target-os = [ feature.get-values target-os : $(condition) ] ; if ! $(target-os) - { + { target-os ?= [ feature.defaults target-os ] ; target-os = $(target-os:G=) ; target-requirements += $(target-os) ; @@ -317,12 +317,12 @@ rule init ( prefix : full_bin ? : full_inc ? : full_lib ? : version ? : conditio # ToDo: 2009-02-12: Maybe throw this away and # require separate setup with debug as condition. .have_separate_debug = FALSE ; - + # Setup other platforms - if $(target-os) in windows cygwin + if $(target-os) in windows cygwin { .have_separate_debug = TRUE ; - + # On NT, the libs have "4" suffix, and "d" suffix in debug builds. .suffix_version = "4" ; .suffix_debug = "d" ; @@ -335,7 +335,7 @@ rule init ( prefix : full_bin ? : full_inc ? : full_lib ? : version ? : conditio debug $(target-requirements) ; - + lib qtmain : # sources : # requirements @@ -370,7 +370,7 @@ rule init ( prefix : full_bin ? : full_inc ? : full_lib ? : version ? : conditio ; if $(.have_separate_debug) = TRUE - { + { debug-message Configure debug libraries with suffix '$(.suffix_debug)' ; lib QtCore : $(main) @@ -389,13 +389,13 @@ rule init ( prefix : full_bin ? : full_inc ? : full_lib ? : version ? : conditio # Initialising the remaining libraries is canonical # parameters 'module' : 'depends-on' : 'usage-define' : 'requirements' : 'include' - # 'include' only for non-canonical include paths. + # 'include' only for non-canonical include paths. add-shared-library QtGui : QtCore : QT_GUI_LIB : $(target-requirements) ; add-shared-library QtNetwork : QtCore : QT_NETWORK_LIB : $(target-requirements) ; add-shared-library QtSql : QtCore : QT_SQL_LIB : $(target-requirements) ; add-shared-library QtXml : QtCore : QT_XML_LIB : $(target-requirements) ; - add-shared-library Qt3Support : QtGui QtNetwork QtXml QtSql + add-shared-library Qt3Support : QtGui QtNetwork QtXml QtSql : QT_QT3SUPPORT_LIB QT3_SUPPORT : on $(target-requirements) ; @@ -432,20 +432,20 @@ rule init ( prefix : full_bin ? : full_inc ? : full_lib ? : version ? : conditio # WebKit (Qt 4.4) add-shared-library QtWebKit : QtGui : QT_WEBKIT_LIB : $(target-requirements) ; - # Phonon Multimedia (Qt 4.4) + # Phonon Multimedia (Qt 4.4) add-shared-library phonon : QtGui QtXml : QT_PHONON_LIB : $(target-requirements) ; - # Multimedia engine (Qt 4.6) + # Multimedia engine (Qt 4.6) add-shared-library QtMultimedia : QtGui : QT_MULTIMEDIA_LIB : $(target-requirements) ; - # XmlPatterns-Engine (Qt 4.4) + # XmlPatterns-Engine (Qt 4.4) add-shared-library QtXmlPatterns : QtNetwork : QT_XMLPATTERNS_LIB : $(target-requirements) ; - # Help-Engine (Qt 4.4) + # Help-Engine (Qt 4.4) add-shared-library QtHelp : QtGui QtSql QtXml : : $(target-requirements) ; add-shared-library QtCLucene : QCore QtSql QtXml : : $(target-requirements) ; - # QML-Engine (Qt 4.7) + # QML-Engine (Qt 4.7) add-shared-library QtDeclarative : QtGui QtXml : : $(target-requirements) ; # AssistantClient Support @@ -627,8 +627,8 @@ rule add-library ( lib-name : version ? : depends-on * : usage-defines * : requi local real_include ; real_include ?= $(include) ; real_include ?= $(lib-name) ; - - lib $(lib-name) + + lib $(lib-name) : # sources $(depends-on) : # requirements @@ -642,7 +642,7 @@ rule add-library ( lib-name : version ? : depends-on * : usage-defines * : requi if $(.have_separate_debug) = TRUE { - lib $(lib-name) + lib $(lib-name) : # sources $(depends-on) : # requirements @@ -655,7 +655,7 @@ rule add-library ( lib-name : version ? : depends-on * : usage-defines * : requi $(.incprefix)/$(real_include) ; } - } + } # Make library explicit so that a simple qt4 will not bring in everything. # And some components like QtDBus/Phonon may not be available on all platforms. @@ -669,21 +669,25 @@ rule add-library ( lib-name : version ? : depends-on * : usage-defines * : requi flags qt4.moc INCLUDES ; flags qt4.moc DEFINES ; +# need a newline for expansion of DEFINES and INCLUDES in the response file. +.nl = " +" ; + # Processes headers to create Qt MetaObject information. Qt4-moc has its # c++-parser, so pass INCLUDES and DEFINES. -# +# We use response file with one INCLUDE/DEFINE per line +# actions moc { - $(.BINPREFIX[-1])/moc -I"$(INCLUDES)" -D$(DEFINES) -f $(>) -o $(<) + $(.BINPREFIX[-1])/moc -f $(>) -o $(<) @"@($(<).rsp:E=-D$(DEFINES)$(.nl) -I"$(INCLUDES:T)"$(.nl))" } - # When moccing files for include only, we don't need -f, otherwise the generated # code will include the .cpp and we'll get duplicated symbols. # actions moc.inc { - $(.BINPREFIX[-1])/moc -I"$(INCLUDES)" -D$(DEFINES) $(>) -o $(<) + $(.BINPREFIX[-1])/moc $(>) -o $(<) @"@($(<).rsp:E=-D$(DEFINES)$(.nl) -I"$(INCLUDES:T)"$(.nl))" }