Commit cd496294 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Added a first basic variable support.

parent 9ea26eae
......@@ -69,6 +69,30 @@ CMakeProjectManager::~CMakeProjectManager()
// return m_project;
// }
bool CMakeProjectManager::isVariable(const QString &name)
{
return name.startsWith("${") && name.endsWith("}");
}
QString CMakeProjectManager::variableName(const QString &name)
{
if(!isVariable(name))
return QString::null;
return name.mid(2, name.length()-3);
}
QStringList CMakeProjectManager::resolveVariables(const QStringList & vars)
{
QStringList rvars;
for(QStringList::const_iterator i=vars.begin(); i!=vars.end(); ++i) {
if(isVariable(*i))
rvars += m_vars.value(variableName(*i));
else
rvars += *i;
}
return rvars;
}
KUrl CMakeProjectManager::buildDirectory(KDevelop::ProjectItem *item) const
{
return item->project()->folder();
......@@ -84,7 +108,7 @@ QList<KDevelop::ProjectFolderItem*> CMakeProjectManager::parse( KDevelop::Projec
kDebug(9025) << "parse: " << folder->url() << endl;
CMakeAst *node = folder->tree();
CMakeProjectVisitor v;
CMakeProjectVisitor v(&m_vars);
node->accept(&v);
// FolderInfo fi = folder->folderInfo();
// for ( QStringList::iterator it = fi.includes.begin();
......@@ -95,7 +119,9 @@ QList<KDevelop::ProjectFolderItem*> CMakeProjectManager::parse( KDevelop::Projec
// m_includeDirList.append( urlCandidate );
// }
foreach ( QString subf, v.subdirectories() ) {
//FIXME:resolveVariables is not working
kDebug(9032) << "resolveVars" << resolveVariables(v.subdirectories()) << v.subdirectories() << endl;
foreach ( QString subf, resolveVariables(v.subdirectories()) ) {
CMakeAst *newFolder = new CMakeAst;
KUrl path(folder->url());
path.addPath(subf);
......@@ -117,12 +143,13 @@ QList<KDevelop::ProjectFolderItem*> CMakeProjectManager::parse( KDevelop::Projec
foreach ( QString t, v.targets())
{
CMakeTargetItem* targetItem = new CMakeTargetItem( item->project(), t, folder );
foreach( QString sFile, v.files(t) )
foreach( QString sFile, resolveVariables(v.files(t)) )
{
KUrl sourceFile = folder->url();
sourceFile.adjustPath( KUrl::AddTrailingSlash );
sourceFile.addPath( sFile );
new KDevelop::ProjectFileItem( item->project(), sourceFile, targetItem );
kDebug(9032) << "..........Adding: " << sFile << endl;
}
}
return folderList;
......@@ -148,7 +175,7 @@ KDevelop::ProjectItem* CMakeProjectManager::import( KDevelop::IProject *project
if ( !CMakeListsParser::parseCMakeFile( rootFolder, cmakeInfoFile.toLocalFile() ) )
{
CMakeProjectVisitor v;
CMakeProjectVisitor v(&m_vars);
rootFolder->accept(&v);
name = v.projectName();
......
......@@ -96,12 +96,16 @@ public:
private:
static bool isVariable(const QString& name);
static QString variableName(const QString &name);
QStringList resolveVariables(const QStringList & vars);
KDevelop::IProject* m_project;
CMakeFolderItem* m_rootItem;
KDevelop::IProjectBuilder* m_builder;
KUrl::List m_includeDirList;
CMakeListsParser m_parser;
QHash<QString, QStringList> m_vars;
// ProjectInfo m_projectInfo;
};
......
......@@ -1635,14 +1635,9 @@ bool SetAst::parseFunctionInfo( const CMakeFunctionDesc& func )
//look for the FORCE argument. Thanks to the CMake folks for letting
//me read their code
if ( argSize > 4 && func.arguments.last().value == "FORCE" )
m_forceStoring = true;
m_forceStoring = ( argSize > 4 && func.arguments.last().value == "FORCE" );
if ( argSize > 3 &&
func.arguments[argSize - 3 - ( m_forceStoring ? 1 : 0 )].value == "CACHE" )
{
m_storeInCache = true;
}
m_storeInCache = ( argSize > 3 && func.arguments[argSize - 3 - ( m_forceStoring ? 1 : 0 )].value == "CACHE" );
int numCacheArgs = ( m_storeInCache ? 3 : 0 );
int numForceArgs = ( m_forceStoring ? 1 : 0 );
......
......@@ -464,7 +464,6 @@ CMAKE_ADD_AST_MEMBER( bool, bool, storeInCache, StoreInCache )
CMAKE_ADD_AST_MEMBER( bool, bool, forceStoring, ForceStoring )
CMAKE_ADD_AST_MEMBER( QString, const QString&, entryType, EntryType )
CMAKE_ADD_AST_MEMBER( QString, const QString&, documentation, Documentation )
CMAKE_END_AST_CLASS( SetAst )
......
......@@ -21,6 +21,12 @@
#include "cmakeast.h"
#include <kdebug.h>
#include <QHash>
CMakeProjectVisitor::CMakeProjectVisitor(QHash<QString, QStringList> *vars) : m_vars(vars)
{
}
void CMakeProjectVisitor::notImplemented() const {
kDebug(9032) << "not implemented!" << endl;
......@@ -49,25 +55,22 @@ void CMakeProjectVisitor::visit(const AddSubdirectoryAst *subd)
m_subdirectories += subd->sourceDir();
}
CMakeProjectVisitor::CMakeProjectVisitor()
{
}
void CMakeProjectVisitor::visit(const AddExecutableAst *exec)
{
foreach(QString s, exec->sourceLists()) {
m_filesPerTarget.insert(exec->executable(), s);
}
m_filesPerTarget.insert(exec->executable(), exec->sourceLists());
kDebug(9032) << "exec: " << exec->executable() << endl;
}
void CMakeProjectVisitor::visit(const AddLibraryAst *lib)
{
foreach(QString s, lib->sourceLists()) {
m_filesPerTarget.insert(lib->libraryName(), s);
}
m_filesPerTarget.insert(lib->libraryName(), lib->sourceLists());
kDebug(9032) << "lib: " << lib->libraryName() << endl;
}
void CMakeProjectVisitor::visit(const SetAst *set)
{
m_vars->remove(set->variableName());
m_vars->insert(set->variableName(), set->values());
kDebug(9032) << "set: " << set->variableName() << "=" << set->values() << endl;
}
......@@ -25,42 +25,46 @@
#include <QString>
#include <QStringList>
#include <QMap>
#include <QHash>
class CMakeProjectVisitor : public CMakeAstVisitor {
class CMakeProjectVisitor : public CMakeAstVisitor
{
public:
CMakeProjectVisitor();
virtual ~CMakeProjectVisitor() {}
virtual void visit( const CustomCommandAst * ) { notImplemented(); }
virtual void visit( const CustomTargetAst * ) { notImplemented(); }
virtual void visit( const AddDefinitionsAst * ) { notImplemented(); }
virtual void visit( const AddDependenciesAst * ) { notImplemented(); }
virtual void visit( const AddExecutableAst * );
virtual void visit( const AddLibraryAst * );
virtual void visit( const AddSubdirectoryAst * );
virtual void visit( const AddTestAst * ) { notImplemented(); }
virtual void visit( const AuxSourceDirectoryAst * ) { notImplemented(); }
virtual void visit( const BuildCommandAst * ) { notImplemented(); }
virtual void visit( const BuildNameAst * ) { notImplemented(); }
virtual void visit( const CMakeMinimumRequiredAst * ) { notImplemented(); }
virtual void visit( const ConfigureFileAst * ) { notImplemented(); }
virtual void visit( const IncludeAst * ) { notImplemented(); }
virtual void visit( const SetAst * ) { notImplemented(); }
CMakeProjectVisitor(QHash<QString, QStringList> *vars);
virtual ~CMakeProjectVisitor() {}
virtual void visit( const CustomCommandAst * ) { notImplemented(); }
virtual void visit( const CustomTargetAst * ) { notImplemented(); }
virtual void visit( const AddDefinitionsAst * ) { notImplemented(); }
virtual void visit( const AddDependenciesAst * ) { notImplemented(); }
virtual void visit( const AddExecutableAst * );
virtual void visit( const AddLibraryAst * );
virtual void visit( const AddSubdirectoryAst * );
virtual void visit( const AddTestAst * ) { notImplemented(); }
virtual void visit( const AuxSourceDirectoryAst * ) { notImplemented(); }
virtual void visit( const BuildCommandAst * ) { notImplemented(); }
virtual void visit( const BuildNameAst * ) { notImplemented(); }
virtual void visit( const CMakeMinimumRequiredAst * ) { notImplemented(); }
virtual void visit( const ConfigureFileAst * ) { notImplemented(); }
virtual void visit( const IncludeAst * ) { notImplemented(); }
virtual void visit( const SetAst * );
virtual void visit( const ProjectAst * );
virtual void visit( const CMakeAst * );
virtual void visit( const CMakeAst * );
QString projectName() const { return m_projectName; }
QStringList subdirectories() const { return m_subdirectories; }
QStringList targets() const { return m_filesPerTarget.keys(); }
QStringList files(const QString &target) const { return m_filesPerTarget.values(target); }
QStringList files(const QString &target) const { return m_filesPerTarget[target]; }
private:
void notImplemented() const;
void notImplemented() const;
QString m_projectName;
QStringList m_subdirectories;
QMap<QString, QString> m_filesPerTarget;
QMap<QString, QStringList> m_filesPerTarget;
QString m_root;
QHash<QString, QStringList> *m_vars;
};
#endif
[Project]
Name=KDevelop
Manager=KDevCMakeManager
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment