cmCablePackageCommand.cxx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. #include "cmTarget.h"
  14. cmCablePackageCommand::~cmCablePackageCommand()
  15. {
  16. // If we are the owner of the cmCableData, we must delete it here.
  17. // For most cmCableCommands, the cmCableCommand destructor will take
  18. // care of this. If this package happens to be the last one, and is
  19. // the owner, then the destructor of cmCableData will call back to a method
  20. // in this class after the package part of it has been freed!
  21. if(m_CableData && m_CableData->OwnerIs(this))
  22. {
  23. delete m_CableData;
  24. // Make sure our superclass's destructor doesn't try to delete the
  25. // cmCableData too.
  26. m_CableData = NULL;
  27. }
  28. }
  29. // cmCablePackageCommand
  30. bool cmCablePackageCommand::Invoke(std::vector<std::string>& args)
  31. {
  32. if(args.size() != 2)
  33. {
  34. this->SetError("called with incorrect number of arguments");
  35. return false;
  36. }
  37. // setup this once. Really this should probably be moved somewhere else
  38. // at some point.
  39. {
  40. // We must add a custom rule to cause the cable_config.xml to be re-built
  41. // when it is removed. Rebuilding it means re-running CMake.
  42. std::string cMakeLists = m_Makefile->GetStartDirectory();
  43. cMakeLists += "/";
  44. cMakeLists += "CMakeLists.txt";
  45. std::string command;
  46. #if defined(_WIN32) && !defined(__CYGWIN__)
  47. command = "\"";
  48. command += m_Makefile->GetHomeDirectory();
  49. command += "/CMake/Source/CMakeSetupCMD\" \"";
  50. command += cMakeLists;
  51. command += "\" -DSP";
  52. #else
  53. command = "\"";
  54. command += m_Makefile->GetHomeOutputDirectory();
  55. command += "/CMake/Source/CMakeBuildTargets\" \"";
  56. command += cMakeLists;
  57. command += "\"";
  58. #endif
  59. command += " -H\"";
  60. command += m_Makefile->GetHomeDirectory();
  61. command += "\" -S\"";
  62. command += m_Makefile->GetStartDirectory();
  63. command += "\" -O\"";
  64. command += m_Makefile->GetStartOutputDirectory();
  65. command += "\" -B\"";
  66. command += m_Makefile->GetHomeOutputDirectory();
  67. command += "\"";
  68. std::vector<std::string> depends;
  69. m_Makefile->AddCustomCommand(cMakeLists.c_str(),
  70. command.c_str(),
  71. depends,
  72. "cable_config.xml", args[1].c_str());
  73. }
  74. // This command needs to access the Cable data.
  75. this->SetupCableData();
  76. // The argument is the package name.
  77. m_PackageName = args[0];
  78. m_TargetName = args[1];
  79. // Ask the cable data to begin the package. This may call another
  80. // cmCablePackageCommand's WritePackageFooter(). This will call
  81. // this cmCablePackageCommand's WritePackageHeader().
  82. m_CableData->BeginPackage(this);
  83. // Tell the makefile that it needs the "cable" utility.
  84. m_Makefile->AddUtility("cable");
  85. // Add custom rules to the makefile to generate this package's source
  86. // files.
  87. std::string command = "${CABLE}";
  88. m_Makefile->ExpandVariablesInString(command);
  89. std::vector<std::string> depends;
  90. depends.push_back(command);
  91. command = "\""+command+"\" cable_config.xml";
  92. std::vector<std::string> outputs;
  93. outputs.push_back("Cxx/"+m_PackageName+"_cxx.cxx");
  94. outputs.push_back("Cxx/"+m_PackageName+"_cxx.h");
  95. // A rule for the package's source files.
  96. m_Makefile->AddCustomCommand("cable_config.xml",
  97. command.c_str(),
  98. depends,
  99. outputs, m_TargetName.c_str());
  100. // add the source list to the target
  101. m_Makefile->GetTargets()[m_TargetName.c_str()].GetSourceLists().push_back(m_PackageName);
  102. return true;
  103. }
  104. void cmCablePackageCommand::FinalPass()
  105. {
  106. // Add a rule to build the generated package.
  107. std::string fileName = "Cxx/"+m_PackageName+"_cxx";
  108. std::string filePath = m_Makefile->GetStartOutputDirectory();
  109. cmClassFile file;
  110. file.m_AbstractClass = false;
  111. file.m_HeaderFileOnly = false;
  112. file.SetName(fileName.c_str(), filePath.c_str(), "cxx", false);
  113. m_Makefile->AddClass(file, m_PackageName.c_str());
  114. }
  115. /**
  116. * Write a CABLE package header.
  117. */
  118. void cmCablePackageCommand::WritePackageHeader() const
  119. {
  120. std::ostream& os = m_CableData->GetOutputStream();
  121. cmCableData::Indentation indent = m_CableData->GetIndentation();
  122. os << indent << "<Package name=\"" << m_PackageName.c_str() << "\">"
  123. << std::endl;
  124. m_CableData->Indent();
  125. }
  126. /**
  127. * Write a CABLE package footer.
  128. */
  129. void cmCablePackageCommand::WritePackageFooter() const
  130. {
  131. m_CableData->Unindent();
  132. std::ostream& os = m_CableData->GetOutputStream();
  133. cmCableData::Indentation indent = m_CableData->GetIndentation();
  134. os << indent << "</Package> <!-- \"" << m_PackageName.c_str() << "\" -->"
  135. << std::endl;
  136. }