Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmLocalGenerator.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmLocalGenerator.h"
13
14 #include "cmComputeLinkInformation.h"
15 #include "cmGeneratedFileStream.h"
16 #include "cmGlobalGenerator.h"
17 #include "cmInstallGenerator.h"
18 #include "cmInstallFilesGenerator.h"
19 #include "cmInstallScriptGenerator.h"
20 #include "cmInstallTargetGenerator.h"
21 #include "cmMakefile.h"
22 #include "cmSourceFile.h"
23 #include "cmTest.h"
24 #include "cmTestGenerator.h"
25 #include "cmVersion.h"
26 #include "cmake.h"
27
28 #if defined(CMAKE_BUILD_WITH_CMAKE)
29 # define CM_LG_ENCODE_OBJECT_NAMES
30 # include <cmsys/MD5.h>
31 #endif
32
33 #include <cmsys/System.h>
34
35 #include <ctype.h> // for isalpha
36
37 #include <assert.h>
38
39 #if defined(__HAIKU__)
40 #include <StorageKit.h>
41 #endif
42
43 cmLocalGenerator::cmLocalGenerator()
44 {
45   this->Makefile = 0; // moved to after set on global
46   this->Parent = 0;
47   this->WindowsShell = false;
48   this->WindowsVSIDE = false;
49   this->WatcomWMake = false;
50   this->MinGWMake = false;
51   this->NMake = false;
52   this->MSYSShell = false;
53   this->LinkScriptShell = false;
54   this->IgnoreLibPrefix = false;
55   this->UseRelativePaths = false;
56   this->Configured = false;
57   this->EmitUniversalBinaryFlags = true;
58   this->RelativePathsConfigured = false;
59   this->PathConversionsSetup = false;
60   this->BackwardsCompatibility = 0;
61   this->BackwardsCompatibilityFinal = false;
62 }
63
64 cmLocalGenerator::~cmLocalGenerator()
65 {
66   delete this->Makefile;
67 }
68
69 //----------------------------------------------------------------------------
70 class cmLocalGeneratorCurrent
71 {
72   cmGlobalGenerator* GG;
73   cmLocalGenerator* LG;
74 public:
75   cmLocalGeneratorCurrent(cmLocalGenerator* lg)
76     {
77     this->GG = lg->GetGlobalGenerator();
78     this->LG = this->GG->GetCurrentLocalGenerator();
79     this->GG->SetCurrentLocalGenerator(lg);
80     }
81   ~cmLocalGeneratorCurrent()
82     {
83     this->GG->SetCurrentLocalGenerator(this->LG);
84     }
85 };
86
87 //----------------------------------------------------------------------------
88 void cmLocalGenerator::Configure()
89 {
90   // Manage the global generator's current local generator.
91   cmLocalGeneratorCurrent clg(this);
92   static_cast<void>(clg);
93
94   // make sure the CMakeFiles dir is there
95   std::string filesDir = this->Makefile->GetStartOutputDirectory();
96   filesDir += cmake::GetCMakeFilesDirectory();
97   cmSystemTools::MakeDirectory(filesDir.c_str());
98
99   // find & read the list file
100   this->ReadInputFile();
101
102   // at the end of the ReadListFile handle any old style subdirs
103   // first get all the subdirectories
104   std::vector<cmLocalGenerator *> subdirs = this->GetChildren();
105
106   // for each subdir recurse
107   std::vector<cmLocalGenerator *>::iterator sdi = subdirs.begin();
108   for (; sdi != subdirs.end(); ++sdi)
109     {
110     if (!(*sdi)->Configured)
111       {
112       this->Makefile->ConfigureSubDirectory(*sdi);
113       }
114     }
115
116   // Check whether relative paths should be used for optionally
117   // relative paths.
118   this->UseRelativePaths = this->Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS");
119
120   this->ComputeObjectMaxPath();
121
122   this->Configured = true;
123 }
124
125 //----------------------------------------------------------------------------
126 void cmLocalGenerator::ComputeObjectMaxPath()
127 {
128   // Choose a maximum object file name length.
129 #if defined(_WIN32) || defined(__CYGWIN__)
130   this->ObjectPathMax = 250;
131 #else
132   this->ObjectPathMax = 1000;
133 #endif
134   const char* plen = this->Makefile->GetDefinition("CMAKE_OBJECT_PATH_MAX");
135   if(plen && *plen)
136     {
137     unsigned int pmax;
138     if(sscanf(plen, "%u", &pmax) == 1)
139       {
140       if(pmax >= 128)
141         {
142         this->ObjectPathMax = pmax;
143         }
144       else
145         {
146         cmOStringStream w;
147         w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax
148           << ", which is less than the minimum of 128.  "
149           << "The value will be ignored.";
150         this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
151         }
152       }
153     else
154       {
155       cmOStringStream w;
156       w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen
157         << "\", which fails to parse as a positive integer.  "
158         << "The value will be ignored.";
159       this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
160       }
161     }
162   this->ObjectMaxPathViolations.clear();
163 }
164
165 //----------------------------------------------------------------------------
166 void cmLocalGenerator::ReadInputFile()
167 {
168   // Look for the CMakeLists.txt file.
169   std::string currentStart = this->Makefile->GetStartDirectory();
170   currentStart += "/CMakeLists.txt";
171   if(cmSystemTools::FileExists(currentStart.c_str(), true))
172     {
173     this->Makefile->ReadListFile(currentStart.c_str());
174     return;
175     }
176
177   if(!this->Parent)
178     {
179     return;
180     }
181
182   // The file is missing.  Check policy CMP0014.
183   cmMakefile* mf = this->Parent->GetMakefile();
184   cmOStringStream e;
185   e << "The source directory\n"
186     << "  " << this->Makefile->GetStartDirectory() << "\n"
187     << "does not contain a CMakeLists.txt file.";
188   switch (mf->GetPolicyStatus(cmPolicies::CMP0014))
189     {
190     case cmPolicies::WARN:
191       // Print the warning.
192       e << "\n"
193         << "CMake does not support this case but it used "
194         << "to work accidentally and is being allowed for "
195         << "compatibility."
196         << "\n"
197         << mf->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0014);
198       mf->IssueMessage(cmake::AUTHOR_WARNING, e.str());
199     case cmPolicies::OLD:
200       // OLD behavior does not warn.
201       return;
202     case cmPolicies::REQUIRED_IF_USED:
203     case cmPolicies::REQUIRED_ALWAYS:
204       e << "\n"
205         << mf->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP0014);
206     case cmPolicies::NEW:
207       // NEW behavior prints the error.
208       mf->IssueMessage(cmake::FATAL_ERROR, e.str());
209       break;
210     }
211 }
212
213 void cmLocalGenerator::SetupPathConversions()
214 {
215   // Setup the current output directory components for use by
216   // Convert
217   std::string outdir;
218   outdir =
219     cmSystemTools::CollapseFullPath(this->Makefile->GetHomeDirectory());
220   cmSystemTools::SplitPath(outdir.c_str(), this->HomeDirectoryComponents);
221   outdir =
222     cmSystemTools::CollapseFullPath(this->Makefile->GetStartDirectory());
223   cmSystemTools::SplitPath(outdir.c_str(), this->StartDirectoryComponents);
224
225   outdir = cmSystemTools::CollapseFullPath
226     (this->Makefile->GetHomeOutputDirectory());
227   cmSystemTools::SplitPath(outdir.c_str(),
228                            this->HomeOutputDirectoryComponents);
229
230   outdir = cmSystemTools::CollapseFullPath
231     (this->Makefile->GetStartOutputDirectory());
232   cmSystemTools::SplitPath(outdir.c_str(),
233                            this->StartOutputDirectoryComponents);
234 }
235
236
237 void cmLocalGenerator::SetGlobalGenerator(cmGlobalGenerator *gg)
238 {
239   this->GlobalGenerator = gg;
240   this->Makefile = new cmMakefile;
241   this->Makefile->SetLocalGenerator(this);
242
243   // setup the home directories
244   this->Makefile->GetProperties().SetCMakeInstance(gg->GetCMakeInstance());
245   this->Makefile->SetHomeDirectory(
246     gg->GetCMakeInstance()->GetHomeDirectory());
247   this->Makefile->SetHomeOutputDirectory(
248     gg->GetCMakeInstance()->GetHomeOutputDirectory());
249 }
250
251 void cmLocalGenerator::ConfigureFinalPass()
252 {
253   this->Makefile->ConfigureFinalPass();
254 }
255
256 void cmLocalGenerator::TraceDependencies()
257 {
258   // Generate the rule files for each target.
259   cmTargets& targets = this->Makefile->GetTargets();
260   for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
261     {
262     t->second.TraceDependencies();
263     }
264 }
265
266 void cmLocalGenerator::GenerateTestFiles()
267 {
268   if ( !this->Makefile->IsOn("CMAKE_TESTING_ENABLED") )
269     {
270     return;
271     }
272
273   // Compute the set of configurations.
274   std::vector<std::string> configurationTypes;
275   const char* config =
276     this->Makefile->GetConfigurations(configurationTypes, false);
277
278   std::string file = this->Makefile->GetStartOutputDirectory();
279   file += "/";
280   file += "CTestTestfile.cmake";
281
282   cmGeneratedFileStream fout(file.c_str());
283   fout.SetCopyIfDifferent(true);
284
285   fout << "# CMake generated Testfile for " << std::endl
286        << "# Source directory: "
287        << this->Makefile->GetStartDirectory() << std::endl
288        << "# Build directory: "
289        << this->Makefile->GetStartOutputDirectory() << std::endl
290        << "# " << std::endl
291        << "# This file includes the relevant testing commands "
292        << "required for " << std::endl
293        << "# testing this directory and lists subdirectories to "
294        << "be tested as well." << std::endl;
295
296   const char* testIncludeFile =
297     this->Makefile->GetProperty("TEST_INCLUDE_FILE");
298   if ( testIncludeFile )
299     {
300     fout << "INCLUDE(\"" << testIncludeFile << "\")" << std::endl;
301     }
302
303   // Ask each test generator to write its code.
304   std::vector<cmTestGenerator*> const&
305     testers = this->Makefile->GetTestGenerators();
306   for(std::vector<cmTestGenerator*>::const_iterator gi = testers.begin();
307       gi != testers.end(); ++gi)
308     {
309     (*gi)->Generate(fout, config, configurationTypes);
310     }
311   if ( this->Children.size())
312     {
313     size_t i;
314     for(i = 0; i < this->Children.size(); ++i)
315       {
316       fout << "SUBDIRS(";
317       std::string outP =
318         this->Children[i]->GetMakefile()->GetStartOutputDirectory();
319       fout << this->Convert(outP.c_str(),START_OUTPUT);
320       fout << ")" << std::endl;
321       }
322     }
323 }
324
325 //----------------------------------------------------------------------------
326 void cmLocalGenerator::GenerateInstallRules()
327 {
328   // Compute the install prefix.
329   const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
330 #if defined(_WIN32) && !defined(__CYGWIN__)
331   std::string prefix_win32;
332   if(!prefix)
333     {
334     if(!cmSystemTools::GetEnv("SystemDrive", prefix_win32))
335       {
336       prefix_win32 = "C:";
337       }
338     const char* project_name = this->Makefile->GetDefinition("PROJECT_NAME");
339     if(project_name && project_name[0])
340       {
341       prefix_win32 += "/Program Files/";
342       prefix_win32 += project_name;
343       }
344     else
345       {
346       prefix_win32 += "/InstalledCMakeProject";
347       }
348     prefix = prefix_win32.c_str();
349     }
350 #elif defined(__HAIKU__)
351   if (!prefix)
352     {
353     BPath dir;
354     if (find_directory(B_COMMON_DIRECTORY, &dir) == B_OK)
355       {
356       prefix = dir.Path();
357       }
358     else
359       {
360       prefix = "/boot/common";
361       }
362     }
363 #else
364   if (!prefix)
365     {
366     prefix = "/usr/local";
367     }
368 #endif
369
370   // Compute the set of configurations.
371   std::vector<std::string> configurationTypes;
372   const char* config =
373     this->Makefile->GetConfigurations(configurationTypes, false);
374
375   // Choose a default install configuration.
376   const char* default_config = config;
377   const char* default_order[] = {"RELEASE", "MINSIZEREL",
378                                  "RELWITHDEBINFO", "DEBUG", 0};
379   for(const char** c = default_order; *c && !default_config; ++c)
380     {
381     for(std::vector<std::string>::iterator i = configurationTypes.begin();
382         i != configurationTypes.end(); ++i)
383       {
384       if(cmSystemTools::UpperCase(*i) == *c)
385         {
386         default_config = i->c_str();
387         }
388       }
389     }
390   if(!default_config && !configurationTypes.empty())
391     {
392     default_config = configurationTypes[0].c_str();
393     }
394   if(!default_config)
395     {
396     default_config = "Release";
397     }
398
399   // Create the install script file.
400   std::string file = this->Makefile->GetStartOutputDirectory();
401   std::string homedir = this->Makefile->GetHomeOutputDirectory();
402   std::string currdir = this->Makefile->GetCurrentOutputDirectory();
403   cmSystemTools::ConvertToUnixSlashes(file);
404   cmSystemTools::ConvertToUnixSlashes(homedir);
405   cmSystemTools::ConvertToUnixSlashes(currdir);
406   int toplevel_install = 0;
407   if ( currdir == homedir )
408     {
409     toplevel_install = 1;
410     }
411   file += "/cmake_install.cmake";
412   cmGeneratedFileStream fout(file.c_str());
413   fout.SetCopyIfDifferent(true);
414
415   // Write the header.
416   fout << "# Install script for directory: "
417        << this->Makefile->GetCurrentDirectory() << std::endl << std::endl;
418   fout << "# Set the install prefix" << std::endl
419        << "IF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
420        << "  SET(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
421        << "ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
422        << "STRING(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
423        << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
424        << std::endl;
425
426   // Write support code for generating per-configuration install rules.
427   fout <<
428     "# Set the install configuration name.\n"
429     "IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
430     "  IF(BUILD_TYPE)\n"
431     "    STRING(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
432     "           CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
433     "  ELSE(BUILD_TYPE)\n"
434     "    SET(CMAKE_INSTALL_CONFIG_NAME \"" << default_config << "\")\n"
435     "  ENDIF(BUILD_TYPE)\n"
436     "  MESSAGE(STATUS \"Install configuration: "
437     "\\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
438     "ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
439     "\n";
440
441   // Write support code for dealing with component-specific installs.
442   fout <<
443     "# Set the component getting installed.\n"
444     "IF(NOT CMAKE_INSTALL_COMPONENT)\n"
445     "  IF(COMPONENT)\n"
446     "    MESSAGE(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
447     "    SET(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
448     "  ELSE(COMPONENT)\n"
449     "    SET(CMAKE_INSTALL_COMPONENT)\n"
450     "  ENDIF(COMPONENT)\n"
451     "ENDIF(NOT CMAKE_INSTALL_COMPONENT)\n"
452     "\n";
453
454   // Copy user-specified install options to the install code.
455   if(const char* so_no_exe =
456      this->Makefile->GetDefinition("CMAKE_INSTALL_SO_NO_EXE"))
457     {
458     fout <<
459       "# Install shared libraries without execute permission?\n"
460       "IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
461       "  SET(CMAKE_INSTALL_SO_NO_EXE \"" << so_no_exe << "\")\n"
462       "ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
463       "\n";
464     }
465
466   // Ask each install generator to write its code.
467   std::vector<cmInstallGenerator*> const& installers =
468     this->Makefile->GetInstallGenerators();
469   for(std::vector<cmInstallGenerator*>::const_iterator
470         gi = installers.begin();
471       gi != installers.end(); ++gi)
472     {
473     (*gi)->Generate(fout, config, configurationTypes);
474     }
475
476   // Write rules from old-style specification stored in targets.
477   this->GenerateTargetInstallRules(fout, config, configurationTypes);
478
479   // Include install scripts from subdirectories.
480   if(!this->Children.empty())
481     {
482     fout << "IF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
483     fout << "  # Include the install script for each subdirectory.\n";
484     for(std::vector<cmLocalGenerator*>::const_iterator
485           ci = this->Children.begin(); ci != this->Children.end(); ++ci)
486       {
487       if(!(*ci)->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
488         {
489         std::string odir = (*ci)->GetMakefile()->GetStartOutputDirectory();
490         cmSystemTools::ConvertToUnixSlashes(odir);
491         fout << "  INCLUDE(\"" <<  odir.c_str()
492              << "/cmake_install.cmake\")" << std::endl;
493         }
494       }
495     fout << "\n";
496     fout << "ENDIF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n\n";
497     }
498
499   // Record the install manifest.
500   if ( toplevel_install )
501     {
502     fout <<
503       "IF(CMAKE_INSTALL_COMPONENT)\n"
504       "  SET(CMAKE_INSTALL_MANIFEST \"install_manifest_"
505       "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
506       "ELSE(CMAKE_INSTALL_COMPONENT)\n"
507       "  SET(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
508       "ENDIF(CMAKE_INSTALL_COMPONENT)\n\n";
509     fout
510       << "FILE(WRITE \""
511       << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
512       << "\"\")" << std::endl;
513     fout
514       << "FOREACH(file ${CMAKE_INSTALL_MANIFEST_FILES})" << std::endl
515       << "  FILE(APPEND \""
516       << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
517       << "\"${file}\\n\")" << std::endl
518       << "ENDFOREACH(file)" << std::endl;
519     }
520 }
521
522 //----------------------------------------------------------------------------
523 void cmLocalGenerator::GenerateTargetManifest()
524 {
525   // Collect the set of configuration types.
526   std::vector<std::string> configNames;
527   this->Makefile->GetConfigurations(configNames);
528
529   // Add our targets to the manifest for each configuration.
530   cmTargets& targets = this->Makefile->GetTargets();
531   for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
532     {
533     cmTarget& target = t->second;
534     if(configNames.empty())
535       {
536       target.GenerateTargetManifest(0);
537       }
538     else
539       {
540       for(std::vector<std::string>::iterator ci = configNames.begin();
541           ci != configNames.end(); ++ci)
542         {
543         const char* config = ci->c_str();
544         target.GenerateTargetManifest(config);
545         }
546       }
547     }
548 }
549
550 void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
551                                                     const char* lang,
552                                                     cmSourceFile& source,
553                                                     cmGeneratorTarget& target)
554 {
555   std::string objectDir = cmSystemTools::GetFilenamePath(std::string(ofname));
556   objectDir = this->Convert(objectDir.c_str(),START_OUTPUT,SHELL);
557   std::string objectFile = this->Convert(ofname,START_OUTPUT,SHELL);
558   std::string sourceFile =
559     this->Convert(source.GetFullPath().c_str(),START_OUTPUT,SHELL,true);
560   std::string varString = "CMAKE_";
561   varString += lang;
562   varString += "_COMPILE_OBJECT";
563   std::vector<std::string> rules;
564   rules.push_back(this->Makefile->GetRequiredDefinition(varString.c_str()));
565   varString = "CMAKE_";
566   varString += lang;
567   varString += "_FLAGS";
568   std::string flags;
569   flags += this->Makefile->GetSafeDefinition(varString.c_str());
570   flags += " ";
571     {
572     std::vector<std::string> includes;
573     this->GetIncludeDirectories(includes, &target, lang);
574     flags += this->GetIncludeFlags(includes, &target, lang);
575     }
576   flags += this->Makefile->GetDefineFlags();
577
578   // Construct the command lines.
579   cmCustomCommandLines commandLines;
580   std::vector<std::string> commands;
581   cmSystemTools::ExpandList(rules, commands);
582   cmLocalGenerator::RuleVariables vars;
583   vars.Language = lang;
584   vars.Source = sourceFile.c_str();
585   vars.Object = objectFile.c_str();
586   vars.ObjectDir = objectDir.c_str();
587   vars.Flags = flags.c_str();
588   for(std::vector<std::string>::iterator i = commands.begin();
589       i != commands.end(); ++i)
590     {
591     // Expand the full command line string.
592     this->ExpandRuleVariables(*i, vars);
593
594     // Parse the string to get the custom command line.
595     cmCustomCommandLine commandLine;
596     std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
597     for(std::vector<cmStdString>::iterator a = cmd.begin();
598         a != cmd.end(); ++a)
599       {
600       commandLine.push_back(*a);
601       }
602
603     // Store this command line.
604     commandLines.push_back(commandLine);
605     }
606
607   // Check for extra object-file dependencies.
608   std::vector<std::string> depends;
609   const char* additionalDeps = source.GetProperty("OBJECT_DEPENDS");
610   if(additionalDeps)
611     {
612     cmSystemTools::ExpandListArgument(additionalDeps, depends);
613     }
614
615   // Generate a meaningful comment for the command.
616   std::string comment = "Building ";
617   comment += lang;
618   comment += " object ";
619   comment += this->Convert(ofname, START_OUTPUT);
620
621   // Add the custom command to build the object file.
622   this->Makefile->AddCustomCommandToOutput(
623     ofname,
624     depends,
625     source.GetFullPath().c_str(),
626     commandLines,
627     comment.c_str(),
628     this->Makefile->GetStartOutputDirectory()
629     );
630 }
631
632 void cmLocalGenerator::AddBuildTargetRule(const char* llang,
633                                           cmGeneratorTarget& target)
634 {
635   cmStdString objs;
636   std::vector<std::string> objVector;
637   // Add all the sources outputs to the depends of the target
638   std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
639   for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
640       i != classes.end(); ++i)
641     {
642     cmSourceFile* sf = *i;
643     if(!sf->GetCustomCommand() &&
644        !sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
645        !sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
646       {
647       std::string dir_max;
648       dir_max += this->Makefile->GetCurrentOutputDirectory();
649       dir_max += "/";
650       std::string obj = this->GetObjectFileNameWithoutTarget(*sf, dir_max);
651       if(!obj.empty())
652         {
653         std::string ofname = this->Makefile->GetCurrentOutputDirectory();
654         ofname += "/";
655         ofname += obj;
656         objVector.push_back(ofname);
657         this->AddCustomCommandToCreateObject(ofname.c_str(),
658                                              llang, *(*i), target);
659         objs += this->Convert(ofname.c_str(),START_OUTPUT,MAKEFILE);
660         objs += " ";
661         }
662       }
663     }
664   std::string createRule = "CMAKE_";
665   createRule += llang;
666   createRule += target.GetCreateRuleVariable();
667   std::string targetName = target.Target->GetFullName();
668   // Executable :
669   // Shared Library:
670   // Static Library:
671   // Shared Module:
672   std::string linkLibs; // should be set
673   std::string frameworkPath;
674   std::string linkPath;
675   std::string flags; // should be set
676   std::string linkFlags; // should be set
677   this->GetTargetFlags(linkLibs, frameworkPath, linkPath, flags, linkFlags,
678                        &target);
679   linkLibs = frameworkPath + linkPath + linkLibs;
680   cmLocalGenerator::RuleVariables vars;
681   vars.Language = llang;
682   vars.Objects = objs.c_str();
683   vars.ObjectDir = ".";
684   vars.Target = targetName.c_str();
685   vars.LinkLibraries = linkLibs.c_str();
686   vars.Flags = flags.c_str();
687   vars.LinkFlags = linkFlags.c_str();
688
689   std::string langFlags;
690   this->AddLanguageFlags(langFlags, llang, 0);
691   this->AddArchitectureFlags(langFlags, &target, llang, 0);
692   vars.LanguageCompileFlags = langFlags.c_str();
693
694   cmCustomCommandLines commandLines;
695   std::vector<std::string> rules;
696   rules.push_back(this->Makefile->GetRequiredDefinition(createRule.c_str()));
697   std::vector<std::string> commands;
698   cmSystemTools::ExpandList(rules, commands);
699   for(std::vector<std::string>::iterator i = commands.begin();
700       i != commands.end(); ++i)
701     {
702     // Expand the full command line string.
703     this->ExpandRuleVariables(*i, vars);
704     // Parse the string to get the custom command line.
705     cmCustomCommandLine commandLine;
706     std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
707     for(std::vector<cmStdString>::iterator a = cmd.begin();
708         a != cmd.end(); ++a)
709       {
710       commandLine.push_back(*a);
711       }
712
713     // Store this command line.
714     commandLines.push_back(commandLine);
715     }
716   std::string targetFullPath = target.Target->GetFullPath();
717   // Generate a meaningful comment for the command.
718   std::string comment = "Linking ";
719   comment += llang;
720   comment += " target ";
721   comment += this->Convert(targetFullPath.c_str(), START_OUTPUT);
722   this->Makefile->AddCustomCommandToOutput(
723     targetFullPath.c_str(),
724     objVector,
725     0,
726     commandLines,
727     comment.c_str(),
728     this->Makefile->GetStartOutputDirectory()
729     );
730   target.Target->AddSourceFile
731     (this->Makefile->GetSource(targetFullPath.c_str()));
732 }
733
734
735 void cmLocalGenerator
736 ::CreateCustomTargetsAndCommands(std::set<cmStdString> const& lang)
737 {
738   cmGeneratorTargetsType tgts = this->Makefile->GetGeneratorTargets();
739   for(cmGeneratorTargetsType::iterator l = tgts.begin();
740       l != tgts.end(); l++)
741     {
742     if (l->first->IsImported())
743       {
744       continue;
745       }
746     cmGeneratorTarget& target = *l->second;
747     switch(target.GetType())
748       {
749       case cmTarget::STATIC_LIBRARY:
750       case cmTarget::SHARED_LIBRARY:
751       case cmTarget::MODULE_LIBRARY:
752       case cmTarget::EXECUTABLE:
753         {
754         const char* llang = target.Target->GetLinkerLanguage();
755         if(!llang)
756           {
757           cmSystemTools::Error
758             ("CMake can not determine linker language for target: ",
759              target.Target->GetName());
760           return;
761           }
762         // if the language is not in the set lang then create custom
763         // commands to build the target
764         if(lang.count(llang) == 0)
765           {
766           this->AddBuildTargetRule(llang, target);
767           }
768         }
769         break;
770       default:
771         break;
772       }
773     }
774 }
775
776 // List of variables that are replaced when
777 // rules are expanced.  These variables are
778 // replaced in the form <var> with GetSafeDefinition(var).
779 // ${LANG} is replaced in the variable first with all enabled
780 // languages.
781 static const char* ruleReplaceVars[] =
782 {
783   "CMAKE_${LANG}_COMPILER",
784   "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
785   "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
786   "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
787   "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
788   "CMAKE_${LANG}_LINK_FLAGS",
789   "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
790   "CMAKE_${LANG}_ARCHIVE",
791   "CMAKE_AR",
792   "CMAKE_CURRENT_SOURCE_DIR",
793   "CMAKE_CURRENT_BINARY_DIR",
794   "CMAKE_RANLIB",
795   "CMAKE_LINKER",
796   0
797 };
798
799 std::string
800 cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
801                                      const RuleVariables& replaceValues)
802 {
803   if(replaceValues.LinkFlags)
804     {
805     if(variable == "LINK_FLAGS")
806       {
807       return replaceValues.LinkFlags;
808       }
809     }
810   if(replaceValues.Flags)
811     {
812     if(variable == "FLAGS")
813       {
814       return replaceValues.Flags;
815       }
816     }
817
818   if(replaceValues.Source)
819     {
820     if(variable == "SOURCE")
821       {
822       return replaceValues.Source;
823       }
824     }
825   if(replaceValues.PreprocessedSource)
826     {
827     if(variable == "PREPROCESSED_SOURCE")
828       {
829       return replaceValues.PreprocessedSource;
830       }
831     }
832   if(replaceValues.AssemblySource)
833     {
834     if(variable == "ASSEMBLY_SOURCE")
835       {
836       return replaceValues.AssemblySource;
837       }
838     }
839   if(replaceValues.Object)
840     {
841     if(variable == "OBJECT")
842       {
843       return replaceValues.Object;
844       }
845     }
846   if(replaceValues.ObjectDir)
847     {
848     if(variable == "OBJECT_DIR")
849       {
850       return replaceValues.ObjectDir;
851       }
852     }
853   if(replaceValues.Objects)
854     {
855     if(variable == "OBJECTS")
856       {
857       return replaceValues.Objects;
858       }
859     }
860   if(replaceValues.ObjectsQuoted)
861     {
862     if(variable == "OBJECTS_QUOTED")
863       {
864       return replaceValues.ObjectsQuoted;
865       }
866     }
867   if(replaceValues.Defines && variable == "DEFINES")
868     {
869     return replaceValues.Defines;
870     }
871   if(replaceValues.TargetPDB )
872     {
873     if(variable == "TARGET_PDB")
874       {
875       return replaceValues.TargetPDB;
876       }
877     }
878   if(replaceValues.DependencyFile )
879     {
880     if(variable == "DEP_FILE")
881       {
882       return replaceValues.DependencyFile;
883       }
884     }
885
886   if(replaceValues.Target)
887     {
888     if(variable == "TARGET_QUOTED")
889       {
890       std::string targetQuoted = replaceValues.Target;
891       if(targetQuoted.size() && targetQuoted[0] != '\"')
892         {
893         targetQuoted = '\"';
894         targetQuoted += replaceValues.Target;
895         targetQuoted += '\"';
896         }
897       return targetQuoted;
898       }
899     if(variable == "TARGET_UNQUOTED")
900       {
901       std::string unquoted = replaceValues.Target;
902       std::string::size_type sz = unquoted.size();
903       if(sz > 2 && unquoted[0] == '\"' && unquoted[sz-1] == '\"')
904         {
905         unquoted = unquoted.substr(1, sz-2);
906         }
907       return unquoted;
908       }
909     if(replaceValues.LanguageCompileFlags)
910       {
911       if(variable == "LANGUAGE_COMPILE_FLAGS")
912         {
913         return replaceValues.LanguageCompileFlags;
914         }
915       }
916     if(replaceValues.Target)
917       {
918       if(variable == "TARGET")
919         {
920         return replaceValues.Target;
921         }
922       }
923     if(variable == "TARGET_IMPLIB")
924       {
925       return this->TargetImplib;
926       }
927     if(variable == "TARGET_VERSION_MAJOR")
928       {
929       if(replaceValues.TargetVersionMajor)
930         {
931         return replaceValues.TargetVersionMajor;
932         }
933       else
934         {
935         return "0";
936         }
937       }
938     if(variable == "TARGET_VERSION_MINOR")
939       {
940       if(replaceValues.TargetVersionMinor)
941         {
942         return replaceValues.TargetVersionMinor;
943         }
944       else
945         {
946         return "0";
947         }
948       }
949     if(replaceValues.Target)
950       {
951       if(variable == "TARGET_BASE")
952         {
953         // Strip the last extension off the target name.
954         std::string targetBase = replaceValues.Target;
955         std::string::size_type pos = targetBase.rfind(".");
956         if(pos != targetBase.npos)
957           {
958         return targetBase.substr(0, pos);
959           }
960         else
961           {
962           return targetBase;
963           }
964         }
965       }
966     }
967   if(variable == "TARGET_SONAME" || variable == "SONAME_FLAG" ||
968      variable == "TARGET_INSTALLNAME_DIR")
969     {
970     // All these variables depend on TargetSOName
971     if(replaceValues.TargetSOName)
972       {
973       if(variable == "TARGET_SONAME")
974         {
975         return replaceValues.TargetSOName;
976         }
977       if(variable == "SONAME_FLAG" && replaceValues.SONameFlag)
978         {
979         return replaceValues.SONameFlag;
980         }
981       if(replaceValues.TargetInstallNameDir &&
982          variable == "TARGET_INSTALLNAME_DIR")
983         {
984         return replaceValues.TargetInstallNameDir;
985         }
986       }
987     return "";
988     }
989   if(replaceValues.LinkLibraries)
990     {
991     if(variable == "LINK_LIBRARIES")
992       {
993       return replaceValues.LinkLibraries;
994       }
995     }
996   if(replaceValues.Language)
997     {
998     if(variable == "LANGUAGE")
999       {
1000       return replaceValues.Language;
1001       }
1002     }
1003   if(replaceValues.CMTarget)
1004     {
1005     if(variable == "TARGET_NAME")
1006       {
1007       return replaceValues.CMTarget->GetName();
1008       }
1009     if(variable == "TARGET_TYPE")
1010       {
1011       return cmTarget::GetTargetTypeName(replaceValues.CMTarget->GetType());
1012       }
1013     }
1014   if(replaceValues.Output)
1015     {
1016     if(variable == "OUTPUT")
1017       {
1018       return replaceValues.Output;
1019       }
1020     }
1021   if(variable == "CMAKE_COMMAND")
1022     {
1023     const char* cmcommand =
1024       this->GetMakefile()->GetDefinition("CMAKE_COMMAND");
1025     return this->Convert(cmcommand, FULL, SHELL);
1026     }
1027   std::vector<std::string> enabledLanguages;
1028   this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
1029   // loop over language specific replace variables
1030   int pos = 0;
1031   while(ruleReplaceVars[pos])
1032     {
1033     for(std::vector<std::string>::iterator i = enabledLanguages.begin();
1034         i != enabledLanguages.end(); ++i)
1035       {
1036       const char* lang = i->c_str();
1037       std::string actualReplace = ruleReplaceVars[pos];
1038       // If this is the compiler then look for the extra variable
1039       // _COMPILER_ARG1 which must be the first argument to the compiler
1040       const char* compilerArg1 = 0;
1041       if(actualReplace == "CMAKE_${LANG}_COMPILER")
1042         {
1043         std::string arg1 = actualReplace + "_ARG1";
1044         cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
1045         compilerArg1 = this->Makefile->GetDefinition(arg1.c_str());
1046         }
1047       if(actualReplace.find("${LANG}") != actualReplace.npos)
1048         {
1049         cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
1050         }
1051       if(actualReplace == variable)
1052         {
1053         std::string replace =
1054           this->Makefile->GetSafeDefinition(variable.c_str());
1055         // if the variable is not a FLAG then treat it like a path
1056         if(variable.find("_FLAG") == variable.npos)
1057           {
1058           std::string ret = this->ConvertToOutputForExisting(replace.c_str());
1059           // if there is a required first argument to the compiler add it
1060           // to the compiler string
1061           if(compilerArg1)
1062             {
1063             ret += " ";
1064             ret += compilerArg1;
1065             }
1066           return ret;
1067           }
1068         return replace;
1069         }
1070       }
1071     pos++;
1072     }
1073   return variable;
1074 }
1075
1076
1077 void
1078 cmLocalGenerator::ExpandRuleVariables(std::string& s,
1079                                       const RuleVariables& replaceValues)
1080 {
1081   this->InsertRuleLauncher(s, replaceValues.CMTarget,
1082                            replaceValues.RuleLauncher);
1083   std::string::size_type start = s.find('<');
1084   // no variables to expand
1085   if(start == s.npos)
1086     {
1087     return;
1088     }
1089   std::string::size_type pos = 0;
1090   std::string expandedInput;
1091   while(start != s.npos && start < s.size()-2)
1092     {
1093     std::string::size_type end = s.find('>', start);
1094     // if we find a < with no > we are done
1095     if(end == s.npos)
1096       {
1097       return;
1098       }
1099     char c = s[start+1];
1100     // if the next char after the < is not A-Za-z then
1101     // skip it and try to find the next < in the string
1102     if(!isalpha(c))
1103       {
1104       start = s.find('<', start+1);
1105       }
1106     else
1107       {
1108       // extract the var
1109       std::string var = s.substr(start+1,  end - start-1);
1110       std::string replace = this->ExpandRuleVariable(var,
1111                                                      replaceValues);
1112       expandedInput += s.substr(pos, start-pos);
1113       expandedInput += replace;
1114       // move to next one
1115       start = s.find('<', start+var.size()+2);
1116       pos = end+1;
1117       }
1118     }
1119   // add the rest of the input
1120   expandedInput += s.substr(pos, s.size()-pos);
1121   s = expandedInput;
1122 }
1123
1124 //----------------------------------------------------------------------------
1125 const char* cmLocalGenerator::GetRuleLauncher(cmTarget* target,
1126                                               const char* prop)
1127 {
1128   if(target)
1129     {
1130     return target->GetProperty(prop);
1131     }
1132   else
1133     {
1134     return this->Makefile->GetProperty(prop);
1135     }
1136 }
1137
1138 //----------------------------------------------------------------------------
1139 void cmLocalGenerator::InsertRuleLauncher(std::string& s, cmTarget* target,
1140                                           const char* prop)
1141 {
1142   if(const char* val = this->GetRuleLauncher(target, prop))
1143     {
1144     cmOStringStream wrapped;
1145     wrapped << val << " " << s;
1146     s = wrapped.str();
1147     }
1148 }
1149
1150 //----------------------------------------------------------------------------
1151 std::string
1152 cmLocalGenerator::ConvertToOutputForExistingCommon(const char* remote,
1153                                                    std::string const& result)
1154 {
1155   // If this is a windows shell, the result has a space, and the path
1156   // already exists, we can use a short-path to reference it without a
1157   // space.
1158   if(this->WindowsShell && result.find(' ') != result.npos &&
1159      cmSystemTools::FileExists(remote))
1160     {
1161     std::string tmp;
1162     if(cmSystemTools::GetShortPath(remote, tmp))
1163       {
1164       return this->Convert(tmp.c_str(), NONE, SHELL, true);
1165       }
1166     }
1167
1168   // Otherwise, leave it unchanged.
1169   return result;
1170 }
1171
1172 //----------------------------------------------------------------------------
1173 std::string
1174 cmLocalGenerator::ConvertToOutputForExisting(const char* remote,
1175                                              RelativeRoot local)
1176 {
1177   // Perform standard conversion.
1178   std::string result = this->Convert(remote, local, SHELL, true);
1179
1180   // Consider short-path.
1181   return this->ConvertToOutputForExistingCommon(remote, result);
1182 }
1183
1184 //----------------------------------------------------------------------------
1185 std::string
1186 cmLocalGenerator::ConvertToOutputForExisting(RelativeRoot remote,
1187                                              const char* local)
1188 {
1189   // Perform standard conversion.
1190   std::string result = this->Convert(remote, local, SHELL, true);
1191
1192   // Consider short-path.
1193   const char* remotePath = this->GetRelativeRootPath(remote);
1194   return this->ConvertToOutputForExistingCommon(remotePath, result);
1195 }
1196
1197 //----------------------------------------------------------------------------
1198 std::string
1199 cmLocalGenerator::ConvertToIncludeReference(std::string const& path)
1200 {
1201   return this->ConvertToOutputForExisting(path.c_str());
1202 }
1203
1204 //----------------------------------------------------------------------------
1205 std::string cmLocalGenerator::GetIncludeFlags(
1206                                      const std::vector<std::string> &includes,
1207                                      cmGeneratorTarget* target,
1208                                      const char* lang, bool forResponseFile,
1209                                      const char *config)
1210 {
1211   if(!lang)
1212     {
1213     return "";
1214     }
1215
1216   cmOStringStream includeFlags;
1217
1218   std::string flagVar = "CMAKE_INCLUDE_FLAG_";
1219   flagVar += lang;
1220   const char* includeFlag =
1221     this->Makefile->GetSafeDefinition(flagVar.c_str());
1222   flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
1223   flagVar += lang;
1224   const char* sep = this->Makefile->GetDefinition(flagVar.c_str());
1225   bool quotePaths = false;
1226   if(this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS"))
1227     {
1228     quotePaths = true;
1229     }
1230   bool repeatFlag = true;
1231   // should the include flag be repeated like ie. -IA -IB
1232   if(!sep)
1233     {
1234     sep = " ";
1235     }
1236   else
1237     {
1238     // if there is a separator then the flag is not repeated but is only
1239     // given once i.e.  -classpath a:b:c
1240     repeatFlag = false;
1241     }
1242
1243   // Support special system include flag if it is available and the
1244   // normal flag is repeated for each directory.
1245   std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
1246   sysFlagVar += lang;
1247   const char* sysIncludeFlag = 0;
1248   if(repeatFlag)
1249     {
1250     sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar.c_str());
1251     }
1252
1253   bool flagUsed = false;
1254   std::set<cmStdString> emitted;
1255 #ifdef __APPLE__
1256   emitted.insert("/System/Library/Frameworks");
1257 #endif
1258   std::vector<std::string>::const_iterator i;
1259   for(i = includes.begin(); i != includes.end(); ++i)
1260     {
1261     if(this->Makefile->IsOn("APPLE")
1262        && cmSystemTools::IsPathToFramework(i->c_str()))
1263       {
1264       std::string frameworkDir = *i;
1265       frameworkDir += "/../";
1266       frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
1267       if(emitted.insert(frameworkDir).second)
1268         {
1269         OutputFormat format = forResponseFile? RESPONSE : SHELL;
1270         includeFlags
1271           << "-F" << this->Convert(frameworkDir.c_str(),
1272                                    START_OUTPUT, format, true)
1273           << " ";
1274         }
1275       continue;
1276       }
1277
1278     if(!flagUsed || repeatFlag)
1279       {
1280       if(sysIncludeFlag && target &&
1281          target->IsSystemIncludeDirectory(i->c_str(), config))
1282         {
1283         includeFlags << sysIncludeFlag;
1284         }
1285       else
1286         {
1287         includeFlags << includeFlag;
1288         }
1289       flagUsed = true;
1290       }
1291     std::string includePath;
1292     if(forResponseFile)
1293       {
1294       includePath = this->Convert(i->c_str(), START_OUTPUT,
1295                                   RESPONSE, true);
1296       }
1297     else
1298       {
1299       includePath = this->ConvertToIncludeReference(*i);
1300       }
1301     if(quotePaths && includePath.size() && includePath[0] != '\"')
1302       {
1303       includeFlags << "\"";
1304       }
1305     includeFlags << includePath;
1306     if(quotePaths && includePath.size() && includePath[0] != '\"')
1307       {
1308       includeFlags << "\"";
1309       }
1310     includeFlags << sep;
1311     }
1312   std::string flags = includeFlags.str();
1313   // remove trailing separators
1314   if((sep[0] != ' ') && flags.size()>0 && flags[flags.size()-1] == sep[0])
1315     {
1316     flags[flags.size()-1] = ' ';
1317     }
1318   return flags;
1319 }
1320
1321 //----------------------------------------------------------------------------
1322 void cmLocalGenerator::AddCompileDefinitions(std::set<std::string>& defines,
1323                                              cmTarget* target,
1324                                              const char* config)
1325 {
1326   std::vector<std::string> targetDefines;
1327   target->GetCompileDefinitions(targetDefines,
1328                                config);
1329   this->AppendDefines(defines, targetDefines);
1330 }
1331
1332 //----------------------------------------------------------------------------
1333 void cmLocalGenerator::AddCompileOptions(
1334   std::string& flags, cmTarget* target,
1335   const char* lang, const char* config
1336   )
1337 {
1338   std::string langFlagRegexVar = std::string("CMAKE_")+lang+"_FLAG_REGEX";
1339   if(const char* langFlagRegexStr =
1340      this->Makefile->GetDefinition(langFlagRegexVar.c_str()))
1341     {
1342     // Filter flags acceptable to this language.
1343     cmsys::RegularExpression r(langFlagRegexStr);
1344     std::vector<std::string> opts;
1345     if(const char* targetFlags = target->GetProperty("COMPILE_FLAGS"))
1346       {
1347       cmSystemTools::ParseWindowsCommandLine(targetFlags, opts);
1348       }
1349     target->GetCompileOptions(opts, config);
1350     for(std::vector<std::string>::const_iterator i = opts.begin();
1351         i != opts.end(); ++i)
1352       {
1353       if(r.find(i->c_str()))
1354         {
1355         // (Re-)Escape this flag.  COMPILE_FLAGS were already parsed
1356         // as a command line above, and COMPILE_OPTIONS are escaped.
1357         this->AppendFlagEscape(flags, i->c_str());
1358         }
1359       }
1360     }
1361   else
1362     {
1363     // Use all flags.
1364     if(const char* targetFlags = target->GetProperty("COMPILE_FLAGS"))
1365       {
1366       // COMPILE_FLAGS are not escaped for historical reasons.
1367       this->AppendFlags(flags, targetFlags);
1368       }
1369     std::vector<std::string> opts;
1370     target->GetCompileOptions(opts, config);
1371     for(std::vector<std::string>::const_iterator i = opts.begin();
1372         i != opts.end(); ++i)
1373       {
1374       // COMPILE_OPTIONS are escaped.
1375       this->AppendFlagEscape(flags, i->c_str());
1376       }
1377     }
1378 }
1379
1380 //----------------------------------------------------------------------------
1381 void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
1382                                              cmGeneratorTarget* target,
1383                                              const char* lang,
1384                                              const char *config,
1385                                              bool stripImplicitInclDirs
1386                                             )
1387 {
1388   // Need to decide whether to automatically include the source and
1389   // binary directories at the beginning of the include path.
1390   bool includeSourceDir = false;
1391   bool includeBinaryDir = false;
1392
1393   // When automatic include directories are requested for a build then
1394   // include the source and binary directories at the beginning of the
1395   // include path to approximate include file behavior for an
1396   // in-source build.  This does not account for the case of a source
1397   // file in a subdirectory of the current source directory but we
1398   // cannot fix this because not all native build tools support
1399   // per-source-file include paths.
1400   if(this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR"))
1401     {
1402     includeSourceDir = true;
1403     includeBinaryDir = true;
1404     }
1405
1406   // CMake versions below 2.0 would add the source tree to the -I path
1407   // automatically.  Preserve compatibility.
1408   if(this->NeedBackwardsCompatibility(1,9))
1409     {
1410     includeSourceDir = true;
1411     }
1412
1413   // Hack for VTK 4.0 - 4.4 which depend on the old behavior but do
1414   // not set the backwards compatibility level automatically.
1415   const char* vtkSourceDir =
1416     this->Makefile->GetDefinition("VTK_SOURCE_DIR");
1417   if(vtkSourceDir)
1418     {
1419     const char* vtk_major =
1420       this->Makefile->GetDefinition("VTK_MAJOR_VERSION");
1421     const char* vtk_minor =
1422       this->Makefile->GetDefinition("VTK_MINOR_VERSION");
1423     vtk_major = vtk_major? vtk_major : "4";
1424     vtk_minor = vtk_minor? vtk_minor : "4";
1425     int vmajor = 0;
1426     int vminor = 0;
1427     if(sscanf(vtk_major, "%d", &vmajor) &&
1428        sscanf(vtk_minor, "%d", &vminor) && vmajor == 4 && vminor <= 4)
1429       {
1430       includeSourceDir = true;
1431       }
1432     }
1433
1434   // Do not repeat an include path.
1435   std::set<cmStdString> emitted;
1436
1437   // Store the automatic include paths.
1438   if(includeBinaryDir)
1439     {
1440     if(emitted.find(
1441                 this->Makefile->GetStartOutputDirectory()) == emitted.end())
1442       {
1443       dirs.push_back(this->Makefile->GetStartOutputDirectory());
1444       emitted.insert(this->Makefile->GetStartOutputDirectory());
1445       }
1446     }
1447   if(includeSourceDir)
1448     {
1449     if(emitted.find(this->Makefile->GetStartDirectory()) == emitted.end())
1450       {
1451       dirs.push_back(this->Makefile->GetStartDirectory());
1452       emitted.insert(this->Makefile->GetStartDirectory());
1453       }
1454     }
1455
1456   if(!target)
1457     {
1458     return;
1459     }
1460
1461   std::vector<std::string> implicitDirs;
1462   // Load implicit include directories for this language.
1463   std::string impDirVar = "CMAKE_";
1464   impDirVar += lang;
1465   impDirVar += "_IMPLICIT_INCLUDE_DIRECTORIES";
1466   if(const char* value = this->Makefile->GetDefinition(impDirVar.c_str()))
1467     {
1468     std::vector<std::string> impDirVec;
1469     cmSystemTools::ExpandListArgument(value, impDirVec);
1470     for(std::vector<std::string>::const_iterator i = impDirVec.begin();
1471         i != impDirVec.end(); ++i)
1472       {
1473       emitted.insert(*i);
1474       if (!stripImplicitInclDirs)
1475         {
1476         implicitDirs.push_back(*i);
1477         }
1478       }
1479     }
1480
1481   // Get the target-specific include directories.
1482   std::vector<std::string> includes;
1483
1484   includes = target->GetIncludeDirectories(config);
1485
1486   // Support putting all the in-project include directories first if
1487   // it is requested by the project.
1488   if(this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"))
1489     {
1490     const char* topSourceDir = this->Makefile->GetHomeDirectory();
1491     const char* topBinaryDir = this->Makefile->GetHomeOutputDirectory();
1492     for(std::vector<std::string>::const_iterator i = includes.begin();
1493         i != includes.end(); ++i)
1494       {
1495       // Emit this directory only if it is a subdirectory of the
1496       // top-level source or binary tree.
1497       if(cmSystemTools::ComparePath(i->c_str(), topSourceDir) ||
1498          cmSystemTools::ComparePath(i->c_str(), topBinaryDir) ||
1499          cmSystemTools::IsSubDirectory(i->c_str(), topSourceDir) ||
1500          cmSystemTools::IsSubDirectory(i->c_str(), topBinaryDir))
1501         {
1502         if(emitted.insert(*i).second)
1503           {
1504           dirs.push_back(*i);
1505           }
1506         }
1507       }
1508     }
1509
1510   // Construct the final ordered include directory list.
1511   for(std::vector<std::string>::const_iterator i = includes.begin();
1512       i != includes.end(); ++i)
1513     {
1514     if(emitted.insert(*i).second)
1515       {
1516       dirs.push_back(*i);
1517       }
1518     }
1519
1520   for(std::vector<std::string>::const_iterator i = implicitDirs.begin();
1521       i != implicitDirs.end(); ++i)
1522     {
1523     if(std::find(includes.begin(), includes.end(), *i) != includes.end())
1524       {
1525       dirs.push_back(*i);
1526       }
1527     }
1528 }
1529
1530 void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags,
1531                                              std::string const& config,
1532                                              cmTarget* target)
1533 {
1534   this->AppendFlags(flags,
1535     this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS"));
1536   if(!config.empty())
1537     {
1538     std::string name = "CMAKE_STATIC_LINKER_FLAGS_" + config;
1539     this->AppendFlags(flags, this->Makefile->GetSafeDefinition(name.c_str()));
1540     }
1541   this->AppendFlags(flags, target->GetProperty("STATIC_LIBRARY_FLAGS"));
1542   if(!config.empty())
1543     {
1544     std::string name = "STATIC_LIBRARY_FLAGS_" + config;
1545     this->AppendFlags(flags, target->GetProperty(name.c_str()));
1546     }
1547 }
1548
1549 void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
1550                                  std::string& flags,
1551                                  std::string& linkFlags,
1552                                  std::string& frameworkPath,
1553                                  std::string& linkPath,
1554                                  cmGeneratorTarget* target)
1555 {
1556   std::string buildType =
1557     this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
1558   buildType = cmSystemTools::UpperCase(buildType);
1559   const char* libraryLinkVariable =
1560     "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
1561
1562   switch(target->GetType())
1563     {
1564     case cmTarget::STATIC_LIBRARY:
1565       this->GetStaticLibraryFlags(linkFlags, buildType, target->Target);
1566       break;
1567     case cmTarget::MODULE_LIBRARY:
1568       libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
1569     case cmTarget::SHARED_LIBRARY:
1570       {
1571       linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
1572       linkFlags += " ";
1573       if(!buildType.empty())
1574         {
1575         std::string build = libraryLinkVariable;
1576         build += "_";
1577         build += buildType;
1578         linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
1579         linkFlags += " ";
1580         }
1581       if(this->Makefile->IsOn("WIN32") &&
1582          !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")))
1583         {
1584         const std::vector<cmSourceFile*>& sources = target->GetSourceFiles();
1585         for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
1586             i != sources.end(); ++i)
1587           {
1588           cmSourceFile* sf = *i;
1589           if(sf->GetExtension() == "def")
1590             {
1591             linkFlags +=
1592               this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
1593             linkFlags += this->Convert(sf->GetFullPath().c_str(),
1594                                        FULL, SHELL);
1595             linkFlags += " ";
1596             }
1597           }
1598         }
1599       const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
1600       if(targetLinkFlags)
1601         {
1602         linkFlags += targetLinkFlags;
1603         linkFlags += " ";
1604         }
1605       if(!buildType.empty())
1606         {
1607         std::string configLinkFlags = "LINK_FLAGS_";
1608         configLinkFlags += buildType;
1609         targetLinkFlags = target->GetProperty(configLinkFlags.c_str());
1610         if(targetLinkFlags)
1611           {
1612           linkFlags += targetLinkFlags;
1613           linkFlags += " ";
1614           }
1615         }
1616       this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath,
1617                                 *target, false);
1618       }
1619       break;
1620     case cmTarget::EXECUTABLE:
1621       {
1622       linkFlags +=
1623         this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
1624       linkFlags += " ";
1625       if(!buildType.empty())
1626         {
1627         std::string build = "CMAKE_EXE_LINKER_FLAGS_";
1628         build += buildType;
1629         linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
1630         linkFlags += " ";
1631         }
1632       const char* linkLanguage = target->Target->GetLinkerLanguage();
1633       if(!linkLanguage)
1634         {
1635         cmSystemTools::Error
1636           ("CMake can not determine linker language for target: ",
1637            target->Target->GetName());
1638         return;
1639         }
1640       this->AddLanguageFlags(flags, linkLanguage, buildType.c_str());
1641       this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath,
1642                                 *target, false);
1643       if(cmSystemTools::IsOn
1644          (this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
1645         {
1646         std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_")
1647           + linkLanguage + std::string("_FLAGS");
1648         linkFlags += this->Makefile->GetSafeDefinition(sFlagVar.c_str());
1649         linkFlags += " ";
1650         }
1651       if ( target->GetPropertyAsBool("WIN32_EXECUTABLE") )
1652         {
1653         linkFlags +=
1654           this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
1655         linkFlags += " ";
1656         }
1657       else
1658         {
1659         linkFlags +=
1660           this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
1661         linkFlags += " ";
1662         }
1663       if (target->Target->IsExecutableWithExports())
1664         {
1665         std::string exportFlagVar = "CMAKE_EXE_EXPORTS_";
1666         exportFlagVar += linkLanguage;
1667         exportFlagVar += "_FLAG";
1668
1669         linkFlags +=
1670           this->Makefile->GetSafeDefinition(exportFlagVar.c_str());
1671         linkFlags += " ";
1672         }
1673       const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
1674       if(targetLinkFlags)
1675         {
1676         linkFlags += targetLinkFlags;
1677         linkFlags += " ";
1678         }
1679       if(!buildType.empty())
1680         {
1681         std::string configLinkFlags = "LINK_FLAGS_";
1682         configLinkFlags += buildType;
1683         targetLinkFlags = target->GetProperty(configLinkFlags.c_str());
1684         if(targetLinkFlags)
1685           {
1686           linkFlags += targetLinkFlags;
1687           linkFlags += " ";
1688           }
1689         }
1690       }
1691       break;
1692     default:
1693       break;
1694     }
1695 }
1696
1697 std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib)
1698 {
1699 #if defined(_WIN32) && !defined(__CYGWIN__)
1700   // Work-ardound command line parsing limitations in MSVC 6.0 and
1701   // Watcom.
1702   if(this->Makefile->IsOn("MSVC60") || this->Makefile->IsOn("WATCOM"))
1703     {
1704     // Search for the last space.
1705     std::string::size_type pos = lib.rfind(' ');
1706     if(pos != lib.npos)
1707       {
1708       // Find the slash after the last space, if any.
1709       pos = lib.find('/', pos);
1710
1711       // Convert the portion of the path with a space to a short path.
1712       std::string sp;
1713       if(cmSystemTools::GetShortPath(lib.substr(0, pos).c_str(), sp))
1714         {
1715         // Append the rest of the path with no space.
1716         sp += lib.substr(pos);
1717
1718         // Convert to an output path.
1719         return this->Convert(sp.c_str(), NONE, SHELL);
1720         }
1721       }
1722     }
1723 #endif
1724
1725   // Normal behavior.
1726   return this->Convert(lib.c_str(), START_OUTPUT, SHELL);
1727 }
1728
1729 /**
1730  * Output the linking rules on a command line.  For executables,
1731  * targetLibrary should be a NULL pointer.  For libraries, it should point
1732  * to the name of the library.  This will not link a library against itself.
1733  */
1734 void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
1735                                            std::string& frameworkPath,
1736                                            std::string& linkPath,
1737                                            cmGeneratorTarget &tgt,
1738                                            bool relink)
1739 {
1740   cmOStringStream fout;
1741   const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
1742   cmComputeLinkInformation* pcli = tgt.Target->GetLinkInformation(config);
1743   if(!pcli)
1744     {
1745     return;
1746     }
1747   cmComputeLinkInformation& cli = *pcli;
1748
1749   // Collect library linking flags command line options.
1750   std::string linkLibs;
1751
1752   const char* linkLanguage = cli.GetLinkLanguage();
1753
1754   std::string libPathFlag =
1755     this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
1756   std::string libPathTerminator =
1757     this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
1758
1759   // Flags to link an executable to shared libraries.
1760   std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
1761   linkFlagsVar += linkLanguage;
1762   linkFlagsVar += "_FLAGS";
1763   if( tgt.GetType() == cmTarget::EXECUTABLE )
1764     {
1765     linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar.c_str());
1766     linkLibs += " ";
1767     }
1768
1769   // Append the framework search path flags.
1770   std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
1771   for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
1772       fdi != fwDirs.end(); ++fdi)
1773     {
1774     frameworkPath += "-F";
1775     frameworkPath += this->Convert(fdi->c_str(), NONE, SHELL, false);
1776     frameworkPath += " ";
1777     }
1778
1779   // Append the library search path flags.
1780   std::vector<std::string> const& libDirs = cli.GetDirectories();
1781   for(std::vector<std::string>::const_iterator libDir = libDirs.begin();
1782       libDir != libDirs.end(); ++libDir)
1783     {
1784     std::string libpath = this->ConvertToOutputForExisting(libDir->c_str());
1785     linkPath += " " + libPathFlag;
1786     linkPath += libpath;
1787     linkPath += libPathTerminator;
1788     linkPath += " ";
1789     }
1790
1791   // Append the link items.
1792   typedef cmComputeLinkInformation::ItemVector ItemVector;
1793   ItemVector const& items = cli.GetItems();
1794   for(ItemVector::const_iterator li = items.begin(); li != items.end(); ++li)
1795     {
1796     if(li->IsPath)
1797       {
1798       linkLibs += this->ConvertToLinkReference(li->Value);
1799       }
1800     else
1801       {
1802       linkLibs += li->Value;
1803       }
1804     linkLibs += " ";
1805     }
1806
1807   // Write the library flags to the build rule.
1808   fout << linkLibs;
1809
1810   // Get the RPATH entries.
1811   std::vector<std::string> runtimeDirs;
1812   cli.GetRPath(runtimeDirs, relink);
1813
1814   // Check what kind of rpath flags to use.
1815   if(cli.GetRuntimeSep().empty())
1816     {
1817     // Each rpath entry gets its own option ("-R a -R b -R c")
1818     std::string rpath;
1819     for(std::vector<std::string>::iterator ri = runtimeDirs.begin();
1820         ri != runtimeDirs.end(); ++ri)
1821       {
1822       rpath += cli.GetRuntimeFlag();
1823       rpath += this->Convert(ri->c_str(), NONE, SHELL, false);
1824       rpath += " ";
1825       }
1826     fout << rpath;
1827     }
1828   else
1829     {
1830     // All rpath entries are combined ("-Wl,-rpath,a:b:c").
1831     std::string rpath = cli.GetRPathString(relink);
1832
1833     // Store the rpath option in the stream.
1834     if(!rpath.empty())
1835       {
1836       fout << cli.GetRuntimeFlag();
1837       fout << this->EscapeForShell(rpath.c_str(), true);
1838       fout << " ";
1839       }
1840     }
1841
1842   // Add the linker runtime search path if any.
1843   std::string rpath_link = cli.GetRPathLinkString();
1844   if(!cli.GetRPathLinkFlag().empty() && !rpath_link.empty())
1845     {
1846     fout << cli.GetRPathLinkFlag();
1847     fout << this->EscapeForShell(rpath_link.c_str(), true);
1848     fout << " ";
1849     }
1850
1851   // Add standard libraries for this language.
1852   std::string standardLibsVar = "CMAKE_";
1853   standardLibsVar += cli.GetLinkLanguage();
1854   standardLibsVar += "_STANDARD_LIBRARIES";
1855   if(const char* stdLibs =
1856      this->Makefile->GetDefinition(standardLibsVar.c_str()))
1857     {
1858     fout << stdLibs << " ";
1859     }
1860
1861   linkLibraries = fout.str();
1862 }
1863
1864
1865 //----------------------------------------------------------------------------
1866 void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
1867                                             cmGeneratorTarget* target,
1868                                             const char *lang,
1869                                             const char* config)
1870 {
1871   // Only add Mac OS X specific flags on Darwin platforms (OSX and iphone):
1872   if(!this->Makefile->IsOn("APPLE"))
1873     {
1874     return;
1875     }
1876
1877   if(this->EmitUniversalBinaryFlags)
1878     {
1879     std::vector<std::string> archs;
1880     target->GetAppleArchs(config, archs);
1881     const char* sysroot = this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
1882     if(sysroot && sysroot[0] == '/' && !sysroot[1])
1883       { sysroot = 0; }
1884     std::string sysrootFlagVar =
1885       std::string("CMAKE_") + lang + "_SYSROOT_FLAG";
1886     const char* sysrootFlag =
1887       this->Makefile->GetDefinition(sysrootFlagVar.c_str());
1888     const char* deploymentTarget =
1889       this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
1890     std::string deploymentTargetFlagVar =
1891       std::string("CMAKE_") + lang + "_OSX_DEPLOYMENT_TARGET_FLAG";
1892     const char* deploymentTargetFlag =
1893       this->Makefile->GetDefinition(deploymentTargetFlagVar.c_str());
1894     if(!archs.empty() && lang && (lang[0] =='C' || lang[0] == 'F'))
1895       {
1896       for(std::vector<std::string>::iterator i = archs.begin();
1897           i != archs.end(); ++i)
1898         {
1899         flags += " -arch ";
1900         flags += *i;
1901         }
1902       }
1903
1904     if(sysrootFlag && *sysrootFlag && sysroot && *sysroot)
1905       {
1906       flags += " ";
1907       flags += sysrootFlag;
1908       flags += " ";
1909       flags += sysroot;
1910       }
1911
1912     if (deploymentTargetFlag && *deploymentTargetFlag &&
1913         deploymentTarget && *deploymentTarget)
1914       {
1915       flags += " ";
1916       flags += deploymentTargetFlag;
1917       flags += deploymentTarget;
1918       }
1919     }
1920 }
1921
1922
1923 //----------------------------------------------------------------------------
1924 void cmLocalGenerator::AddLanguageFlags(std::string& flags,
1925                                         const char* lang,
1926                                         const char* config)
1927 {
1928   // Add language-specific flags.
1929   std::string flagsVar = "CMAKE_";
1930   flagsVar += lang;
1931   flagsVar += "_FLAGS";
1932   this->AddConfigVariableFlags(flags, flagsVar.c_str(), config);
1933 }
1934
1935 //----------------------------------------------------------------------------
1936 bool cmLocalGenerator::GetRealDependency(const char* inName,
1937                                          const char* config,
1938                                          std::string& dep)
1939 {
1940   // Older CMake code may specify the dependency using the target
1941   // output file rather than the target name.  Such code would have
1942   // been written before there was support for target properties that
1943   // modify the name so stripping down to just the file name should
1944   // produce the target name in this case.
1945   std::string name = cmSystemTools::GetFilenameName(inName);
1946
1947   // If the input name is the empty string, there is no real
1948   // dependency. Short-circuit the other checks:
1949   if(name == "")
1950     {
1951     return false;
1952     }
1953
1954   if(cmSystemTools::GetFilenameLastExtension(name) == ".exe")
1955     {
1956     name = cmSystemTools::GetFilenameWithoutLastExtension(name);
1957     }
1958
1959   // Look for a CMake target with the given name.
1960   if(cmTarget* target = this->Makefile->FindTargetToUse(name.c_str()))
1961     {
1962     // make sure it is not just a coincidence that the target name
1963     // found is part of the inName
1964     if(cmSystemTools::FileIsFullPath(inName))
1965       {
1966       std::string tLocation;
1967       if(target->GetType() >= cmTarget::EXECUTABLE &&
1968          target->GetType() <= cmTarget::MODULE_LIBRARY)
1969         {
1970         tLocation = target->GetLocation(config);
1971         tLocation = cmSystemTools::GetFilenamePath(tLocation);
1972         tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
1973         }
1974       std::string depLocation = cmSystemTools::GetFilenamePath(
1975         std::string(inName));
1976       depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
1977       if(depLocation != tLocation)
1978         {
1979         // it is a full path to a depend that has the same name
1980         // as a target but is in a different location so do not use
1981         // the target as the depend
1982         dep = inName;
1983         return true;
1984         }
1985       }
1986     switch (target->GetType())
1987       {
1988       case cmTarget::EXECUTABLE:
1989       case cmTarget::STATIC_LIBRARY:
1990       case cmTarget::SHARED_LIBRARY:
1991       case cmTarget::MODULE_LIBRARY:
1992       case cmTarget::UNKNOWN_LIBRARY:
1993         dep = target->GetLocation(config);
1994         return true;
1995       case cmTarget::OBJECT_LIBRARY:
1996         // An object library has no single file on which to depend.
1997         // This was listed to get the target-level dependency.
1998         return false;
1999       case cmTarget::UTILITY:
2000       case cmTarget::GLOBAL_TARGET:
2001         // A utility target has no file on which to depend.  This was listed
2002         // only to get the target-level dependency.
2003         return false;
2004       }
2005     }
2006
2007   // The name was not that of a CMake target.  It must name a file.
2008   if(cmSystemTools::FileIsFullPath(inName))
2009     {
2010     // This is a full path.  Return it as given.
2011     dep = inName;
2012     return true;
2013     }
2014
2015   // Check for a source file in this directory that matches the
2016   // dependency.
2017   if(cmSourceFile* sf = this->Makefile->GetSource(inName))
2018     {
2019     dep = sf->GetFullPath();
2020     return true;
2021     }
2022
2023   // Treat the name as relative to the source directory in which it
2024   // was given.
2025   dep = this->Makefile->GetCurrentDirectory();
2026   dep += "/";
2027   dep += inName;
2028   return true;
2029 }
2030
2031 //----------------------------------------------------------------------------
2032 void cmLocalGenerator::AddSharedFlags(std::string& flags,
2033                                       const char* lang,
2034                                       bool shared)
2035 {
2036   std::string flagsVar;
2037
2038   // Add flags for dealing with shared libraries for this language.
2039   if(shared)
2040     {
2041     flagsVar = "CMAKE_SHARED_LIBRARY_";
2042     flagsVar += lang;
2043     flagsVar += "_FLAGS";
2044     this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
2045     }
2046 }
2047
2048 static void AddVisibilityCompileOption(std::string &flags, cmTarget* target,
2049                                        cmLocalGenerator *lg, const char *lang)
2050 {
2051   std::string l(lang);
2052   std::string compileOption = "CMAKE_" + l + "_COMPILE_OPTIONS_VISIBILITY";
2053   const char *opt = lg->GetMakefile()->GetDefinition(compileOption.c_str());
2054   if (!opt)
2055     {
2056     return;
2057     }
2058   std::string flagDefine = l + "_VISIBILITY_PRESET";
2059
2060   const char *prop = target->GetProperty(flagDefine.c_str());
2061   if (!prop)
2062     {
2063     return;
2064     }
2065   if (strcmp(prop, "hidden") != 0
2066       && strcmp(prop, "default") != 0
2067       && strcmp(prop, "protected") != 0
2068       && strcmp(prop, "internal") != 0 )
2069     {
2070     cmOStringStream e;
2071     e << "Target " << target->GetName() << " uses unsupported value \""
2072       << prop << "\" for " << flagDefine << ".";
2073     cmSystemTools::Error(e.str().c_str());
2074     return;
2075     }
2076   std::string option = std::string(opt) + prop;
2077   lg->AppendFlags(flags, option.c_str());
2078 }
2079
2080 static void AddInlineVisibilityCompileOption(std::string &flags,
2081                                        cmTarget* target,
2082                                        cmLocalGenerator *lg)
2083 {
2084   std::string compileOption
2085                 = "CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN";
2086   const char *opt = lg->GetMakefile()->GetDefinition(compileOption.c_str());
2087   if (!opt)
2088     {
2089     return;
2090     }
2091
2092   bool prop = target->GetPropertyAsBool("VISIBILITY_INLINES_HIDDEN");
2093   if (!prop)
2094     {
2095     return;
2096     }
2097   lg->AppendFlags(flags, opt);
2098 }
2099
2100 //----------------------------------------------------------------------------
2101 void cmLocalGenerator
2102 ::AddVisibilityPresetFlags(std::string &flags, cmTarget* target,
2103                             const char *lang)
2104 {
2105   int targetType = target->GetType();
2106   bool suitableTarget = ((targetType == cmTarget::SHARED_LIBRARY)
2107                       || (targetType == cmTarget::MODULE_LIBRARY)
2108                       || (target->IsExecutableWithExports()));
2109
2110   if (!suitableTarget)
2111     {
2112     return;
2113     }
2114
2115   if (!lang)
2116     {
2117     return;
2118     }
2119   AddVisibilityCompileOption(flags, target, this, lang);
2120   AddInlineVisibilityCompileOption(flags, target, this);
2121 }
2122
2123 //----------------------------------------------------------------------------
2124 void cmLocalGenerator::AddCMP0018Flags(std::string &flags, cmTarget* target,
2125                                        std::string const& lang,
2126                                        const char *config)
2127 {
2128   int targetType = target->GetType();
2129
2130   bool shared = ((targetType == cmTarget::SHARED_LIBRARY) ||
2131                   (targetType == cmTarget::MODULE_LIBRARY));
2132
2133   if (this->GetShouldUseOldFlags(shared, lang))
2134     {
2135     this->AddSharedFlags(flags, lang.c_str(), shared);
2136     }
2137   else
2138     {
2139     if (target->GetType() == cmTarget::OBJECT_LIBRARY)
2140       {
2141       if (target->GetPropertyAsBool("POSITION_INDEPENDENT_CODE"))
2142         {
2143         this->AddPositionIndependentFlags(flags, lang, targetType);
2144         }
2145       return;
2146       }
2147
2148     if (target->GetLinkInterfaceDependentBoolProperty(
2149                                                 "POSITION_INDEPENDENT_CODE",
2150                                                 config))
2151       {
2152       this->AddPositionIndependentFlags(flags, lang, targetType);
2153       }
2154     if (shared)
2155       {
2156       this->AppendFeatureOptions(flags, lang.c_str(), "DLL");
2157       }
2158     }
2159 }
2160
2161 //----------------------------------------------------------------------------
2162 bool cmLocalGenerator::GetShouldUseOldFlags(bool shared,
2163                                             const std::string &lang) const
2164 {
2165   std::string originalFlags =
2166     this->GlobalGenerator->GetSharedLibFlagsForLanguage(lang);
2167   if (shared)
2168     {
2169     std::string flagsVar = "CMAKE_SHARED_LIBRARY_";
2170     flagsVar += lang;
2171     flagsVar += "_FLAGS";
2172     const char* flags =
2173         this->Makefile->GetSafeDefinition(flagsVar.c_str());
2174
2175     if (flags && flags != originalFlags)
2176       {
2177       switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0018))
2178         {
2179         case cmPolicies::WARN:
2180         {
2181           cmOStringStream e;
2182           e << "Variable " << flagsVar << " has been modified. CMake "
2183             "will ignore the POSITION_INDEPENDENT_CODE target property for "
2184             "shared libraries and will use the " << flagsVar << " variable "
2185             "instead.  This may cause errors if the original content of "
2186             << flagsVar << " was removed.\n"
2187             << this->Makefile->GetPolicies()->GetPolicyWarning(
2188                                                       cmPolicies::CMP0018);
2189
2190           this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
2191           // fall through to OLD behaviour
2192         }
2193         case cmPolicies::OLD:
2194           return true;
2195         case cmPolicies::REQUIRED_IF_USED:
2196         case cmPolicies::REQUIRED_ALWAYS:
2197         case cmPolicies::NEW:
2198         default:
2199           return false;
2200         }
2201       }
2202     }
2203   return false;
2204 }
2205
2206 //----------------------------------------------------------------------------
2207 void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags,
2208                                                    std::string const& lang,
2209                                                    int targetType)
2210 {
2211   const char* picFlags = 0;
2212
2213   if(targetType == cmTarget::EXECUTABLE)
2214     {
2215     std::string flagsVar = "CMAKE_";
2216     flagsVar += lang;
2217     flagsVar += "_COMPILE_OPTIONS_PIE";
2218     picFlags = this->Makefile->GetSafeDefinition(flagsVar.c_str());
2219     }
2220   if (!picFlags)
2221     {
2222     std::string flagsVar = "CMAKE_";
2223     flagsVar += lang;
2224     flagsVar += "_COMPILE_OPTIONS_PIC";
2225     picFlags = this->Makefile->GetSafeDefinition(flagsVar.c_str());
2226     }
2227   if (picFlags)
2228     {
2229     std::vector<std::string> options;
2230     cmSystemTools::ExpandListArgument(picFlags, options);
2231     for(std::vector<std::string>::const_iterator oi = options.begin();
2232         oi != options.end(); ++oi)
2233       {
2234       this->AppendFlagEscape(flags, oi->c_str());
2235       }
2236     }
2237 }
2238
2239 //----------------------------------------------------------------------------
2240 void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
2241                                               const char* var,
2242                                               const char* config)
2243 {
2244   // Add the flags from the variable itself.
2245   std::string flagsVar = var;
2246   this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
2247   // Add the flags from the build-type specific variable.
2248   if(config && *config)
2249     {
2250     flagsVar += "_";
2251     flagsVar += cmSystemTools::UpperCase(config);
2252     this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
2253     }
2254 }
2255
2256 //----------------------------------------------------------------------------
2257 void cmLocalGenerator::AppendFlags(std::string& flags,
2258                                                 const char* newFlags)
2259 {
2260   if(newFlags && *newFlags)
2261     {
2262     std::string newf = newFlags;
2263     if(flags.size())
2264       {
2265       flags += " ";
2266       }
2267     flags += newFlags;
2268     }
2269 }
2270
2271 //----------------------------------------------------------------------------
2272 void cmLocalGenerator::AppendFlagEscape(std::string& flags,
2273                                         const char* rawFlag)
2274 {
2275   this->AppendFlags(flags, this->EscapeForShell(rawFlag).c_str());
2276 }
2277
2278 //----------------------------------------------------------------------------
2279 void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
2280                                      const char* defines_list)
2281 {
2282   // Short-circuit if there are no definitions.
2283   if(!defines_list)
2284     {
2285     return;
2286     }
2287
2288   // Expand the list of definitions.
2289   std::vector<std::string> defines_vec;
2290   cmSystemTools::ExpandListArgument(defines_list, defines_vec);
2291   this->AppendDefines(defines, defines_vec);
2292 }
2293
2294 //----------------------------------------------------------------------------
2295 void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
2296                                   const std::vector<std::string> &defines_vec)
2297 {
2298   for(std::vector<std::string>::const_iterator di = defines_vec.begin();
2299       di != defines_vec.end(); ++di)
2300     {
2301     // Skip unsupported definitions.
2302     if(!this->CheckDefinition(*di))
2303       {
2304       continue;
2305       }
2306     defines.insert(*di);
2307     }
2308 }
2309
2310 //----------------------------------------------------------------------------
2311 void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines,
2312                                    std::string &definesString,
2313                                    const char* lang)
2314 {
2315   // Lookup the define flag for the current language.
2316   std::string dflag = "-D";
2317   if(lang)
2318     {
2319     std::string defineFlagVar = "CMAKE_";
2320     defineFlagVar += lang;
2321     defineFlagVar += "_DEFINE_FLAG";
2322     const char* df = this->Makefile->GetDefinition(defineFlagVar.c_str());
2323     if(df && *df)
2324       {
2325       dflag = df;
2326       }
2327     }
2328
2329   std::set<std::string>::const_iterator defineIt = defines.begin();
2330   const std::set<std::string>::const_iterator defineEnd = defines.end();
2331   const char* itemSeparator = definesString.empty() ? "" : " ";
2332   for( ; defineIt != defineEnd; ++defineIt)
2333     {
2334     // Append the definition with proper escaping.
2335     std::string def = dflag;
2336     if(this->WatcomWMake)
2337       {
2338       // The Watcom compiler does its own command line parsing instead
2339       // of using the windows shell rules.  Definitions are one of
2340       //   -DNAME
2341       //   -DNAME=<cpp-token>
2342       //   -DNAME="c-string with spaces and other characters(?@#$)"
2343       //
2344       // Watcom will properly parse each of these cases from the
2345       // command line without any escapes.  However we still have to
2346       // get the '$' and '#' characters through WMake as '$$' and
2347       // '$#'.
2348       for(const char* c = defineIt->c_str(); *c; ++c)
2349         {
2350         if(*c == '$' || *c == '#')
2351           {
2352           def += '$';
2353           }
2354         def += *c;
2355         }
2356       }
2357     else
2358       {
2359       // Make the definition appear properly on the command line.  Use
2360       // -DNAME="value" instead of -D"NAME=value" to help VS6 parser.
2361       std::string::size_type eq = defineIt->find("=");
2362       def += defineIt->substr(0, eq);
2363       if(eq != defineIt->npos)
2364         {
2365         def += "=";
2366         def += this->EscapeForShell(defineIt->c_str() + eq + 1, true);
2367         }
2368       }
2369     definesString += itemSeparator;
2370     itemSeparator = " ";
2371     definesString += def;
2372     }
2373 }
2374
2375 //----------------------------------------------------------------------------
2376 void cmLocalGenerator::AppendFeatureOptions(
2377   std::string& flags, const char* lang, const char* feature)
2378 {
2379   std::string optVar = "CMAKE_";
2380   optVar += lang;
2381   optVar += "_COMPILE_OPTIONS_";
2382   optVar += feature;
2383   if(const char* optionList = this->Makefile->GetDefinition(optVar.c_str()))
2384     {
2385     std::vector<std::string> options;
2386     cmSystemTools::ExpandListArgument(optionList, options);
2387     for(std::vector<std::string>::const_iterator oi = options.begin();
2388         oi != options.end(); ++oi)
2389       {
2390       this->AppendFlagEscape(flags, oi->c_str());
2391       }
2392     }
2393 }
2394
2395 //----------------------------------------------------------------------------
2396 std::string
2397 cmLocalGenerator::ConstructComment(const cmCustomCommand& cc,
2398                                    const char* default_comment)
2399 {
2400   // Check for a comment provided with the command.
2401   if(cc.GetComment())
2402     {
2403     return cc.GetComment();
2404     }
2405
2406   // Construct a reasonable default comment if possible.
2407   if(!cc.GetOutputs().empty())
2408     {
2409     std::string comment;
2410     comment = "Generating ";
2411     const char* sep = "";
2412     for(std::vector<std::string>::const_iterator o = cc.GetOutputs().begin();
2413         o != cc.GetOutputs().end(); ++o)
2414       {
2415       comment += sep;
2416       comment += this->Convert(o->c_str(), cmLocalGenerator::START_OUTPUT);
2417       sep = ", ";
2418       }
2419     return comment;
2420     }
2421
2422   // Otherwise use the provided default.
2423   return default_comment;
2424 }
2425
2426 //----------------------------------------------------------------------------
2427 std::string
2428 cmLocalGenerator::ConvertToOptionallyRelativeOutputPath(const char* remote)
2429 {
2430   return this->Convert(remote, START_OUTPUT, SHELL, true);
2431 }
2432
2433 //----------------------------------------------------------------------------
2434 const char* cmLocalGenerator::GetRelativeRootPath(RelativeRoot relroot)
2435 {
2436   switch (relroot)
2437     {
2438     case HOME:         return this->Makefile->GetHomeDirectory();
2439     case START:        return this->Makefile->GetStartDirectory();
2440     case HOME_OUTPUT:  return this->Makefile->GetHomeOutputDirectory();
2441     case START_OUTPUT: return this->Makefile->GetStartOutputDirectory();
2442     default: break;
2443     }
2444   return 0;
2445 }
2446
2447 //----------------------------------------------------------------------------
2448 std::string cmLocalGenerator::Convert(const char* source,
2449                                       RelativeRoot relative,
2450                                       OutputFormat output,
2451                                       bool optional)
2452 {
2453   // Make sure the relative path conversion components are set.
2454   if(!this->PathConversionsSetup)
2455     {
2456     this->SetupPathConversions();
2457     this->PathConversionsSetup = true;
2458     }
2459
2460   // Convert the path to a relative path.
2461   std::string result = source;
2462
2463   if (!optional || this->UseRelativePaths)
2464     {
2465     switch (relative)
2466       {
2467       case HOME:
2468         //result = cmSystemTools::CollapseFullPath(result.c_str());
2469         result = this->ConvertToRelativePath(this->HomeDirectoryComponents,
2470                                              result.c_str());
2471         break;
2472       case START:
2473         //result = cmSystemTools::CollapseFullPath(result.c_str());
2474         result = this->ConvertToRelativePath(this->StartDirectoryComponents,
2475                                              result.c_str());
2476         break;
2477       case HOME_OUTPUT:
2478         //result = cmSystemTools::CollapseFullPath(result.c_str());
2479         result =
2480           this->ConvertToRelativePath(this->HomeOutputDirectoryComponents,
2481                                       result.c_str());
2482         break;
2483       case START_OUTPUT:
2484         //result = cmSystemTools::CollapseFullPath(result.c_str());
2485         result =
2486           this->ConvertToRelativePath(this->StartOutputDirectoryComponents,
2487                                       result.c_str());
2488         break;
2489       case FULL:
2490         result = cmSystemTools::CollapseFullPath(result.c_str());
2491         break;
2492       case NONE:
2493         break;
2494       }
2495     }
2496   return this->ConvertToOutputFormat(result.c_str(), output);
2497 }
2498
2499 //----------------------------------------------------------------------------
2500 std::string cmLocalGenerator::ConvertToOutputFormat(const char* source,
2501                                                     OutputFormat output)
2502 {
2503   std::string result = source;
2504   // Convert it to an output path.
2505   if (output == MAKEFILE)
2506     {
2507     result = cmSystemTools::ConvertToOutputPath(result.c_str());
2508     }
2509   else if( output == SHELL)
2510     {
2511         // For the MSYS shell convert drive letters to posix paths, so
2512     // that c:/some/path becomes /c/some/path.  This is needed to
2513     // avoid problems with the shell path translation.
2514     if(this->MSYSShell && !this->LinkScriptShell)
2515       {
2516       if(result.size() > 2 && result[1] == ':')
2517         {
2518         result[1] = result[0];
2519         result[0] = '/';
2520         }
2521       }
2522     if(this->WindowsShell)
2523       {
2524       std::string::size_type pos = 0;
2525       while((pos = result.find('/', pos)) != std::string::npos)
2526         {
2527         result[pos] = '\\';
2528         pos++;
2529         }
2530       }
2531     result = this->EscapeForShell(result.c_str(), true, false);
2532     }
2533   else if(output == RESPONSE)
2534     {
2535     result = this->EscapeForShell(result.c_str(), false, false);
2536     }
2537   return result;
2538 }
2539
2540 //----------------------------------------------------------------------------
2541 std::string cmLocalGenerator::Convert(RelativeRoot remote,
2542                                       const char* local,
2543                                       OutputFormat output,
2544                                       bool optional)
2545 {
2546   const char* remotePath = this->GetRelativeRootPath(remote);
2547
2548   // The relative root must have a path (i.e. not FULL or NONE)
2549   assert(remotePath != 0);
2550
2551   if(local && (!optional || this->UseRelativePaths))
2552     {
2553     std::vector<std::string> components;
2554     cmSystemTools::SplitPath(local, components);
2555     std::string result = this->ConvertToRelativePath(components, remotePath);
2556     return this->ConvertToOutputFormat(result.c_str(), output);
2557     }
2558   else
2559     {
2560     return this->ConvertToOutputFormat(remotePath, output);
2561     }
2562 }
2563
2564 //----------------------------------------------------------------------------
2565 std::string cmLocalGenerator::FindRelativePathTopSource()
2566 {
2567   // Relative path conversion within a single tree managed by CMake is
2568   // safe.  We can use our parent relative path top if and only if
2569   // this is a subdirectory of that top.
2570   if(cmLocalGenerator* parent = this->GetParent())
2571     {
2572     std::string parentTop = parent->FindRelativePathTopSource();
2573     if(cmSystemTools::IsSubDirectory(
2574          this->Makefile->GetStartDirectory(), parentTop.c_str()))
2575       {
2576       return parentTop;
2577       }
2578     }
2579
2580   // Otherwise this directory itself is the new top.
2581   return this->Makefile->GetStartDirectory();
2582 }
2583
2584 //----------------------------------------------------------------------------
2585 std::string cmLocalGenerator::FindRelativePathTopBinary()
2586 {
2587   // Relative path conversion within a single tree managed by CMake is
2588   // safe.  We can use our parent relative path top if and only if
2589   // this is a subdirectory of that top.
2590   if(cmLocalGenerator* parent = this->GetParent())
2591     {
2592     std::string parentTop = parent->FindRelativePathTopBinary();
2593     if(cmSystemTools::IsSubDirectory(
2594          this->Makefile->GetStartOutputDirectory(), parentTop.c_str()))
2595       {
2596       return parentTop;
2597       }
2598     }
2599
2600   // Otherwise this directory itself is the new top.
2601   return this->Makefile->GetStartOutputDirectory();
2602 }
2603
2604 //----------------------------------------------------------------------------
2605 void cmLocalGenerator::ConfigureRelativePaths()
2606 {
2607   // Relative path conversion inside the source tree is not used to
2608   // construct relative paths passed to build tools so it is safe to
2609   // even when the source is a network path.
2610   std::string source = this->FindRelativePathTopSource();
2611   this->RelativePathTopSource = source;
2612
2613   // The current working directory on Windows cannot be a network
2614   // path.  Therefore relative paths cannot work when the binary tree
2615   // is a network path.
2616   std::string binary = this->FindRelativePathTopBinary();
2617   if(binary.size() < 2 || binary.substr(0, 2) != "//")
2618     {
2619     this->RelativePathTopBinary = binary;
2620     }
2621   else
2622     {
2623     this->RelativePathTopBinary = "";
2624     }
2625 }
2626
2627 //----------------------------------------------------------------------------
2628 static bool cmLocalGeneratorNotAbove(const char* a, const char* b)
2629 {
2630   return (cmSystemTools::ComparePath(a, b) ||
2631           cmSystemTools::IsSubDirectory(a, b));
2632 }
2633
2634 //----------------------------------------------------------------------------
2635 std::string
2636 cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
2637                                         const char* in_remote, bool force)
2638 {
2639   // The path should never be quoted.
2640   assert(in_remote[0] != '\"');
2641
2642   // The local path should never have a trailing slash.
2643   assert(local.size() > 0 && !(local[local.size()-1] == ""));
2644
2645   // If the path is already relative then just return the path.
2646   if(!cmSystemTools::FileIsFullPath(in_remote))
2647     {
2648     return in_remote;
2649     }
2650
2651   // Make sure relative path conversion is configured.
2652   if(!this->RelativePathsConfigured)
2653     {
2654     this->ConfigureRelativePaths();
2655     this->RelativePathsConfigured = true;
2656     }
2657
2658   if(!force)
2659     {
2660     // Skip conversion if the path and local are not both in the source
2661     // or both in the binary tree.
2662     std::string local_path = cmSystemTools::JoinPath(local);
2663     if(!((cmLocalGeneratorNotAbove(local_path.c_str(),
2664                                    this->RelativePathTopBinary.c_str()) &&
2665           cmLocalGeneratorNotAbove(in_remote,
2666                                    this->RelativePathTopBinary.c_str())) ||
2667          (cmLocalGeneratorNotAbove(local_path.c_str(),
2668                                    this->RelativePathTopSource.c_str()) &&
2669           cmLocalGeneratorNotAbove(in_remote,
2670                                    this->RelativePathTopSource.c_str()))))
2671       {
2672       return in_remote;
2673       }
2674     }
2675
2676   // Identify the longest shared path component between the remote
2677   // path and the local path.
2678   std::vector<std::string> remote;
2679   cmSystemTools::SplitPath(in_remote, remote);
2680   unsigned int common=0;
2681   while(common < remote.size() &&
2682         common < local.size() &&
2683         cmSystemTools::ComparePath(remote[common].c_str(),
2684                                    local[common].c_str()))
2685     {
2686     ++common;
2687     }
2688
2689   // If no part of the path is in common then return the full path.
2690   if(common == 0)
2691     {
2692     return in_remote;
2693     }
2694
2695   // If the entire path is in common then just return a ".".
2696   if(common == remote.size() &&
2697      common == local.size())
2698     {
2699     return ".";
2700     }
2701
2702   // If the entire path is in common except for a trailing slash then
2703   // just return a "./".
2704   if(common+1 == remote.size() &&
2705      remote[common].size() == 0 &&
2706      common == local.size())
2707     {
2708     return "./";
2709     }
2710
2711   // Construct the relative path.
2712   std::string relative;
2713
2714   // First add enough ../ to get up to the level of the shared portion
2715   // of the path.  Leave off the trailing slash.  Note that the last
2716   // component of local will never be empty because local should never
2717   // have a trailing slash.
2718   for(unsigned int i=common; i < local.size(); ++i)
2719     {
2720     relative += "..";
2721     if(i < local.size()-1)
2722       {
2723       relative += "/";
2724       }
2725     }
2726
2727   // Now add the portion of the destination path that is not included
2728   // in the shared portion of the path.  Add a slash the first time
2729   // only if there was already something in the path.  If there was a
2730   // trailing slash in the input then the last iteration of the loop
2731   // will add a slash followed by an empty string which will preserve
2732   // the trailing slash in the output.
2733   for(unsigned int i=common; i < remote.size(); ++i)
2734     {
2735     if(relative.size() > 0)
2736       {
2737       relative += "/";
2738       }
2739     relative += remote[i];
2740     }
2741
2742   // Finally return the path.
2743   return relative;
2744 }
2745
2746 //----------------------------------------------------------------------------
2747 void
2748 cmLocalGenerator
2749 ::GenerateTargetInstallRules(
2750   std::ostream& os, const char* config,
2751   std::vector<std::string> const& configurationTypes)
2752 {
2753   // Convert the old-style install specification from each target to
2754   // an install generator and run it.
2755   cmTargets& tgts = this->Makefile->GetTargets();
2756   for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
2757     {
2758     // Include the user-specified pre-install script for this target.
2759     if(const char* preinstall = l->second.GetProperty("PRE_INSTALL_SCRIPT"))
2760       {
2761       cmInstallScriptGenerator g(preinstall, false, 0);
2762       g.Generate(os, config, configurationTypes);
2763       }
2764
2765     // Install this target if a destination is given.
2766     if(l->second.GetInstallPath() != "")
2767       {
2768       // Compute the full install destination.  Note that converting
2769       // to unix slashes also removes any trailing slash.
2770       // We also skip over the leading slash given by the user.
2771       std::string destination = l->second.GetInstallPath().substr(1);
2772       cmSystemTools::ConvertToUnixSlashes(destination);
2773       if(destination.empty())
2774         {
2775         destination = ".";
2776         }
2777
2778       // Generate the proper install generator for this target type.
2779       switch(l->second.GetType())
2780         {
2781         case cmTarget::EXECUTABLE:
2782         case cmTarget::STATIC_LIBRARY:
2783         case cmTarget::MODULE_LIBRARY:
2784           {
2785           // Use a target install generator.
2786           cmInstallTargetGenerator g(l->second, destination.c_str(), false);
2787           g.Generate(os, config, configurationTypes);
2788           }
2789           break;
2790         case cmTarget::SHARED_LIBRARY:
2791           {
2792 #if defined(_WIN32) || defined(__CYGWIN__)
2793           // Special code to handle DLL.  Install the import library
2794           // to the normal destination and the DLL to the runtime
2795           // destination.
2796           cmInstallTargetGenerator g1(l->second, destination.c_str(), true);
2797           g1.Generate(os, config, configurationTypes);
2798           // We also skip over the leading slash given by the user.
2799           destination = l->second.GetRuntimeInstallPath().substr(1);
2800           cmSystemTools::ConvertToUnixSlashes(destination);
2801           cmInstallTargetGenerator g2(l->second, destination.c_str(), false);
2802           g2.Generate(os, config, configurationTypes);
2803 #else
2804           // Use a target install generator.
2805           cmInstallTargetGenerator g(l->second, destination.c_str(), false);
2806           g.Generate(os, config, configurationTypes);
2807 #endif
2808           }
2809           break;
2810         default:
2811           break;
2812         }
2813       }
2814
2815     // Include the user-specified post-install script for this target.
2816     if(const char* postinstall = l->second.GetProperty("POST_INSTALL_SCRIPT"))
2817       {
2818       cmInstallScriptGenerator g(postinstall, false, 0);
2819       g.Generate(os, config, configurationTypes);
2820       }
2821     }
2822 }
2823
2824 #if defined(CM_LG_ENCODE_OBJECT_NAMES)
2825 static std::string cmLocalGeneratorMD5(const char* input)
2826 {
2827   char md5out[32];
2828   cmsysMD5* md5 = cmsysMD5_New();
2829   cmsysMD5_Initialize(md5);
2830   cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
2831   cmsysMD5_FinalizeHex(md5, md5out);
2832   cmsysMD5_Delete(md5);
2833   return std::string(md5out, 32);
2834 }
2835
2836 static bool
2837 cmLocalGeneratorShortenObjectName(std::string& objName,
2838                                   std::string::size_type max_len)
2839 {
2840   // Replace the beginning of the path portion of the object name with
2841   // its own md5 sum.
2842   std::string::size_type pos = objName.find('/', objName.size()-max_len+32);
2843   if(pos != objName.npos)
2844     {
2845     std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
2846     md5name += objName.substr(pos);
2847     objName = md5name;
2848
2849     // The object name is now short enough.
2850     return true;
2851     }
2852   else
2853     {
2854     // The object name could not be shortened enough.
2855     return false;
2856     }
2857 }
2858
2859 static
2860 bool cmLocalGeneratorCheckObjectName(std::string& objName,
2861                                      std::string::size_type dir_len,
2862                                      std::string::size_type max_total_len)
2863 {
2864   // Enforce the maximum file name length if possible.
2865   std::string::size_type max_obj_len = max_total_len;
2866   if(dir_len < max_total_len)
2867     {
2868     max_obj_len = max_total_len - dir_len;
2869     if(objName.size() > max_obj_len)
2870       {
2871       // The current object file name is too long.  Try to shorten it.
2872       return cmLocalGeneratorShortenObjectName(objName, max_obj_len);
2873       }
2874     else
2875       {
2876       // The object file name is short enough.
2877       return true;
2878       }
2879     }
2880   else
2881     {
2882     // The build directory in which the object will be stored is
2883     // already too deep.
2884     return false;
2885     }
2886 }
2887 #endif
2888
2889 //----------------------------------------------------------------------------
2890 std::string&
2891 cmLocalGenerator
2892 ::CreateSafeUniqueObjectFileName(const char* sin,
2893                                  std::string const& dir_max)
2894 {
2895   // Look for an existing mapped name for this object file.
2896   std::map<cmStdString,cmStdString>::iterator it =
2897     this->UniqueObjectNamesMap.find(sin);
2898
2899   // If no entry exists create one.
2900   if(it == this->UniqueObjectNamesMap.end())
2901     {
2902     // Start with the original name.
2903     std::string ssin = sin;
2904
2905     // Avoid full paths by removing leading slashes.
2906     std::string::size_type pos = 0;
2907     for(;pos < ssin.size() && ssin[pos] == '/'; ++pos)
2908       {
2909       }
2910     ssin = ssin.substr(pos);
2911
2912     // Avoid full paths by removing colons.
2913     cmSystemTools::ReplaceString(ssin, ":", "_");
2914
2915     // Avoid relative paths that go up the tree.
2916     cmSystemTools::ReplaceString(ssin, "../", "__/");
2917
2918     // Avoid spaces.
2919     cmSystemTools::ReplaceString(ssin, " ", "_");
2920
2921     // Mangle the name if necessary.
2922     if(this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
2923       {
2924       bool done;
2925       int cc = 0;
2926       char rpstr[100];
2927       sprintf(rpstr, "_p_");
2928       cmSystemTools::ReplaceString(ssin, "+", rpstr);
2929       std::string sssin = sin;
2930       do
2931         {
2932         done = true;
2933         for ( it = this->UniqueObjectNamesMap.begin();
2934               it != this->UniqueObjectNamesMap.end();
2935               ++ it )
2936           {
2937           if ( it->second == ssin )
2938             {
2939             done = false;
2940             }
2941           }
2942         if ( done )
2943           {
2944           break;
2945           }
2946         sssin = ssin;
2947         cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
2948         sprintf(rpstr, "_p%d_", cc++);
2949         }
2950       while ( !done );
2951       }
2952
2953 #if defined(CM_LG_ENCODE_OBJECT_NAMES)
2954     if(!cmLocalGeneratorCheckObjectName(ssin, dir_max.size(),
2955                                         this->ObjectPathMax))
2956       {
2957       // Warn if this is the first time the path has been seen.
2958       if(this->ObjectMaxPathViolations.insert(dir_max).second)
2959         {
2960         cmOStringStream m;
2961         m << "The object file directory\n"
2962           << "  " << dir_max << "\n"
2963           << "has " << dir_max.size() << " characters.  "
2964           << "The maximum full path to an object file is "
2965           << this->ObjectPathMax << " characters "
2966           << "(see CMAKE_OBJECT_PATH_MAX).  "
2967           << "Object file\n"
2968           << "  " << ssin << "\n"
2969           << "cannot be safely placed under this directory.  "
2970           << "The build may not work correctly.";
2971         this->Makefile->IssueMessage(cmake::WARNING, m.str());
2972         }
2973       }
2974 #else
2975     (void)dir_max;
2976 #endif
2977
2978     // Insert the newly mapped object file name.
2979     std::map<cmStdString, cmStdString>::value_type e(sin, ssin);
2980     it = this->UniqueObjectNamesMap.insert(e).first;
2981     }
2982
2983   // Return the map entry.
2984   return it->second;
2985 }
2986
2987 //----------------------------------------------------------------------------
2988 std::string
2989 cmLocalGenerator
2990 ::GetObjectFileNameWithoutTarget(const cmSourceFile& source,
2991                                  std::string const& dir_max,
2992                                  bool* hasSourceExtension)
2993 {
2994   // Construct the object file name using the full path to the source
2995   // file which is its only unique identification.
2996   const char* fullPath = source.GetFullPath().c_str();
2997
2998   // Try referencing the source relative to the source tree.
2999   std::string relFromSource = this->Convert(fullPath, START);
3000   assert(!relFromSource.empty());
3001   bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
3002   bool subSource = relSource && relFromSource[0] != '.';
3003
3004   // Try referencing the source relative to the binary tree.
3005   std::string relFromBinary = this->Convert(fullPath, START_OUTPUT);
3006   assert(!relFromBinary.empty());
3007   bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
3008   bool subBinary = relBinary && relFromBinary[0] != '.';
3009
3010   // Select a nice-looking reference to the source file to construct
3011   // the object file name.
3012   std::string objectName;
3013   if((relSource && !relBinary) || (subSource && !subBinary))
3014     {
3015     objectName = relFromSource;
3016     }
3017   else if((relBinary && !relSource) || (subBinary && !subSource))
3018     {
3019     objectName = relFromBinary;
3020     }
3021   else if(relFromBinary.length() < relFromSource.length())
3022     {
3023     objectName = relFromBinary;
3024     }
3025   else
3026     {
3027     objectName = relFromSource;
3028     }
3029
3030   // if it is still a full path check for the try compile case
3031   // try compile never have in source sources, and should not
3032   // have conflicting source file names in the same target
3033   if(cmSystemTools::FileIsFullPath(objectName.c_str()))
3034     {
3035     if(this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile())
3036       {
3037       objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
3038       }
3039     }
3040
3041   // Replace the original source file extension with the object file
3042   // extension.
3043   bool keptSourceExtension = true;
3044   if(!source.GetPropertyAsBool("KEEP_EXTENSION"))
3045     {
3046     // Decide whether this language wants to replace the source
3047     // extension with the object extension.  For CMake 2.4
3048     // compatibility do this by default.
3049     bool replaceExt = this->NeedBackwardsCompatibility(2, 4);
3050     if(!replaceExt)
3051       {
3052       if(const char* lang = source.GetLanguage())
3053         {
3054         std::string repVar = "CMAKE_";
3055         repVar += lang;
3056         repVar += "_OUTPUT_EXTENSION_REPLACE";
3057         replaceExt = this->Makefile->IsOn(repVar.c_str());
3058         }
3059       }
3060
3061     // Remove the source extension if it is to be replaced.
3062     if(replaceExt)
3063       {
3064       keptSourceExtension = false;
3065       std::string::size_type dot_pos = objectName.rfind(".");
3066       if(dot_pos != std::string::npos)
3067         {
3068         objectName = objectName.substr(0, dot_pos);
3069         }
3070       }
3071
3072     // Store the new extension.
3073     objectName +=
3074       this->GlobalGenerator->GetLanguageOutputExtension(source);
3075     }
3076   if(hasSourceExtension)
3077     {
3078     *hasSourceExtension = keptSourceExtension;
3079     }
3080
3081   // Convert to a safe name.
3082   return this->CreateSafeUniqueObjectFileName(objectName.c_str(), dir_max);
3083 }
3084
3085 //----------------------------------------------------------------------------
3086 const char*
3087 cmLocalGenerator
3088 ::GetSourceFileLanguage(const cmSourceFile& source)
3089 {
3090   return source.GetLanguage();
3091 }
3092
3093 //----------------------------------------------------------------------------
3094 std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str)
3095 {
3096   std::string result;
3097 #if defined(_WIN32) && !defined(__CYGWIN__)
3098   // if there are spaces
3099   std::string temp = str;
3100   if (temp.find(" ") != std::string::npos &&
3101       temp.find("\"")==std::string::npos)
3102     {
3103     result = "\"";
3104     result += str;
3105     result += "\"";
3106     return result;
3107     }
3108   return str;
3109 #else
3110   for(const char* ch = str; *ch != '\0'; ++ch)
3111     {
3112     if(*ch == ' ')
3113       {
3114       result += '\\';
3115       }
3116     result += *ch;
3117     }
3118   return result;
3119 #endif
3120 }
3121
3122 //----------------------------------------------------------------------------
3123 static bool cmLocalGeneratorIsShellOperator(const char* str)
3124 {
3125   if(strcmp(str, "<") == 0 ||
3126      strcmp(str, ">") == 0 ||
3127      strcmp(str, "<<") == 0 ||
3128      strcmp(str, ">>") == 0 ||
3129      strcmp(str, "|") == 0 ||
3130      strcmp(str, "||") == 0 ||
3131      strcmp(str, "&&") == 0 ||
3132      strcmp(str, "&>") == 0 ||
3133      strcmp(str, "1>") == 0 ||
3134      strcmp(str, "2>") == 0 ||
3135      strcmp(str, "2>&1") == 0 ||
3136      strcmp(str, "1>&2") == 0)
3137     {
3138     return true;
3139     }
3140   return false;
3141 }
3142
3143 //----------------------------------------------------------------------------
3144 std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars,
3145                                              bool forEcho)
3146 {
3147   // Do not escape shell operators.
3148   if(cmLocalGeneratorIsShellOperator(str))
3149     {
3150     return str;
3151     }
3152
3153   // Compute the flags for the target shell environment.
3154   int flags = 0;
3155   if(this->WindowsVSIDE)
3156     {
3157     flags |= cmsysSystem_Shell_Flag_VSIDE;
3158     }
3159   else if(!this->LinkScriptShell)
3160     {
3161     flags |= cmsysSystem_Shell_Flag_Make;
3162     }
3163   if(makeVars)
3164     {
3165     flags |= cmsysSystem_Shell_Flag_AllowMakeVariables;
3166     }
3167   if(forEcho)
3168     {
3169     flags |= cmsysSystem_Shell_Flag_EchoWindows;
3170     }
3171   if(this->WatcomWMake)
3172     {
3173     flags |= cmsysSystem_Shell_Flag_WatcomWMake;
3174     }
3175   if(this->MinGWMake)
3176     {
3177     flags |= cmsysSystem_Shell_Flag_MinGWMake;
3178     }
3179   if(this->NMake)
3180     {
3181     flags |= cmsysSystem_Shell_Flag_NMake;
3182     }
3183
3184   // Compute the buffer size needed.
3185   int size = (this->WindowsShell ?
3186               cmsysSystem_Shell_GetArgumentSizeForWindows(str, flags) :
3187               cmsysSystem_Shell_GetArgumentSizeForUnix(str, flags));
3188
3189   // Compute the shell argument itself.
3190   std::vector<char> arg(size);
3191   if(this->WindowsShell)
3192     {
3193     cmsysSystem_Shell_GetArgumentForWindows(str, &arg[0], flags);
3194     }
3195   else
3196     {
3197     cmsysSystem_Shell_GetArgumentForUnix(str, &arg[0], flags);
3198     }
3199   return std::string(&arg[0]);
3200 }
3201
3202 //----------------------------------------------------------------------------
3203 std::string cmLocalGenerator::EscapeForCMake(const char* str)
3204 {
3205   // Always double-quote the argument to take care of most escapes.
3206   std::string result = "\"";
3207   for(const char* c = str; *c; ++c)
3208     {
3209     if(*c == '"')
3210       {
3211       // Escape the double quote to avoid ending the argument.
3212       result += "\\\"";
3213       }
3214     else if(*c == '$')
3215       {
3216       // Escape the dollar to avoid expanding variables.
3217       result += "\\$";
3218       }
3219     else if(*c == '\\')
3220       {
3221       // Escape the backslash to avoid other escapes.
3222       result += "\\\\";
3223       }
3224     else
3225       {
3226       // Other characters will be parsed correctly.
3227       result += *c;
3228       }
3229     }
3230   result += "\"";
3231   return result;
3232 }
3233
3234 //----------------------------------------------------------------------------
3235 cmLocalGenerator::FortranFormat
3236 cmLocalGenerator::GetFortranFormat(const char* value)
3237 {
3238   FortranFormat format = FortranFormatNone;
3239   if(value && *value)
3240     {
3241     std::vector<std::string> fmt;
3242     cmSystemTools::ExpandListArgument(value, fmt);
3243     for(std::vector<std::string>::iterator fi = fmt.begin();
3244         fi != fmt.end(); ++fi)
3245       {
3246       if(*fi == "FIXED")
3247         {
3248         format = FortranFormatFixed;
3249         }
3250       if(*fi == "FREE")
3251         {
3252         format = FortranFormatFree;
3253         }
3254       }
3255     }
3256   return format;
3257 }
3258
3259 //----------------------------------------------------------------------------
3260 std::string
3261 cmLocalGenerator::GetTargetDirectory(cmTarget const&) const
3262 {
3263   cmSystemTools::Error("GetTargetDirectory"
3264                        " called on cmLocalGenerator");
3265   return "";
3266 }
3267
3268 //----------------------------------------------------------------------------
3269 unsigned int cmLocalGenerator::GetBackwardsCompatibility()
3270 {
3271   // The computed version may change until the project is fully
3272   // configured.
3273   if(!this->BackwardsCompatibilityFinal)
3274     {
3275     unsigned int major = 0;
3276     unsigned int minor = 0;
3277     unsigned int patch = 0;
3278     if(const char* value
3279        = this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"))
3280       {
3281       switch(sscanf(value, "%u.%u.%u", &major, &minor, &patch))
3282         {
3283         case 2: patch = 0; break;
3284         case 1: minor = 0; patch = 0; break;
3285         default: break;
3286         }
3287       }
3288     this->BackwardsCompatibility = CMake_VERSION_ENCODE(major, minor, patch);
3289     this->BackwardsCompatibilityFinal = this->Configured;
3290     }
3291
3292   return this->BackwardsCompatibility;
3293 }
3294
3295 //----------------------------------------------------------------------------
3296 bool cmLocalGenerator::NeedBackwardsCompatibility(unsigned int major,
3297                                                   unsigned int minor,
3298                                                   unsigned int patch)
3299 {
3300   // Check the policy to decide whether to pay attention to this
3301   // variable.
3302   switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0001))
3303     {
3304     case cmPolicies::WARN:
3305       // WARN is just OLD without warning because user code does not
3306       // always affect whether this check is done.
3307     case cmPolicies::OLD:
3308       // Old behavior is to check the variable.
3309       break;
3310     case cmPolicies::NEW:
3311       // New behavior is to ignore the variable.
3312       return false;
3313     case cmPolicies::REQUIRED_IF_USED:
3314     case cmPolicies::REQUIRED_ALWAYS:
3315       // This will never be the case because the only way to require
3316       // the setting is to require the user to specify version policy
3317       // 2.6 or higher.  Once we add that requirement then this whole
3318       // method can be removed anyway.
3319       return false;
3320     }
3321
3322   // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set
3323   // equal to or lower than the given version.
3324   unsigned int actual_compat = this->GetBackwardsCompatibility();
3325   return (actual_compat &&
3326           actual_compat <= CMake_VERSION_ENCODE(major, minor, patch));
3327 }
3328
3329 //----------------------------------------------------------------------------
3330 bool cmLocalGenerator::CheckDefinition(std::string const& define) const
3331 {
3332   // Many compilers do not support -DNAME(arg)=sdf so we disable it.
3333   bool function_style = false;
3334   for(const char* c = define.c_str(); *c && *c != '='; ++c)
3335     {
3336     if(*c == '(')
3337       {
3338       function_style = true;
3339       break;
3340       }
3341     }
3342   if(function_style)
3343     {
3344     cmOStringStream e;
3345     e << "WARNING: Function-style preprocessor definitions may not be "
3346       << "passed on the compiler command line because many compilers "
3347       << "do not support it.\n"
3348       << "CMake is dropping a preprocessor definition: " << define << "\n"
3349       << "Consider defining the macro in a (configured) header file.\n";
3350     cmSystemTools::Message(e.str().c_str());
3351     return false;
3352     }
3353
3354   // Many compilers do not support # in the value so we disable it.
3355   if(define.find_first_of("#") != define.npos)
3356     {
3357     cmOStringStream e;
3358     e << "WARNING: Preprocessor definitions containing '#' may not be "
3359       << "passed on the compiler command line because many compilers "
3360       << "do not support it.\n"
3361       << "CMake is dropping a preprocessor definition: " << define << "\n"
3362       << "Consider defining the macro in a (configured) header file.\n";
3363     cmSystemTools::Message(e.str().c_str());
3364     return false;
3365     }
3366
3367   // Assume it is supported.
3368   return true;
3369 }
3370
3371 //----------------------------------------------------------------------------
3372 static void cmLGInfoProp(cmMakefile* mf, cmTarget* target, const char* prop)
3373 {
3374   if(const char* val = target->GetProperty(prop))
3375     {
3376     mf->AddDefinition(prop, val);
3377     }
3378 }
3379
3380 //----------------------------------------------------------------------------
3381 void cmLocalGenerator::GenerateAppleInfoPList(cmTarget* target,
3382                                               const char* targetName,
3383                                               const char* fname)
3384 {
3385   // Find the Info.plist template.
3386   const char* in = target->GetProperty("MACOSX_BUNDLE_INFO_PLIST");
3387   std::string inFile = (in && *in)? in : "MacOSXBundleInfo.plist.in";
3388   if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
3389     {
3390     std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
3391     if(!inMod.empty())
3392       {
3393       inFile = inMod;
3394       }
3395     }
3396   if(!cmSystemTools::FileExists(inFile.c_str(), true))
3397     {
3398     cmOStringStream e;
3399     e << "Target " << target->GetName() << " Info.plist template \""
3400       << inFile << "\" could not be found.";
3401     cmSystemTools::Error(e.str().c_str());
3402     return;
3403     }
3404
3405   // Convert target properties to variables in an isolated makefile
3406   // scope to configure the file.  If properties are set they will
3407   // override user make variables.  If not the configuration will fall
3408   // back to the directory-level values set by the user.
3409   cmMakefile* mf = this->Makefile;
3410   mf->PushScope();
3411   mf->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName);
3412   cmLGInfoProp(mf, target, "MACOSX_BUNDLE_INFO_STRING");
3413   cmLGInfoProp(mf, target, "MACOSX_BUNDLE_ICON_FILE");
3414   cmLGInfoProp(mf, target, "MACOSX_BUNDLE_GUI_IDENTIFIER");
3415   cmLGInfoProp(mf, target, "MACOSX_BUNDLE_LONG_VERSION_STRING");
3416   cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_NAME");
3417   cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
3418   cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION");
3419   cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT");
3420   mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
3421   mf->PopScope();
3422 }
3423
3424 //----------------------------------------------------------------------------
3425 void cmLocalGenerator::GenerateFrameworkInfoPList(cmTarget* target,
3426                                                   const char* targetName,
3427                                                   const char* fname)
3428 {
3429   // Find the Info.plist template.
3430   const char* in = target->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST");
3431   std::string inFile = (in && *in)? in : "MacOSXFrameworkInfo.plist.in";
3432   if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
3433     {
3434     std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
3435     if(!inMod.empty())
3436       {
3437       inFile = inMod;
3438       }
3439     }
3440   if(!cmSystemTools::FileExists(inFile.c_str(), true))
3441     {
3442     cmOStringStream e;
3443     e << "Target " << target->GetName() << " Info.plist template \""
3444       << inFile << "\" could not be found.";
3445     cmSystemTools::Error(e.str().c_str());
3446     return;
3447     }
3448
3449   // Convert target properties to variables in an isolated makefile
3450   // scope to configure the file.  If properties are set they will
3451   // override user make variables.  If not the configuration will fall
3452   // back to the directory-level values set by the user.
3453   cmMakefile* mf = this->Makefile;
3454   mf->PushScope();
3455   mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName);
3456   cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_ICON_FILE");
3457   cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER");
3458   cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
3459   cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
3460   mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
3461   mf->PopScope();
3462 }