cmCablePackageCommand.cxx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. // Tell the makefile that it needs the "cable" utility.
  30. m_Makefile->AddUtility("cable");
  31. // Add custom rules to the makefile to generate this package's source
  32. // files.
  33. std::string command = "${CABLE}";
  34. m_Makefile->ExpandVariablesInString(command);
  35. std::vector<std::string> depends;
  36. depends.push_back(command);
  37. command += " cable_config.xml";
  38. std::string packageFile = "Cxx/"+m_PackageName+"_cxx.cxx";
  39. // A rule for the package's source file.
  40. m_Makefile->AddCustomCommand("cable_config.xml",
  41. packageFile.c_str(),
  42. command.c_str(),
  43. depends);
  44. return true;
  45. }
  46. void cmCablePackageCommand::FinalPass()
  47. {
  48. // Add a rule to build the generated package.
  49. std::string fileName = "Cxx/"+m_PackageName+"_cxx";
  50. std::string filePath = m_Makefile->GetStartOutputDirectory();
  51. cmClassFile file;
  52. file.m_AbstractClass = false;
  53. file.m_HeaderFileOnly = false;
  54. file.SetName(fileName.c_str(), filePath.c_str(), "cxx", false);
  55. m_CableData->SetPackageClassIndex(m_Makefile->GetClasses().size());
  56. m_Makefile->AddClass(file);
  57. }
  58. /**
  59. * Write a CABLE package header.
  60. */
  61. void cmCablePackageCommand::WritePackageHeader() const
  62. {
  63. std::ostream& os = m_CableData->GetOutputStream();
  64. cmCableData::Indentation indent = m_CableData->GetIndentation();
  65. os << indent << "<Package name=\"" << m_PackageName.c_str() << "\">"
  66. << std::endl;
  67. m_CableData->Indent();
  68. }
  69. /**
  70. * Write a CABLE package footer.
  71. */
  72. void cmCablePackageCommand::WritePackageFooter() const
  73. {
  74. m_CableData->Unindent();
  75. std::ostream& os = m_CableData->GetOutputStream();
  76. cmCableData::Indentation indent = m_CableData->GetIndentation();
  77. os << indent << "</Package> <!-- \"" << m_PackageName.c_str() << "\" -->"
  78. << std::endl;
  79. }