Explorar o código

ENH: add new command VARIABLE_REQUIRES for better debugging of list files

Bill Hoffman %!s(int64=24) %!d(string=hai) anos
pai
achega
da17f30cb5

+ 8 - 3
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();

+ 2 - 0
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<cmCommand*>& 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);

+ 3 - 3
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

+ 3 - 0
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;
 };
 

+ 33 - 12
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<std::string> 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()))
+  m_Arguments = args;
+  return true;
+}
+
+void cmVariableRequiresCommand::FinalPass()
+{
+  std::string testVarible = m_Arguments[0]; 
+  if(!m_Makefile->IsOn(testVarible.c_str()))
     {
-    return true;
+    return;
     }
-  std::string resultVarible = args[1];
-  std::string message = args[2];
+  std::string resultVarible = m_Arguments[1];
   bool requirementsMet = true;
   std::string notSet;
-  for(int i = 3; i < args.size(); ++i)
+  for(int i = 2; i < m_Arguments.size(); ++i)
     {
-    if(!m_Makefile->IsOn(args[i].c_str()))
+    if(!m_Makefile->IsOn(m_Arguments[i].c_str()))
       {
       requirementsMet = false;
-      notSet += args[i];
-      notSet += " ";
+      notSet += m_Arguments[i];
+      notSet += "\n";
       }
     }
-  return true;
-}
+  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());
+    }
+}

+ 11 - 6
Source/cmVariableRequiresCommand.h

@@ -64,11 +64,13 @@ public:
    * the CMakeLists.txt file.
    */
   virtual bool InitialPass(std::vector<std::string> 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<std::string> m_Arguments;
+  bool m_RequirementsMet;
 };