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
|
/* KDevelop CMake Support
*
* Copyright 2009 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 "cmakeutils.h"
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <kconfig.h>
#include <klocale.h>
#include <kconfiggroup.h>
#include <kurl.h>
#include <kparts/mainwindow.h>
#include <kdialog.h>
#include <kdebug.h>
#include <kprocess.h>
#include <kstandarddirs.h>
#include <KMessageBox>
#include <project/projectmodel.h>
#include <interfaces/iproject.h>
#include <interfaces/icore.h>
#include <interfaces/iuicontroller.h>
#include "cmakebuilddirchooser.h"
#include "icmakedocumentation.h"
#include <interfaces/idocumentationcontroller.h>
#include <interfaces/iplugincontroller.h>
static QString currentBuildDirKey = "CurrentBuildDir";
static QString currentCMakeBinaryKey = "Current CMake Binary";
static QString currentBuildTypeKey = "CurrentBuildType";
static QString currentInstallDirKey = "CurrentInstallDir";
static QString currentEnvironmentKey = "CurrentEnvironment";
static QString currentExtraArgumentsKey = "Extra Arguments";
static QString projectRootRelativeKey = "ProjectRootRelative";
static QString projectBuildDirs = "BuildDirs";
namespace CMake
{
///NOTE: when you change this, update @c defaultConfigure in cmakemanagertest.cpp
bool checkForNeedingConfigure( KDevelop::ProjectBaseItem* item )
{
KConfigGroup cmakeGrp = item->project()->projectConfiguration()->group("CMake");
KUrl builddir = cmakeGrp.readEntry( currentBuildDirKey, KUrl() );
QStringList builddirs = cmakeGrp.readEntry( "BuildDirs", QStringList() );
if( !builddir.isValid() || builddir.isEmpty() )
{
CMakeBuildDirChooser bd;
KUrl folderUrl=item->project()->folder();
QString relative=CMake::projectRootRelative(item->project());
folderUrl.cd(relative);
bd.setSourceFolder( folderUrl );
if( !bd.exec() )
{
return false;
}
{ // if the buildfolder does not exist, create it
// TODO: the whole configuration stuff has to be changed since it expects a configured cmake project
// creating the buildfolder alone is not enough.
QDir buildFolder( bd.buildFolder().toLocalFile() );
if ( !buildFolder.exists() ) {
if ( !buildFolder.mkpath( buildFolder.absolutePath() ) ) {
KMessageBox::error( KDevelop::ICore::self()->uiController()->activeMainWindow(),
i18n( "The build directory did not exist and could not be created." ),
i18n("Error creating build directory") );
return false;
}
}
}
cmakeGrp.writeEntry( currentBuildDirKey, bd.buildFolder() );
cmakeGrp.writeEntry( currentCMakeBinaryKey, bd.cmakeBinary() );
cmakeGrp.writeEntry( currentInstallDirKey, bd.installPrefix() );
cmakeGrp.writeEntry( currentExtraArgumentsKey, bd.extraArguments() );
cmakeGrp.writeEntry( currentBuildTypeKey, bd.buildType() );
if(!builddirs.contains(bd.buildFolder().toLocalFile())) {
builddirs.append(bd.buildFolder().toLocalFile());
cmakeGrp.writeEntry( "BuildDirs", builddirs);
}
cmakeGrp.sync();
return true;
} else if( !QFileInfo( builddir.toLocalFile() + "/CMakeCache.txt" ).exists() )
{
// User entered information already, but cmake hasn't actually been run yet.
return true;
}
return false;
}
KUrl projectRoot(KDevelop::IProject* project)
{
KUrl projectPath = project->folder();
bool correct=projectPath.cd(CMake::projectRootRelative(project));
Q_ASSERT(correct);
return projectPath;
}
KUrl currentBuildDir( KDevelop::IProject* project )
{
KConfigGroup cmakeGrp = project->projectConfiguration()->group("CMake");
return cmakeGrp.readEntry( currentBuildDirKey, KUrl() );
}
QString currentBuildType( KDevelop::IProject* project )
{
KConfigGroup cmakeGrp = project->projectConfiguration()->group("CMake");
return cmakeGrp.readEntry( currentBuildTypeKey, "Release" );
}
KUrl currentCMakeBinary( KDevelop::IProject* project )
{
KConfigGroup cmakeGrp = project->projectConfiguration()->group("CMake");
return cmakeGrp.readEntry( currentCMakeBinaryKey, KStandardDirs::findExe( "cmake" ) );
}
KUrl currentInstallDir( KDevelop::IProject* project )
{
KConfigGroup cmakeGrp = project->projectConfiguration()->group("CMake");
return cmakeGrp.readEntry( currentInstallDirKey, KUrl("/usr/local") );
}
QString projectRootRelative( KDevelop::IProject* project )
{
KConfigGroup cmakeGrp = project->projectConfiguration()->group("CMake");
return cmakeGrp.readEntry( projectRootRelativeKey, QString());
}
QString currentExtraArguments( KDevelop::IProject* project )
{
KConfigGroup cmakeGrp = project->projectConfiguration()->group("CMake");
return cmakeGrp.readEntry( currentExtraArgumentsKey, "");
}
void setCurrentInstallDir( KDevelop::IProject* project, const KUrl& url )
{
KConfigGroup cmakeGrp = project->projectConfiguration()->group("CMake");
cmakeGrp.writeEntry( currentInstallDirKey, url );
cmakeGrp.sync();
}
void setCurrentBuildType( KDevelop::IProject* project, const QString& type )
{
KConfigGroup cmakeGrp = project->projectConfiguration()->group("CMake");
cmakeGrp.writeEntry( currentBuildTypeKey, type );
cmakeGrp.sync();
}
void setCurrentCMakeBinary( KDevelop::IProject* project, const KUrl& url )
{
KConfigGroup cmakeGrp = project->projectConfiguration()->group("CMake");
cmakeGrp.writeEntry( currentCMakeBinaryKey, url );
cmakeGrp.sync();
}
void setCurrentBuildDir( KDevelop::IProject* project, const KUrl& url )
{
KConfigGroup cmakeGrp = project->projectConfiguration()->group("CMake");
cmakeGrp.writeEntry( currentBuildDirKey, url );
cmakeGrp.sync();
}
void setProjectRootRelative( KDevelop::IProject* project, const QString& relative)
{
KConfigGroup cmakeGrp = project->projectConfiguration()->group("CMake");
cmakeGrp.writeEntry( projectRootRelativeKey, relative );
cmakeGrp.sync();
}
void setCurrentExtraArguments( KDevelop::IProject* project, const QString& string)
{
KConfigGroup cmakeGrp = project->projectConfiguration()->group("CMake");
cmakeGrp.writeEntry( currentExtraArgumentsKey, string );
cmakeGrp.sync();
}
QString currentEnvironment(KDevelop::IProject* project)
{
KConfigGroup cmakeGrp = project->projectConfiguration()->group("CMake");
return cmakeGrp.readEntry(currentEnvironmentKey, QString());
}
ICMakeDocumentation* cmakeDocumentation()
{
ICMakeDocumentation* p=KDevelop::ICore::self()->pluginController()->extensionForPlugin<ICMakeDocumentation>("org.kdevelop.ICMakeDocumentation");
if( !p )
{
return 0;
}
Q_ASSERT(p);
return p;
}
QStringList allBuildDirs(KDevelop::IProject* project)
{
KConfigGroup cmakeGrp = project->projectConfiguration()->group("CMake");
return cmakeGrp.readEntry( projectBuildDirs, QStringList() );
}
}
|