packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmNinjaTargetGenerator.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
4   Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
5
6   Distributed under the OSI-approved BSD License (the "License");
7   see accompanying file Copyright.txt for details.
8
9   This software is distributed WITHOUT ANY WARRANTY; without even the
10   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11   See the License for more information.
12 ============================================================================*/
13 #include "cmNinjaTargetGenerator.h"
14 #include "cmGlobalNinjaGenerator.h"
15 #include "cmLocalNinjaGenerator.h"
16 #include "cmGeneratedFileStream.h"
17 #include "cmGeneratorTarget.h"
18 #include "cmNinjaNormalTargetGenerator.h"
19 #include "cmNinjaUtilityTargetGenerator.h"
20 #include "cmSystemTools.h"
21 #include "cmMakefile.h"
22 #include "cmComputeLinkInformation.h"
23 #include "cmSourceFile.h"
24 #include "cmCustomCommandGenerator.h"
25
26 #include <algorithm>
27
28 cmNinjaTargetGenerator *
29 cmNinjaTargetGenerator::New(cmTarget* target)
30 {
31   switch (target->GetType())
32     {
33       case cmTarget::EXECUTABLE:
34       case cmTarget::SHARED_LIBRARY:
35       case cmTarget::STATIC_LIBRARY:
36       case cmTarget::MODULE_LIBRARY:
37       case cmTarget::OBJECT_LIBRARY:
38         return new cmNinjaNormalTargetGenerator(target);
39
40       case cmTarget::UTILITY:
41         return new cmNinjaUtilityTargetGenerator(target);;
42
43       case cmTarget::GLOBAL_TARGET: {
44         // We only want to process global targets that live in the home
45         // (i.e. top-level) directory.  CMake creates copies of these targets
46         // in every directory, which we don't need.
47         cmMakefile *mf = target->GetMakefile();
48         if (strcmp(mf->GetStartDirectory(), mf->GetHomeDirectory()) == 0)
49           return new cmNinjaUtilityTargetGenerator(target);
50         // else fallthrough
51       }
52
53       default:
54         return 0;
55     }
56 }
57
58 cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmTarget* target)
59   :
60     MacOSXContentGenerator(0),
61     OSXBundleGenerator(0),
62     MacContentFolders(),
63     Target(target),
64     Makefile(target->GetMakefile()),
65     LocalGenerator(
66       static_cast<cmLocalNinjaGenerator*>(Makefile->GetLocalGenerator())),
67     Objects()
68 {
69   this->GeneratorTarget =
70     this->GetGlobalGenerator()->GetGeneratorTarget(target);
71   MacOSXContentGenerator = new MacOSXContentGeneratorType(this);
72 }
73
74 cmNinjaTargetGenerator::~cmNinjaTargetGenerator()
75 {
76   delete this->MacOSXContentGenerator;
77 }
78
79 cmGeneratedFileStream& cmNinjaTargetGenerator::GetBuildFileStream() const
80 {
81   return *this->GetGlobalGenerator()->GetBuildFileStream();
82 }
83
84 cmGeneratedFileStream& cmNinjaTargetGenerator::GetRulesFileStream() const
85 {
86   return *this->GetGlobalGenerator()->GetRulesFileStream();
87 }
88
89 cmGlobalNinjaGenerator* cmNinjaTargetGenerator::GetGlobalGenerator() const
90 {
91   return this->LocalGenerator->GetGlobalNinjaGenerator();
92 }
93
94 const char* cmNinjaTargetGenerator::GetConfigName() const
95 {
96   return this->LocalGenerator->GetConfigName();
97 }
98
99 // TODO: Picked up from cmMakefileTargetGenerator.  Refactor it.
100 const char* cmNinjaTargetGenerator::GetFeature(const char* feature)
101 {
102   return this->Target->GetFeature(feature, this->GetConfigName());
103 }
104
105 // TODO: Picked up from cmMakefileTargetGenerator.  Refactor it.
106 bool cmNinjaTargetGenerator::GetFeatureAsBool(const char* feature)
107 {
108   return cmSystemTools::IsOn(this->GetFeature(feature));
109 }
110
111 // TODO: Picked up from cmMakefileTargetGenerator.  Refactor it.
112 void cmNinjaTargetGenerator::AddFeatureFlags(std::string& flags,
113                                              const char* lang)
114 {
115   // Add language-specific flags.
116   this->LocalGenerator->AddLanguageFlags(flags, lang, this->GetConfigName());
117
118   if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION"))
119     {
120     this->LocalGenerator->AppendFeatureOptions(flags, lang, "IPO");
121     }
122 }
123
124 // TODO: Most of the code is picked up from
125 // void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink),
126 // void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
127 // Refactor it.
128 std::string
129 cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile *source,
130                                               const std::string& language)
131 {
132   std::string flags;
133
134   this->AddFeatureFlags(flags, language.c_str());
135
136   this->GetLocalGenerator()->AddArchitectureFlags(flags,
137                                                   this->GeneratorTarget,
138                                                   language.c_str(),
139                                                   this->GetConfigName());
140
141   // TODO: Fortran support.
142   // // Fortran-specific flags computed for this target.
143   // if(*l == "Fortran")
144   //   {
145   //   this->AddFortranFlags(flags);
146   //   }
147
148   // Add shared-library flags if needed.
149   this->LocalGenerator->AddCMP0018Flags(flags, this->Target,
150                                         language.c_str(),
151                                         this->GetConfigName());
152
153   this->LocalGenerator->AddVisibilityPresetFlags(flags, this->Target,
154                                                  language.c_str());
155
156   // Add include directory flags.
157   const char *config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
158   {
159   std::vector<std::string> includes;
160   this->LocalGenerator->GetIncludeDirectories(includes,
161                                               this->GeneratorTarget,
162                                               language.c_str(), config);
163   std::string includeFlags =
164     this->LocalGenerator->GetIncludeFlags(includes, this->GeneratorTarget,
165                                           language.c_str(),
166     language == "RC" ? true : false); // full include paths for RC
167                                       // needed by cmcldeps
168   if(cmGlobalNinjaGenerator::IsMinGW())
169     cmSystemTools::ReplaceString(includeFlags, "\\", "/");
170
171   this->LocalGenerator->AppendFlags(flags, includeFlags.c_str());
172   }
173
174   // Append old-style preprocessor definition flags.
175   this->LocalGenerator->AppendFlags(flags, this->Makefile->GetDefineFlags());
176
177   // Add target-specific flags.
178   this->LocalGenerator->AddCompileOptions(flags, this->Target,
179                                           language.c_str(), config);
180
181     // Add source file specific flags.
182     this->LocalGenerator->AppendFlags(flags,
183       source->GetProperty("COMPILE_FLAGS"));
184
185   // TODO: Handle Apple frameworks.
186
187   return flags;
188 }
189
190 // TODO: Refactor with
191 // void cmMakefileTargetGenerator::WriteTargetLanguageFlags().
192 std::string
193 cmNinjaTargetGenerator::
194 ComputeDefines(cmSourceFile *source, const std::string& language)
195 {
196   std::set<std::string> defines;
197
198   // Add the export symbol definition for shared library objects.
199   if(const char* exportMacro = this->Target->GetExportMacro())
200     {
201     this->LocalGenerator->AppendDefines(defines, exportMacro);
202     }
203
204   // Add preprocessor definitions for this target and configuration.
205   this->LocalGenerator->AddCompileDefinitions(defines, this->Target,
206                                              this->GetConfigName());
207   this->LocalGenerator->AppendDefines
208     (defines,
209      source->GetProperty("COMPILE_DEFINITIONS"));
210   {
211   std::string defPropName = "COMPILE_DEFINITIONS_";
212   defPropName += cmSystemTools::UpperCase(this->GetConfigName());
213   this->LocalGenerator->AppendDefines
214     (defines,
215      source->GetProperty(defPropName.c_str()));
216   }
217
218   std::string definesString;
219   this->LocalGenerator->JoinDefines(defines, definesString,
220      language.c_str());
221
222   return definesString;
223 }
224
225 cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const
226 {
227   // Static libraries never depend on other targets for linking.
228   if (this->Target->GetType() == cmTarget::STATIC_LIBRARY ||
229       this->Target->GetType() == cmTarget::OBJECT_LIBRARY)
230     return cmNinjaDeps();
231
232   cmComputeLinkInformation* cli =
233     this->Target->GetLinkInformation(this->GetConfigName());
234   if(!cli)
235     return cmNinjaDeps();
236
237   const std::vector<std::string> &deps = cli->GetDepends();
238   cmNinjaDeps result(deps.size());
239   std::transform(deps.begin(), deps.end(), result.begin(), MapToNinjaPath());
240
241   // Add a dependency on the link definitions file, if any.
242   if(!this->ModuleDefinitionFile.empty())
243     {
244     result.push_back(this->ModuleDefinitionFile);
245     }
246
247   return result;
248 }
249
250 std::string
251 cmNinjaTargetGenerator
252 ::GetSourceFilePath(cmSourceFile* source) const
253 {
254   return ConvertToNinjaPath(source->GetFullPath().c_str());
255 }
256
257 std::string
258 cmNinjaTargetGenerator
259 ::GetObjectFilePath(cmSourceFile* source) const
260 {
261   std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
262   if(!path.empty())
263     path += "/";
264   std::string const& objectName = this->GeneratorTarget->Objects[source];
265   path += this->LocalGenerator->GetTargetDirectory(*this->Target);
266   path += "/";
267   path += objectName;
268   return path;
269 }
270
271 std::string cmNinjaTargetGenerator::GetTargetOutputDir() const
272 {
273   std::string dir = this->Target->GetDirectory(this->GetConfigName());
274   return ConvertToNinjaPath(dir.c_str());
275 }
276
277 std::string
278 cmNinjaTargetGenerator
279 ::GetTargetFilePath(const std::string& name) const
280 {
281   std::string path = this->GetTargetOutputDir();
282   if (path.empty() || path == ".")
283     return name;
284   path += "/";
285   path += name;
286   return path;
287 }
288
289 std::string cmNinjaTargetGenerator::GetTargetName() const
290 {
291   return this->Target->GetName();
292 }
293
294
295 bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable(cmNinjaVars& vars) const
296 {
297   cmMakefile* mf = this->GetMakefile();
298   if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") ||
299       mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID"))
300     {
301     std::string pdbPath;
302     if(this->Target->GetType() == cmTarget::EXECUTABLE ||
303        this->Target->GetType() == cmTarget::STATIC_LIBRARY ||
304        this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
305        this->Target->GetType() == cmTarget::MODULE_LIBRARY)
306       {
307       pdbPath = this->Target->GetPDBDirectory(this->GetConfigName());
308       pdbPath += "/";
309       pdbPath += this->Target->GetPDBName(this->GetConfigName());
310       }
311
312     vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
313                           ConvertToNinjaPath(pdbPath.c_str()).c_str(),
314                           cmLocalGenerator::SHELL);
315     EnsureParentDirectoryExists(pdbPath);
316     return true;
317     }
318   return false;
319 }
320
321 void
322 cmNinjaTargetGenerator
323 ::WriteLanguageRules(const std::string& language)
324 {
325 #ifdef NINJA_GEN_VERBOSE_FILES
326   this->GetRulesFileStream()
327     << "# Rules for language " << language << "\n\n";
328 #endif
329   this->WriteCompileRule(language);
330 }
331
332 void
333 cmNinjaTargetGenerator
334 ::WriteCompileRule(const std::string& language)
335 {
336   cmLocalGenerator::RuleVariables vars;
337   vars.RuleLauncher = "RULE_LAUNCH_COMPILE";
338   vars.CMTarget = this->GetTarget();
339   std::string lang = language;
340   vars.Language = lang.c_str();
341   vars.Source = "$in";
342   vars.Object = "$out";
343   std::string flags = "$FLAGS";
344   vars.Defines = "$DEFINES";
345   vars.TargetPDB = "$TARGET_PDB";
346   vars.ObjectDir = "$OBJECT_DIR";
347
348   cmMakefile* mf = this->GetMakefile();
349
350   bool useClDeps = false;
351   std::string clBinary;
352   std::string clDepsBinary;
353   std::string clShowPrefix;
354   if (lang == "C" || lang == "CXX" || lang == "RC")
355     {
356     clDepsBinary = mf->GetSafeDefinition("CMAKE_CMCLDEPS_EXECUTABLE");
357     if (!clDepsBinary.empty() && !mf->GetIsSourceFileTryCompile())
358       {
359       clShowPrefix = mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDE_PREFIX");
360       clBinary = mf->GetDefinition("CMAKE_C_COMPILER") ?
361                  mf->GetSafeDefinition("CMAKE_C_COMPILER") :
362                  mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
363       if (!clBinary.empty() && !clShowPrefix.empty())
364         {
365         useClDeps = true;
366         const std::string quote = " \"";
367         clBinary     = quote + clBinary     + "\" ";
368         clDepsBinary = quote + clDepsBinary + "\" ";
369         clShowPrefix = quote + clShowPrefix + "\" ";
370         vars.DependencyFile = "$DEP_FILE";
371         }
372       }
373     }
374
375
376   std::string depfile;
377   std::string depfileFlagsName = "CMAKE_DEPFILE_FLAGS_" + language;
378   const char *depfileFlags = mf->GetDefinition(depfileFlagsName.c_str());
379   if (depfileFlags || useClDeps) {
380     std::string depFlagsStr = depfileFlags ? depfileFlags : "";
381     depfile = "$DEP_FILE";
382     cmSystemTools::ReplaceString(depFlagsStr, "<DEPFILE>", "\"$DEP_FILE\"");
383     cmSystemTools::ReplaceString(depFlagsStr, "<OBJECT>",  "$out");
384     cmSystemTools::ReplaceString(depFlagsStr, "<CMAKE_C_COMPILER>",
385                        mf->GetDefinition("CMAKE_C_COMPILER"));
386     flags += " " + depFlagsStr;
387   }
388   vars.Flags = flags.c_str();
389
390
391   // Rule for compiling object file.
392   std::string compileCmdVar = "CMAKE_";
393   compileCmdVar += language;
394   compileCmdVar += "_COMPILE_OBJECT";
395   std::string compileCmd = mf->GetRequiredDefinition(compileCmdVar.c_str());
396   std::vector<std::string> compileCmds;
397   cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
398
399   if(useClDeps)
400     {
401     std::string cmdPrefix = clDepsBinary + lang + " $in \"$DEP_FILE\" $out " +
402                             clShowPrefix + clBinary;
403     compileCmds.front().insert(0, cmdPrefix);
404     }
405
406   for (std::vector<std::string>::iterator i = compileCmds.begin();
407        i != compileCmds.end(); ++i)
408     this->GetLocalGenerator()->ExpandRuleVariables(*i, vars);
409
410   std::string cmdLine =
411     this->GetLocalGenerator()->BuildCommandLine(compileCmds);
412
413
414   // Write the rule for compiling file of the given language.
415   cmOStringStream comment;
416   comment << "Rule for compiling " << language << " files.";
417   cmOStringStream description;
418   description << "Building " << language << " object $out";
419   this->GetGlobalGenerator()->AddRule(this->LanguageCompilerRule(language),
420                                       cmdLine,
421                                       description.str(),
422                                       comment.str(),
423                                       depfile);
424 }
425
426 void
427 cmNinjaTargetGenerator
428 ::WriteObjectBuildStatements()
429 {
430   // Write comments.
431   cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
432   this->GetBuildFileStream()
433     << "# Object build statements for "
434     << cmTarget::GetTargetTypeName(this->GetTarget()->GetType())
435     << " target "
436     << this->GetTargetName()
437     << "\n\n";
438
439   for(std::vector<cmSourceFile*>::const_iterator
440         si = this->GeneratorTarget->CustomCommands.begin();
441       si != this->GeneratorTarget->CustomCommands.end(); ++si)
442      {
443      cmCustomCommand const* cc = (*si)->GetCustomCommand();
444      this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget());
445      }
446   this->OSXBundleGenerator->GenerateMacOSXContentStatements(
447     this->GeneratorTarget->HeaderSources,
448     this->MacOSXContentGenerator);
449   this->OSXBundleGenerator->GenerateMacOSXContentStatements(
450     this->GeneratorTarget->ExtraSources,
451     this->MacOSXContentGenerator);
452   for(std::vector<cmSourceFile*>::const_iterator
453         si = this->GeneratorTarget->ExternalObjects.begin();
454       si != this->GeneratorTarget->ExternalObjects.end(); ++si)
455     {
456     this->Objects.push_back(this->GetSourceFilePath(*si));
457     }
458   for(std::vector<cmSourceFile*>::const_iterator
459         si = this->GeneratorTarget->ObjectSources.begin();
460       si != this->GeneratorTarget->ObjectSources.end(); ++si)
461     {
462     this->WriteObjectBuildStatement(*si);
463     }
464   if(!this->GeneratorTarget->ModuleDefinitionFile.empty())
465     {
466     this->ModuleDefinitionFile = this->ConvertToNinjaPath(
467       this->GeneratorTarget->ModuleDefinitionFile.c_str());
468     }
469
470   {
471   // Add object library contents as external objects.
472   std::vector<std::string> objs;
473   this->GeneratorTarget->UseObjectLibraries(objs);
474   for(std::vector<std::string>::iterator oi = objs.begin();
475       oi != objs.end(); ++oi)
476     {
477     this->Objects.push_back(ConvertToNinjaPath(oi->c_str()));
478     }
479   }
480
481   this->GetBuildFileStream() << "\n";
482 }
483
484 void
485 cmNinjaTargetGenerator
486 ::WriteObjectBuildStatement(cmSourceFile* source)
487 {
488   std::string comment;
489   const std::string language = source->GetLanguage();
490   std::string rule = this->LanguageCompilerRule(language);
491
492   cmNinjaDeps outputs;
493   std::string objectFileName = this->GetObjectFilePath(source);
494   outputs.push_back(objectFileName);
495   // Add this object to the list of object files.
496   this->Objects.push_back(objectFileName);
497
498   cmNinjaDeps explicitDeps;
499   std::string sourceFileName;
500   if (language == "RC")
501     sourceFileName = source->GetFullPath();
502   else
503     sourceFileName = this->GetSourceFilePath(source);
504   explicitDeps.push_back(sourceFileName);
505
506   // Ensure that the target dependencies are built before any source file in
507   // the target, using order-only dependencies.
508   cmNinjaDeps orderOnlyDeps;
509   this->GetLocalGenerator()->AppendTargetDepends(this->Target, orderOnlyDeps);
510
511   cmNinjaDeps implicitDeps;
512   if(const char* objectDeps = source->GetProperty("OBJECT_DEPENDS")) {
513     std::vector<std::string> depList;
514     cmSystemTools::ExpandListArgument(objectDeps, depList);
515     std::transform(depList.begin(), depList.end(),
516                    std::back_inserter(implicitDeps), MapToNinjaPath());
517   }
518
519   // Add order-only dependencies on custom command outputs.
520   for(std::vector<cmSourceFile*>::const_iterator
521         si = this->GeneratorTarget->CustomCommands.begin();
522       si != this->GeneratorTarget->CustomCommands.end(); ++si)
523     {
524     cmCustomCommand const* cc = (*si)->GetCustomCommand();
525     const std::vector<std::string>& ccoutputs = cc->GetOutputs();
526     std::transform(ccoutputs.begin(), ccoutputs.end(),
527                    std::back_inserter(orderOnlyDeps), MapToNinjaPath());
528     }
529
530   // If the source file is GENERATED and does not have a custom command
531   // (either attached to this source file or another one), assume that one of
532   // the target dependencies, OBJECT_DEPENDS or header file custom commands
533   // will rebuild the file.
534   if (source->GetPropertyAsBool("GENERATED") && !source->GetCustomCommand() &&
535       !this->GetGlobalGenerator()->HasCustomCommandOutput(sourceFileName)) {
536     this->GetGlobalGenerator()->AddAssumedSourceDependencies(sourceFileName,
537                                                              orderOnlyDeps);
538   }
539
540   cmNinjaVars vars;
541   vars["FLAGS"] = this->ComputeFlagsForObject(source, language);
542   vars["DEFINES"] = this->ComputeDefines(source, language);
543   vars["DEP_FILE"] = objectFileName + ".d";;
544   EnsureParentDirectoryExists(objectFileName);
545
546   std::string objectDir = this->Target->GetSupportDirectory();
547   vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
548                          ConvertToNinjaPath(objectDir.c_str()).c_str(),
549                          cmLocalGenerator::SHELL);
550
551   this->SetMsvcTargetPdbVariable(vars);
552
553   if(this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS"))
554     {
555     cmLocalGenerator::RuleVariables compileObjectVars;
556     std::string lang = language;
557     compileObjectVars.Language = lang.c_str();
558
559     std::string escapedSourceFileName = sourceFileName;
560
561     if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str()))
562       {
563       escapedSourceFileName = cmSystemTools::CollapseFullPath(
564         escapedSourceFileName.c_str(),
565         this->GetGlobalGenerator()->GetCMakeInstance()->
566           GetHomeOutputDirectory());
567       }
568
569     escapedSourceFileName =
570       this->LocalGenerator->ConvertToOutputFormat(
571         escapedSourceFileName.c_str(), cmLocalGenerator::SHELL);
572
573     compileObjectVars.Source = escapedSourceFileName.c_str();
574     compileObjectVars.Object = objectFileName.c_str();
575     compileObjectVars.ObjectDir = objectDir.c_str();
576     compileObjectVars.Flags = vars["FLAGS"].c_str();
577     compileObjectVars.Defines = vars["DEFINES"].c_str();
578
579     // Rule for compiling object file.
580     std::string compileCmdVar = "CMAKE_";
581     compileCmdVar += language;
582     compileCmdVar += "_COMPILE_OBJECT";
583     std::string compileCmd =
584       this->GetMakefile()->GetRequiredDefinition(compileCmdVar.c_str());
585     std::vector<std::string> compileCmds;
586     cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
587
588     for (std::vector<std::string>::iterator i = compileCmds.begin();
589         i != compileCmds.end(); ++i)
590       this->GetLocalGenerator()->ExpandRuleVariables(*i, compileObjectVars);
591
592     std::string cmdLine =
593       this->GetLocalGenerator()->BuildCommandLine(compileCmds);
594
595     this->GetGlobalGenerator()->AddCXXCompileCommand(cmdLine,
596                                                      sourceFileName);
597     }
598
599   this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(),
600                                          comment,
601                                          rule,
602                                          outputs,
603                                          explicitDeps,
604                                          implicitDeps,
605                                          orderOnlyDeps,
606                                          vars);
607
608   if(const char* objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) {
609     std::vector<std::string> outputList;
610     cmSystemTools::ExpandListArgument(objectOutputs, outputList);
611     std::transform(outputList.begin(), outputList.end(), outputList.begin(),
612                    MapToNinjaPath());
613     this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
614                                                 "Additional output files.",
615                                                 outputList,
616                                                 outputs);
617   }
618 }
619
620 //----------------------------------------------------------------------------
621 void
622 cmNinjaTargetGenerator
623 ::AddModuleDefinitionFlag(std::string& flags)
624 {
625   if(this->ModuleDefinitionFile.empty())
626     {
627     return;
628     }
629
630   // TODO: Create a per-language flag variable.
631   const char* defFileFlag =
632     this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG");
633   if(!defFileFlag)
634     {
635     return;
636     }
637
638   // Append the flag and value.  Use ConvertToLinkReference to help
639   // vs6's "cl -link" pass it to the linker.
640   std::string flag = defFileFlag;
641   flag += (this->LocalGenerator->ConvertToLinkReference(
642              this->ModuleDefinitionFile.c_str()));
643   this->LocalGenerator->AppendFlags(flags, flag.c_str());
644 }
645
646 void
647 cmNinjaTargetGenerator
648 ::EnsureDirectoryExists(const std::string& path) const
649 {
650   if (cmSystemTools::FileIsFullPath(path.c_str()))
651     {
652     cmSystemTools::MakeDirectory(path.c_str());
653     }
654   else
655     {
656     const std::string fullPath = std::string(this->GetGlobalGenerator()->
657                                  GetCMakeInstance()->GetHomeOutputDirectory())
658                                    + "/" + path;
659     cmSystemTools::MakeDirectory(fullPath.c_str());
660     }
661 }
662
663 void
664 cmNinjaTargetGenerator
665 ::EnsureParentDirectoryExists(const std::string& path) const
666 {
667   EnsureDirectoryExists(cmSystemTools::GetParentDirectory(path.c_str()));
668 }
669
670
671 //----------------------------------------------------------------------------
672 void
673 cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
674   cmSourceFile& source, const char* pkgloc)
675 {
676   // Skip OS X content when not building a Framework or Bundle.
677   if(!this->Generator->GetTarget()->IsBundleOnApple())
678     {
679     return;
680     }
681
682   std::string macdir =
683     this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(pkgloc);
684
685   // Get the input file location.
686   std::string input = source.GetFullPath();
687   input =
688     this->Generator->GetLocalGenerator()->ConvertToNinjaPath(input.c_str());
689
690   // Get the output file location.
691   std::string output = macdir;
692   output += "/";
693   output += cmSystemTools::GetFilenameName(input);
694   output =
695     this->Generator->GetLocalGenerator()->ConvertToNinjaPath(output.c_str());
696
697   // Write a build statement to copy the content into the bundle.
698   this->Generator->GetGlobalGenerator()->WriteMacOSXContentBuild(input,
699                                                                  output);
700
701   // Add as a dependency of all target so that it gets called.
702   this->Generator->GetGlobalGenerator()->AddDependencyToAll(output);
703 }