summaryrefslogtreecommitdiffstats
path: root/Source/cmGlobalCodeWarriorGenerator.cxx
blob: 91ff5b3e35f1ac6893baa437e2b1ba77cd9daa3a (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*=========================================================================

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "cmGlobalCodeWarriorGenerator.h"
#include "cmLocalCodeWarriorGenerator.h"
#include "cmMakefile.h"
#include "cmake.h"
#include "cmTarget.h"

void cmGlobalCodeWarriorGenerator::EnableLanguage(const char*, 
                                                  cmMakefile *mf)
{
  // now load the settings
  if(!mf->GetDefinition("CMAKE_ROOT"))
    {
    cmSystemTools::Error(
      "CMAKE_ROOT has not been defined, bad GUI or driver program");
    return;
    }
  if(!this->GetLanguageEnabled("CXX"))
    {
    std::string fpath = 
      mf->GetDefinition("CMAKE_ROOT");
    fpath += "/Templates/CMakeDotNetSystemConfig.cmake";
    mf->ReadListFile(0,fpath.c_str());
    this->SetLanguageEnabled("CXX");
    }
}

int cmGlobalCodeWarriorGenerator::TryCompile(const char *, 
                                             const char* /*bindir*/, 
                                             const char* /*projectName*/,
                                             const char* /*targetName*/,
                                             std::string* /*output*/)
{
  return 1;
}

///! Create a local generator appropriate to this Global Generator
cmLocalGenerator *cmGlobalCodeWarriorGenerator::CreateLocalGenerator()
{
  cmLocalGenerator *lg = new cmLocalCodeWarriorGenerator;
  lg->SetGlobalGenerator(this);
  return lg;
}

void cmGlobalCodeWarriorGenerator::Generate()
{
  // first do the superclass method
  this->cmGlobalGenerator::Generate();
  
  // Now write out the Project File
  this->OutputProject();
}

void cmGlobalCodeWarriorGenerator::OutputProject()
{
  // if this is an out of source build, create the output directory
  if(strcmp(m_CMakeInstance->GetStartOutputDirectory(),
            m_CMakeInstance->GetHomeDirectory()) != 0)
    {
    if(!cmSystemTools::MakeDirectory(m_CMakeInstance->GetStartOutputDirectory()))
      {
      cmSystemTools::Error("Error creating output directory for Project file",
                           m_CMakeInstance->GetStartOutputDirectory());
      }
    }
  // create the project file name
  std::string fname;
  fname = m_CMakeInstance->GetStartOutputDirectory();
  fname += "/";
  if(strlen(m_LocalGenerators[0]->GetMakefile()->GetProjectName()) == 0)
    {
    m_LocalGenerators[0]->GetMakefile()->SetProjectName("Project");
    }
  fname += m_LocalGenerators[0]->GetMakefile()->GetProjectName();
  fname += ".xml";
  std::ofstream fout(fname.c_str());
  if(!fout)
    {
    cmSystemTools::Error("Error can not open project file for write: "
                         ,fname.c_str());
    return;
    }
  this->WriteProject(fout);
}

void cmGlobalCodeWarriorGenerator::WriteProject(std::ostream& fout)
{
  // Write out the header for a SLN file
  this->WriteProjectHeader(fout);

  // start the project
  fout << "<PROJECT>\n";
  
  // write the target list
  this->WriteTargetList(fout);
  
  // write the target order
  this->WriteTargetOrder(fout);
  
  // write the group list
  this->WriteGroupList(fout);
  
  // close the project
  fout << "</PROJECT>\n";
}

void cmGlobalCodeWarriorGenerator::WriteProjectHeader(std::ostream& fout)
{
  fout << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n";
  fout << "<?codewarrior exportversion=\"1.0.1\" ideversion=\"5.0\" ?>\n";

  fout << "<!DOCTYPE PROJECT [\n";
  fout << "<!ELEMENT PROJECT (TARGETLIST, TARGETORDER, GROUPLIST, DESIGNLIST?)>\n";
  fout << "<!ELEMENT TARGETLIST (TARGET+)>\n";
  fout << "<!ELEMENT TARGET (NAME, SETTINGLIST, FILELIST?, LINKORDER?, SEGMENTLIST?, OVERLAYGROUPLIST?, SUBTARGETLIST?, SUBPROJECTLIST?, FRAMEWORKLIST)>\n";
  fout << "<!ELEMENT NAME (#PCDATA)>\n";
  fout << "<!ELEMENT USERSOURCETREETYPE (#PCDATA)>\n";
  fout << "<!ELEMENT PATH (#PCDATA)>\n";
  fout << "<!ELEMENT FILELIST (FILE*)>\n";
  fout << "<!ELEMENT FILE (PATHTYPE, PATHROOT?, ACCESSPATH?, PATH, PATHFORMAT?, ROOTFILEREF?, FILEKIND?, FILEFLAGS?)>\n";
  fout << "<!ELEMENT PATHTYPE (#PCDATA)>\n";
  fout << "<!ELEMENT PATHROOT (#PCDATA)>\n";
  fout << "<!ELEMENT ACCESSPATH (#PCDATA)>\n";
  fout << "<!ELEMENT PATHFORMAT (#PCDATA)>\n";
  fout << "<!ELEMENT ROOTFILEREF (PATHTYPE, PATHROOT?, ACCESSPATH?, PATH, PATHFORMAT?)>\n";
  fout << "<!ELEMENT FILEKIND (#PCDATA)>\n";
  fout << "<!ELEMENT FILEFLAGS (#PCDATA)>\n";
  fout << "<!ELEMENT FILEREF (TARGETNAME?, PATHTYPE, PATHROOT?, ACCESSPATH?, PATH, PATHFORMAT?)>\n";
  fout << "<!ELEMENT TARGETNAME (#PCDATA)>\n";
  fout << "<!ELEMENT SETTINGLIST ((SETTING|PANELDATA)+)>\n";
  fout << "<!ELEMENT SETTING (NAME?, (VALUE|(SETTING+)))>\n";
  fout << "<!ELEMENT PANELDATA (NAME, VALUE)>\n";
  fout << "<!ELEMENT VALUE (#PCDATA)>\n";
  fout << "<!ELEMENT LINKORDER (FILEREF*)>\n";
  fout << "<!ELEMENT SEGMENTLIST (SEGMENT+)>\n";
  fout << "<!ELEMENT SEGMENT (NAME, ATTRIBUTES?, FILEREF*)>\n";
  fout << "<!ELEMENT ATTRIBUTES (#PCDATA)>\n";
  fout << "<!ELEMENT OVERLAYGROUPLIST (OVERLAYGROUP+)>\n";
  fout << "<!ELEMENT OVERLAYGROUP (NAME, BASEADDRESS, OVERLAY*)>\n";
  fout << "<!ELEMENT BASEADDRESS (#PCDATA)>\n";
  fout << "<!ELEMENT OVERLAY (NAME, FILEREF*)>\n";
  fout << "<!ELEMENT SUBTARGETLIST (SUBTARGET+)>\n";
  fout << "<!ELEMENT SUBTARGET (TARGETNAME, ATTRIBUTES?, FILEREF?)>\n";
  fout << "<!ELEMENT SUBPROJECTLIST (SUBPROJECT+)>\n";
  fout << "<!ELEMENT SUBPROJECT (FILEREF, SUBPROJECTTARGETLIST)>\n";
  fout << "<!ELEMENT SUBPROJECTTARGETLIST (SUBPROJECTTARGET*)>\n";
  fout << "<!ELEMENT SUBPROJECTTARGET (TARGETNAME, ATTRIBUTES?, FILEREF?)>\n";
  fout << "<!ELEMENT FRAMEWORKLIST (FRAMEWORK+)>\n";
  fout << "<!ELEMENT FRAMEWORK (FILEREF, LIBRARYFILE?, VERSION?)>\n";
  fout << "<!ELEMENT LIBRARYFILE (FILEREF)>\n";
  fout << "<!ELEMENT VERSION (#PCDATA)>\n";
  fout << "<!ELEMENT TARGETORDER (ORDEREDTARGET|ORDEREDDESIGN)*>\n";
  fout << "<!ELEMENT ORDEREDTARGET (NAME)>\n";
  fout << "<!ELEMENT ORDEREDDESIGN (NAME, ORDEREDTARGET+)>\n";
  fout << "<!ELEMENT GROUPLIST (GROUP|FILEREF)*>\n";
  fout << "<!ELEMENT GROUP (NAME, (GROUP|FILEREF)*)>\n";
  fout << "<!ELEMENT DESIGNLIST (DESIGN+)>\n";
  fout << "<!ELEMENT DESIGN (NAME, DESIGNDATA)>\n";
  fout << "<!ELEMENT DESIGNDATA (#PCDATA)>\n";
  fout << "]>\n\n";
}

void cmGlobalCodeWarriorGenerator::WriteTargetList(std::ostream& fout)
{
  fout << "<TARGETLIST>\n";
  
  unsigned int i;
  // for each local generator
  for (i = 0; i < m_LocalGenerators.size(); ++i)
    {
    static_cast<cmLocalCodeWarriorGenerator *>(m_LocalGenerators[i])->WriteTargets(fout);
    }
  fout << "</TARGETLIST>\n";
}

cmTarget *cmGlobalCodeWarriorGenerator::GetTargetFromName(const char *tgtName)
{
  // for each local generator, and each target
  unsigned int i;
  for(i = 0; i < m_LocalGenerators.size(); ++i)
    {
    cmMakefile* mf = m_LocalGenerators[i]->GetMakefile();
    cmTargets &tgts = mf->GetTargets();
    for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
      {
      if (l->first == tgtName)
        {
        return &(l->second);
        }
      }
    }
  return 0;
}

void cmGlobalCodeWarriorGenerator::ComputeTargetOrder(
  std::vector<std::string> &tgtOrder, const char *tgtName,
  cmTarget const *target)
{
  // if the target is already listed then we are done
  if (std::find(tgtOrder.begin(),tgtOrder.end(),tgtName) != tgtOrder.end())
    {
    return;
    }
  
  // otherwise find all this target depends on and add them first
  cmTarget::LinkLibraries::const_iterator j, jend;
  j = target->GetLinkLibraries().begin();
  jend = target->GetLinkLibraries().end();
  for(;j!= jend; ++j)
    {
    if(j->first != tgtName)
      {
      // is the library part of this Project ? 
      std::string libPath = j->first + "_CMAKE_PATH";
      const char* cacheValue
        = m_CMakeInstance->GetCacheDefinition(libPath.c_str());
      if(cacheValue)
        {
        // so add it to the tgtOrder vector if it isn't already there
        // to do this we need the actual target
        cmTarget *tgt = this->GetTargetFromName(j->first.c_str());
        this->ComputeTargetOrder(tgtOrder,j->first.c_str(), tgt);
        }
      }
    }
  // finally add the target
  tgtOrder.push_back(tgtName);
}

void cmGlobalCodeWarriorGenerator::WriteTargetOrder(std::ostream& fout)
{
  fout << "<TARGETORDER>\n";
  
  std::vector<std::string> tgtOrder;
  unsigned int i;
  // for each local generator, and each target
  for(i = 0; i < m_LocalGenerators.size(); ++i)
    {
    cmMakefile* mf = m_LocalGenerators[i]->GetMakefile();
    cmTargets &tgts = mf->GetTargets();
    for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
      {
      this->ComputeTargetOrder(tgtOrder, l->first.c_str(), &(l->second));
      }
    }

  // now write out the target order
  for(i = 0; i < tgtOrder.size(); ++i)
    {
    fout << "<ORDEREDTARGET><NAME>" << tgtOrder[i] 
         << "</NAME></ORDEREDTARGET>\n";
    }
  fout << "</TARGETORDER>\n";
}

void cmGlobalCodeWarriorGenerator::WriteGroupList(std::ostream& fout)
{
  fout << "<GROUPLIST>\n";
  
  unsigned int i;
  // for each local generator
  for (i = 0; i < m_LocalGenerators.size(); ++i)
    {
    static_cast<cmLocalCodeWarriorGenerator *>(m_LocalGenerators[i])->WriteGroups(fout);
    }
  

  fout << "</GROUPLIST>\n";
}

void cmGlobalCodeWarriorGenerator::LocalGenerate()
{
  this->cmGlobalGenerator::LocalGenerate();
}


//----------------------------------------------------------------------------
void cmGlobalCodeWarriorGenerator::GetDocumentation(cmDocumentationEntry& entry) const
{
  entry.name = this->GetName();
  entry.brief = "Generates CodeWarrior project files.";
  entry.full = "";
}