automoc: add special handling for including basename_p.moc, with test

Alex
This commit is contained in:
Alex Neundorf 2011-11-22 22:01:13 +01:00
parent 74ab0f6aa4
commit bde4edb6ab
6 changed files with 124 additions and 8 deletions

View File

@ -650,14 +650,39 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
{
if (basename != scannedFileBasename)
{
std::cerr << "AUTOMOC: error: " << absFilename << ": The file "
<< "includes the moc file \"" << currentMoc
<< "\", which seems to be the moc file from a different "
<< "source file. This is not supported. "
<< "Include \"" << scannedFileBasename << ".moc\" to run "
<< "moc on this source file." << std::endl;
bool fail = true;
if ((this->QtMajorVersion == "4")
&& (basename == scannedFileBasename +"_p"))
{
std::string mocSubDir = extractSubDir(absPath, currentMoc);
std::string headerToMoc = findMatchingHeader(
absPath, mocSubDir, basename, headerExtensions);
if (!headerToMoc.empty())
{
// this is for KDE4 compatibility:
fail = false;
includedMocs[headerToMoc] = currentMoc;
std::cerr << "AUTOMOC: warning: " << absFilename << ": The file "
"includes the moc file \"" << currentMoc <<
"\" instead of \"moc_" << basename << ".cpp\". "
"Running moc on "
<< "\"" << headerToMoc << "\" ! Better include \"moc_"
<< basename << ".cpp\" for a robust build."
<< std::endl;
}
}
if (fail)
{
std::cerr <<"AUTOMOC: error: " << absFilename << ": The file "
"includes the moc file \"" << currentMoc <<
"\", which seems to be the moc file from a different "
"source file. This is not supported. "
"Include \"" << scannedFileBasename << ".moc\" to run "
"moc on this source file." << std::endl;
::exit(EXIT_FAILURE);
}
}
includedMocs[absFilename] = currentMoc;
dotMocIncluded = true;
}

View File

@ -13,7 +13,7 @@ add_definitions(-DFOO)
# create an executable and a library target, both requiring automoc:
add_library(codeeditorLib STATIC codeeditor.cpp)
add_executable(foo main.cpp calwidget.cpp foo.cpp blub.cpp bar.cpp abc.cpp xyz.cpp)
add_executable(foo main.cpp calwidget.cpp foo.cpp blub.cpp bar.cpp abc.cpp xyz.cpp yaf.cpp)
set_target_properties(foo codeeditorLib PROPERTIES AUTOMOC TRUE)

View File

@ -47,6 +47,7 @@
#include "sub/bar.h"
#include "abc.h"
#include "xyz.h"
#include "yaf.h"
int main(int argv, char **args)
{
@ -74,5 +75,8 @@ int main(int argv, char **args)
Xyz xyz;
xyz.doXyz();
Yaf yaf;
yaf.doYaf();
return app.exec();
}

32
Tests/QtAutomoc/yaf.cpp Normal file
View File

@ -0,0 +1,32 @@
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2004-2011 Kitware, Inc.
Copyright 2011 Alexander Neundorf (neundorf@kde.org)
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#include "yaf.h"
#include "yaf_p.h"
#include <stdio.h>
Yaf::Yaf()
{
}
void Yaf::doYaf()
{
YafP yafP;
yafP.doYafP();
}
// check that including a moc file from a private header the wrong way works:
#include "yaf_p.moc"

25
Tests/QtAutomoc/yaf.h Normal file
View File

@ -0,0 +1,25 @@
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2004-2011 Kitware, Inc.
Copyright 2011 Alexander Neundorf (neundorf@kde.org)
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#ifndef YAF_H
#define YAF_H
class Yaf
{
public:
Yaf();
public:
void doYaf();
};
#endif

30
Tests/QtAutomoc/yaf_p.h Normal file
View File

@ -0,0 +1,30 @@
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2004-2011 Kitware, Inc.
Copyright 2011 Alexander Neundorf (neundorf@kde.org)
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#ifndef YAF_P_H
#define YAF_P_H
#include <QObject>
#include <stdio.h>
class YafP : public QObject
{
Q_OBJECT
public:
YafP() {}
public slots:
void doYafP() { printf("I am yet another file !\n"); }
};
#endif