cmCablePackageCommand.cxx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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() != 2)
  32. {
  33. this->SetError("called with incorrect number of arguments");
  34. return false;
  35. }
  36. // setup this once. Really this should probably be moved somewhere else
  37. // at some point.
  38. {
  39. // We must add a custom rule to cause the cable_config.xml to be re-built
  40. // when it is removed. Rebuilding it means re-running CMake.
  41. std::string cMakeLists = m_Makefile->GetStartDirectory();
  42. cMakeLists += "/";
  43. cMakeLists += "CMakeLists.txt";
  44. std::string command;
  45. #if defined(_WIN32) && !defined(__CYGWIN__)
  46. command = "\"";
  47. command += m_Makefile->GetHomeDirectory();
  48. command += "/CMake/Source/CMakeSetupCMD\" \"";
  49. command += cMakeLists;
  50. command += "\" -DSP";
  51. #else
  52. command = "\"";
  53. command += m_Makefile->GetHomeOutputDirectory();
  54. command += "/CMake/Source/CMakeBuildTargets\" \"";
  55. command += cMakeLists;
  56. command += "\"";
  57. #endif
  58. command += " -H\"";
  59. command += m_Makefile->GetHomeDirectory();
  60. command += "\" -S\"";
  61. command += m_Makefile->GetStartDirectory();
  62. command += "\" -O\"";
  63. command += m_Makefile->GetStartOutputDirectory();
  64. command += "\" -B\"";
  65. command += m_Makefile->GetHomeOutputDirectory();
  66. command += "\"";
  67. std::vector<std::string> depends;
  68. m_Makefile->AddCustomCommand(cMakeLists.c_str(),
  69. command.c_str(),
  70. depends,
  71. "cable_config.xml", args[1].c_str());
  72. }
  73. // This command needs to access the Cable data.
  74. this->SetupCableData();
  75. // The argument is the package name.
  76. m_PackageName = args[0];
  77. m_TargetName = args[1];
  78. // Ask the cable data to begin the package. This may call another
  79. // cmCablePackageCommand's WritePackageFooter(). This will call
  80. // this cmCablePackageCommand's WritePackageHeader().
  81. m_CableData->BeginPackage(this);
  82. // Tell the makefile that it needs the "cable" utility.
  83. m_Makefile->AddUtility("cable");
  84. // Add custom rules to the makefile to generate this package's source
  85. // files.
  86. std::string command = "${CABLE}";
  87. m_Makefile->ExpandVariablesInString(command);
  88. std::vector<std::string> depends;
  89. depends.push_back(command);
  90. command = "\""+command+"\" cable_config.xml";
  91. std::vector<std::string> outputs;
  92. outputs.push_back("Cxx/"+m_PackageName+"_cxx.cxx");
  93. outputs.push_back("Cxx/"+m_PackageName+"_cxx.h");
  94. // A rule for the package's source files.
  95. m_Makefile->AddCustomCommand("cable_config.xml",
  96. command.c_str(),
  97. depends,
  98. outputs, m_TargetName.c_str());
  99. return true;
  100. }
  101. void cmCablePackageCommand::FinalPass()
  102. {
  103. // Add a rule to build the generated package.
  104. std::string fileName = "Cxx/"+m_PackageName+"_cxx";
  105. std::string filePath = m_Makefile->GetStartOutputDirectory();
  106. cmClassFile file;
  107. file.m_AbstractClass = false;
  108. file.m_HeaderFileOnly = false;
  109. file.SetName(fileName.c_str(), filePath.c_str(), "cxx", false);
  110. m_Makefile->AddClass(file, m_PackageName.c_str());
  111. }
  112. /**
  113. * Write a CABLE package header.
  114. */
  115. void cmCablePackageCommand::WritePackageHeader() const
  116. {
  117. std::ostream& os = m_CableData->GetOutputStream();
  118. cmCableData::Indentation indent = m_CableData->GetIndentation();
  119. os << indent << "<Package name=\"" << m_PackageName.c_str() << "\">"
  120. << std::endl;
  121. m_CableData->Indent();
  122. }
  123. /**
  124. * Write a CABLE package footer.
  125. */
  126. void cmCablePackageCommand::WritePackageFooter() const
  127. {
  128. m_CableData->Unindent();
  129. std::ostream& os = m_CableData->GetOutputStream();
  130. cmCableData::Indentation indent = m_CableData->GetIndentation();
  131. os << indent << "</Package> <!-- \"" << m_PackageName.c_str() << "\" -->"
  132. << std::endl;
  133. }