ENH: Start includding the scripting support
This commit is contained in:
parent
69dd3218ba
commit
ac2859aaa3
|
@ -218,7 +218,9 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff)
|
|||
cmCommand* usedCommand = rm->Clone();
|
||||
usedCommand->SetMakefile(this);
|
||||
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 the command is inherited then InitialPass it.
|
||||
|
@ -232,6 +234,10 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff)
|
|||
<< usedCommand->GetError();
|
||||
cmSystemTools::Error(error.str().c_str());
|
||||
result = false;
|
||||
if ( this->GetCMakeInstance()->GetScriptMode() )
|
||||
{
|
||||
cmSystemTools::SetFatalErrorOccured();
|
||||
}
|
||||
}
|
||||
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
|
||||
// then delete it
|
||||
if(!keepCommand)
|
||||
|
@ -279,7 +295,6 @@ bool cmMakefile::ReadListFile(const char* filename_in, const char* external_in)
|
|||
// e.g. mismatched IF statement
|
||||
std::set<cmFunctionBlocker *> originalBlockers;
|
||||
|
||||
|
||||
const char* external = 0;
|
||||
std::string external_abs;
|
||||
|
||||
|
|
|
@ -95,6 +95,7 @@ cmake::cmake()
|
|||
m_ProgressCallback = 0;
|
||||
m_ProgressCallbackClientData = 0;
|
||||
m_VariableWatch = new cmVariableWatch;
|
||||
m_ScriptMode = false;
|
||||
|
||||
this->AddDefaultGenerators();
|
||||
this->AddDefaultCommands();
|
||||
|
@ -178,7 +179,7 @@ void cmake::Usage(const char* program)
|
|||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
|
@ -199,15 +200,34 @@ void cmake::SetCacheArgs(const std::vector<std::string>& args)
|
|||
{
|
||||
std::cerr << "Parse error in command line argument: " << arg << "\n"
|
||||
<< "Should be: VAR:type=value\n";
|
||||
cmSystemTools::Error("No cmake scrpt provided.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(arg.find("-C",0) == 0)
|
||||
{
|
||||
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";
|
||||
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)
|
||||
|
@ -288,6 +308,10 @@ void cmake::SetArgs(const std::vector<std::string>& args)
|
|||
{
|
||||
// skip for now
|
||||
}
|
||||
else if(arg.find("-M",0) == 0)
|
||||
{
|
||||
// skip for now
|
||||
}
|
||||
else if(arg.find("-G",0) == 0)
|
||||
{
|
||||
std::string value = arg.substr(2);
|
||||
|
@ -856,7 +880,11 @@ int cmake::DoPreConfigureChecks()
|
|||
|
||||
int cmake::Configure()
|
||||
{
|
||||
int res = this->DoPreConfigureChecks();
|
||||
int res = 0;
|
||||
if ( !m_ScriptMode )
|
||||
{
|
||||
res = this->DoPreConfigureChecks();
|
||||
}
|
||||
if ( res < 0 )
|
||||
{
|
||||
return -2;
|
||||
|
@ -970,7 +998,10 @@ int cmake::Configure()
|
|||
// user can select another.
|
||||
m_CacheManager->RemoveCacheEntry("CMAKE_GENERATOR");
|
||||
}
|
||||
this->m_CacheManager->SaveCache(this->GetHomeOutputDirectory());
|
||||
if ( !m_ScriptMode )
|
||||
{
|
||||
this->m_CacheManager->SaveCache(this->GetHomeOutputDirectory());
|
||||
}
|
||||
if(cmSystemTools::GetErrorOccuredFlag())
|
||||
{
|
||||
return -1;
|
||||
|
@ -1004,15 +1035,22 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
|
|||
// set the cmake command
|
||||
m_CMakeCommand = args[0];
|
||||
|
||||
// load the cache
|
||||
if(this->LoadCache() < 0)
|
||||
if ( !m_ScriptMode )
|
||||
{
|
||||
cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
|
||||
// load the cache
|
||||
if(this->LoadCache() < 0)
|
||||
{
|
||||
cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Add any cache args
|
||||
if ( !this->SetCacheArgs(args) )
|
||||
{
|
||||
cmSystemTools::Error("Problem processing arguments. Aborting.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Add any cache args
|
||||
this->SetCacheArgs(args);
|
||||
|
||||
std::string systemFile = this->GetHomeOutputDirectory();
|
||||
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
|
||||
// of cmake, or CMakeSystem.cmake file is not in the root binary
|
||||
// directory, run a global generate
|
||||
if(!m_Local || !this->CacheVersionMatches() ||
|
||||
if(m_ScriptMode || !m_Local || !this->CacheVersionMatches() ||
|
||||
!cmSystemTools::FileExists(systemFile.c_str()) )
|
||||
{
|
||||
// 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;
|
||||
m_Local = false;
|
||||
ret = this->Configure();
|
||||
if (ret)
|
||||
if (ret || m_ScriptMode)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -219,7 +219,7 @@ class cmake
|
|||
void SetIsInTryCompile(bool i) { m_InTryCompile = i; }
|
||||
|
||||
///! 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 *);
|
||||
/**
|
||||
|
@ -243,6 +243,14 @@ 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) { m_ScriptMode = mode; }
|
||||
bool GetScriptMode() { return m_ScriptMode; }
|
||||
|
||||
protected:
|
||||
typedef cmGlobalGenerator* (*CreateGeneratorFunctionType)();
|
||||
|
@ -282,6 +290,7 @@ private:
|
|||
bool m_Verbose;
|
||||
bool m_Local;
|
||||
bool m_InTryCompile;
|
||||
bool m_ScriptMode;
|
||||
std::string m_CMakeCommand;
|
||||
const char* m_CXXEnvironment;
|
||||
const char* m_CCEnvironment;
|
||||
|
|
|
@ -149,6 +149,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;
|
||||
std::vector<std::string> args;
|
||||
for(int i =0; i < ac; ++i)
|
||||
{
|
||||
|
@ -182,6 +183,11 @@ int do_cmake(int ac, char** av)
|
|||
list_all_cached = true;
|
||||
list_help = true;
|
||||
}
|
||||
else if (strncmp(av[i], "-M", 2) == 0)
|
||||
{
|
||||
script_mode = true;
|
||||
args.push_back(av[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
args.push_back(av[i]);
|
||||
|
@ -200,6 +206,7 @@ int do_cmake(int ac, char** av)
|
|||
}
|
||||
cmake cm;
|
||||
cm.SetProgressCallback(updateProgress, 0);
|
||||
cm.SetScriptMode(script_mode);
|
||||
int res = cm.Run(args, view_only);
|
||||
if ( list_cached || list_all_cached )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue