From faaadc4a08e8103e25346a437fc203e05b43566c Mon Sep 17 00:00:00 2001
From: Ken Martin <ken.martin@kitware.com>
Date: Fri, 4 May 2001 08:46:05 -0400
Subject: better If checks

---
 Source/cmFunctionBlocker.h      | 14 +++++++++++---
 Source/cmIfCommand.cxx          |  9 +++++++++
 Source/cmIfCommand.h            |  8 ++++++--
 Source/cmMakefile.cxx           | 13 +++++++++++++
 Source/cmVTKWrapJavaCommand.cxx | 19 ++++++++++---------
 5 files changed, 49 insertions(+), 14 deletions(-)

diff --git a/Source/cmFunctionBlocker.h b/Source/cmFunctionBlocker.h
index 46f6447..5c8c70d 100644
--- a/Source/cmFunctionBlocker.h
+++ b/Source/cmFunctionBlocker.h
@@ -59,11 +59,19 @@ public:
                                  const cmMakefile &mf) const = 0;
 
   /**
-   * should this function blocker be removed, useful when one function adds a blocker
-   * and another must remove it
+   * should this function blocker be removed, useful when one function adds a
+   * blocker and another must remove it 
    */
-  virtual bool ShouldRemove(const char *name, const std::vector<std::string> &args, 
+  virtual bool ShouldRemove(const char *name, 
+                            const std::vector<std::string> &args, 
                             const cmMakefile &mf) const {return false;}
+
+  /**
+   * When the end of a CMakeList file is reached this method is called.  It
+   * is not called on the end of an INCLUDE cmake file, just at the end of a
+   * regular CMakeList file 
+   */
+  virtual void ScopeEnded(const cmMakefile &mf) const {}
 };
 
 #endif
diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx
index 1425cbb..908d50b 100644
--- a/Source/cmIfCommand.cxx
+++ b/Source/cmIfCommand.cxx
@@ -68,6 +68,15 @@ ShouldRemove(const char *name, const std::vector<std::string> &args,
   return !this->IsFunctionBlocked(name,args,mf);
 }
 
+void cmIfFunctionBlocker::
+ScopeEnded(const cmMakefile &mf) const
+{
+  cmSystemTools::Error("The end of a CMakeLists file was reached with an IF statement that was not closed properly. Within the directory: ", 
+                       mf.GetCurrentDirectory(),
+                       (m_Not ? " The arguments to the if were: NOT " : " The arguments to the if were: "),
+                       m_Define.c_str());
+}
+
 bool cmIfCommand::Invoke(std::vector<std::string>& args)
 {
   if(args.size() < 1 )
diff --git a/Source/cmIfCommand.h b/Source/cmIfCommand.h
index 6bb3102..612f57b 100644
--- a/Source/cmIfCommand.h
+++ b/Source/cmIfCommand.h
@@ -55,10 +55,14 @@ class cmIfFunctionBlocker : public cmFunctionBlocker
 public:
   cmIfFunctionBlocker() {m_Not = false;}
   virtual ~cmIfFunctionBlocker() {}
-  virtual bool IsFunctionBlocked(const char *name, const std::vector<std::string> &args, 
+  virtual bool IsFunctionBlocked(const char *name, 
+                                 const std::vector<std::string> &args, 
                                  const cmMakefile &mf) const;
-  virtual bool ShouldRemove(const char *name, const std::vector<std::string> &args, 
+  virtual bool ShouldRemove(const char *name, 
+                            const std::vector<std::string> &args, 
                             const cmMakefile &mf) const;
+  virtual void ScopeEnded(const cmMakefile &mf) const;
+  
   std::string m_Define;
   bool m_Not;
 };
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 72dd9a6..9be764f 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -290,6 +290,19 @@ bool cmMakefile::ReadListFile(const char* filename, const char* external)
         }
       }
     }
+
+  // send scope ended to and funciton blockers
+  if (filename)
+    {
+    // loop over all function blockers to see if any block this command
+    std::set<cmFunctionBlocker *>::const_iterator pos;
+    for (pos = m_FunctionBlockers.begin(); 
+         pos != m_FunctionBlockers.end(); ++pos)
+      {
+      (*pos)->ScopeEnded(*this);
+      }
+    }
+  
   return true;
 }
 
diff --git a/Source/cmVTKWrapJavaCommand.cxx b/Source/cmVTKWrapJavaCommand.cxx
index 45b3af1..ec9fff1 100644
--- a/Source/cmVTKWrapJavaCommand.cxx
+++ b/Source/cmVTKWrapJavaCommand.cxx
@@ -58,6 +58,7 @@ bool cmVTKWrapJavaCommand::Invoke(std::vector<std::string>& args)
 
   // add in a depend in the vtkVTKWrapJava executable
   m_Makefile->AddUtility("vtkWrapJava");
+  m_Makefile->AddUtility("vtkParseJava");
   
   // what is the current source dir
   std::string cdir = m_Makefile->GetCurrentDirectory();
@@ -108,25 +109,25 @@ void cmVTKWrapJavaCommand::FinalPass()
   
   // wrap all the .h files
   depends.push_back(wjava);
+  depends.push_back(pjava);
   for(int classNum = 0; classNum < lastClass; classNum++)
     {
     m_Makefile->AddSource(m_WrapClasses[classNum],m_SourceList.c_str());
 
     // wrap java
     std::string res = m_WrapClasses[classNum].GetSourceName() + ".cxx";
+    std::string res2 = m_OriginalNames[classNum] + ".java";
+    std::vector<std::string> resvec;
+    resvec.push_back(res);
+    resvec.push_back(res2);
+    
     std::string cmd = wjava + " " + m_WrapHeaders[classNum] + " "
-      + hints + (m_WrapClasses[classNum].IsAnAbstractClass() ? " 0 " : " 1 ") + " > " + m_WrapClasses[classNum].GetSourceName() + ".cxx";
-    m_Makefile->AddCustomCommand(m_WrapHeaders[classNum].c_str(),
-                                 cmd.c_str(), depends, 
-                                 res.c_str(), m_LibraryName.c_str());
-
-    // parse java
-    res = m_WrapClasses[classNum].GetSourceName() + ".cxx";
-    cmd = pjava + " " + m_WrapHeaders[classNum] + " "
+      + hints + (m_WrapClasses[classNum].IsAnAbstractClass() ? " 0 " : " 1 ") + " > " + m_WrapClasses[classNum].GetSourceName() + ".cxx\\\n\t" + 
+      pjava + " " + m_WrapHeaders[classNum] + " "
       + hints + (m_WrapClasses[classNum].IsAnAbstractClass() ? " 0 " : " 1 ") + " > " + m_OriginalNames[classNum] + ".java";
     m_Makefile->AddCustomCommand(m_WrapHeaders[classNum].c_str(),
                                  cmd.c_str(), depends, 
-                                 res.c_str(), m_LibraryName.c_str());
+                                 resvec, m_LibraryName.c_str());
     }
 }
 
-- 
cgit v0.12