Replace cmake::GetScriptMode() with GetWorkingMode()

GetWorkingMode() returns a new enum WorkingMode, which is one of
NORMAL_MODE, SCRIPT_MODE and FIND_PACKAGE_MODE.

Alex
This commit is contained in:
Alex Neundorf 2011-07-13 18:59:51 +02:00
parent e4f603b698
commit 7690edffd9
5 changed files with 38 additions and 31 deletions

View File

@ -782,7 +782,7 @@ void cmGlobalGenerator::Configure()
// so create the map from project name to vector of local generators
this->FillProjectMap();
if ( !this->CMakeInstance->GetScriptMode() )
if ( this->CMakeInstance->GetWorkingMode() == cmake::NORMAL_MODE)
{
const char* msg = "Configuring done";
if(cmSystemTools::GetErrorOccuredFlag())

View File

@ -384,8 +384,8 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
// Decide whether to invoke the command.
if(pcmd->GetEnabled() && !cmSystemTools::GetFatalErrorOccured() &&
(this->GetCMakeInstance()->GetFindPackageMode()
|| !this->GetCMakeInstance()->GetScriptMode() || pcmd->IsScriptable()))
(this->GetCMakeInstance()->GetWorkingMode() != cmake::SCRIPT_MODE
|| pcmd->IsScriptable()))
{
// if trace is one, print out invoke information
@ -413,7 +413,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
this->IssueMessage(cmake::FATAL_ERROR, pcmd->GetError());
}
result = false;
if ( this->GetCMakeInstance()->GetScriptMode() )
if ( this->GetCMakeInstance()->GetWorkingMode() != cmake::NORMAL_MODE)
{
cmSystemTools::SetFatalErrorOccured();
}
@ -424,7 +424,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
this->UsedCommands.push_back(pcmd.release());
}
}
else if ( this->GetCMakeInstance()->GetScriptMode()
else if ( this->GetCMakeInstance()->GetWorkingMode() == cmake::SCRIPT_MODE
&& !pcmd->IsScriptable() )
{
std::string error = "Command ";

View File

@ -180,8 +180,7 @@ cmake::cmake()
this->GlobalGenerator = 0;
this->ProgressCallback = 0;
this->ProgressCallbackClientData = 0;
this->ScriptMode = false;
this->FindPackageMode = false;
this->CurrentWorkingMode = NORMAL_MODE;
#ifdef CMAKE_BUILD_WITH_CMAKE
this->VariableWatch = new cmVariableWatch;
@ -523,7 +522,7 @@ void cmake::ReadListFile(const std::vector<std::string>& args,
(cmSystemTools::GetCurrentWorkingDirectory().c_str());
lg->GetMakefile()->SetStartDirectory
(cmSystemTools::GetCurrentWorkingDirectory().c_str());
if (this->GetScriptMode())
if (this->GetWorkingMode() != NORMAL_MODE)
{
std::string file(cmSystemTools::CollapseFullPath(path));
cmSystemTools::ConvertToUnixSlashes(file);
@ -2147,7 +2146,7 @@ int cmake::ActualConfigure()
this->CleanupCommandsAndMacros();
int res = 0;
if ( !this->ScriptMode )
if ( this->GetWorkingMode() == NORMAL_MODE )
{
res = this->DoPreConfigureChecks();
}
@ -2335,7 +2334,7 @@ int cmake::ActualConfigure()
this->CacheManager->RemoveCacheEntry("CMAKE_EXTRA_GENERATOR");
}
// only save the cache if there were no fatal errors
if ( !this->ScriptMode )
if ( this->GetWorkingMode() == NORMAL_MODE )
{
this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
}
@ -2401,7 +2400,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
// set the cmake command
this->CMakeCommand = args[0];
if ( !this->ScriptMode )
if ( this->GetWorkingMode() == NORMAL_MODE )
{
// load the cache
if(this->LoadCache() < 0)
@ -2422,7 +2421,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
}
// In script mode we terminate after running the script.
if(this->ScriptMode)
if(this->GetWorkingMode() != NORMAL_MODE)
{
if(cmSystemTools::GetErrorOccuredFlag())
{
@ -2468,7 +2467,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
this->SetStartDirectory(this->GetHomeDirectory());
this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
int ret = this->Configure();
if (ret || this->ScriptMode)
if (ret || this->GetWorkingMode() != NORMAL_MODE)
{
#if defined(CMAKE_HAVE_VS_GENERATORS)
if(!this->VSSolutionFile.empty() && this->GlobalGenerator)

View File

@ -64,6 +64,25 @@ class cmake
WARNING,
LOG
};
/** Describes the working modes of cmake.
* NORMAL_MODE: cmake runs to create project files
* SCRIPT_MODE: in script mode there is no generator and no cache. Also,
* language are not enabled, so add_executable and things do
* not do anything. Started by using -P
* FIND_PACKAGE_MODE: cmake runs in pkg-config like mode, i.e. it just
* searches for a package and prints the results to stdout.
* This is similar to SCRIPT_MODE, but commands like
* add_library() work too, since they may be used e.g. in
* exported target files. Started via --find-package
*/
enum WorkingMode
{
NORMAL_MODE,
SCRIPT_MODE,
FIND_PACKAGE_MODE
};
typedef std::map<cmStdString, cmCommand*> RegisteredCommandsMap;
///! construct an instance of cmake
@ -274,16 +293,8 @@ class cmake
///! Do all the checks before running configure
int DoPreConfigureChecks();
/**
* Set and get the script mode option. In script mode there is no
* generator and no cache. Also, language are not enabled, so
* add_executable and things do not do anything.
*/
void SetScriptMode(bool mode) { this->ScriptMode = mode; }
bool GetScriptMode() { return this->ScriptMode; }
void SetFindPackageMode(bool mode) {this->FindPackageMode = mode; }
bool GetFindPackageMode() {return this->FindPackageMode;}
void SetWorkingMode(WorkingMode mode) { this->CurrentWorkingMode = mode; }
WorkingMode GetWorkingMode() { return this->CurrentWorkingMode; }
///! Debug the try compile stuff by not delelting the files
bool GetDebugTryCompile(){return this->DebugTryCompile;}
@ -464,8 +475,7 @@ private:
void* ProgressCallbackClientData;
bool Verbose;
bool InTryCompile;
bool ScriptMode;
bool FindPackageMode;
WorkingMode CurrentWorkingMode;
bool DebugOutput;
bool Trace;
bool WarnUninitialized;

View File

@ -436,8 +436,7 @@ int do_cmake(int ac, char** av)
bool list_all_cached = false;
bool list_help = false;
bool view_only = false;
bool script_mode = false;
bool find_package_mode = false;
cmake::WorkingMode workingMode = cmake::NORMAL_MODE;
std::vector<std::string> args;
for(int i =0; i < ac; ++i)
{
@ -485,7 +484,7 @@ int do_cmake(int ac, char** av)
}
else
{
script_mode = true;
workingMode = cmake::SCRIPT_MODE;
args.push_back(av[i]);
i++;
args.push_back(av[i]);
@ -494,7 +493,7 @@ int do_cmake(int ac, char** av)
else if (!command && strncmp(av[i], "--find-package",
strlen("--find-package")) == 0)
{
find_package_mode = true;
workingMode = cmake::FIND_PACKAGE_MODE;
args.push_back(av[i]);
}
else
@ -521,8 +520,7 @@ int do_cmake(int ac, char** av)
cmake cm;
cmSystemTools::SetErrorCallback(cmakemainErrorCallback, (void *)&cm);
cm.SetProgressCallback(cmakemainProgressCallback, (void *)&cm);
cm.SetScriptMode(script_mode || find_package_mode);
cm.SetFindPackageMode(find_package_mode);
cm.SetWorkingMode(workingMode);
int res = cm.Run(args, view_only);
if ( list_cached || list_all_cached )