1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
/* KDevelop CMake Support
*
* Copyright 2006-2007 Andreas Pakulat <apaku@gmx.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include "cmakebuilder.h"
#include "imakebuilder.h"
#include <config.h>
#include <QtCore/QStringList>
#include <QtCore/QSignalMapper>
#include <QtCore/QFile>
#include <QtCore/QDir>
#include <project/projectmodel.h>
#include <interfaces/iproject.h>
#include <interfaces/icore.h>
#include <interfaces/iuicontroller.h>
#include <interfaces/iplugincontroller.h>
#include <project/interfaces/ibuildsystemmanager.h>
#include <outputview/ioutputview.h>
#include <outputview/outputmodel.h>
#include <util/commandexecutor.h>
#include <QtDesigner/QExtensionFactory>
#include <kpluginfactory.h>
#include <kpluginloader.h>
#include <kparts/mainwindow.h>
#include <kio/deletejob.h>
#include <kaboutdata.h>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <kmessagebox.h>
#include <kdialog.h>
#include <kglobal.h>
#include <klocale.h>
#include <kdebug.h>
#include <KProcess>
#include <kjob.h>
#include <kurl.h>
#include <kconfig.h>
#include "configureandbuildjob.h"
#include "cmakejob.h"
#include "cmakeutils.h"
K_PLUGIN_FACTORY(CMakeBuilderFactory, registerPlugin<CMakeBuilder>(); )
K_EXPORT_PLUGIN(CMakeBuilderFactory(KAboutData("kdevcmakebuilder","kdevcmakebuilder", ki18n("CMake Builder"),
"0.1", ki18n("Support for building CMake projects"), KAboutData::License_GPL)))
CMakeBuilder::CMakeBuilder(QObject *parent, const QVariantList &)
: KDevelop::IPlugin(CMakeBuilderFactory::componentData(), parent),
m_dirty(true), m_builder( 0 )
{
KDEV_USE_EXTENSION_INTERFACE( KDevelop::IProjectBuilder )
KDEV_USE_EXTENSION_INTERFACE( ICMakeBuilder )
IPlugin* i = core()->pluginController()->pluginForExtension("org.kdevelop.IMakeBuilder");
if( i )
{
m_builder = i->extension<IMakeBuilder>();
if( m_builder )
{
connect(i, SIGNAL(built(KDevelop::ProjectBaseItem*)), this, SLOT(buildFinished(KDevelop::ProjectBaseItem*)));
connect(i, SIGNAL(failed(KDevelop::ProjectBaseItem*)), this, SLOT(buildFinished(KDevelop::ProjectBaseItem*)));
connect(i, SIGNAL(built(KDevelop::ProjectBaseItem*)), this, SIGNAL(built(KDevelop::ProjectBaseItem*)));
connect(i, SIGNAL(failed(KDevelop::ProjectBaseItem*)), this, SIGNAL(failed(KDevelop::ProjectBaseItem*)));
connect(i, SIGNAL(cleaned(KDevelop::ProjectBaseItem*)), this, SIGNAL(cleaned(KDevelop::ProjectBaseItem*)));
connect(i, SIGNAL(installed(KDevelop::ProjectBaseItem*)), this, SIGNAL(installed(KDevelop::ProjectBaseItem*)));
}
}
}
CMakeBuilder::~CMakeBuilder()
{
}
void CMakeBuilder::buildFinished(KDevelop::ProjectBaseItem* it)
{
if(m_deleteWhenDone.remove(it)) {
delete it;
}
}
KJob* CMakeBuilder::build(KDevelop::ProjectBaseItem *dom)
{
KDevelop::ProjectBaseItem* builditem = dom;
if( m_builder )
{
if(dom->file())
{
KDevelop::ProjectFileItem* file = dom->file();
int lastDot = file->text().lastIndexOf('.');
QString target = file->text().mid(0, lastDot)+".o";
KDevelop::ProjectBuildFolderItem *fldr = new KDevelop::ProjectBuildFolderItem(dom->project(), file->url().upUrl());
KDevelop::ProjectTargetItem *it = new KDevelop::ProjectTargetItem(dom->project(), target);
fldr->add(it);
builditem=it;
m_deleteWhenDone << fldr << it;
}
KJob* configure = 0;
if( CMake::checkForNeedingConfigure(builditem) )
{
kDebug() << "Needing configure, adding item and setting job";
configure = this->configure(builditem->project());
} else if( CMake::currentBuildDir( builditem->project() ).isEmpty() )
{
KMessageBox::error(KDevelop::ICore::self()->uiController()->activeMainWindow(),
i18n("No Build Directory configured, cannot build"), i18n("Aborting build") );
return 0;
}
kDebug(9032) << "Building with make";
KJob* build = m_builder->build(builditem);
if( configure )
{
kDebug() << "creating composite job";
build = new ConfigureAndBuildJob( configure, build );
}
return build;
}
return 0;
}
KJob* CMakeBuilder::clean(KDevelop::ProjectBaseItem *dom)
{
KDevelop::ProjectBaseItem* item = dom;
if( m_builder )
{
if(dom->file()) //It doesn't work to compile a file
item=(KDevelop::ProjectBaseItem*) dom->parent();
KJob* configure = 0;
if( CMake::checkForNeedingConfigure(item) )
{
configure = this->configure(item->project());
} else if( CMake::currentBuildDir( item->project() ).isEmpty() )
{
KMessageBox::error(KDevelop::ICore::self()->uiController()->activeMainWindow(),
i18n("No Build Directory configured, cannot clean"), i18n("Aborting clean") );
return 0;
}
kDebug(9032) << "Cleaning with make";
KJob* clean = m_builder->clean(item);
if( configure ) {
clean = new ConfigureAndBuildJob( configure, clean );
}
return clean;
}
return 0;
}
KJob* CMakeBuilder::install(KDevelop::ProjectBaseItem *dom)
{
KDevelop::ProjectBaseItem* item = dom;
if( m_builder )
{
if(dom->file())
item=(KDevelop::ProjectBaseItem*) dom->parent();
KJob* configure = 0;
if( CMake::checkForNeedingConfigure(item) )
{
configure = this->configure(item->project());
} else if( CMake::currentBuildDir( item->project() ).isEmpty() )
{
KMessageBox::error(KDevelop::ICore::self()->uiController()->activeMainWindow(),
i18n("No Build Directory configured, cannot install"), i18n("Aborting install") );
return 0;
}
kDebug(9032) << "Installing with make";
KJob* install = m_builder->install(item);
if( configure ) {
install = new ConfigureAndBuildJob( configure, install );
}
return install;
}
return 0;
}
KJob* CMakeBuilder::configure( KDevelop::IProject* project )
{
if( CMake::currentBuildDir( project ).isEmpty() )
{
KMessageBox::error(KDevelop::ICore::self()->uiController()->activeMainWindow(),
i18n("No Build Directory configured, cannot configure"), i18n("Aborting configure") );
return 0;
}
CMakeJob* job = new CMakeJob(this);
job->setProject(project);
return job;
}
KJob* CMakeBuilder::prune( KDevelop::IProject* project )
{
KUrl builddir = CMake::currentBuildDir( project );
if( builddir.isEmpty() )
{
KMessageBox::information(KDevelop::ICore::self()->uiController()->activeMainWindow(),
i18n("No Build Directory configured, cannot clear builddir"), i18n("No clearing of builddir possible") );
return 0;
}
QDir d( builddir.toLocalFile() );
KUrl::List urls;
foreach( const QString& entry, d.entryList( QDir::NoDotAndDotDot | QDir::AllEntries ) )
{
KUrl tmp = builddir;
tmp.addPath( entry );
urls << tmp;
}
return KIO::del( urls );
}
#include "cmakebuilder.moc"
|