1
/*=========================================================================
3
Program: Insight Segmentation & Registration Toolkit
4
Module: $RCSfile: cmBorlandMakefileGenerator.cxx,v $
6
Date: $Date: 2002/01/13 03:55:35 $
7
Version: $Revision: 1.11 $
9
Copyright (c) 2001 Insight Consortium
12
Redistribution and use in source and binary forms, with or without
13
modification, are permitted provided that the following conditions are met:
15
* Redistributions of source code must retain the above copyright notice,
16
this list of conditions and the following disclaimer.
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.
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.
26
* Modified source versions must be plainly marked as such, and must not be
27
misrepresented as being the original software.
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.
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"
52
cmBorlandMakefileGenerator::cmBorlandMakefileGenerator()
54
this->SetLibraryPathOption("-L");
55
this->SetLibraryLinkOption("");
58
cmBorlandMakefileGenerator::~cmBorlandMakefileGenerator()
63
void cmBorlandMakefileGenerator::ComputeSystemInfo()
65
// now load the settings
66
if(!m_Makefile->GetDefinition("CMAKE_ROOT"))
69
"CMAKE_ROOT has not been defined, bad GUI or driver program");
72
std::string outdir = m_Makefile->GetCurrentOutputDirectory();
73
if(outdir.find('-') != std::string::npos)
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: ";
78
cmSystemTools::Error(message.c_str());
82
m_Makefile->GetDefinition("CMAKE_ROOT");
83
fpath += "/Templates/CMakeBorlandWindowsSystemConfig.cmake";
84
m_Makefile->ReadListFile(NULL,fpath.c_str());
89
void cmBorlandMakefileGenerator::OutputMakeVariables(std::ostream& fout)
91
fout << "# NMake Makefile generated by cmake\n";
92
const char* variables =
93
"# general varibles used in the makefile\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"
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(
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(
124
std::string replaceVars = variables;
125
m_Makefile->ExpandVariablesInString(replaceVars);
127
std::string ccompiler = m_Makefile->GetDefinition("CMAKE_C_COMPILER");
128
cmSystemTools::ConvertToWindowsSlashes(ccompiler);
129
fout << "CMAKE_C_COMPILER = " << cmSystemTools::EscapeSpaces(ccompiler.c_str())
131
std::string cxxcompiler = m_Makefile->GetDefinition("CMAKE_CXX_COMPILER");
132
cmSystemTools::ConvertToWindowsSlashes(cxxcompiler);
133
fout << "CMAKE_CXX_COMPILER = " << cmSystemTools::EscapeSpaces(cxxcompiler.c_str())
137
std::string cmakecommand = m_Makefile->GetDefinition("CMAKE_COMMAND");
138
cmSystemTools::ConvertToWindowsSlashes(cmakecommand);
139
fout << "CMAKE_COMMAND = " << cmSystemTools::EscapeSpaces(cmakecommand.c_str()) << "\n";
141
fout << replaceVars.c_str();
142
fout << "CMAKE_CURRENT_SOURCE = "
143
<< ShortPath(m_Makefile->GetStartDirectory() )
145
fout << "CMAKE_CURRENT_BINARY = "
146
<< ShortPath(m_Makefile->GetStartOutputDirectory())
148
fout << "CMAKE_SOURCE_DIR = "
149
<< ShortPath(m_Makefile->GetHomeDirectory()) << "\n";
150
fout << "CMAKE_BINARY_DIR = "
151
<< ShortPath(m_Makefile->GetHomeOutputDirectory() )
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)
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")
166
fout << "-I" << cmSystemTools::EscapeSpaces(i->c_str()).c_str() << " ";
169
fout << m_Makefile->GetDefineFlags();
176
cmBorlandMakefileGenerator::
177
OutputBuildObjectFromSource(std::ostream& fout,
178
const char* shortName,
179
const cmSourceFile& source,
180
const char* extraCompileFlags,
183
// force shared flag if building shared libraries
184
if(cmSystemTools::IsOn(m_Makefile->GetDefinition("BUILD_SHARED_LIBS")))
188
// Header files shouldn't have build rules.
189
if(source.IsAHeaderFileOnly())
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();
202
compileCommand = "$(CMAKE_C_COMPILER) $(CMAKE_C_FLAGS) ";
203
compileCommand += extraCompileFlags;
206
compileCommand += "$(CMAKE_SHLIB_CFLAGS) ";
208
compileCommand += " -o";
209
compileCommand += objectFile;
210
compileCommand += " $(INCLUDE_FLAGS) -c ";
212
cmSystemTools::EscapeSpaces(source.GetFullPath().c_str());
214
else if (ext == "rc")
216
compileCommand = "$(RC) -o\"";
217
compileCommand += objectFile;
218
compileCommand += "\" ";
220
cmSystemTools::EscapeSpaces(source.GetFullPath().c_str());
222
else if (ext == "def")
224
// no rule to output for this one
227
// assume c++ if not c rc or def
230
compileCommand = "$(CMAKE_CXX_COMPILER) $(CMAKE_CXX_FLAGS) ";
231
compileCommand += extraCompileFlags;
234
compileCommand += "$(CMAKE_SHLIB_CFLAGS) ";
236
compileCommand += " -o";
237
compileCommand += objectFile;
238
compileCommand += " $(INCLUDE_FLAGS) -c ";
240
cmSystemTools::EscapeSpaces(source.GetFullPath().c_str());
242
this->OutputMakeRule(fout,
245
cmSystemTools::EscapeSpaces(
246
source.GetFullPath().c_str()).c_str(),
247
compileCommand.c_str());
250
void cmBorlandMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
254
std::string target = m_LibraryOutputPath + name;
255
std::string libpath = target + ".lib";
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 = "$(";
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
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)
283
if(i->GetSourceExtension() == "def")
286
command += i->GetFullPath();
291
std::string customCommands = this->CreateTargetRules(t, name);
293
if(customCommands.size() > 0)
295
cc = customCommands.c_str();
297
this->OutputMakeRule(fout, "rules for a shared library",
305
void cmBorlandMakefileGenerator::OutputModuleLibraryRule(std::ostream& fout,
307
const cmTarget &target)
309
this->OutputSharedLibraryRule(fout, name, target);
312
void cmBorlandMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
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 ";
324
std::string deleteCommand = "if exist ";
325
deleteCommand += target;
326
deleteCommand += " del ";
327
deleteCommand += target;
330
command += std::string(name) + "_SRC_OBJS)";
332
std::string comment = "rule to build static library: ";
334
std::string customCommands = this->CreateTargetRules(t, name);
336
if(customCommands.size() > 0)
338
cc = customCommands.c_str();
340
this->OutputMakeRule(fout,
344
deleteCommand.c_str(),
345
command.c_str(), cc);
348
void cmBorlandMakefileGenerator::OutputExecutableRule(std::ostream& fout,
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")))
362
command += " $(CMAKE_SHLIB_CFLAGS) ";
364
if(t.GetType() == cmTarget::WIN32_EXECUTABLE)
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) ";
379
std::string comment = "rule to build executable: ";
381
std::string customCommands = this->CreateTargetRules(t, name);
383
if(customCommands.size() > 0)
385
cc = customCommands.c_str();
387
this->OutputMakeRule(fout,
391
command.c_str(), cc);
397
std::string cmBorlandMakefileGenerator::GetOutputExtension(const char* s)
399
std::string sourceExtension = s;
400
if(sourceExtension == "def")
404
if(sourceExtension == "ico" || sourceExtension == "rc2")
408
if(sourceExtension == "rc")
417
bool cmBorlandMakefileGenerator::SamePath(const char* path1, const char* path2)
419
// first check to see if they are the same anyway
420
if (strcmp(path1, path2) == 0)
424
// next short path and lower case both of them for the compare
426
cmSystemTools::LowerCase(ShortPath(path1)) ==
427
cmSystemTools::LowerCase(ShortPath(path2));