cmCablePackageCommand.cxx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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
  14. bool cmCablePackageCommand::Invoke(std::vector<std::string>& args)
  15. {
  16. if(args.size() != 1)
  17. {
  18. this->SetError("called with incorrect number of arguments");
  19. return false;
  20. }
  21. // This command needs to access the Cable data.
  22. this->SetupCableData();
  23. // The argument is the package name.
  24. m_PackageName = args[0];
  25. // Ask the cable data to begin the package. This may call another
  26. // cmCablePackageCommand's WritePackageFooter(). This will call
  27. // this cmCablePackageCommand's WritePackageHeader().
  28. m_CableData->BeginPackage(this);
  29. // Add custom rules to the makefile to generate this package's source
  30. // files.
  31. std::string command = "${CABLE}";
  32. m_Makefile->ExpandVariablesInString(command);
  33. std::vector<std::string> depends;
  34. depends.push_back(command);
  35. command += " cable_config.xml";
  36. std::string packageFile = "Cxx/"+m_PackageName+"_cxx";
  37. std::string packageHeader = packageFile+".h";
  38. std::string packageSource = packageFile+".cxx";
  39. // A rule for the package's header file.
  40. m_Makefile->AddCustomCommand("cable_config.xml",
  41. packageHeader.c_str(),
  42. command.c_str(),
  43. depends);
  44. // A rule for the package's source file.
  45. m_Makefile->AddCustomCommand("cable_config.xml",
  46. packageSource.c_str(),
  47. command.c_str(),
  48. depends);
  49. return true;
  50. }
  51. void cmCablePackageCommand::FinalPass()
  52. {
  53. // Add a rule to build the generated package.
  54. std::string fileName = "Cxx/"+m_PackageName+"_cxx";
  55. std::string filePath = m_Makefile->GetStartOutputDirectory();
  56. cmClassFile file;
  57. file.m_AbstractClass = false;
  58. file.SetName(fileName.c_str(), filePath.c_str(), "cxx", false);
  59. m_CableData->SetPackageClassIndex(m_Makefile->GetClasses().size());
  60. m_Makefile->AddClass(file);
  61. }
  62. /**
  63. * Write a CABLE package header.
  64. */
  65. void cmCablePackageCommand::WritePackageHeader() const
  66. {
  67. std::ostream& os = m_CableData->GetOutputStream();
  68. cmCableData::Indentation indent = m_CableData->GetIndentation();
  69. os << indent << "<Package name=\"" << m_PackageName.c_str() << "\">"
  70. << std::endl;
  71. m_CableData->Indent();
  72. }
  73. /**
  74. * Write a CABLE package footer.
  75. */
  76. void cmCablePackageCommand::WritePackageFooter() const
  77. {
  78. m_CableData->Unindent();
  79. std::ostream& os = m_CableData->GetOutputStream();
  80. cmCableData::Indentation indent = m_CableData->GetIndentation();
  81. os << indent << "</Package> <!-- \"" << m_PackageName.c_str() << "\" -->"
  82. << std::endl;
  83. }