cmCableCommand.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "cmCableCommand.h"
  12. #include "cmCacheManager.h"
  13. // cmCableCommand
  14. /**
  15. * Constructor initializes to empty m_CableData.
  16. */
  17. cmCableCommand::cmCableCommand(): m_CableData(0)
  18. {
  19. }
  20. /**
  21. * Destructor frees the cmCableData only if this command is its owner.
  22. */
  23. cmCableCommand::~cmCableCommand()
  24. {
  25. if(m_CableData && m_CableData->OwnerIs(this))
  26. {
  27. delete m_CableData;
  28. }
  29. }
  30. /**
  31. * Ensure that this cmCableCommand has a valid m_CableData pointer.
  32. */
  33. void cmCableCommand::SetupCableData()
  34. {
  35. // Only do something if the pointer is invalid.
  36. if(m_CableData)
  37. { return; }
  38. // Look through the vector of commands from the makefile.
  39. const std::vector<cmCommand*>& usedCommands =
  40. m_Makefile->GetUsedCommands();
  41. for(std::vector<cmCommand*>::const_iterator commandIter =
  42. usedCommands.begin(); commandIter != usedCommands.end(); ++commandIter)
  43. {
  44. // If this command is a cmCableCommand, see if it has a cmCableData
  45. // instance.
  46. cmCableCommand* command = cmCableCommand::SafeDownCast(*commandIter);
  47. if(command)
  48. { m_CableData = command->m_CableData; }
  49. // If we found an instance of cmCableData, then we are done.
  50. if(m_CableData)
  51. { return; }
  52. }
  53. // We must make sure the output directory exists so that the CABLE
  54. // configuration file can be opened by the cmCableData.
  55. std::string pathName = m_Makefile->GetStartOutputDirectory();
  56. if(!cmSystemTools::MakeDirectory(pathName.c_str()))
  57. {
  58. cmSystemTools::Error("Unable to make directory ", pathName.c_str());
  59. }
  60. // We didn't find another cmCableCommand with a valid cmCableData.
  61. // We must allocate the new cmCableData ourselves, and with this
  62. // command as its owner.
  63. pathName += "/cable_config.xml";
  64. m_CableData = new cmCableData(this, pathName);
  65. // We must add a custom rule to cause the cable_config.xml to be re-built
  66. // when it is removed. Rebuilding it means re-running CMake.
  67. std::string cMakeLists = m_Makefile->GetStartDirectory();
  68. cMakeLists += "/";
  69. cMakeLists += "CMakeLists.txt";
  70. std::string command;
  71. #if defined(_WIN32) && !defined(__CYGWIN__)
  72. command = m_Makefile->GetHomeDirectory();
  73. command += "/CMake/Source/CMakeSetupCMD ";
  74. command += cMakeLists;
  75. command += " -DSP";
  76. #else
  77. command = m_Makefile->GetHomeOutputDirectory();
  78. command += "/CMake/Source/CMakeBuildTargets ";
  79. command += cMakeLists;
  80. #endif
  81. command += " -H";
  82. command += m_Makefile->GetHomeDirectory();
  83. command += " -S";
  84. command += m_Makefile->GetStartDirectory();
  85. command += " -O";
  86. command += m_Makefile->GetStartOutputDirectory();
  87. command += " -B";
  88. command += m_Makefile->GetHomeOutputDirectory();
  89. std::vector<std::string> depends;
  90. m_Makefile->AddCustomCommand(cMakeLists.c_str(),
  91. command.c_str(),
  92. depends,
  93. "cable_config.xml");
  94. }