Browse Source

ENH: Added creation of custom rules for generating CABLE packages.

Brad King 25 years ago
parent
commit
71153219e1

+ 0 - 7
Source/cmCableCommand.cxx

@@ -71,11 +71,4 @@ void cmCableCommand::SetupCableData()
   std::string pathName = m_Makefile->GetStartOutputDirectory();
   pathName += "/cable_config.xml";
   m_CableData = new cmCableData(this, pathName);
-  
-//  std::vector<std::string> depends;
-//  depends.push_back("cable_config.xml");
-//  m_Makefile->AddCustomCommand("source_cable_config.xml",
-//                               "result_file",
-//                               "cable cable_config.xml",
-//                               depends);
 }

+ 5 - 1
Source/cmCableData.cxx

@@ -27,7 +27,8 @@ cmCableData::cmCableData(const cmCableCommand* owner,
   m_Owner(owner),
   m_Indentation(0),
   m_Package(NULL),
-  m_PackageNamespaceDepth(0)
+  m_PackageNamespaceDepth(0),
+  m_PackageClassIndex(-1)
 {
   this->OpenOutputFile(configurationFile);
 }
@@ -167,6 +168,9 @@ void cmCableData::BeginPackage(cmCablePackageCommand* command)
   // Open this package.
   m_Package = command;
   
+  // Write out the package's header.
+  m_Package->WritePackageHeader();
+  
   // Save the package's opening namespace depth for later verification
   // on the end of the package.
   m_PackageNamespaceDepth = m_NamespaceStack.size();

+ 10 - 0
Source/cmCableData.h

@@ -71,6 +71,9 @@ public:
   void BeginPackage(cmCablePackageCommand*);
   void EndPackage();
   
+  void SetPackageClassIndex(int index) { m_PackageClassIndex = index; }
+  int GetPackageClassIndex() const { return m_PackageClassIndex; }
+  
 private:
   /**
    * The cmCableCommand which created this instance of cmCableCommand.
@@ -102,6 +105,13 @@ private:
    * This must be the level when the package is ended.
    */
   unsigned int m_PackageNamespaceDepth;
+  
+  /**
+   * During the final pass, this maintains the index into a cmMakefile's
+   * m_Classes corresponding to the cmClassFile for this package's generated
+   * file.
+   */
+  int m_PackageClassIndex;
 };
 
 std::ostream& operator<<(std::ostream&, const cmCableData::Indentation&);

+ 41 - 4
Source/cmCablePackageCommand.cxx

@@ -32,17 +32,54 @@ bool cmCablePackageCommand::Invoke(std::vector<std::string>& args)
   m_PackageName = args[0];
   
   // Ask the cable data to begin the package.  This may call another
-  // cmCablePackageCommand's WritePackageFooter().
+  // cmCablePackageCommand's WritePackageFooter().  This will call
+  // this cmCablePackageCommand's WritePackageHeader().
   m_CableData->BeginPackage(this);
   
-  // Write the configuration for this command.
-  // The cmCableData::EndPackage() later on will call WritePackageFooter().
-  this->WritePackageHeader();
+  // Add custom rules to the makefile to generate this package's source
+  // files.
+  std::vector<std::string> depends;
+  depends.push_back("cable_config.xml");
+  
+  std::string command = "${CABLE}";
+  m_Makefile->ExpandVariablesInString(command);  
+  depends.push_back(command);
+  command += " cable_config.xml";
+  
+  std::string packageFile = "Cxx/"+m_PackageName+"_cxx";
+  std::string packageHeader = packageFile+".h";
+  std::string packageSource = packageFile+".cxx";
+  
+  // A rule for the package's header file.
+  m_Makefile->AddCustomCommand("",
+                               packageHeader.c_str(),
+                               command.c_str(),
+                               depends);
+  
+  // A rule for the package's source file.
+  m_Makefile->AddCustomCommand("",
+                               packageSource.c_str(),
+                               command.c_str(),
+                               depends);
   
   return true;
 }
 
 
+void cmCablePackageCommand::FinalPass()
+{
+  // Add a rule to build the generated package.
+  std::string fileName = "Cxx/"+m_PackageName+"_cxx";
+  std::string filePath = m_Makefile->GetStartOutputDirectory();
+  cmClassFile file;
+  file.m_AbstractClass = false;
+  file.SetName(fileName.c_str(), filePath.c_str(), "cxx", false);
+  
+  m_CableData->SetPackageClassIndex(m_Makefile->GetClasses().size());
+  m_Makefile->AddClass(file);
+}
+
+
 /**
  * Write a CABLE package header.
  */

+ 8 - 0
Source/cmCablePackageCommand.h

@@ -46,6 +46,14 @@ public:
    */
   virtual bool Invoke(std::vector<std::string>& args);  
 
+  /**
+   * This is called at the end after all the information
+   * specified by the command is accumulated. Most commands do
+   * not implement this method.  At this point, reading and
+   * writing to the cache can be done.
+   */
+  virtual void FinalPass();
+  
   /**
    * The name of the command as specified in CMakeList.txt.
    */

+ 24 - 0
Source/cmCableSourceFilesCommand.cxx

@@ -16,6 +16,30 @@
 #include "cmCableSourceFilesCommand.h"
 #include "cmCacheManager.h"
 
+void cmCableSourceFilesCommand::FinalPass()
+{
+  // Get the index of the current package's cmClassFile.
+  // If it doesn't exist, ignore this command.
+  int index = m_CableData->GetPackageClassIndex();
+  if(index < 0)
+    { return; }
+  
+  // The package's file has not yet been generated yet.  The dependency
+  // finder will need hints.  Add one for each source file.
+  cmClassFile& cFile = m_Makefile->GetClasses()[index];
+  
+  std::string curPath = m_Makefile->GetCurrentDirectory();
+  curPath += "/";
+  
+  for(Entries::const_iterator f = m_Entries.begin();
+      f != m_Entries.end(); ++f)
+    {
+    std::string header = curPath+*f+".h";
+    cFile.m_Depends.push_back(header);
+    }
+}
+
+
 /**
  * Write the CABLE configuration code to indicate header dependencies for
  * a package.

+ 8 - 0
Source/cmCableSourceFilesCommand.h

@@ -36,6 +36,14 @@ public:
     return new cmCableSourceFilesCommand;
     }
 
+  /**
+   * This is called at the end after all the information
+   * specified by the command is accumulated. Most commands do
+   * not implement this method.  At this point, reading and
+   * writing to the cache can be done.
+   */
+  virtual void FinalPass();  
+  
   /**
    * The name of the command as specified in CMakeList.txt.
    */