2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "libraryparameters.h"
|
|
|
|
|
|
2008-12-02 16:19:05 +01:00
|
|
|
#include <utils/codegeneration.h>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QTextStream>
|
|
|
|
|
#include <QtCore/QStringList>
|
|
|
|
|
|
|
|
|
|
// Contents of the header defining the shared library export.
|
|
|
|
|
#define GUARD_VARIABLE "<GUARD>"
|
|
|
|
|
#define EXPORT_MACRO_VARIABLE "<EXPORT_MACRO>"
|
|
|
|
|
#define LIBRARY_MACRO_VARIABLE "<LIBRARY_MACRO>"
|
|
|
|
|
|
|
|
|
|
static const char *globalHeaderContentsC =
|
|
|
|
|
"#ifndef "GUARD_VARIABLE"\n"
|
|
|
|
|
"#define "GUARD_VARIABLE"\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"#include <QtCore/qglobal.h>\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"#if defined("LIBRARY_MACRO_VARIABLE")\n"
|
|
|
|
|
"# define "EXPORT_MACRO_VARIABLE" Q_DECL_EXPORT\n"
|
|
|
|
|
"#else\n"
|
|
|
|
|
"# define "EXPORT_MACRO_VARIABLE" Q_DECL_IMPORT\n"
|
|
|
|
|
"#endif\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"#endif // "GUARD_VARIABLE"\n";
|
|
|
|
|
|
|
|
|
|
namespace Qt4ProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
void LibraryParameters::generateCode(QtProjectParameters:: Type t,
|
|
|
|
|
const QString &projectTarget,
|
|
|
|
|
const QString &headerName,
|
|
|
|
|
const QString &sharedHeader,
|
|
|
|
|
const QString &exportMacro,
|
|
|
|
|
int indentation,
|
|
|
|
|
QString *header,
|
|
|
|
|
QString *source) const
|
|
|
|
|
{
|
|
|
|
|
QString rc;
|
|
|
|
|
QTextStream headerStr(header);
|
|
|
|
|
|
|
|
|
|
const QString indent = QString(indentation, QLatin1Char(' '));
|
|
|
|
|
|
2011-01-18 12:18:08 +01:00
|
|
|
// Do we have namespaces?
|
|
|
|
|
QStringList namespaceList = className.split(QLatin1String("::"));
|
|
|
|
|
if (namespaceList.empty()) // Paranoia!
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const QString unqualifiedClassName = namespaceList.takeLast();
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// 1) Header
|
2011-01-18 12:18:08 +01:00
|
|
|
const QString guard = Utils::headerGuard(headerFileName, namespaceList);
|
2008-12-02 12:01:29 +01:00
|
|
|
headerStr << "#ifndef " << guard
|
|
|
|
|
<< "\n#define " << guard << '\n' << '\n';
|
|
|
|
|
|
|
|
|
|
if (!sharedHeader.isEmpty())
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::writeIncludeFileDirective(sharedHeader, false, headerStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// include base class header
|
|
|
|
|
if (!baseClassName.isEmpty()) {
|
|
|
|
|
QString include;
|
|
|
|
|
if (!baseClassModule.isEmpty()) {
|
|
|
|
|
include += baseClassModule;
|
|
|
|
|
include += QLatin1Char('/');
|
|
|
|
|
}
|
|
|
|
|
include += baseClassName;
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::writeIncludeFileDirective(include, true, headerStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
headerStr << '\n';
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
const QString namespaceIndent = Utils::writeOpeningNameSpaces(namespaceList, indent, headerStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Class declaraction
|
|
|
|
|
headerStr << '\n' << namespaceIndent << "class ";
|
|
|
|
|
if (t == QtProjectParameters::SharedLibrary && !exportMacro.isEmpty())
|
|
|
|
|
headerStr << exportMacro << ' ';
|
|
|
|
|
|
|
|
|
|
headerStr << unqualifiedClassName;
|
|
|
|
|
if (!baseClassName.isEmpty())
|
|
|
|
|
headerStr << " : public " << baseClassName;
|
|
|
|
|
headerStr << " {\n";
|
|
|
|
|
|
|
|
|
|
// Is this a QObject (plugin)
|
|
|
|
|
const bool inheritsQObject = t == QtProjectParameters::Qt4Plugin;
|
|
|
|
|
if (inheritsQObject) {
|
2009-06-09 13:50:37 +02:00
|
|
|
headerStr << namespaceIndent << indent << "Q_OBJECT\n";
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
headerStr << namespaceIndent << "public:\n";
|
|
|
|
|
if (inheritsQObject) {
|
2009-06-09 15:52:58 +02:00
|
|
|
headerStr << namespaceIndent << indent << unqualifiedClassName << "(QObject *parent = 0);\n";
|
2008-12-02 12:01:29 +01:00
|
|
|
} else {
|
|
|
|
|
headerStr << namespaceIndent << indent << unqualifiedClassName << "();\n";
|
|
|
|
|
}
|
|
|
|
|
headerStr << namespaceIndent << "};\n\n";
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::writeClosingNameSpaces(namespaceList, indent, headerStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
headerStr << "#endif // "<< guard << '\n';
|
|
|
|
|
/// 2) Source
|
|
|
|
|
QTextStream sourceStr(source);
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::writeIncludeFileDirective(headerName, false, sourceStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
sourceStr << '\n';
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::writeOpeningNameSpaces(namespaceList, indent, sourceStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
// Constructor
|
|
|
|
|
sourceStr << '\n' << namespaceIndent << unqualifiedClassName << "::" << unqualifiedClassName;
|
|
|
|
|
if (inheritsQObject) {
|
|
|
|
|
sourceStr << "(QObject *parent) :\n"
|
|
|
|
|
<< namespaceIndent << indent << baseClassName << "(parent)\n";
|
|
|
|
|
} else {
|
|
|
|
|
sourceStr << "()\n";
|
|
|
|
|
}
|
|
|
|
|
sourceStr << namespaceIndent << "{\n" << namespaceIndent << "}\n";
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::writeClosingNameSpaces(namespaceList, indent, sourceStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
if (t == QtProjectParameters::Qt4Plugin)
|
|
|
|
|
sourceStr << '\n' << "Q_EXPORT_PLUGIN2(" << projectTarget << ", " << className << ")\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString LibraryParameters::generateSharedHeader(const QString &globalHeaderFileName,
|
|
|
|
|
const QString &projectTarget,
|
|
|
|
|
const QString &exportMacro)
|
|
|
|
|
{
|
|
|
|
|
QString contents = QLatin1String(globalHeaderContentsC);
|
2009-10-05 11:06:05 +02:00
|
|
|
contents.replace(QLatin1String(GUARD_VARIABLE), Utils::headerGuard(globalHeaderFileName));
|
2008-12-02 12:01:29 +01:00
|
|
|
contents.replace(QLatin1String(EXPORT_MACRO_VARIABLE), exportMacro);
|
|
|
|
|
contents.replace(QLatin1String(LIBRARY_MACRO_VARIABLE), QtProjectParameters::libraryMacro(projectTarget));
|
|
|
|
|
return contents;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 16:19:05 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Qt4ProjectManager
|