Commit d0be2896 authored by Ken Martin's avatar Ken Martin
Browse files

changed cache manager and registered generators to no longer be singletons

parent 4855fe5c
......@@ -78,8 +78,6 @@ BOOL CMakeSetup::InitInstance()
// clean up globals
cmListFileCache::GetInstance()->ClearCache();
cmMakefileGenerator::UnRegisterGenerators();
cmCacheManager::DeleteInstance();
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
......
......@@ -110,6 +110,7 @@ CMakeSetupDialog::CMakeSetupDialog(const CMakeCommandLineInfo& cmdInfo,
{
cmSystemTools::SetErrorCallback(MFCMessageCallback);
m_RegistryKey = "Software\\Kitware\\CMakeSetup\\Settings\\StartPath";
m_CacheEntriesList.m_CMakeSetupDialog = this;
//{{AFX_DATA_INIT(CMakeSetupDialog)
// Get the parameters from the command line info
......@@ -145,6 +146,7 @@ CMakeSetupDialog::CMakeSetupDialog(const CMakeCommandLineInfo& cmdInfo,
m_oldCX = -1;
m_deltaXRemainder = 0;
m_CMakeInstance = 0;
}
void CMakeSetupDialog::DoDataExchange(CDataExchange* pDX)
......@@ -243,9 +245,9 @@ BOOL CMakeSetupDialog::OnInitDialog()
SetIcon(m_hIcon, FALSE); // Set small icon
// Load source and build dirs from registry
this->LoadFromRegistry();
cmake m; // force a register of generators
this->m_CMakeInstance = new cmake;
std::vector<std::string> names;
cmMakefileGenerator::GetRegisteredGenerators(names);
this->m_CMakeInstance->GetRegisteredGenerators(names);
for(std::vector<std::string>::iterator i = names.begin();
i != names.end(); ++i)
{
......@@ -558,11 +560,16 @@ void CMakeSetupDialog::RunCMake(bool generateProjectFiles)
this->UpdateData();
// always save the current gui values to disk
this->SaveCacheFromGUI();
// free the old cmake and create a new one here
if (this->m_CMakeInstance)
{
delete this->m_CMakeInstance;
this->m_CMakeInstance = 0;
}
this->m_CMakeInstance = new cmake;
// Make sure we are working from the cache on disk
this->LoadCacheFromDiskToGUI();
m_OKButton.EnableWindow(false);
// create a cmake object
cmake make;
// create the arguments for the cmake object
std::vector<std::string> args;
args.push_back((const char*)m_PathToExecutable);
......@@ -577,7 +584,7 @@ void CMakeSetupDialog::RunCMake(bool generateProjectFiles)
arg += m_GeneratorChoiceString;
args.push_back(arg);
// run the generate process
if(make.Generate(args, generateProjectFiles) != 0)
if(this->m_CMakeInstance->Generate(args, generateProjectFiles) != 0)
{
cmSystemTools::Error(
"Error in generation process, project files may be invalid");
......@@ -643,14 +650,14 @@ void CMakeSetupDialog::OnChangeWhereBuild()
std::string cache_file = path;
cache_file += "/CMakeCache.txt";
cmCacheManager *cache = cmCacheManager::GetInstance();
cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
if (cmSystemTools::FileExists(cache_file.c_str()) &&
cache->LoadCache(path.c_str()) &&
cache->GetCacheEntry("CMAKE_HOME_DIRECTORY"))
cachem->LoadCache(path.c_str()) &&
cachem->GetCacheEntry("CMAKE_HOME_DIRECTORY"))
{
path = ConvertToWindowsPath(
cache->GetCacheEntry("CMAKE_HOME_DIRECTORY")->m_Value.c_str());
cachem->GetCacheEntry("CMAKE_HOME_DIRECTORY")->m_Value.c_str());
this->m_WhereSource = path.c_str();
this->m_WhereSourceControl.SetWindowText(this->m_WhereSource);
this->OnChangeWhereSource();
......@@ -666,6 +673,7 @@ void CMakeSetupDialog::OnChangeWhereBuild()
// copy from the cache manager to the cache edit list box
void CMakeSetupDialog::FillCacheGUIFromCacheManager()
{
cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
size_t size = m_CacheEntriesList.GetItems().size();
bool reverseOrder = false;
// if there are already entries in the cache, then
......@@ -683,7 +691,7 @@ void CMakeSetupDialog::FillCacheGUIFromCacheManager()
CPropertyItem* item = *i;
item->m_NewValue = false;
}
for(cmCacheManager::CacheIterator i = cmCacheManager::GetInstance()->NewIterator();
for(cmCacheManager::CacheIterator i = cachem->NewIterator();
!i.IsAtEnd(); i.Next())
{
const char* key = i.GetName();
......@@ -700,7 +708,7 @@ void CMakeSetupDialog::FillCacheGUIFromCacheManager()
if(!m_AdvancedValues)
{
if(cmCacheManager::GetInstance()->IsAdvanced(key))
if(cachem->IsAdvanced(key))
{
m_CacheEntriesList.RemoveProperty(key);
continue;
......@@ -758,7 +766,7 @@ void CMakeSetupDialog::FillCacheGUIFromCacheManager()
}
}
m_OKButton.EnableWindow(false);
if(cmCacheManager::GetInstance()->GetSize() > 0 && !cmSystemTools::GetErrorOccuredFlag())
if(cachem->GetSize() > 0 && !cmSystemTools::GetErrorOccuredFlag())
{
bool enable = true;
items = m_CacheEntriesList.GetItems();
......@@ -787,13 +795,13 @@ void CMakeSetupDialog::FillCacheGUIFromCacheManager()
// copy from the list box to the cache manager
void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
{
cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
for(std::set<CPropertyItem*>::iterator i = items.begin();
i != items.end(); ++i)
{
CPropertyItem* item = *i;
cmCacheManager::CacheEntry *entry =
cmCacheManager::GetInstance()->GetCacheEntry(
cmCacheManager::CacheEntry *entry = cachem->GetCacheEntry(
(const char*)item->m_propName);
if (entry)
{
......@@ -820,14 +828,15 @@ void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
//! Load cache file from m_WhereBuild and display in GUI editor
void CMakeSetupDialog::LoadCacheFromDiskToGUI()
{
cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
if(m_WhereBuild != "")
{
cmCacheManager::GetInstance()->LoadCache(m_WhereBuild);
cachem->LoadCache(m_WhereBuild);
this->FillCacheGUIFromCacheManager();
if(cmCacheManager::GetInstance()->GetCacheEntry("CMAKE_GENERATOR"))
if(cachem->GetCacheEntry("CMAKE_GENERATOR"))
{
std::string curGen =
cmCacheManager::GetInstance()->GetCacheEntry("CMAKE_GENERATOR")->m_Value;
cachem->GetCacheEntry("CMAKE_GENERATOR")->m_Value;
if(m_GeneratorChoiceString != curGen.c_str())
{
m_GeneratorChoiceString = curGen.c_str();
......@@ -840,10 +849,11 @@ void CMakeSetupDialog::LoadCacheFromDiskToGUI()
//! Save GUI values to cmCacheManager and then save to disk.
void CMakeSetupDialog::SaveCacheFromGUI()
{
cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
this->FillCacheManagerFromCacheGUI();
if(m_WhereBuild != "")
{
cmCacheManager::GetInstance()->SaveCache(m_WhereBuild);
cachem->SaveCache(m_WhereBuild);
}
}
......@@ -958,7 +968,6 @@ void CMakeSetupDialog::OnOk()
cmSystemTools::EnableMessages();
m_CacheEntriesList.ClearDirty();
this->RunCMake(true);
cmMakefileGenerator::UnRegisterGenerators();
if (!(::GetKeyState(VK_SHIFT) & 0x1000))
{
CDialog::OnOK();
......@@ -1111,12 +1120,13 @@ void CMakeSetupDialog::OnHelpButton()
void CMakeSetupDialog::ShowAdvancedValues()
{
for(cmCacheManager::CacheIterator i = cmCacheManager::GetInstance()->NewIterator();
cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
for(cmCacheManager::CacheIterator i = cachem->NewIterator();
!i.IsAtEnd(); i.Next())
{
const char* key = i.GetName();
const cmCacheManager::CacheEntry& value = i.GetEntry();
if(!cmCacheManager::GetInstance()->IsAdvanced(key))
if(!cachem->IsAdvanced(key))
{
continue;
}
......@@ -1175,12 +1185,14 @@ void CMakeSetupDialog::ShowAdvancedValues()
void CMakeSetupDialog::RemoveAdvancedValues()
{
for(cmCacheManager::CacheIterator i = cmCacheManager::GetInstance()->NewIterator();
cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
for(cmCacheManager::CacheIterator i = cachem->NewIterator();
!i.IsAtEnd(); i.Next())
{
const char* key = i.GetName();
const cmCacheManager::CacheEntry& value = i.GetEntry();
if(cmCacheManager::GetInstance()->IsAdvanced(key))
if(cachem->IsAdvanced(key))
{
m_CacheEntriesList.RemoveProperty(key);
}
......@@ -1229,17 +1241,17 @@ void CMakeSetupDialog::ChangeDirectoriesFromFile(const char* buffer)
std::string cache_file = path;
cache_file += "/CMakeCache.txt";
cmCacheManager *cache = cmCacheManager::GetInstance();
cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
if (cmSystemTools::FileExists(cache_file.c_str()) &&
cache->LoadCache(path.c_str()) &&
cache->GetCacheEntry("CMAKE_HOME_DIRECTORY"))
cachem->LoadCache(path.c_str()) &&
cachem->GetCacheEntry("CMAKE_HOME_DIRECTORY"))
{
path = ConvertToWindowsPath(path.c_str());
this->m_WhereBuild = path.c_str();
path = ConvertToWindowsPath(
cache->GetCacheEntry("CMAKE_HOME_DIRECTORY")->m_Value.c_str());
cachem->GetCacheEntry("CMAKE_HOME_DIRECTORY")->m_Value.c_str());
this->m_WhereSource = path.c_str();
}
else
......
......@@ -30,6 +30,7 @@
// CMakeSetupDialog dialog
class CMakeCommandLineInfo;
class cmake;
class CMakeSetupDialog : public CDialog
{
......@@ -37,6 +38,9 @@ class CMakeSetupDialog : public CDialog
public:
CMakeSetupDialog(const CMakeCommandLineInfo& cmdInfo,
CWnd* pParent = NULL);
// return the cmake that is currently being used
cmake *GetCMakeInstance() {
return m_CMakeInstance; }
protected:
//! Load cache file from m_WhereBuild and display in GUI editor
void LoadCacheFromDiskToGUI();
......@@ -119,8 +123,9 @@ protected:
DECLARE_MESSAGE_MAP()
int m_oldCX;
int m_oldCY;
int m_oldCY;
float m_deltaXRemainder;
cmake *m_CMakeInstance;
};
//{{AFX_INSERT_LOCATION}}
......
......@@ -2,11 +2,13 @@
//
#include "stdafx.h"
#include "PropertyList.h"
#include "shellapi.h"
#include "CMakeSetup.h"
#include "CMakeSetupDialog.h"
#include "PathDialog.h"
#include "../cmCacheManager.h"
#include "../cmSystemTools.h"
#include "../cmake.h"
#define IDC_PROPCMBBOX 712
#define IDC_PROPEDITBOX 713
#define IDC_PROPBTNCTRL 714
......@@ -655,7 +657,7 @@ void CPropertyList::OnDelete()
return;
}
CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
cmCacheManager::GetInstance()->RemoveCacheEntry(pItem->m_propName);
m_CMakeSetupDialog->GetCMakeInstance()->GetCacheManager()->RemoveCacheEntry(pItem->m_propName);
m_PropertyItems.erase(pItem);
delete pItem;
this->DeleteString(m_curSel);
......@@ -680,7 +682,8 @@ void CPropertyList::RemoveAll()
for(int i =0; i < c; ++i)
{
CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(0);
cmCacheManager::GetInstance()->RemoveCacheEntry(pItem->m_propName);
m_CMakeSetupDialog->GetCMakeInstance()->GetCacheManager()
->RemoveCacheEntry(pItem->m_propName);
m_PropertyItems.erase(pItem);
delete pItem;
this->DeleteString(0);
......
......@@ -20,6 +20,7 @@
#include "../cmStandardIncludes.h"
class CMakeSetupDialog;
/////////////////////////////////////////////////////////////////////////////
//CPropertyList Items
......@@ -34,6 +35,7 @@ public:
CString m_cmbItems;
bool m_NewValue;
bool m_Removed;
public:
CPropertyItem(CString propName, CString curValue,
CString helpString,
......@@ -70,6 +72,7 @@ public:
// Attributes
public:
CMakeSetupDialog *m_CMakeSetupDialog;
// Operations
public:
......
......@@ -32,13 +32,15 @@ void cmSetClientData(void *info, void *cd)
((cmLoadedCommandInfo *)info)->ClientData = cd;
}
unsigned int cmGetCacheMajorVersion(void *)
unsigned int cmGetCacheMajorVersion(void *arg)
{
return cmMakefile::GetCacheMajorVersion();
cmMakefile *mf = static_cast<cmMakefile *>(arg);
return mf->GetCacheMajorVersion();
}
unsigned int cmGetCacheMinorVersion(void *)
unsigned int cmGetCacheMinorVersion(void *arg)
{
return cmMakefile::GetCacheMinorVersion();
cmMakefile *mf = static_cast<cmMakefile *>(arg);
return mf->GetCacheMinorVersion();
}
unsigned int cmGetMajorVersion(void *)
......
......@@ -50,27 +50,6 @@ cmCacheManager::CacheEntryType cmCacheManager::StringToType(const char* s)
return STRING;
}
void cmCacheManager::DeleteInstance()
{
delete cmCacheManager::GetInstance();
cmCacheManager::s_Instance = 0;
}
cmCacheManager* cmCacheManager::s_Instance = 0;
cmCacheManager* cmCacheManager::GetInstance()
{
if(!cmCacheManager::s_Instance)
{
cmCacheManager::s_Instance = new cmCacheManager;
}
return cmCacheManager::s_Instance;
}
bool cmCacheManager::LoadCache(cmMakefile* mf)
{
return this->LoadCache(mf->GetHomeOutputDirectory());
......@@ -523,8 +502,7 @@ bool cmCacheManager::IsAdvanced(const char* key)
{
std::string advancedVar = key;
advancedVar += "-ADVANCED";
const char* value =
cmCacheManager::GetInstance()->GetCacheValue(advancedVar.c_str());
const char* value = this->GetCacheValue(advancedVar.c_str());
if(value)
{
return cmSystemTools::IsOn(value);
......
......@@ -69,9 +69,6 @@ public:
* can be different than just a path input
*/
static CacheEntryType StringToType(const char*);
///! Singleton pattern get instance of the cmCacheManager.
static cmCacheManager* GetInstance();
static void DeleteInstance();
///! Load a cache for given makefile. Loads from ouput home.
bool LoadCache(cmMakefile*);
......@@ -122,7 +119,6 @@ protected:
private:
static void OutputHelpString(std::ofstream& fout,
const std::string& helpString);
static cmCacheManager* s_Instance;
CacheEntryMap m_Cache;
// Only cmake and cmMakefile should be able to add cache values
// the commands should never use the cmCacheManager directly
......
......@@ -76,6 +76,7 @@
#include "cmSubdirCommand.cxx"
#include "cmSubdirDependsCommand.cxx"
#include "cmTargetLinkLibrariesCommand.cxx"
#include "cmTryCompileCommand.cxx"
#include "cmUseMangledMesaCommand.cxx"
#include "cmUtilitySourceCommand.cxx"
#include "cmVariableRequiresCommand.cxx"
......@@ -157,6 +158,7 @@ void GetPredefinedCommands(std::list<cmCommand*>& commands)
commands.push_back(new cmSubdirCommand);
commands.push_back(new cmSubdirDependsCommand);
commands.push_back(new cmTargetLinkLibrariesCommand);
commands.push_back(new cmTryCompileCommand);
commands.push_back(new cmUseMangledMesaCommand);
commands.push_back(new cmUtilitySourceCommand);
commands.push_back(new cmVariableRequiresCommand);
......
......@@ -59,7 +59,7 @@ bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn)
if(cacheValue)
{
cmCacheManager::CacheEntry* e =
cmCacheManager::GetInstance()->GetCacheEntry(args[0].c_str());
m_Makefile->GetCacheManager()->GetCacheEntry(args[0].c_str());
if(e)
{
helpString = e->m_HelpString;
......
......@@ -65,7 +65,7 @@ bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn)
if(cacheValue)
{
cmCacheManager::CacheEntry* e =
cmCacheManager::GetInstance()->GetCacheEntry(args[0].c_str());
m_Makefile->GetCacheManager()->GetCacheEntry(args[0].c_str());
if(e)
{
doc = e->m_HelpString;
......
......@@ -80,7 +80,7 @@ bool cmLoadCacheCommand::InitialPass(std::vector<std::string> const& argsIn)
{
break;
}
cmCacheManager::GetInstance()->LoadCache(args[i].c_str(), false,
m_Makefile->GetCacheManager()->LoadCache(args[i].c_str(), false,
excludes, includes);
}
......
......@@ -152,7 +152,7 @@ bool cmLoadCommandCommand::InitialPass(std::vector<std::string> const& argsIn)
// the file must exist
std::string fullPath = cmDynamicLoader::LibPrefix();
fullPath += argsIn[0] + cmDynamicLoader::LibExtension();
fullPath += "cm" + argsIn[0] + cmDynamicLoader::LibExtension();
std::vector<std::string> args;
cmSystemTools::ExpandListArguments(argsIn, args);
......
......@@ -1380,3 +1380,50 @@ std::string cmMSDotNETGenerator::ConvertToXMLOutputPathSingle(const char* path)
cmSystemTools::ReplaceString(ret, "\"", "");
return ret;
}
int cmMSDotNETGenerator::TryCompile(const char *srcdir,
const char *bindir,
const char *projectName)
{
// now build the test
std::string makeCommand = m_Makefile->GetDefinition("CMAKE_MAKE_PROGRAM");
if(makeCommand.size() == 0)
{
cmSystemTools::Error(
"Generator cannot find the appropriate make command.");
return 1;
}
makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
std::string lowerCaseCommand = makeCommand;
cmSystemTools::LowerCase(lowerCaseCommand);
/**
* Run an executable command and put the stdout in output.
*/
std::string output;
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
cmSystemTools::ChangeDirectory(bindir);
#if defined(_WIN32) && !defined(__CYGWIN__)
if(makeCommand.find(' ') != std::string::npos)
{
cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
}
#endif
makeCommand += " ";
makeCommand += projectName;
makeCommand += ".sln /rebuild Debug /project ALL_BUILD";
if (!cmSystemTools::RunCommand(makeCommand.c_str(), output))
{
cmSystemTools::Error("Generator: execution of devenv failed.");
// return to the original directory
cmSystemTools::ChangeDirectory(cwd.c_str());
return 1;
}
cmSystemTools::ChangeDirectory(cwd.c_str());
return 0;
}
......@@ -66,6 +66,16 @@ public:
*/
virtual void EnableLanguage(const char*);
/**
* Try running cmake and building a file. This is used for dynalically
* loaded commands, not as part of the usual build process. For the
* generator, it can assume that cmake has been run on the srcdir/bindir
* and it just needs to be compiled.
*/
virtual int TryCompile(const char *srcdir, const char *bindir,
const char *projectName);
protected:
/**
* Return array of created VCProj names in a STL vector.
......
......@@ -75,3 +75,51 @@ void cmMSProjectGenerator::EnableLanguage(const char*)
}
}
int cmMSProjectGenerator::TryCompile(const char *srcdir,
const char *bindir,
const char *projectName)
{
// now build the test
std::string makeCommand = m_Makefile->GetDefinition("CMAKE_MAKE_PROGRAM");
if(makeCommand.size() == 0)
{
cmSystemTools::Error(
"Generator cannot find the appropriate make command.");
return 1;
}
makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
std::string lowerCaseCommand = makeCommand;
cmSystemTools::LowerCase(lowerCaseCommand);
/**
* Run an executable command and put the stdout in output.
*/
std::string output;
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
cmSystemTools::ChangeDirectory(bindir);
// if there are spaces in the makeCommand, assume a full path
// and convert it to a path with no spaces in it as the
// RunCommand does not like spaces
#if defined(_WIN32) && !defined(__CYGWIN__)
if(makeCommand.find(' ') != std::string::npos)
{
cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
}
#endif
makeCommand += " ";
makeCommand += projectName;
makeCommand += ".dsw /MAKE \"ALL_BUILD - Debug\" /REBUILD";
if (!cmSystemTools::RunCommand(makeCommand.c_str(), output))
{
cmSystemTools::Error("Generator: execution of msdev failed.");
// return to the original directory
cmSystemTools::ChangeDirectory(cwd.c_str());
return 1;
}
cmSystemTools::ChangeDirectory(cwd.c_str());
return 0;
}
......@@ -75,6 +75,15 @@ public:
*/
virtual void EnableLanguage(const char*);
/**
* Try running cmake and building a file. This is used for dynalically
* loaded commands, not as part of the usual build process. For the
* generator, it can assume that cmake has been run on the srcdir/bindir
* and it just needs to be compiled.
*/
virtual int TryCompile(const char *srcdir, const char *bindir,
const char *projectName);
private:
cmDSWWriter* m_DSWWriter;
cmDSPWriter* m_DSPWriter;
......
......@@ -25,6 +25,7 @@
#include "cmCacheManager.h"
#include "cmFunctionBlocker.h"
#include "cmListFileCache.h"
#include "cmake.h"
#include <stdio.h> // required for sprintf
// default is not to be building executables
......@@ -48,6 +49,7 @@ cmMakefile::cmMakefile()
m_DefineFlags = " ";
m_MakefileGenerator = 0;
m_CacheManager = 0;
this->AddSourceGroup("", "^.*$");
this->AddSourceGroup("Source Files", "\\.(cpp|C|c|cxx|rc|def|r|odl|idl|hpj|bat)$");
this->AddSourceGroup("Header Files", "\\.(h|hh|hpp|hxx|hm|inl)$");
......@@ -57,24 +59,20 @@ cmMakefile::cmMakefile()
unsigned int cmMakefile::GetCacheMajorVersion()
{
if(!cmCacheManager::GetInstance()->
GetCacheValue("CMAKE_CACHE_MAJOR_VERSION"))
if(!this->m_CacheManager->GetCacheValue("CMAKE_CACHE_MAJOR_VERSION"))
{