From ac2859aaa36ad25ff71da0a2dae54b84e6378897 Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Wed, 29 Oct 2003 09:45:26 -0500 Subject: [PATCH] ENH: Start includding the scripting support --- Source/cmMakefile.cxx | 19 ++++++++++++-- Source/cmake.cxx | 60 +++++++++++++++++++++++++++++++++++-------- Source/cmake.h | 11 +++++++- Source/cmakemain.cxx | 7 +++++ 4 files changed, 83 insertions(+), 14 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 178e7ac63..d7ec58256 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -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 originalBlockers; - const char* external = 0; std::string external_abs; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 11561e813..da7d2905e 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -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& args) +bool cmake::SetCacheArgs(const std::vector& args) { for(unsigned int i=1; i < args.size(); ++i) { @@ -199,15 +200,34 @@ void cmake::SetCacheArgs(const std::vector& 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& 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& 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& 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& args, bool noconfigure) bool saveLocalFlag = m_Local; m_Local = false; ret = this->Configure(); - if (ret) + if (ret || m_ScriptMode) { return ret; } diff --git a/Source/cmake.h b/Source/cmake.h index b3c4a45fa..eca769448 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -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&); + bool SetCacheArgs(const std::vector&); 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; diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 5833dd122..3f9433227 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -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 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 ) {