From 71153219e19446350006f84e0b712e912bb0e291 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 8 Mar 2001 16:13:27 -0500 Subject: ENH: Added creation of custom rules for generating CABLE packages. --- Source/cmCableCommand.cxx | 7 ------ Source/cmCableData.cxx | 6 ++++- Source/cmCableData.h | 10 ++++++++ Source/cmCablePackageCommand.cxx | 45 ++++++++++++++++++++++++++++++++---- Source/cmCablePackageCommand.h | 8 +++++++ Source/cmCableSourceFilesCommand.cxx | 24 +++++++++++++++++++ Source/cmCableSourceFilesCommand.h | 8 +++++++ 7 files changed, 96 insertions(+), 12 deletions(-) diff --git a/Source/cmCableCommand.cxx b/Source/cmCableCommand.cxx index 1dbd3f9..df6b6e3 100644 --- a/Source/cmCableCommand.cxx +++ b/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 depends; -// depends.push_back("cable_config.xml"); -// m_Makefile->AddCustomCommand("source_cable_config.xml", -// "result_file", -// "cable cable_config.xml", -// depends); } diff --git a/Source/cmCableData.cxx b/Source/cmCableData.cxx index 0e833ee..7fadb41 100644 --- a/Source/cmCableData.cxx +++ b/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(); diff --git a/Source/cmCableData.h b/Source/cmCableData.h index afa7985..f3788d7 100644 --- a/Source/cmCableData.h +++ b/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&); diff --git a/Source/cmCablePackageCommand.cxx b/Source/cmCablePackageCommand.cxx index a6787e2..50332b3 100644 --- a/Source/cmCablePackageCommand.cxx +++ b/Source/cmCablePackageCommand.cxx @@ -32,17 +32,54 @@ bool cmCablePackageCommand::Invoke(std::vector& 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 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. */ diff --git a/Source/cmCablePackageCommand.h b/Source/cmCablePackageCommand.h index 8546556..b8a76c7 100644 --- a/Source/cmCablePackageCommand.h +++ b/Source/cmCablePackageCommand.h @@ -47,6 +47,14 @@ public: virtual bool Invoke(std::vector& 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. */ virtual const char* GetName() { return "CABLE_PACKAGE";} diff --git a/Source/cmCableSourceFilesCommand.cxx b/Source/cmCableSourceFilesCommand.cxx index 97a6c51..f384cd8 100644 --- a/Source/cmCableSourceFilesCommand.cxx +++ b/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. diff --git a/Source/cmCableSourceFilesCommand.h b/Source/cmCableSourceFilesCommand.h index 24f185c..866eb50 100644 --- a/Source/cmCableSourceFilesCommand.h +++ b/Source/cmCableSourceFilesCommand.h @@ -37,6 +37,14 @@ public: } /** + * 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. */ virtual const char* GetName() { return "CABLE_SOURCE_FILES";} -- cgit v0.12