2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, 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.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "librarywizard.h"
|
|
|
|
|
#include "librarywizarddialog.h"
|
|
|
|
|
|
2010-12-03 13:49:35 +01:00
|
|
|
#include <cpptools/abstracteditorsupport.h>
|
2010-01-13 18:44:15 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2013-02-12 17:26:43 +01:00
|
|
|
#include <qtsupport/qtsupportconstants.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QTextStream>
|
2013-09-20 15:12:44 +02:00
|
|
|
#include <QCoreApplication>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-04-19 15:42:14 +02:00
|
|
|
static const char sharedHeaderPostfixC[] = "_global";
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-10-16 11:02:37 +02:00
|
|
|
namespace QmakeProjectManager {
|
2008-12-02 12:01:29 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2009-01-20 15:31:33 +01:00
|
|
|
LibraryWizard::LibraryWizard()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-09-20 15:12:44 +02:00
|
|
|
setId(QLatin1String("H.Qt4Library"));
|
|
|
|
|
setCategory(QLatin1String(ProjectExplorer::Constants::LIBRARIES_WIZARD_CATEGORY));
|
|
|
|
|
setDisplayCategory(QCoreApplication::translate("ProjectExplorer",
|
|
|
|
|
ProjectExplorer::Constants::LIBRARIES_WIZARD_CATEGORY_DISPLAY));
|
|
|
|
|
setDisplayName(tr("C++ Library"));
|
|
|
|
|
setDescription(tr("Creates a C++ library based on qmake. This can be used to create:<ul>"
|
|
|
|
|
"<li>a shared C++ library for use with <tt>QPluginLoader</tt> and runtime (Plugins)</li>"
|
|
|
|
|
"<li>a shared or static C++ library for use with another project at linktime</li></ul>"));
|
|
|
|
|
setIcon(QIcon(QLatin1String(":/wizards/images/lib.png")));
|
|
|
|
|
setRequiredFeatures(Core::Feature(QtSupport::Constants::FEATURE_QT));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-03 18:00:08 +01:00
|
|
|
QWizard *LibraryWizard::createWizardDialog(QWidget *parent, const Core::WizardDialogParameters &wizardDialogParameters) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-02-03 18:00:08 +01:00
|
|
|
LibraryWizardDialog *dialog = new LibraryWizardDialog(displayName(),
|
|
|
|
|
icon(),
|
|
|
|
|
showModulesPageForLibraries(),
|
|
|
|
|
parent,
|
|
|
|
|
wizardDialogParameters);
|
2009-06-17 12:40:54 +02:00
|
|
|
dialog->setLowerCaseFiles(QtWizard::lowerCaseFiles());
|
2012-02-03 18:00:08 +01:00
|
|
|
dialog->setProjectName(LibraryWizardDialog::uniqueProjectName(wizardDialogParameters.defaultPath()));
|
2010-01-29 21:33:57 +01:00
|
|
|
dialog->setSuffixes(headerSuffix(), sourceSuffix(), formSuffix());
|
2008-12-02 12:01:29 +01:00
|
|
|
return dialog;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 12:10:26 +02:00
|
|
|
static void writeLinuxProFile(QTextStream &str)
|
|
|
|
|
{
|
|
|
|
|
str << "\n"
|
|
|
|
|
"unix {\n"
|
|
|
|
|
" target.path = /usr/lib\n"
|
|
|
|
|
" INSTALLS += target\n"
|
|
|
|
|
"}\n";
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w,
|
2009-01-20 15:31:33 +01:00
|
|
|
QString *errorMessage) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(errorMessage)
|
2008-12-02 12:01:29 +01:00
|
|
|
const LibraryWizardDialog *dialog = qobject_cast<const LibraryWizardDialog *>(w);
|
|
|
|
|
const QtProjectParameters projectParams = dialog->parameters();
|
|
|
|
|
const QString projectPath = projectParams.projectPath();
|
|
|
|
|
const LibraryParameters params = dialog->libraryParameters();
|
|
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
const QString sharedLibExportMacro = QtProjectParameters::exportMacro(projectParams.fileName);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
Core::GeneratedFiles rc;
|
|
|
|
|
// Class header + source
|
|
|
|
|
const QString sourceFileName = buildFileName(projectPath, params.sourceFileName, sourceSuffix());
|
|
|
|
|
Core::GeneratedFile source(sourceFileName);
|
2010-04-16 15:55:32 +02:00
|
|
|
source.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
const QString headerFileFullName = buildFileName(projectPath, params.headerFileName, headerSuffix());
|
|
|
|
|
const QString headerFileName = QFileInfo(headerFileFullName).fileName();
|
2013-02-12 14:02:07 +01:00
|
|
|
QString pluginJsonFileFullName;
|
|
|
|
|
QString pluginJsonFileName;
|
|
|
|
|
if (projectParams.type == QtProjectParameters::Qt4Plugin) {
|
|
|
|
|
pluginJsonFileFullName = buildFileName(projectPath, projectParams.fileName, QLatin1String("json"));
|
|
|
|
|
pluginJsonFileName = QFileInfo(pluginJsonFileFullName).fileName();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
Core::GeneratedFile header(headerFileFullName);
|
|
|
|
|
|
|
|
|
|
// Create files: global header for shared libs
|
|
|
|
|
QString globalHeaderFileName;
|
|
|
|
|
if (projectParams.type == QtProjectParameters::SharedLibrary) {
|
2013-01-17 16:52:44 +01:00
|
|
|
const QString globalHeaderName = buildFileName(projectPath, projectParams.fileName.toLower() + QLatin1String(sharedHeaderPostfixC), headerSuffix());
|
2008-12-02 12:01:29 +01:00
|
|
|
Core::GeneratedFile globalHeader(globalHeaderName);
|
|
|
|
|
globalHeaderFileName = QFileInfo(globalHeader.path()).fileName();
|
2010-08-09 12:23:21 +02:00
|
|
|
globalHeader.setContents(CppTools::AbstractEditorSupport::licenseTemplate(globalHeaderFileName)
|
|
|
|
|
+ LibraryParameters::generateSharedHeader(globalHeaderFileName, projectParams.fileName, sharedLibExportMacro));
|
2008-12-02 12:01:29 +01:00
|
|
|
rc.push_back(globalHeader);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate code
|
|
|
|
|
QString headerContents, sourceContents;
|
2010-01-07 18:17:24 +01:00
|
|
|
params.generateCode(projectParams.type, projectParams.fileName, headerFileName,
|
2013-02-12 14:02:07 +01:00
|
|
|
globalHeaderFileName, sharedLibExportMacro, pluginJsonFileName,
|
2008-12-02 12:01:29 +01:00
|
|
|
/* indentation*/ 4, &headerContents, &sourceContents);
|
|
|
|
|
|
2010-08-09 12:23:21 +02:00
|
|
|
source.setContents(CppTools::AbstractEditorSupport::licenseTemplate(sourceFileName, params.className)
|
|
|
|
|
+ sourceContents);
|
|
|
|
|
header.setContents(CppTools::AbstractEditorSupport::licenseTemplate(headerFileFullName, params.className)
|
|
|
|
|
+ headerContents);
|
2008-12-02 12:01:29 +01:00
|
|
|
rc.push_back(source);
|
|
|
|
|
rc.push_back(header);
|
|
|
|
|
// Create files: profile
|
2010-01-07 18:17:24 +01:00
|
|
|
const QString profileName = buildFileName(projectPath, projectParams.fileName, profileSuffix());
|
2008-12-02 12:01:29 +01:00
|
|
|
Core::GeneratedFile profile(profileName);
|
2010-04-16 15:55:32 +02:00
|
|
|
profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
|
2008-12-02 12:01:29 +01:00
|
|
|
QString profileContents;
|
|
|
|
|
{
|
|
|
|
|
QTextStream proStr(&profileContents);
|
|
|
|
|
QtProjectParameters::writeProFileHeader(proStr);
|
|
|
|
|
projectParams.writeProFile(proStr);
|
|
|
|
|
proStr << "\nSOURCES += " << QFileInfo(source.path()).fileName()
|
|
|
|
|
<< "\n\nHEADERS += " << headerFileName;
|
|
|
|
|
if (!globalHeaderFileName.isEmpty())
|
|
|
|
|
proStr << "\\\n " << globalHeaderFileName << '\n';
|
2013-02-12 14:02:07 +01:00
|
|
|
if (!pluginJsonFileName.isEmpty())
|
|
|
|
|
proStr << "\nOTHER_FILES += " << pluginJsonFileName << '\n';
|
2013-10-25 12:10:26 +02:00
|
|
|
writeLinuxProFile(proStr);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
profile.setContents(profileContents);
|
|
|
|
|
rc.push_back(profile);
|
2013-02-12 14:02:07 +01:00
|
|
|
|
|
|
|
|
if (!pluginJsonFileName.isEmpty()) {
|
|
|
|
|
Core::GeneratedFile jsonFile(pluginJsonFileFullName);
|
|
|
|
|
jsonFile.setContents(QLatin1String("{\n \"Keys\" : [ ]\n}\n"));
|
|
|
|
|
rc.push_back(jsonFile);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 16:19:05 +01:00
|
|
|
} // namespace Internal
|
2013-10-16 11:02:37 +02:00
|
|
|
} // namespace QmakeProjectManager
|