summaryrefslogtreecommitdiffstats
path: root/Source/cmCablePackageCommand.cxx
blob: 84656bde36ab552ac1fae2427727089d13c2a5e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) 2000 National Library of Medicine
  All rights reserved.

  See COPYRIGHT.txt for copyright details.

=========================================================================*/
#include "cmCablePackageCommand.h"
#include "cmCacheManager.h"


cmCablePackageCommand::~cmCablePackageCommand()
{
  // If we are the owner of the cmCableData, we must delete it here.
  // For most cmCableCommands, the cmCableCommand destructor will take
  // care of this.  If this package happens to be the last one, and is
  // the owner, then the destructor of cmCableData will call back to a method
  // in this class after the package part of it has been freed!
  if(m_CableData && m_CableData->OwnerIs(this))
    {
    delete m_CableData;
    // Make sure our superclass's destructor doesn't try to delete the
    // cmCableData too.
    m_CableData = NULL;
    }
}

// cmCablePackageCommand
bool cmCablePackageCommand::Invoke(std::vector<std::string>& args)
{
  if(args.size() != 1)
    {
    this->SetError("called with incorrect number of arguments");
    return false;
    }
  
  // This command needs to access the Cable data.
  this->SetupCableData();
  
  // The argument is the package name.
  m_PackageName = args[0];

  // Ask the cable data to begin the package.  This may call another
  // cmCablePackageCommand's WritePackageFooter().  This will call
  // this cmCablePackageCommand's WritePackageHeader().
  m_CableData->BeginPackage(this);

  // Tell the makefile that it needs the "cable" utility.  
  m_Makefile->AddUtility("cable");

  // Add custom rules to the makefile to generate this package's source
  // files.
  std::string command = "${CABLE}";
  m_Makefile->ExpandVariablesInString(command);
  std::vector<std::string> depends;
  depends.push_back(command);
  command = "\""+command+"\" cable_config.xml";
  
  std::vector<std::string> outputs;
  outputs.push_back("Cxx/"+m_PackageName+"_cxx.cxx");
  outputs.push_back("Cxx/"+m_PackageName+"_cxx.h");
  
  // A rule for the package's source files.
  m_Makefile->AddCustomCommand("cable_config.xml",
                               command.c_str(),
                               depends,
                               outputs);
  
  return true;
}


void cmCablePackageCommand::FinalPass()
{
  // Add a rule to build the generated package.
  std::string fileName = "Cxx/"+m_PackageName+"_cxx";
  std::string filePath = m_Makefile->GetStartOutputDirectory();
  cmClassFile file;
  file.m_AbstractClass = false;
  file.m_HeaderFileOnly = false;
  file.SetName(fileName.c_str(), filePath.c_str(), "cxx", false);
  
  m_CableData->SetPackageClassIndex(m_Makefile->GetClasses().size());
  m_Makefile->AddClass(file);
}


/**
 * Write a CABLE package header.
 */
void cmCablePackageCommand::WritePackageHeader() const
{
  std::ostream& os = m_CableData->GetOutputStream();
  cmCableData::Indentation indent = m_CableData->GetIndentation();
  os << indent << "<Package name=\"" << m_PackageName.c_str() << "\">"
     << std::endl;
  m_CableData->Indent();
}


/**
 * Write a CABLE package footer.
 */
void cmCablePackageCommand::WritePackageFooter() const
{
  m_CableData->Unindent();
  std::ostream& os = m_CableData->GetOutputStream();
  cmCableData::Indentation indent = m_CableData->GetIndentation();
  os << indent << "</Package> <!-- \"" << m_PackageName.c_str() << "\" -->"
     << std::endl;
}