forked from qt-creator/qt-creator
Actually watch all the project files of a CMake project.
And react to changes to one of them.
This commit is contained in:
@@ -84,18 +84,20 @@ void CMakeProject::slotActiveBuildConfiguration()
|
||||
{
|
||||
// Pop up a dialog asking the user to rerun cmake
|
||||
QFileInfo sourceFileInfo(m_fileName);
|
||||
QStringList needToCreate;
|
||||
QStringList needToUpdate;
|
||||
|
||||
QString cbpFile = CMakeManager::findCbpFile(QDir(buildDirectory(activeBuildConfiguration())));
|
||||
QFileInfo cbpFileFi(cbpFile);
|
||||
CMakeOpenProjectWizard::Mode mode;
|
||||
if (!cbpFileFi.exists())
|
||||
CMakeOpenProjectWizard::Mode mode = CMakeOpenProjectWizard::Nothing;
|
||||
if (!cbpFileFi.exists()) {
|
||||
mode = CMakeOpenProjectWizard::NeedToCreate;
|
||||
else if (cbpFileFi.lastModified() < sourceFileInfo.lastModified())
|
||||
} else {
|
||||
foreach(const QString &file, m_watchedFiles) {
|
||||
if (QFileInfo(file).lastModified() > sourceFileInfo.lastModified()) {
|
||||
mode = CMakeOpenProjectWizard::NeedToUpdate;
|
||||
else
|
||||
mode = CMakeOpenProjectWizard::Nothing;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mode != CMakeOpenProjectWizard::Nothing) {
|
||||
CMakeOpenProjectWizard copw(m_manager,
|
||||
@@ -115,10 +117,7 @@ void CMakeProject::fileChanged(const QString &fileName)
|
||||
if (m_insideFileChanged== true)
|
||||
return;
|
||||
m_insideFileChanged = true;
|
||||
if (fileName == m_fileName) {
|
||||
// Oh we have changed...
|
||||
slotActiveBuildConfiguration();
|
||||
}
|
||||
m_insideFileChanged = false;
|
||||
}
|
||||
|
||||
@@ -189,13 +188,27 @@ bool CMakeProject::parseCMakeLists()
|
||||
|
||||
QList<ProjectExplorer::FileNode *> fileList = cbpparser.fileList();
|
||||
|
||||
QSet<QString> projectFiles;
|
||||
if (cbpparser.hasCMakeFiles()) {
|
||||
fileList.append(cbpparser.cmakeFileList());
|
||||
foreach(ProjectExplorer::FileNode *node, cbpparser.cmakeFileList())
|
||||
projectFiles.insert(node->path());
|
||||
} else {
|
||||
// Manually add the CMakeLists.txt file
|
||||
fileList.append(new ProjectExplorer::FileNode(sourceDirectory() + "/CMakeLists.txt", ProjectExplorer::ProjectFileType, false));
|
||||
QString cmakeListTxt = sourceDirectory() + "/CMakeLists.txt";
|
||||
fileList.append(new ProjectExplorer::FileNode(cmakeListTxt, ProjectExplorer::ProjectFileType, false));
|
||||
projectFiles.insert(cmakeListTxt);
|
||||
}
|
||||
|
||||
|
||||
QSet<QString> added = projectFiles;
|
||||
added.subtract(m_watchedFiles);
|
||||
foreach(const QString &add, added)
|
||||
m_watcher->addFile(add);
|
||||
foreach(const QString &remove, m_watchedFiles.subtract(projectFiles))
|
||||
m_watcher->removeFile(remove);
|
||||
m_watchedFiles = projectFiles;
|
||||
|
||||
m_files.clear();
|
||||
foreach (ProjectExplorer::FileNode *fn, fileList)
|
||||
m_files.append(fn->path());
|
||||
@@ -620,16 +633,15 @@ bool CMakeProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader
|
||||
setValue(activeBuildConfiguration(), "msvcVersion", copw.msvcVersion());
|
||||
}
|
||||
}
|
||||
bool result = parseCMakeLists(); // Gets the directory from the active buildconfiguration
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
if (!hasUserFile && targets().contains("all"))
|
||||
makeStep->setBuildTarget("all", "all", true);
|
||||
|
||||
m_watcher = new ProjectExplorer::FileWatcher(this);
|
||||
connect(m_watcher, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString)));
|
||||
m_watcher->addFile(m_fileName);
|
||||
bool result = parseCMakeLists(); // Gets the directory from the active buildconfiguration
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
connect(this, SIGNAL(activeBuildConfigurationChanged()),
|
||||
this, SLOT(slotActiveBuildConfiguration()));
|
||||
|
||||
@@ -139,6 +139,7 @@ private:
|
||||
ProjectExplorer::ToolChain *m_toolChain;
|
||||
ProjectExplorer::FileWatcher *m_watcher;
|
||||
bool m_insideFileChanged;
|
||||
QSet<QString> m_watchedFiles;
|
||||
};
|
||||
|
||||
class CMakeCbpParser : public QXmlStreamReader
|
||||
|
||||
Reference in New Issue
Block a user