From da17f30cb515775000ec7dd1d3fab8b3621c2587 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Mon, 19 Nov 2001 17:52:08 -0500 Subject: [PATCH] ENH: add new command VARIABLE_REQUIRES for better debugging of list files --- Source/MFCDialog/CMakeSetupDialog.cpp | 11 +++-- Source/cmCommands.cxx | 2 + Source/cmSystemTools.cxx | 6 +-- Source/cmSystemTools.h | 3 ++ Source/cmVariableRequiresCommand.cxx | 59 ++++++++++++++++++--------- Source/cmVariableRequiresCommand.h | 17 +++++--- 6 files changed, 67 insertions(+), 31 deletions(-) diff --git a/Source/MFCDialog/CMakeSetupDialog.cpp b/Source/MFCDialog/CMakeSetupDialog.cpp index 0d0e504b7..705d83081 100644 --- a/Source/MFCDialog/CMakeSetupDialog.cpp +++ b/Source/MFCDialog/CMakeSetupDialog.cpp @@ -507,7 +507,8 @@ void CMakeSetupDialog::RunCMake(bool generateProjectFiles) // always save the current gui values to disk this->SaveCacheFromGUI(); // Make sure we are working from the cache on disk - this->LoadCacheFromDiskToGUI(); + this->LoadCacheFromDiskToGUI(); + m_OKButton.EnableWindow(false); // create a cmake object cmake make; // create the arguments for the cmake object @@ -528,7 +529,6 @@ void CMakeSetupDialog::RunCMake(bool generateProjectFiles) { cmSystemTools::Error( "Error in generation process, project files may be invalid"); - cmSystemTools::ResetErrorOccuredFlag(); } // update the GUI with any new values in the caused by the // generation process @@ -539,12 +539,15 @@ void CMakeSetupDialog::RunCMake(bool generateProjectFiles) m_BuildPathChanged = false; // put the cursor back ::SetCursor(LoadCursor(NULL, IDC_ARROW)); + cmSystemTools::ResetErrorOccuredFlag(); } // Callback for build projects button void CMakeSetupDialog::OnConfigure() { + // enable error messages each time configure is pressed + cmSystemTools::EnableMessages(); this->RunCMake(false); } @@ -666,7 +669,7 @@ void CMakeSetupDialog::FillCacheGUIFromCacheManager() } } m_OKButton.EnableWindow(false); - if(cache.size() > 0) + if(cache.size() > 0 && !cmSystemTools::GetErrorOccuredFlag()) { bool enable = true; items = m_CacheEntriesList.GetItems(); @@ -850,6 +853,8 @@ void CMakeSetupDialog::OnCancel() void CMakeSetupDialog::OnOk() { + // enable error messages each time configure is pressed + cmSystemTools::EnableMessages(); m_CacheEntriesList.ClearDirty(); this->RunCMake(true); cmMakefileGenerator::UnRegisterGenerators(); diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 9f9f64eec..c51b263ce 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -54,6 +54,7 @@ #include "cmTargetLinkLibrariesCommand.cxx" #include "cmUseMangledMesaCommand.cxx" #include "cmUtilitySourceCommand.cxx" +#include "cmVariableRequiresCommand.cxx" #include "cmVTKWrapJavaCommand.cxx" #include "cmVTKWrapPythonCommand.cxx" #include "cmVTKWrapTclCommand.cxx" @@ -115,6 +116,7 @@ void GetPredefinedCommands(std::list& commands) commands.push_back(new cmTargetLinkLibrariesCommand); commands.push_back(new cmUseMangledMesaCommand); commands.push_back(new cmUtilitySourceCommand); + commands.push_back(new cmVariableRequiresCommand); commands.push_back(new cmVTKWrapJavaCommand); commands.push_back(new cmVTKWrapPythonCommand); commands.push_back(new cmVTKWrapTclCommand); diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index c2ff2012a..517d5002f 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -92,6 +92,7 @@ inline int Chdir(const char* dir) #endif bool cmSystemTools::s_ErrorOccured = false; +bool cmSystemTools::s_DisableMessages = false; void (*cmSystemTools::s_ErrorCallback)(const char*, const char*, bool&); @@ -711,14 +712,13 @@ void cmSystemTools::SetErrorCallback(ErrorCallback f) void cmSystemTools::Message(const char* m1, const char *title) { - static bool disableMessages = false; - if(disableMessages) + if(s_DisableMessages) { return; } if(s_ErrorCallback) { - (*s_ErrorCallback)(m1, title, disableMessages); + (*s_ErrorCallback)(m1, title, s_DisableMessages); return; } else diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index f38249369..b24e681be 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -285,8 +285,11 @@ public: ///! change directory the the directory specified static int ChangeDirectory(const char* dir); + static void EnableMessages() { s_DisableMessages = false; } + static void DisableMessages() { s_DisableMessages = true; } private: static bool s_ErrorOccured; + static bool s_DisableMessages; static ErrorCallback s_ErrorCallback; }; diff --git a/Source/cmVariableRequiresCommand.cxx b/Source/cmVariableRequiresCommand.cxx index d108e8b4b..a4352b181 100644 --- a/Source/cmVariableRequiresCommand.cxx +++ b/Source/cmVariableRequiresCommand.cxx @@ -44,29 +44,50 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // cmLibraryCommand bool cmVariableRequiresCommand::InitialPass(std::vector const& args) { - if(args.size() < 4 ) + if(args.size() < 3 ) { this->SetError("called with incorrect number of arguments"); return false; } - std::string testVarible = args[0]; - if(m_Makefile->IsON(testVarible.c_str())) - { - return true; - } - std::string resultVarible = args[1]; - std::string message = args[2]; - bool requirementsMet = true; - std::string notSet; - for(int i = 3; i < args.size(); ++i) - { - if(!m_Makefile->IsOn(args[i].c_str())) - { - requirementsMet = false; - notSet += args[i]; - notSet += " "; - } - } + m_Arguments = args; return true; } +void cmVariableRequiresCommand::FinalPass() +{ + std::string testVarible = m_Arguments[0]; + if(!m_Makefile->IsOn(testVarible.c_str())) + { + return; + } + std::string resultVarible = m_Arguments[1]; + bool requirementsMet = true; + std::string notSet; + for(int i = 2; i < m_Arguments.size(); ++i) + { + if(!m_Makefile->IsOn(m_Arguments[i].c_str())) + { + requirementsMet = false; + notSet += m_Arguments[i]; + notSet += "\n"; + } + } + const char* reqVar = m_Makefile->GetDefinition(resultVarible.c_str()); + // if reqVar is unset, then set it to requirementsMet + // if reqVar is set to true, but requirementsMet is false , then + // set reqVar to false. + if(!reqVar || (!requirementsMet && m_Makefile->IsOn(reqVar))) + { + m_Makefile->AddDefinition(resultVarible.c_str(), requirementsMet); + } + + if(!requirementsMet) + { + std::string message = "Variable assertion failed:\n"; + message += testVarible + " Requires that the following unset varibles are set:\n"; + message += notSet; + message += "\nPlease set them, or set "; + message += testVarible + " to false, and re-configure."; + cmSystemTools::Error(message.c_str()); + } +} diff --git a/Source/cmVariableRequiresCommand.h b/Source/cmVariableRequiresCommand.h index 0080cff5a..ca3d66f04 100644 --- a/Source/cmVariableRequiresCommand.h +++ b/Source/cmVariableRequiresCommand.h @@ -64,11 +64,13 @@ public: * the CMakeLists.txt file. */ virtual bool InitialPass(std::vector const& args); - + + ///! + virtual void FinalPass(); /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "MESSAGE";} + virtual const char* GetName() { return "VARIABLE_REQUIRES";} /** * Succinct documentation. @@ -84,20 +86,23 @@ public: virtual const char* GetFullDocumentation() { return - "VARIABLE_REQUIRES(TEST_VARIBLE RESULT_VARIBLE\"Error Message\" " + "VARIABLE_REQUIRES(TEST_VARIBLE RESULT_VARIBLE " "REQUIRED_VARIABLE1 REQUIRED_VARIABLE2 ...) " "The first argument (TEST_VARIABLE) is the name of the varible to be " "tested, if that varible is false nothing else is done. If " "TEST_VARIABLE is true, then " - "The next arguemnt (RESULT_VARIABLE) is a vairable that is set to true " + "the next arguemnt (RESULT_VARIABLE) is a vairable that is set to true " "if all the " - "required variables are set, the next argument " - "is a message to be displayed if required varibles are not set. " + "required variables are set." "The rest of the arguments are varibles that must be true or not " "set to NOTFOUND to avoid an error. "; } cmTypeMacro(cmVariableRequiresCommand, cmCommand); +private: + std::string m_ErrorMessage; + std::vector m_Arguments; + bool m_RequirementsMet; };