forked from qt-creator/qt-creator
CMake: Add ability to force CMake cache clear
Some CMake parameters changes requires to clear cache and run CMake from scratch. Add ability to force it from the CMake configuration dialog. This change based on the work of Alexander Drozdov. Change-Id: I21d8e12eec7e1f7bca560f44c43f25e4f333fcf0 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -225,6 +225,21 @@ void BuildDirManager::parse()
|
||||
}
|
||||
}
|
||||
|
||||
void BuildDirManager::clearCache()
|
||||
{
|
||||
auto cmakeCache = Utils::FileName(buildDirectory()).appendPath(QLatin1String("CMakeCache.txt"));
|
||||
auto cmakeFiles = Utils::FileName(buildDirectory()).appendPath(QLatin1String("CMakeFiles"));
|
||||
|
||||
const bool mustCleanUp = cmakeCache.exists() || cmakeFiles.exists();
|
||||
if (!mustCleanUp)
|
||||
return;
|
||||
|
||||
Utils::FileUtils::removeRecursively(cmakeCache);
|
||||
Utils::FileUtils::removeRecursively(cmakeFiles);
|
||||
|
||||
forceReparse();
|
||||
}
|
||||
|
||||
bool BuildDirManager::isProjectFile(const Utils::FileName &fileName) const
|
||||
{
|
||||
return m_watchedFiles.contains(fileName);
|
||||
|
||||
@@ -75,6 +75,7 @@ public:
|
||||
bool isParsing() const;
|
||||
|
||||
void parse();
|
||||
void clearCache();
|
||||
void forceReparse();
|
||||
void resetData();
|
||||
bool persistCMakeState();
|
||||
|
||||
@@ -34,6 +34,7 @@ const char CMAKEPROJECTMIMETYPE[] = "text/x-cmake-project";
|
||||
const char CMAKE_EDITOR_ID[] = "CMakeProject.CMakeEditor";
|
||||
const char CMAKE_EDITOR_DISPLAY_NAME[] = "CMake Editor";
|
||||
const char RUNCMAKE[] = "CMakeProject.RunCMake";
|
||||
const char CLEARCMAKECACHE[] = "CMakeProject.ClearCache";
|
||||
const char RUNCMAKECONTEXTMENU[] = "CMakeProject.RunCMakeContextMenu";
|
||||
|
||||
// Project
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "cmakeprojectmanager.h"
|
||||
#include "builddirmanager.h"
|
||||
#include "cmakebuildconfiguration.h"
|
||||
#include "cmakekitinformation.h"
|
||||
#include "cmakeprojectconstants.h"
|
||||
#include "cmakeproject.h"
|
||||
#include "cmakesettingspage.h"
|
||||
@@ -52,6 +55,7 @@ using namespace CMakeProjectManager::Internal;
|
||||
|
||||
CMakeManager::CMakeManager() :
|
||||
m_runCMakeAction(new QAction(QIcon(), tr("Run CMake"), this)),
|
||||
m_clearCMakeCacheAction(new QAction(QIcon(), tr("Clear CMake Configuration"), this)),
|
||||
m_runCMakeActionContextMenu(new QAction(QIcon(), tr("Run CMake"), this))
|
||||
{
|
||||
Core::ActionContainer *mbuild =
|
||||
@@ -62,16 +66,24 @@ CMakeManager::CMakeManager() :
|
||||
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT);
|
||||
|
||||
const Core::Context projectContext(CMakeProjectManager::Constants::PROJECTCONTEXT);
|
||||
const Core::Context globalcontext(Core::Constants::C_GLOBAL);
|
||||
const Core::Context globalContext(Core::Constants::C_GLOBAL);
|
||||
|
||||
Core::Command *command = Core::ActionManager::registerAction(m_runCMakeAction,
|
||||
Constants::RUNCMAKE, globalcontext);
|
||||
Constants::RUNCMAKE, globalContext);
|
||||
command->setAttribute(Core::Command::CA_Hide);
|
||||
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_DEPLOY);
|
||||
connect(m_runCMakeAction, &QAction::triggered, [this]() {
|
||||
runCMake(SessionManager::startupProject());
|
||||
});
|
||||
|
||||
command = Core::ActionManager::registerAction(m_clearCMakeCacheAction,
|
||||
Constants::CLEARCMAKECACHE, globalContext);
|
||||
command->setAttribute(Core::Command::CA_Hide);
|
||||
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_DEPLOY);
|
||||
connect(m_clearCMakeCacheAction, &QAction::triggered, [this]() {
|
||||
clearCMakeCache(SessionManager::startupProject());
|
||||
});
|
||||
|
||||
command = Core::ActionManager::registerAction(m_runCMakeActionContextMenu,
|
||||
Constants::RUNCMAKECONTEXTMENU, projectContext);
|
||||
command->setAttribute(Core::Command::CA_Hide);
|
||||
@@ -82,16 +94,31 @@ CMakeManager::CMakeManager() :
|
||||
});
|
||||
|
||||
connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
|
||||
this, &CMakeManager::updateRunCmakeAction);
|
||||
this, &CMakeManager::updateCmakeActions);
|
||||
connect(BuildManager::instance(), &BuildManager::buildStateChanged,
|
||||
this, &CMakeManager::updateRunCmakeAction);
|
||||
this, &CMakeManager::updateCmakeActions);
|
||||
|
||||
updateCmakeActions();
|
||||
}
|
||||
|
||||
void CMakeManager::updateRunCmakeAction()
|
||||
void CMakeManager::updateCmakeActions()
|
||||
{
|
||||
auto project = qobject_cast<CMakeProject *>(SessionManager::startupProject());
|
||||
m_runCMakeAction->setVisible(project && !BuildManager::isBuilding(project));
|
||||
const bool visible = project && !BuildManager::isBuilding(project);
|
||||
m_runCMakeAction->setVisible(visible);
|
||||
m_clearCMakeCacheAction->setVisible(visible);
|
||||
}
|
||||
|
||||
void CMakeManager::clearCMakeCache(Project *project)
|
||||
{
|
||||
if (!project || !project->activeTarget())
|
||||
return;
|
||||
auto bc = qobject_cast<CMakeBuildConfiguration *>(project->activeTarget()->activeBuildConfiguration());
|
||||
if (!bc)
|
||||
return;
|
||||
|
||||
bc->setCMakeConfiguration(CMakeConfigurationKitInformation::configuration(bc->target()->kit()));
|
||||
bc->buildDirManager()->clearCache();
|
||||
}
|
||||
|
||||
void CMakeManager::runCMake(Project *project)
|
||||
|
||||
@@ -58,10 +58,12 @@ public:
|
||||
static QString findCbpFile(const QDir &);
|
||||
|
||||
private:
|
||||
void updateRunCmakeAction();
|
||||
void updateCmakeActions();
|
||||
void clearCMakeCache(ProjectExplorer::Project *project);
|
||||
void runCMake(ProjectExplorer::Project *project);
|
||||
|
||||
QAction *m_runCMakeAction;
|
||||
QAction *m_clearCMakeCacheAction;
|
||||
QAction *m_runCMakeActionContextMenu;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user