cleaned up some of the cmake interface

This commit is contained in:
Ken Martin 2002-09-17 13:59:58 -04:00
parent e68e917d9f
commit 2a68d21e85
5 changed files with 60 additions and 37 deletions

View File

@ -580,7 +580,9 @@ void CMakeSetupDialog::RunCMake(bool generateProjectFiles)
m_CMakeInstance->SetStartOutputDirectory(m_WhereBuild);
m_CMakeInstance->SetGlobalGenerator(
m_CMakeInstance->CreateGlobalGenerator(m_GeneratorChoiceString));
if(m_CMakeInstance->Configure(m_PathToExecutable) != 0)
m_CMakeInstance->SetCMakeCommand(m_PathToExecutable);
m_CMakeInstance->LoadCache();
if(m_CMakeInstance->Configure() != 0)
{
cmSystemTools::Error(
"Error in configuration process, project files may be invalid");

View File

@ -1352,7 +1352,6 @@ int cmMakefile::TryCompile(const char *srcdir, const char *bindir,
// be run that way but the cmake object requires a vailid path
std::string cmakeCommand = this->GetDefinition("CMAKE_COMMAND");
cmake cm;
cm.AddCMakePaths(cmakeCommand.c_str());
cm.SetIsInTryCompile(true);
cmGlobalGenerator *gg =
cm.CreateGlobalGenerator(m_LocalGenerator->GetGlobalGenerator()->GetName());
@ -1371,12 +1370,14 @@ int cmMakefile::TryCompile(const char *srcdir, const char *bindir,
cm.SetHomeOutputDirectory(bindir);
cm.SetStartDirectory(srcdir);
cm.SetStartOutputDirectory(bindir);
cm.SetCMakeCommand(cmakeCommand.c_str());
cm.LoadCache();
// to save time we pass the EnableLanguage info directly
gg->EnableLanguagesFromGenerator(m_LocalGenerator->GetGlobalGenerator(),
this);
if (cm.Configure(cmakeCommand.c_str()) != 0)
if (cm.Configure() != 0)
{
cmSystemTools::Error(
"Internal CMake error, TryCompile configure of cmake failed");

View File

@ -625,15 +625,8 @@ void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
gg->SetCMakeInstance(this);
}
int cmake::Configure(const char *arg0, const std::vector<std::string>* args)
int cmake::Configure()
{
// Read in the cache, but not for a try compile
// because there will be no cache
if (!m_InTryCompile)
{
m_CacheManager->LoadCache(this->GetHomeOutputDirectory());
}
// do a sanity check on some values
if(m_CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY"))
{
@ -661,18 +654,6 @@ int cmake::Configure(const char *arg0, const std::vector<std::string>* args)
cmCacheManager::INTERNAL);
}
// extract command line arguments that might add cache entries
if (args)
{
this->SetCacheArgs(*args);
}
// setup CMAKE_ROOT and CMAKE_COMMAND
if(!this->AddCMakePaths(arg0))
{
return -3;
}
// no generator specified on the command line
if(!m_GlobalGenerator)
{
@ -785,6 +766,15 @@ int cmake::Run(const std::vector<std::string>& args)
// Process the arguments
this->SetArgs(args);
// set the cmake command
m_CMakeCommand = args[0];
// load the cache
this->LoadCache();
// Add any cache args
this->SetCacheArgs(args);
// if we are local do the local thing, otherwise do global
if (m_Local)
{
@ -792,7 +782,7 @@ int cmake::Run(const std::vector<std::string>& args)
}
// otherwise global
int ret = this->Configure(args[0].c_str(),&args);
int ret = this->Configure();
if (ret)
{
return ret;
@ -892,3 +882,21 @@ void cmake::AddDefaultCommands()
}
}
int cmake::LoadCache()
{
m_CacheManager->LoadCache(this->GetHomeOutputDirectory());
if (m_CMakeCommand.size() < 2)
{
cmSystemTools::Error("cmake command was not specified prior to loading the cache in cmake.cxx");
return -1;
}
// setup CMAKE_ROOT and CMAKE_COMMAND
if(!this->AddCMakePaths(m_CMakeCommand.c_str()))
{
return -3;
}
return 0;
}

View File

@ -119,7 +119,15 @@ class cmake
* GlobalGenerator. This in turn will read in an process all the CMakeList
* files for the tree. It will not produce any actual Makefiles, or
* workspaces. Generate does that. */
int Configure(const char *cmakeexec, const std::vector<std::string> *args = 0);
int Configure();
/**
* Configure the cmMakefiles. This routine will create a GlobalGenerator if
* one has not already been set. It will then Call Configure on the
* GlobalGenerator. This in turn will read in an process all the CMakeList
* files for the tree. It will not produce any actual Makefiles, or
* workspaces. Generate does that. */
int LoadCache();
///! Create a GlobalGenerator
cmGlobalGenerator* CreateGlobalGenerator(const char* name);
@ -136,6 +144,9 @@ class cmake
///! get the cmCachemManager used by this invocation of cmake
cmCacheManager *GetCacheManager() { return m_CacheManager; }
///! set the cmake command this instance of cmake should use
void SetCMakeCommand(const char* cmd) { m_CMakeCommand = cmd; }
/**
* Given a variable name, return its value (as a string).
*/
@ -164,10 +175,7 @@ class cmake
* Is cmake in the process of a local cmake invocation. If so, we know the
* cache is already configured and ready to go.
*/
bool GetLocal()
{
return m_Local;
}
bool GetLocal() { return m_Local; }
///! Display command line useage
void Usage(const char *program);
@ -181,10 +189,8 @@ class cmake
///! Is this cmake running as a result of a TRY_COMPILE command
void SetIsInTryCompile(bool i) { m_InTryCompile = i; }
/**
* Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
*/
int AddCMakePaths(const char *arg0);
///! Parse command line arguments that might set cache values
void SetCacheArgs(const std::vector<std::string>&);
protected:
typedef std::map<cmStdString, cmCommand*> RegisteredCommandsMap;
@ -198,18 +204,21 @@ protected:
std::string m_cmStartDirectory;
std::string m_StartOutputDirectory;
///! Parse command line arguments that might set cache values
void SetCacheArgs(const std::vector<std::string>&);
///! read in a cmake list file to initialize the cache
void ReadListFile(const char *path);
///! used by Run
int LocalGenerate();
/**
* Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
*/
int AddCMakePaths(const char *arg0);
private:
bool m_Verbose;
bool m_Local;
bool m_InTryCompile;
std::string m_CMakeCommand;
};

View File

@ -89,6 +89,9 @@ void cmakewizard::RunWizard(std::vector<std::string> const& args)
cmSystemTools::DisableRunCommandOutput();
cmake make;
make.SetArgs(args);
make.SetCMakeCommand(args[0].c_str());
make.LoadCache();
make.SetCacheArgs(args);
std::map<std::string,std::string> askedCache;
bool asked = false;
// continue asking questions until no new questions are asked
@ -98,7 +101,7 @@ void cmakewizard::RunWizard(std::vector<std::string> const& args)
// run cmake
this->ShowMessage("Please wait while cmake processes CMakeLists.txt files....\n");
make.Configure(args[0].c_str(),&args);
make.Configure();
this->ShowMessage("\n");
// load the cache from disk
cmCacheManager *cachem = make.GetCacheManager();