~ubuntu-branches/ubuntu/intrepid/cmake/intrepid-backports

« back to all changes in this revision

Viewing changes to Source/cmBorlandMakefileGenerator.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Maitland Bottoms
  • Date: 2002-02-14 18:36:25 UTC
  • Revision ID: james.westby@ubuntu.com-20020214183625-8m44isdas2k4l0f7
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
 
 
3
  Program:   Insight Segmentation & Registration Toolkit
 
4
  Module:    $RCSfile: cmBorlandMakefileGenerator.cxx,v $
 
5
  Language:  C++
 
6
  Date:      $Date: 2002/01/13 03:55:35 $
 
7
  Version:   $Revision: 1.11 $
 
8
 
 
9
Copyright (c) 2001 Insight Consortium
 
10
All rights reserved.
 
11
 
 
12
Redistribution and use in source and binary forms, with or without
 
13
modification, are permitted provided that the following conditions are met:
 
14
 
 
15
 * Redistributions of source code must retain the above copyright notice,
 
16
   this list of conditions and the following disclaimer.
 
17
 
 
18
 * Redistributions in binary form must reproduce the above copyright notice,
 
19
   this list of conditions and the following disclaimer in the documentation
 
20
   and/or other materials provided with the distribution.
 
21
 
 
22
 * The name of the Insight Consortium, nor the names of any consortium members,
 
23
   nor of any contributors, may be used to endorse or promote products derived
 
24
   from this software without specific prior written permission.
 
25
 
 
26
  * Modified source versions must be plainly marked as such, and must not be
 
27
    misrepresented as being the original software.
 
28
 
 
29
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
 
30
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
31
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
32
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
 
33
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
34
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
35
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
36
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
37
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
38
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
39
 
 
40
=========================================================================*/
 
41
#include "cmBorlandMakefileGenerator.h"
 
42
#include "cmMakefile.h"
 
43
#include "cmStandardIncludes.h"
 
44
#include "cmSystemTools.h"
 
45
#include "cmSourceFile.h"
 
46
#include "cmMakeDepend.h"
 
47
#include "cmCacheManager.h"
 
48
#include "cmGeneratedFileStream.h"
 
49
#include "windows.h"
 
50
 
 
51
 
 
52
cmBorlandMakefileGenerator::cmBorlandMakefileGenerator()
 
53
{
 
54
  this->SetLibraryPathOption("-L");
 
55
  this->SetLibraryLinkOption("");
 
56
}
 
57
 
 
58
cmBorlandMakefileGenerator::~cmBorlandMakefileGenerator()
 
59
{
 
60
}
 
61
 
 
62
 
 
63
void cmBorlandMakefileGenerator::ComputeSystemInfo()
 
64
{
 
65
  // now load the settings
 
66
  if(!m_Makefile->GetDefinition("CMAKE_ROOT"))
 
67
    {
 
68
    cmSystemTools::Error(
 
69
      "CMAKE_ROOT has not been defined, bad GUI or driver program");
 
70
    return;
 
71
    }
 
72
  std::string outdir = m_Makefile->GetCurrentOutputDirectory();
 
73
  if(outdir.find('-') != std::string::npos)
 
74
    {
 
75
    std::string message = "The Borland command line tools do not support path names that have - in them.  Please re-name your output directory and use _ instead of -.";
 
76
    message += "\nYour path currently is: ";
 
77
    message += outdir;
 
78
    cmSystemTools::Error(message.c_str());
 
79
    }
 
80
  
 
81
  std::string fpath = 
 
82
    m_Makefile->GetDefinition("CMAKE_ROOT");
 
83
  fpath += "/Templates/CMakeBorlandWindowsSystemConfig.cmake";
 
84
  m_Makefile->ReadListFile(NULL,fpath.c_str());
 
85
}
 
86
 
 
87
 
 
88
  
 
89
void cmBorlandMakefileGenerator::OutputMakeVariables(std::ostream& fout)
 
90
{
 
91
  fout << "# NMake Makefile generated by cmake\n";
 
92
  const char* variables = 
 
93
    "# general varibles used in the makefile\n"
 
94
    "\n"
 
95
    "CMAKE_STANDARD_WINDOWS_LIBRARIES = @CMAKE_STANDARD_WINDOWS_LIBRARIES@\n"
 
96
    "CMAKE_C_FLAGS        = @CMAKE_C_FLAGS@ @BUILD_FLAGS@\n"
 
97
    "CMAKE_OBJECT_FILE_SUFFIX            = @CMAKE_OBJECT_FILE_SUFFIX@\n"
 
98
    "CMAKE_EXECUTABLE_SUFFIX             = @CMAKE_EXECUTABLE_SUFFIX@\n"
 
99
    "CMAKE_STATICLIB_SUFFIX              = @CMAKE_STATICLIB_SUFFIX@\n"
 
100
    "CMAKE_SHLIB_SUFFIX                  = @CMAKE_SHLIB_SUFFIX@\n" 
 
101
    "CMAKE_SHLIB_CFLAGS                  = -tWR\n" 
 
102
    "CMAKE_LINKER_FLAGS                  = @CMAKE_LINKER_FLAGS@ @LINKER_BUILD_FLAGS@\n"
 
103
    "CMAKE_CXX_FLAGS      = -P @CMAKE_CXX_FLAGS@ @BUILD_FLAGS@\n"
 
104
    "!IF \"$(OS)\" == \"Windows_NT\"\n"
 
105
    "NULL=\n"
 
106
    "!ELSE \n"
 
107
    "NULL=nul\n"
 
108
    "!ENDIF \n"
 
109
    "RM = del\n";
 
110
  std::string buildType = "CMAKE_CXX_FLAGS_";
 
111
  buildType +=  m_Makefile->GetDefinition("CMAKE_BUILD_TYPE");
 
112
  buildType = cmSystemTools::UpperCase(buildType);
 
113
  m_Makefile->AddDefinition("BUILD_FLAGS",
 
114
                            m_Makefile->GetDefinition(
 
115
                              buildType.c_str()));
 
116
  
 
117
  buildType = "CMAKE_LINKER_FLAGS_";
 
118
  buildType +=  m_Makefile->GetDefinition("CMAKE_BUILD_TYPE");
 
119
  buildType = cmSystemTools::UpperCase(buildType);
 
120
  m_Makefile->AddDefinition("LINKER_BUILD_FLAGS",
 
121
                            m_Makefile->GetDefinition(
 
122
                              buildType.c_str()));
 
123
 
 
124
  std::string replaceVars = variables;
 
125
  m_Makefile->ExpandVariablesInString(replaceVars);
 
126
  
 
127
  std::string ccompiler = m_Makefile->GetDefinition("CMAKE_C_COMPILER");
 
128
  cmSystemTools::ConvertToWindowsSlashes(ccompiler);
 
129
  fout << "CMAKE_C_COMPILER  = " << cmSystemTools::EscapeSpaces(ccompiler.c_str())
 
130
       << "\n";
 
131
  std::string cxxcompiler = m_Makefile->GetDefinition("CMAKE_CXX_COMPILER");
 
132
  cmSystemTools::ConvertToWindowsSlashes(cxxcompiler);
 
133
  fout << "CMAKE_CXX_COMPILER  = " << cmSystemTools::EscapeSpaces(cxxcompiler.c_str())
 
134
       << "\n";
 
135
 
 
136
  
 
137
  std::string cmakecommand = m_Makefile->GetDefinition("CMAKE_COMMAND");
 
138
  cmSystemTools::ConvertToWindowsSlashes(cmakecommand);
 
139
  fout << "CMAKE_COMMAND = " << cmSystemTools::EscapeSpaces(cmakecommand.c_str()) << "\n";
 
140
 
 
141
  fout << replaceVars.c_str();
 
142
  fout << "CMAKE_CURRENT_SOURCE = " 
 
143
       << ShortPath(m_Makefile->GetStartDirectory() )
 
144
       << "\n";
 
145
  fout << "CMAKE_CURRENT_BINARY = " 
 
146
       << ShortPath(m_Makefile->GetStartOutputDirectory())
 
147
       << "\n";
 
148
  fout << "CMAKE_SOURCE_DIR = " 
 
149
       << ShortPath(m_Makefile->GetHomeDirectory()) << "\n";
 
150
  fout << "CMAKE_BINARY_DIR = " 
 
151
       << ShortPath(m_Makefile->GetHomeOutputDirectory() )
 
152
       << "\n";
 
153
  // Output Include paths
 
154
  fout << "INCLUDE_FLAGS = ";
 
155
  std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
 
156
  std::vector<std::string>::iterator i;
 
157
  fout << "-I" << cmSystemTools::EscapeSpaces(m_Makefile->GetStartDirectory()) << " ";
 
158
  for(i = includes.begin(); i != includes.end(); ++i)
 
159
    {
 
160
    std::string include = *i;
 
161
    // Don't output a -I for the standard include path "/usr/include".
 
162
    // This can cause problems with certain standard library
 
163
    // implementations because the wrong headers may be found first.
 
164
    if(include != "/usr/include")
 
165
      {
 
166
      fout << "-I" << cmSystemTools::EscapeSpaces(i->c_str()).c_str() << " ";
 
167
      }
 
168
    } 
 
169
  fout << m_Makefile->GetDefineFlags();
 
170
  fout << "\n\n";
 
171
}
 
172
 
 
173
 
 
174
 
 
175
void 
 
176
cmBorlandMakefileGenerator::
 
177
OutputBuildObjectFromSource(std::ostream& fout,
 
178
                            const char* shortName,
 
179
                            const cmSourceFile& source,
 
180
                            const char* extraCompileFlags,
 
181
                            bool shared)
 
182
{
 
183
  // force shared flag if building shared libraries
 
184
  if(cmSystemTools::IsOn(m_Makefile->GetDefinition("BUILD_SHARED_LIBS")))
 
185
    {
 
186
    shared = true;
 
187
    }
 
188
  // Header files shouldn't have build rules.
 
189
  if(source.IsAHeaderFileOnly())
 
190
    return;
 
191
 
 
192
  std::string comment = "Build ";
 
193
  std::string objectFile = std::string(shortName) + 
 
194
    this->GetOutputExtension(source.GetSourceExtension().c_str());
 
195
  cmSystemTools::ConvertToWindowsSlashes(objectFile);
 
196
  comment += objectFile + "  From ";
 
197
  comment += source.GetFullPath();
 
198
  std::string compileCommand;
 
199
  std::string ext = source.GetSourceExtension();
 
200
  if(ext == "c" )
 
201
    {
 
202
    compileCommand = "$(CMAKE_C_COMPILER) $(CMAKE_C_FLAGS) ";
 
203
    compileCommand += extraCompileFlags;
 
204
    if(shared)
 
205
      {
 
206
      compileCommand += "$(CMAKE_SHLIB_CFLAGS) ";
 
207
      }
 
208
    compileCommand += " -o";
 
209
    compileCommand += objectFile;
 
210
    compileCommand += " $(INCLUDE_FLAGS) -c ";
 
211
    compileCommand += 
 
212
      cmSystemTools::EscapeSpaces(source.GetFullPath().c_str());
 
213
    }
 
214
  else if (ext == "rc")
 
215
    {
 
216
    compileCommand = "$(RC) -o\"";
 
217
    compileCommand += objectFile;
 
218
    compileCommand += "\" ";
 
219
    compileCommand += 
 
220
      cmSystemTools::EscapeSpaces(source.GetFullPath().c_str());
 
221
    }
 
222
  else if (ext == "def")
 
223
    {
 
224
    // no rule to output for this one
 
225
    return;
 
226
    }
 
227
  // assume c++ if not c rc or def
 
228
  else
 
229
    {
 
230
    compileCommand = "$(CMAKE_CXX_COMPILER) $(CMAKE_CXX_FLAGS) ";
 
231
    compileCommand += extraCompileFlags;
 
232
    if(shared)
 
233
      {
 
234
      compileCommand += "$(CMAKE_SHLIB_CFLAGS) ";
 
235
      }
 
236
    compileCommand += " -o";
 
237
    compileCommand += objectFile;
 
238
    compileCommand += " $(INCLUDE_FLAGS) -c ";
 
239
    compileCommand += 
 
240
      cmSystemTools::EscapeSpaces(source.GetFullPath().c_str());
 
241
    }
 
242
  this->OutputMakeRule(fout,
 
243
                       comment.c_str(),
 
244
                       objectFile.c_str(),
 
245
                       cmSystemTools::EscapeSpaces(
 
246
                         source.GetFullPath().c_str()).c_str(),
 
247
                       compileCommand.c_str());
 
248
}
 
249
 
 
250
void cmBorlandMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout, 
 
251
                                                       const char* name,
 
252
                                                       const cmTarget &t)
 
253
{
 
254
  std::string target = m_LibraryOutputPath + name;
 
255
  std::string libpath = target + ".lib";
 
256
  target += ".dll";
 
257
  cmSystemTools::ConvertToWindowsSlashes(libpath);
 
258
  cmSystemTools::ConvertToWindowsSlashes(target);
 
259
  target = cmSystemTools::EscapeSpaces(target.c_str());
 
260
  libpath = cmSystemTools::EscapeSpaces(libpath.c_str());
 
261
  std::string depend = "$(";
 
262
  depend += name;
 
263
  depend += "_SRC_OBJS) $(" + std::string(name) + "_DEPEND_LIBS)";
 
264
  std::string command = "$(CMAKE_CXX_COMPILER) -tWD $(CMAKE_SHLIB_CFLAGS) $(CMAKE_LINKER_FLAGS) @&&|\n";
 
265
  // must be executable name
 
266
  command += "-e";
 
267
  command += target;
 
268
  command += " ";
 
269
  std::strstream linklibs;
 
270
  this->OutputLinkLibraries(linklibs, name, t);
 
271
  linklibs << std::ends;
 
272
  // then the linker options -L and libraries (any other order will fail!)
 
273
  command += linklibs.str();
 
274
  delete [] linklibs.str();
 
275
  // then list of object files
 
276
  command += " $(" + std::string(name) + "_SRC_OBJS) ";
 
277
  std::string command2 = "implib -w ";
 
278
  command2 += libpath + " " + target;
 
279
  const std::vector<cmSourceFile>& sources = t.GetSourceFiles();
 
280
  for(std::vector<cmSourceFile>::const_iterator i = sources.begin();
 
281
      i != sources.end(); ++i)
 
282
    {
 
283
    if(i->GetSourceExtension() == "def")
 
284
      {
 
285
      command += "";
 
286
      command += i->GetFullPath();
 
287
      }
 
288
    }
 
289
  command += "\n|\n";
 
290
    
 
291
  std::string customCommands = this->CreateTargetRules(t, name);
 
292
  const char* cc = 0;
 
293
  if(customCommands.size() > 0)
 
294
    {
 
295
    cc = customCommands.c_str();
 
296
    }
 
297
  this->OutputMakeRule(fout, "rules for a shared library",
 
298
                       target.c_str(),
 
299
                       depend.c_str(),
 
300
                       command.c_str(),
 
301
                       command2.c_str(),
 
302
                       cc);
 
303
}
 
304
 
 
305
void cmBorlandMakefileGenerator::OutputModuleLibraryRule(std::ostream& fout, 
 
306
                                                       const char* name, 
 
307
                                                       const cmTarget &target)
 
308
{
 
309
  this->OutputSharedLibraryRule(fout, name, target);
 
310
}
 
311
 
 
312
void cmBorlandMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout, 
 
313
                                                       const char* name,
 
314
                                                       const cmTarget &t)
 
315
{
 
316
  std::string target = m_LibraryOutputPath + std::string(name) + ".lib";
 
317
  cmSystemTools::ConvertToWindowsSlashes(target);
 
318
  target = cmSystemTools::EscapeSpaces(target.c_str());
 
319
  std::string depend = "$(";
 
320
  depend += std::string(name) + "_SRC_OBJS)";
 
321
  std::string command = "tlib  @&&|\n\t /p512 /a ";
 
322
  command += target;
 
323
  command += " ";
 
324
  std::string deleteCommand = "if exist ";
 
325
  deleteCommand +=  target;
 
326
  deleteCommand += " del ";
 
327
  deleteCommand += target;
 
328
 
 
329
  command += " $(";
 
330
  command += std::string(name) + "_SRC_OBJS)";
 
331
  command += "\n|\n";
 
332
  std::string comment = "rule to build static library: ";
 
333
  comment += name;
 
334
  std::string customCommands = this->CreateTargetRules(t, name);
 
335
  const char* cc = 0;
 
336
  if(customCommands.size() > 0)
 
337
    {
 
338
    cc = customCommands.c_str();
 
339
    }
 
340
  this->OutputMakeRule(fout,
 
341
                       comment.c_str(),
 
342
                       target.c_str(),
 
343
                       depend.c_str(),
 
344
                       deleteCommand.c_str(),
 
345
                       command.c_str(), cc);
 
346
}
 
347
 
 
348
void cmBorlandMakefileGenerator::OutputExecutableRule(std::ostream& fout,
 
349
                                                    const char* name,
 
350
                                                    const cmTarget &t)
 
351
{
 
352
  std::string target = m_ExecutableOutputPath + name + m_ExecutableExtension;
 
353
  cmSystemTools::ConvertToWindowsSlashes(target);
 
354
  target = cmSystemTools::EscapeSpaces(target.c_str());
 
355
  std::string depend = "$(";
 
356
  depend += std::string(name) + "_SRC_OBJS) $(" + std::string(name) + "_DEPEND_LIBS)";
 
357
  std::string command = 
 
358
    "$(CMAKE_CXX_COMPILER) ";
 
359
  command += " $(CMAKE_LINKER_FLAGS) -e" + target;
 
360
  if(cmSystemTools::IsOn(m_Makefile->GetDefinition("BUILD_SHARED_LIBS")))
 
361
    {
 
362
    command += " $(CMAKE_SHLIB_CFLAGS) ";
 
363
    }
 
364
  if(t.GetType() == cmTarget::WIN32_EXECUTABLE)
 
365
    {
 
366
    command +=  " -tWM ";
 
367
    }
 
368
  else
 
369
    {
 
370
    command += " -tWC ";
 
371
    }
 
372
  std::strstream linklibs;
 
373
  this->OutputLinkLibraries(linklibs, 0, t);
 
374
  linklibs << std::ends;
 
375
  command += linklibs.str();
 
376
  delete [] linklibs.str();
 
377
  command += " $(" + std::string(name) + "_SRC_OBJS) ";
 
378
  
 
379
  std::string comment = "rule to build executable: ";
 
380
  comment += name;
 
381
  std::string customCommands = this->CreateTargetRules(t, name);
 
382
  const char* cc = 0;
 
383
  if(customCommands.size() > 0)
 
384
    {
 
385
    cc = customCommands.c_str();
 
386
    }
 
387
  this->OutputMakeRule(fout, 
 
388
                       comment.c_str(),
 
389
                       target.c_str(),
 
390
                       depend.c_str(),
 
391
                       command.c_str(), cc);
 
392
}
 
393
 
 
394
  
 
395
 
 
396
 
 
397
std::string cmBorlandMakefileGenerator::GetOutputExtension(const char* s)
 
398
{
 
399
  std::string sourceExtension = s;
 
400
  if(sourceExtension == "def")
 
401
    {
 
402
    return "";
 
403
    }
 
404
  if(sourceExtension == "ico" || sourceExtension == "rc2")
 
405
    {
 
406
    return "";
 
407
    }
 
408
  if(sourceExtension == "rc")
 
409
    {
 
410
    return ".res";
 
411
    }
 
412
  return ".obj";
 
413
}
 
414
 
 
415
 
 
416
 
 
417
bool cmBorlandMakefileGenerator::SamePath(const char* path1, const char* path2)
 
418
{
 
419
  // first check to see if they are the same anyway
 
420
  if (strcmp(path1, path2) == 0)
 
421
    {
 
422
    return true;
 
423
    }
 
424
  // next short path and lower case both of them for the compare
 
425
  return 
 
426
    cmSystemTools::LowerCase(ShortPath(path1)) ==
 
427
    cmSystemTools::LowerCase(ShortPath(path2));
 
428
}
 
429
 
 
430