cmCablePackageCommand.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2000 National Library of Medicine
  8. All rights reserved.
  9. See COPYRIGHT.txt for copyright details.
  10. =========================================================================*/
  11. #include "cmCablePackageCommand.h"
  12. #include "cmCacheManager.h"
  13. cmCablePackageCommand::~cmCablePackageCommand()
  14. {
  15. // If we are the owner of the cmCableData, we must delete it here.
  16. // For most cmCableCommands, the cmCableCommand destructor will take
  17. // care of this. If this package happens to be the last one, and is
  18. // the owner, then the destructor of cmCableData will call back to a method
  19. // in this class after the package part of it has been freed!
  20. if(m_CableData && m_CableData->OwnerIs(this))
  21. {
  22. delete m_CableData;
  23. // Make sure our superclass's destructor doesn't try to delete the
  24. // cmCableData too.
  25. m_CableData = NULL;
  26. }
  27. }
  28. // cmCablePackageCommand
  29. bool cmCablePackageCommand::Invoke(std::vector<std::string>& args)
  30. {
  31. if(args.size() != 1)
  32. {
  33. this->SetError("called with incorrect number of arguments");
  34. return false;
  35. }
  36. // This command needs to access the Cable data.
  37. this->SetupCableData();
  38. // The argument is the package name.
  39. m_PackageName = args[0];
  40. // Ask the cable data to begin the package. This may call another
  41. // cmCablePackageCommand's WritePackageFooter(). This will call
  42. // this cmCablePackageCommand's WritePackageHeader().
  43. m_CableData->BeginPackage(this);
  44. // Tell the makefile that it needs the "cable" utility.
  45. m_Makefile->AddUtility("cable");
  46. // Add custom rules to the makefile to generate this package's source
  47. // files.
  48. std::string command = "${CABLE}";
  49. m_Makefile->ExpandVariablesInString(command);
  50. std::vector<std::string> depends;
  51. depends.push_back(command);
  52. command = "\""+command+"\" cable_config.xml";
  53. std::vector<std::string> outputs;
  54. outputs.push_back("Cxx/"+m_PackageName+"_cxx.cxx");
  55. outputs.push_back("Cxx/"+m_PackageName+"_cxx.h");
  56. // A rule for the package's source files.
  57. m_Makefile->AddCustomCommand("cable_config.xml",
  58. command.c_str(),
  59. depends,
  60. outputs);
  61. return true;
  62. }
  63. void cmCablePackageCommand::FinalPass()
  64. {
  65. // Add a rule to build the generated package.
  66. std::string fileName = "Cxx/"+m_PackageName+"_cxx";
  67. std::string filePath = m_Makefile->GetStartOutputDirectory();
  68. cmClassFile file;
  69. file.m_AbstractClass = false;
  70. file.m_HeaderFileOnly = false;
  71. file.SetName(fileName.c_str(), filePath.c_str(), "cxx", false);
  72. m_CableData->SetPackageClassIndex(m_Makefile->GetClasses().size());
  73. m_Makefile->AddClass(file);
  74. }
  75. /**
  76. * Write a CABLE package header.
  77. */
  78. void cmCablePackageCommand::WritePackageHeader() const
  79. {
  80. std::ostream& os = m_CableData->GetOutputStream();
  81. cmCableData::Indentation indent = m_CableData->GetIndentation();
  82. os << indent << "<Package name=\"" << m_PackageName.c_str() << "\">"
  83. << std::endl;
  84. m_CableData->Indent();
  85. }
  86. /**
  87. * Write a CABLE package footer.
  88. */
  89. void cmCablePackageCommand::WritePackageFooter() const
  90. {
  91. m_CableData->Unindent();
  92. std::ostream& os = m_CableData->GetOutputStream();
  93. cmCableData::Indentation indent = m_CableData->GetIndentation();
  94. os << indent << "</Package> <!-- \"" << m_PackageName.c_str() << "\" -->"
  95. << std::endl;
  96. }