ENH: Start includding the scripting support

This commit is contained in:
Andy Cedilnik 2003-10-29 09:45:26 -05:00
parent 69dd3218ba
commit ac2859aaa3
4 changed files with 83 additions and 14 deletions

View File

@ -218,7 +218,9 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff)
cmCommand* usedCommand = rm->Clone(); cmCommand* usedCommand = rm->Clone();
usedCommand->SetMakefile(this); usedCommand->SetMakefile(this);
bool keepCommand = false; bool keepCommand = false;
if(usedCommand->GetEnabled() && !cmSystemTools::GetFatalErrorOccured()) if(usedCommand->GetEnabled() && !cmSystemTools::GetFatalErrorOccured() &&
(!this->GetCMakeInstance()->GetScriptMode() ||
usedCommand->IsScriptable()))
{ {
// if not running in inherit mode or // if not running in inherit mode or
// if the command is inherited then InitialPass it. // if the command is inherited then InitialPass it.
@ -232,6 +234,10 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff)
<< usedCommand->GetError(); << usedCommand->GetError();
cmSystemTools::Error(error.str().c_str()); cmSystemTools::Error(error.str().c_str());
result = false; result = false;
if ( this->GetCMakeInstance()->GetScriptMode() )
{
cmSystemTools::SetFatalErrorOccured();
}
} }
else else
{ {
@ -241,6 +247,16 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff)
} }
} }
} }
else if ( this->GetCMakeInstance()->GetScriptMode() && !usedCommand->IsScriptable() )
{
cmOStringStream error;
error << "Error in cmake code at\n"
<< lff.m_FilePath << ":" << lff.m_Line << ":\n"
<< "Command " << usedCommand->GetName() << " not scriptable" << std::endl;
cmSystemTools::Error(error.str().c_str());
result = false;
cmSystemTools::SetFatalErrorOccured();
}
// if the Cloned command was not used // if the Cloned command was not used
// then delete it // then delete it
if(!keepCommand) if(!keepCommand)
@ -279,7 +295,6 @@ bool cmMakefile::ReadListFile(const char* filename_in, const char* external_in)
// e.g. mismatched IF statement // e.g. mismatched IF statement
std::set<cmFunctionBlocker *> originalBlockers; std::set<cmFunctionBlocker *> originalBlockers;
const char* external = 0; const char* external = 0;
std::string external_abs; std::string external_abs;

View File

@ -95,6 +95,7 @@ cmake::cmake()
m_ProgressCallback = 0; m_ProgressCallback = 0;
m_ProgressCallbackClientData = 0; m_ProgressCallbackClientData = 0;
m_VariableWatch = new cmVariableWatch; m_VariableWatch = new cmVariableWatch;
m_ScriptMode = false;
this->AddDefaultGenerators(); this->AddDefaultGenerators();
this->AddDefaultCommands(); this->AddDefaultCommands();
@ -178,7 +179,7 @@ void cmake::Usage(const char* program)
} }
// Parse the args // Parse the args
void cmake::SetCacheArgs(const std::vector<std::string>& args) bool cmake::SetCacheArgs(const std::vector<std::string>& args)
{ {
for(unsigned int i=1; i < args.size(); ++i) for(unsigned int i=1; i < args.size(); ++i)
{ {
@ -199,15 +200,34 @@ void cmake::SetCacheArgs(const std::vector<std::string>& args)
{ {
std::cerr << "Parse error in command line argument: " << arg << "\n" std::cerr << "Parse error in command line argument: " << arg << "\n"
<< "Should be: VAR:type=value\n"; << "Should be: VAR:type=value\n";
cmSystemTools::Error("No cmake scrpt provided.");
return false;
} }
} }
else if(arg.find("-C",0) == 0) else if(arg.find("-C",0) == 0)
{ {
std::string path = arg.substr(2); std::string path = arg.substr(2);
if ( path.size() == 0 )
{
cmSystemTools::Error("No initial cache file provided.");
return false;
}
std::cerr << "loading initial cache file " << path.c_str() << "\n"; std::cerr << "loading initial cache file " << path.c_str() << "\n";
this->ReadListFile(path.c_str()); this->ReadListFile(path.c_str());
} }
else if(arg.find("-M",0) == 0)
{
std::string path = arg.substr(2);
if ( path.size() == 0 )
{
cmSystemTools::Error("No cmake scrpt provided.");
return false;
} }
std::cerr << "Running cmake script file " << path.c_str() << "\n";
this->ReadListFile(path.c_str());
}
}
return true;
} }
void cmake::ReadListFile(const char *path) void cmake::ReadListFile(const char *path)
@ -288,6 +308,10 @@ void cmake::SetArgs(const std::vector<std::string>& args)
{ {
// skip for now // skip for now
} }
else if(arg.find("-M",0) == 0)
{
// skip for now
}
else if(arg.find("-G",0) == 0) else if(arg.find("-G",0) == 0)
{ {
std::string value = arg.substr(2); std::string value = arg.substr(2);
@ -856,7 +880,11 @@ int cmake::DoPreConfigureChecks()
int cmake::Configure() int cmake::Configure()
{ {
int res = this->DoPreConfigureChecks(); int res = 0;
if ( !m_ScriptMode )
{
res = this->DoPreConfigureChecks();
}
if ( res < 0 ) if ( res < 0 )
{ {
return -2; return -2;
@ -970,7 +998,10 @@ int cmake::Configure()
// user can select another. // user can select another.
m_CacheManager->RemoveCacheEntry("CMAKE_GENERATOR"); m_CacheManager->RemoveCacheEntry("CMAKE_GENERATOR");
} }
if ( !m_ScriptMode )
{
this->m_CacheManager->SaveCache(this->GetHomeOutputDirectory()); this->m_CacheManager->SaveCache(this->GetHomeOutputDirectory());
}
if(cmSystemTools::GetErrorOccuredFlag()) if(cmSystemTools::GetErrorOccuredFlag())
{ {
return -1; return -1;
@ -1004,15 +1035,22 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
// set the cmake command // set the cmake command
m_CMakeCommand = args[0]; m_CMakeCommand = args[0];
if ( !m_ScriptMode )
{
// load the cache // load the cache
if(this->LoadCache() < 0) if(this->LoadCache() < 0)
{ {
cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n"); cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
return -1; return -1;
} }
}
// Add any cache args // Add any cache args
this->SetCacheArgs(args); if ( !this->SetCacheArgs(args) )
{
cmSystemTools::Error("Problem processing arguments. Aborting.\n");
return -1;
}
std::string systemFile = this->GetHomeOutputDirectory(); std::string systemFile = this->GetHomeOutputDirectory();
systemFile += "/CMakeSystem.cmake"; systemFile += "/CMakeSystem.cmake";
@ -1026,7 +1064,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
// if not local or the cmake version has changed since the last run // if not local or the cmake version has changed since the last run
// of cmake, or CMakeSystem.cmake file is not in the root binary // of cmake, or CMakeSystem.cmake file is not in the root binary
// directory, run a global generate // directory, run a global generate
if(!m_Local || !this->CacheVersionMatches() || if(m_ScriptMode || !m_Local || !this->CacheVersionMatches() ||
!cmSystemTools::FileExists(systemFile.c_str()) ) !cmSystemTools::FileExists(systemFile.c_str()) )
{ {
// If we are doing global generate, we better set start and start // If we are doing global generate, we better set start and start
@ -1038,7 +1076,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
bool saveLocalFlag = m_Local; bool saveLocalFlag = m_Local;
m_Local = false; m_Local = false;
ret = this->Configure(); ret = this->Configure();
if (ret) if (ret || m_ScriptMode)
{ {
return ret; return ret;
} }

View File

@ -219,7 +219,7 @@ class cmake
void SetIsInTryCompile(bool i) { m_InTryCompile = i; } void SetIsInTryCompile(bool i) { m_InTryCompile = i; }
///! Parse command line arguments that might set cache values ///! Parse command line arguments that might set cache values
void SetCacheArgs(const std::vector<std::string>&); bool SetCacheArgs(const std::vector<std::string>&);
typedef void (*ProgressCallback)(const char*msg, float progress, void *); typedef void (*ProgressCallback)(const char*msg, float progress, void *);
/** /**
@ -244,6 +244,14 @@ class cmake
///! Do all the checks before running configure ///! Do all the checks before running configure
int DoPreConfigureChecks(); 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) { m_ScriptMode = mode; }
bool GetScriptMode() { return m_ScriptMode; }
protected: protected:
typedef cmGlobalGenerator* (*CreateGeneratorFunctionType)(); typedef cmGlobalGenerator* (*CreateGeneratorFunctionType)();
typedef std::map<cmStdString, CreateGeneratorFunctionType> RegisteredGeneratorsMap; typedef std::map<cmStdString, CreateGeneratorFunctionType> RegisteredGeneratorsMap;
@ -282,6 +290,7 @@ private:
bool m_Verbose; bool m_Verbose;
bool m_Local; bool m_Local;
bool m_InTryCompile; bool m_InTryCompile;
bool m_ScriptMode;
std::string m_CMakeCommand; std::string m_CMakeCommand;
const char* m_CXXEnvironment; const char* m_CXXEnvironment;
const char* m_CCEnvironment; const char* m_CCEnvironment;

View File

@ -149,6 +149,7 @@ int do_cmake(int ac, char** av)
bool list_all_cached = false; bool list_all_cached = false;
bool list_help = false; bool list_help = false;
bool view_only = false; bool view_only = false;
bool script_mode = false;
std::vector<std::string> args; std::vector<std::string> args;
for(int i =0; i < ac; ++i) for(int i =0; i < ac; ++i)
{ {
@ -182,6 +183,11 @@ int do_cmake(int ac, char** av)
list_all_cached = true; list_all_cached = true;
list_help = true; list_help = true;
} }
else if (strncmp(av[i], "-M", 2) == 0)
{
script_mode = true;
args.push_back(av[i]);
}
else else
{ {
args.push_back(av[i]); args.push_back(av[i]);
@ -200,6 +206,7 @@ int do_cmake(int ac, char** av)
} }
cmake cm; cmake cm;
cm.SetProgressCallback(updateProgress, 0); cm.SetProgressCallback(updateProgress, 0);
cm.SetScriptMode(script_mode);
int res = cm.Run(args, view_only); int res = cm.Run(args, view_only);
if ( list_cached || list_all_cached ) if ( list_cached || list_all_cached )
{ {