Commit d122c34c authored by Tobias Hunger's avatar Tobias Hunger
Browse files

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: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 361ea246
...@@ -225,6 +225,21 @@ void BuildDirManager::parse() ...@@ -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 bool BuildDirManager::isProjectFile(const Utils::FileName &fileName) const
{ {
return m_watchedFiles.contains(fileName); return m_watchedFiles.contains(fileName);
......
...@@ -75,6 +75,7 @@ public: ...@@ -75,6 +75,7 @@ public:
bool isParsing() const; bool isParsing() const;
void parse(); void parse();
void clearCache();
void forceReparse(); void forceReparse();
void resetData(); void resetData();
bool persistCMakeState(); bool persistCMakeState();
......
...@@ -34,6 +34,7 @@ const char CMAKEPROJECTMIMETYPE[] = "text/x-cmake-project"; ...@@ -34,6 +34,7 @@ const char CMAKEPROJECTMIMETYPE[] = "text/x-cmake-project";
const char CMAKE_EDITOR_ID[] = "CMakeProject.CMakeEditor"; const char CMAKE_EDITOR_ID[] = "CMakeProject.CMakeEditor";
const char CMAKE_EDITOR_DISPLAY_NAME[] = "CMake Editor"; const char CMAKE_EDITOR_DISPLAY_NAME[] = "CMake Editor";
const char RUNCMAKE[] = "CMakeProject.RunCMake"; const char RUNCMAKE[] = "CMakeProject.RunCMake";
const char CLEARCMAKECACHE[] = "CMakeProject.ClearCache";
const char RUNCMAKECONTEXTMENU[] = "CMakeProject.RunCMakeContextMenu"; const char RUNCMAKECONTEXTMENU[] = "CMakeProject.RunCMakeContextMenu";
// Project // Project
......
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
****************************************************************************/ ****************************************************************************/
#include "cmakeprojectmanager.h" #include "cmakeprojectmanager.h"
#include "builddirmanager.h"
#include "cmakebuildconfiguration.h"
#include "cmakekitinformation.h"
#include "cmakeprojectconstants.h" #include "cmakeprojectconstants.h"
#include "cmakeproject.h" #include "cmakeproject.h"
#include "cmakesettingspage.h" #include "cmakesettingspage.h"
...@@ -52,6 +55,7 @@ using namespace CMakeProjectManager::Internal; ...@@ -52,6 +55,7 @@ using namespace CMakeProjectManager::Internal;
CMakeManager::CMakeManager() : CMakeManager::CMakeManager() :
m_runCMakeAction(new QAction(QIcon(), tr("Run CMake"), this)), 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)) m_runCMakeActionContextMenu(new QAction(QIcon(), tr("Run CMake"), this))
{ {
Core::ActionContainer *mbuild = Core::ActionContainer *mbuild =
...@@ -62,16 +66,24 @@ CMakeManager::CMakeManager() : ...@@ -62,16 +66,24 @@ CMakeManager::CMakeManager() :
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT); Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT);
const Core::Context projectContext(CMakeProjectManager::Constants::PROJECTCONTEXT); 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, Core::Command *command = Core::ActionManager::registerAction(m_runCMakeAction,
Constants::RUNCMAKE, globalcontext); Constants::RUNCMAKE, globalContext);
command->setAttribute(Core::Command::CA_Hide); command->setAttribute(Core::Command::CA_Hide);
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_DEPLOY); mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_DEPLOY);
connect(m_runCMakeAction, &QAction::triggered, [this]() { connect(m_runCMakeAction, &QAction::triggered, [this]() {
runCMake(SessionManager::startupProject()); 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, command = Core::ActionManager::registerAction(m_runCMakeActionContextMenu,
Constants::RUNCMAKECONTEXTMENU, projectContext); Constants::RUNCMAKECONTEXTMENU, projectContext);
command->setAttribute(Core::Command::CA_Hide); command->setAttribute(Core::Command::CA_Hide);
...@@ -82,16 +94,31 @@ CMakeManager::CMakeManager() : ...@@ -82,16 +94,31 @@ CMakeManager::CMakeManager() :
}); });
connect(SessionManager::instance(), &SessionManager::startupProjectChanged, connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
this, &CMakeManager::updateRunCmakeAction); this, &CMakeManager::updateCmakeActions);
connect(BuildManager::instance(), &BuildManager::buildStateChanged, 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()); 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) void CMakeManager::runCMake(Project *project)
......
...@@ -58,10 +58,12 @@ public: ...@@ -58,10 +58,12 @@ public:
static QString findCbpFile(const QDir &); static QString findCbpFile(const QDir &);
private: private:
void updateRunCmakeAction(); void updateCmakeActions();
void clearCMakeCache(ProjectExplorer::Project *project);
void runCMake(ProjectExplorer::Project *project); void runCMake(ProjectExplorer::Project *project);
QAction *m_runCMakeAction; QAction *m_runCMakeAction;
QAction *m_clearCMakeCacheAction;
QAction *m_runCMakeActionContextMenu; QAction *m_runCMakeActionContextMenu;
}; };
......
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