Files
qt-creator/src/plugins/qmakeprojectmanager/wizards/librarywizard.cpp

163 lines
7.4 KiB
C++
Raw Normal View History

/****************************************************************************
2008-12-02 12:01:29 +01:00
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator.
2008-12-02 12:01:29 +01: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.
**
** GNU Lesser General Public License Usage
** 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.
**
****************************************************************************/
2008-12-02 16:19:05 +01:00
2008-12-02 12:01:29 +01:00
#include "librarywizard.h"
#include "librarywizarddialog.h"
#include <cpptools/abstracteditorsupport.h>
2010-01-13 18:44:15 +01:00
#include <projectexplorer/projectexplorerconstants.h>
#include <qtsupport/qtsupportconstants.h>
2008-12-02 12:01:29 +01:00
#include <QFileInfo>
#include <QTextStream>
#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
namespace QmakeProjectManager {
2008-12-02 12:01:29 +01:00
namespace Internal {
LibraryWizard::LibraryWizard()
2008-12-02 12:01:29 +01: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
}
QWizard *LibraryWizard::createWizardDialog(QWidget *parent, const Core::WizardDialogParameters &wizardDialogParameters) const
2008-12-02 12:01:29 +01:00
{
LibraryWizardDialog *dialog = new LibraryWizardDialog(displayName(),
icon(),
showModulesPageForLibraries(),
parent,
wizardDialogParameters);
dialog->setLowerCaseFiles(QtWizard::lowerCaseFiles());
dialog->setProjectName(LibraryWizardDialog::uniqueProjectName(wizardDialogParameters.defaultPath()));
dialog->setSuffixes(headerSuffix(), sourceSuffix(), formSuffix());
2008-12-02 12:01:29 +01:00
return dialog;
}
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,
QString *errorMessage) const
2008-12-02 12:01:29 +01: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();
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);
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();
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) {
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();
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;
params.generateCode(projectParams.type, projectParams.fileName, headerFileName,
globalHeaderFileName, sharedLibExportMacro, pluginJsonFileName,
2008-12-02 12:01:29 +01:00
/* indentation*/ 4, &headerContents, &sourceContents);
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
const QString profileName = buildFileName(projectPath, projectParams.fileName, profileSuffix());
2008-12-02 12:01:29 +01:00
Core::GeneratedFile profile(profileName);
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';
if (!pluginJsonFileName.isEmpty())
proStr << "\nOTHER_FILES += " << pluginJsonFileName << '\n';
writeLinuxProFile(proStr);
2008-12-02 12:01:29 +01:00
}
profile.setContents(profileContents);
rc.push_back(profile);
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
} // namespace QmakeProjectManager