Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmLocalUnixMakefileGenerator3.cxx
blob9039394b6c7c32dc7aa607a4c7932661149ab220
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmLocalUnixMakefileGenerator3.cxx,v $
5 Language: C++
6 Date: $Date: 2009-02-24 20:37:09 $
7 Version: $Revision: 1.262 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmLocalUnixMakefileGenerator3.h"
19 #include "cmDepends.h"
20 #include "cmGeneratedFileStream.h"
21 #include "cmGlobalUnixMakefileGenerator3.h"
22 #include "cmMakefile.h"
23 #include "cmMakefileTargetGenerator.h"
24 #include "cmSourceFile.h"
25 #include "cmake.h"
26 #include "cmVersion.h"
27 #include "cmFileTimeComparison.h"
29 // Include dependency scanners for supported languages. Only the
30 // C/C++ scanner is needed for bootstrapping CMake.
31 #include "cmDependsC.h"
32 #ifdef CMAKE_BUILD_WITH_CMAKE
33 # include "cmDependsFortran.h"
34 # include "cmDependsJava.h"
35 # include <cmsys/Terminal.h>
36 #endif
38 #include <memory> // auto_ptr
39 #include <queue>
41 //----------------------------------------------------------------------------
42 // Helper function used below.
43 static std::string cmSplitExtension(std::string const& in, std::string& base)
45 std::string ext;
46 std::string::size_type dot_pos = in.rfind(".");
47 if(dot_pos != std::string::npos)
49 // Remove the extension first in case &base == &in.
50 ext = in.substr(dot_pos, std::string::npos);
51 base = in.substr(0, dot_pos);
53 else
55 base = in;
57 return ext;
60 //----------------------------------------------------------------------------
61 cmLocalUnixMakefileGenerator3::cmLocalUnixMakefileGenerator3()
63 this->SilentNoColon = false;
64 this->WindowsShell = false;
65 this->IncludeDirective = "include";
66 this->MakefileVariableSize = 0;
67 this->IgnoreLibPrefix = false;
68 this->PassMakeflags = false;
69 this->DefineWindowsNULL = false;
70 this->UnixCD = true;
71 this->ColorMakefile = false;
72 this->SkipPreprocessedSourceRules = false;
73 this->SkipAssemblySourceRules = false;
74 this->NativeEchoCommand = "@echo ";
75 this->NativeEchoWindows = true;
76 this->MakeCommandEscapeTargetTwice = false;
77 this->IsMakefileGenerator = true;
78 this->BorlandMakeCurlyHack = false;
81 //----------------------------------------------------------------------------
82 cmLocalUnixMakefileGenerator3::~cmLocalUnixMakefileGenerator3()
86 //----------------------------------------------------------------------------
87 void cmLocalUnixMakefileGenerator3::Configure()
89 // Compute the path to use when referencing the current output
90 // directory from the top output directory.
91 this->HomeRelativeOutputPath =
92 this->Convert(this->Makefile->GetStartOutputDirectory(), HOME_OUTPUT);
93 if(this->HomeRelativeOutputPath == ".")
95 this->HomeRelativeOutputPath = "";
97 if(!this->HomeRelativeOutputPath.empty())
99 this->HomeRelativeOutputPath += "/";
101 this->cmLocalGenerator::Configure();
104 //----------------------------------------------------------------------------
105 void cmLocalUnixMakefileGenerator3::Generate()
107 // Store the configuration name that will be generated.
108 if(const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"))
110 // Use the build type given by the user.
111 this->ConfigurationName = config;
113 else
115 // No configuration type given.
116 this->ConfigurationName = "";
119 // Record whether some options are enabled to avoid checking many
120 // times later.
121 this->ColorMakefile = this->Makefile->IsOn("CMAKE_COLOR_MAKEFILE");
122 this->SkipPreprocessedSourceRules =
123 this->Makefile->IsOn("CMAKE_SKIP_PREPROCESSED_SOURCE_RULES");
124 this->SkipAssemblySourceRules =
125 this->Makefile->IsOn("CMAKE_SKIP_ASSEMBLY_SOURCE_RULES");
127 // Generate the rule files for each target.
128 cmTargets& targets = this->Makefile->GetTargets();
129 std::string empty;
130 for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
132 cmMakefileTargetGenerator *tg =
133 cmMakefileTargetGenerator::New(&(t->second));
134 if (tg)
136 this->TargetGenerators.push_back(tg);
137 tg->WriteRuleFiles();
141 // write the local Makefile
142 this->WriteLocalMakefile();
144 // Write the cmake file with information for this directory.
145 this->WriteDirectoryInformationFile();
148 //----------------------------------------------------------------------------
149 // return info about progress actions
150 unsigned long cmLocalUnixMakefileGenerator3::GetNumberOfProgressActions()
152 unsigned long result = 0;
154 for (std::vector<cmMakefileTargetGenerator *>::iterator mtgIter =
155 this->TargetGenerators.begin();
156 mtgIter != this->TargetGenerators.end(); ++mtgIter)
158 result += (*mtgIter)->GetNumberOfProgressActions();
160 return result;
163 //----------------------------------------------------------------------------
164 // return info about progress actions
165 unsigned long cmLocalUnixMakefileGenerator3
166 ::GetNumberOfProgressActionsForTarget(const char *name)
168 for (std::vector<cmMakefileTargetGenerator *>::iterator mtgIter =
169 this->TargetGenerators.begin();
170 mtgIter != this->TargetGenerators.end(); ++mtgIter)
172 if (!strcmp(name,(*mtgIter)->GetTarget()->GetName()))
174 return (*mtgIter)->GetNumberOfProgressActions();
177 return 0;
181 //----------------------------------------------------------------------------
182 // writes the progreess variables and also closes out the targets
183 void cmLocalUnixMakefileGenerator3
184 ::WriteProgressVariables(unsigned long total,
185 unsigned long &current)
187 // delete the makefile target generator objects
188 for (std::vector<cmMakefileTargetGenerator *>::iterator mtgIter =
189 this->TargetGenerators.begin();
190 mtgIter != this->TargetGenerators.end(); ++mtgIter)
192 (*mtgIter)->WriteProgressVariables(total,current);
193 delete *mtgIter;
195 this->TargetGenerators.clear();
198 void cmLocalUnixMakefileGenerator3::WriteAllProgressVariable()
200 // write the top level progress for the all target
201 std::string progressFile = cmake::GetCMakeFilesDirectory();
202 progressFile += "/progress.make";
203 std::string progressFileNameFull =
204 this->ConvertToFullPath(progressFile.c_str());
205 cmGeneratedFileStream ruleFileStream(progressFileNameFull.c_str());
206 if(!ruleFileStream)
208 return;
211 cmGlobalUnixMakefileGenerator3 *gg =
212 static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
214 ruleFileStream << gg->GetNumberOfProgressActionsInAll(this) << "\n";
217 //----------------------------------------------------------------------------
218 void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
220 // generate the includes
221 std::string ruleFileName = "Makefile";
223 // Open the rule file. This should be copy-if-different because the
224 // rules may depend on this file itself.
225 std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
226 cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
227 if(!ruleFileStream)
229 return;
231 // always write the top makefile
232 if (this->Parent)
234 ruleFileStream.SetCopyIfDifferent(true);
237 // write the all rules
238 this->WriteLocalAllRules(ruleFileStream);
240 // only write local targets unless at the top Keep track of targets already
241 // listed.
242 std::set<cmStdString> emittedTargets;
243 if (this->Parent)
245 // write our targets, and while doing it collect up the object
246 // file rules
247 this->WriteLocalMakefileTargets(ruleFileStream,emittedTargets);
249 else
251 cmGlobalUnixMakefileGenerator3 *gg =
252 static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
253 gg->WriteConvenienceRules(ruleFileStream,emittedTargets);
256 bool do_preprocess_rules =
257 this->GetCreatePreprocessedSourceRules();
258 bool do_assembly_rules =
259 this->GetCreateAssemblySourceRules();
261 // now write out the object rules
262 // for each object file name
263 for (std::map<cmStdString, LocalObjectInfo>::iterator lo =
264 this->LocalObjectFiles.begin();
265 lo != this->LocalObjectFiles.end(); ++lo)
267 // Add a convenience rule for building the object file.
268 this->WriteObjectConvenienceRule(ruleFileStream,
269 "target to build an object file",
270 lo->first.c_str(), lo->second);
272 // Check whether preprocessing and assembly rules make sense.
273 // They make sense only for C and C++ sources.
274 bool lang_is_c_or_cxx = false;
275 for(std::vector<LocalObjectEntry>::const_iterator ei =
276 lo->second.begin(); ei != lo->second.end(); ++ei)
278 if(ei->Language == "C" || ei->Language == "CXX")
280 lang_is_c_or_cxx = true;
284 // Add convenience rules for preprocessed and assembly files.
285 if(lang_is_c_or_cxx && (do_preprocess_rules || do_assembly_rules))
287 std::string::size_type dot_pos = lo->first.rfind(".");
288 std::string base = lo->first.substr(0, dot_pos);
289 if(do_preprocess_rules)
291 this->WriteObjectConvenienceRule(
292 ruleFileStream, "target to preprocess a source file",
293 (base + ".i").c_str(), lo->second);
295 if(do_assembly_rules)
297 this->WriteObjectConvenienceRule(
298 ruleFileStream, "target to generate assembly for a file",
299 (base + ".s").c_str(), lo->second);
304 // add a help target as long as there isn;t a real target named help
305 if(emittedTargets.insert("help").second)
307 cmGlobalUnixMakefileGenerator3 *gg =
308 static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
309 gg->WriteHelpRule(ruleFileStream,this);
312 this->WriteSpecialTargetsBottom(ruleFileStream);
315 //----------------------------------------------------------------------------
316 void
317 cmLocalUnixMakefileGenerator3
318 ::WriteObjectConvenienceRule(std::ostream& ruleFileStream,
319 const char* comment, const char* output,
320 LocalObjectInfo const& info)
322 // If the rule includes the source file extension then create a
323 // version that has the extension removed. The help should include
324 // only the version without source extension.
325 bool inHelp = true;
326 if(info.HasSourceExtension)
328 // Remove the last extension. This should be kept.
329 std::string outBase1 = output;
330 std::string outExt1 = cmSplitExtension(outBase1, outBase1);
332 // Now remove the source extension and put back the last
333 // extension.
334 std::string outNoExt;
335 cmSplitExtension(outBase1, outNoExt);
336 outNoExt += outExt1;
338 // Add a rule to drive the rule below.
339 std::vector<std::string> depends;
340 depends.push_back(output);
341 std::vector<std::string> no_commands;
342 this->WriteMakeRule(ruleFileStream, 0,
343 outNoExt.c_str(), depends, no_commands, true, true);
344 inHelp = false;
347 // Recursively make the rule for each target using the object file.
348 std::vector<std::string> commands;
349 for(std::vector<LocalObjectEntry>::const_iterator t = info.begin();
350 t != info.end(); ++t)
352 std::string tgtMakefileName =
353 this->GetRelativeTargetDirectory(*(t->Target));
354 std::string targetName = tgtMakefileName;
355 tgtMakefileName += "/build.make";
356 targetName += "/";
357 targetName += output;
358 commands.push_back(
359 this->GetRecursiveMakeCall(tgtMakefileName.c_str(), targetName.c_str())
362 this->CreateCDCommand(commands,
363 this->Makefile->GetHomeOutputDirectory(),
364 cmLocalGenerator::START_OUTPUT);
366 // Write the rule to the makefile.
367 std::vector<std::string> no_depends;
368 this->WriteMakeRule(ruleFileStream, comment,
369 output, no_depends, commands, true, inHelp);
372 //----------------------------------------------------------------------------
373 void cmLocalUnixMakefileGenerator3
374 ::WriteLocalMakefileTargets(std::ostream& ruleFileStream,
375 std::set<cmStdString> &emitted)
377 std::vector<std::string> depends;
378 std::vector<std::string> commands;
380 // for each target we just provide a rule to cd up to the top and do a make
381 // on the target
382 cmTargets& targets = this->Makefile->GetTargets();
383 std::string localName;
384 for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
386 if((t->second.GetType() == cmTarget::EXECUTABLE) ||
387 (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
388 (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
389 (t->second.GetType() == cmTarget::MODULE_LIBRARY) ||
390 (t->second.GetType() == cmTarget::UTILITY))
392 emitted.insert(t->second.GetName());
394 // for subdirs add a rule to build this specific target by name.
395 localName = this->GetRelativeTargetDirectory(t->second);
396 localName += "/rule";
397 commands.clear();
398 depends.clear();
400 // Build the target for this pass.
401 std::string makefile2 = cmake::GetCMakeFilesDirectoryPostSlash();
402 makefile2 += "Makefile2";
403 commands.push_back(this->GetRecursiveMakeCall
404 (makefile2.c_str(),localName.c_str()));
405 this->CreateCDCommand(commands,
406 this->Makefile->GetHomeOutputDirectory(),
407 cmLocalGenerator::START_OUTPUT);
408 this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
409 localName.c_str(), depends, commands, true);
411 // Add a target with the canonical name (no prefix, suffix or path).
412 if(localName != t->second.GetName())
414 commands.clear();
415 depends.push_back(localName);
416 this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
417 t->second.GetName(), depends, commands, true);
420 // Add a fast rule to build the target
421 std::string makefileName = this->GetRelativeTargetDirectory(t->second);
422 makefileName += "/build.make";
423 // make sure the makefile name is suitable for a makefile
424 std::string makeTargetName =
425 this->GetRelativeTargetDirectory(t->second);
426 makeTargetName += "/build";
427 localName = t->second.GetName();
428 localName += "/fast";
429 depends.clear();
430 commands.clear();
431 commands.push_back(this->GetRecursiveMakeCall
432 (makefileName.c_str(), makeTargetName.c_str()));
433 this->CreateCDCommand(commands,
434 this->Makefile->GetHomeOutputDirectory(),
435 cmLocalGenerator::START_OUTPUT);
436 this->WriteMakeRule(ruleFileStream, "fast build rule for target.",
437 localName.c_str(), depends, commands, true);
439 // Add a local name for the rule to relink the target before
440 // installation.
441 if(t->second.NeedRelinkBeforeInstall())
443 makeTargetName = this->GetRelativeTargetDirectory(t->second);
444 makeTargetName += "/preinstall";
445 localName = t->second.GetName();
446 localName += "/preinstall";
447 depends.clear();
448 commands.clear();
449 commands.push_back(this->GetRecursiveMakeCall
450 (makefile2.c_str(), makeTargetName.c_str()));
451 this->CreateCDCommand(commands,
452 this->Makefile->GetHomeOutputDirectory(),
453 cmLocalGenerator::START_OUTPUT);
454 this->WriteMakeRule(ruleFileStream,
455 "Manual pre-install relink rule for target.",
456 localName.c_str(), depends, commands, true);
462 //----------------------------------------------------------------------------
463 void cmLocalUnixMakefileGenerator3::WriteDirectoryInformationFile()
465 std::string infoFileName = this->Makefile->GetStartOutputDirectory();
466 infoFileName += cmake::GetCMakeFilesDirectory();
467 infoFileName += "/CMakeDirectoryInformation.cmake";
469 // Open the output file.
470 cmGeneratedFileStream infoFileStream(infoFileName.c_str());
471 if(!infoFileStream)
473 return;
476 // Write the do not edit header.
477 this->WriteDisclaimer(infoFileStream);
479 // Setup relative path conversion tops.
480 infoFileStream
481 << "# Relative path conversion top directories.\n"
482 << "SET(CMAKE_RELATIVE_PATH_TOP_SOURCE \"" << this->RelativePathTopSource
483 << "\")\n"
484 << "SET(CMAKE_RELATIVE_PATH_TOP_BINARY \"" << this->RelativePathTopBinary
485 << "\")\n"
486 << "\n";
488 // Tell the dependency scanner to use unix paths if necessary.
489 if(cmSystemTools::GetForceUnixPaths())
491 infoFileStream
492 << "# Force unix paths in dependencies.\n"
493 << "SET(CMAKE_FORCE_UNIX_PATHS 1)\n"
494 << "\n";
497 // Store the include search path for this directory.
498 infoFileStream
499 << "# The C and CXX include file search paths:\n";
500 infoFileStream
501 << "SET(CMAKE_C_INCLUDE_PATH\n";
502 std::vector<std::string> includeDirs;
503 this->GetIncludeDirectories(includeDirs);
504 for(std::vector<std::string>::iterator i = includeDirs.begin();
505 i != includeDirs.end(); ++i)
507 infoFileStream
508 << " \"" << this->Convert(i->c_str(),HOME_OUTPUT).c_str() << "\"\n";
510 infoFileStream
511 << " )\n";
512 infoFileStream
513 << "SET(CMAKE_CXX_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH})\n";
514 infoFileStream
515 << "SET(CMAKE_Fortran_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH})\n";
517 // Store the include regular expressions for this directory.
518 infoFileStream
519 << "\n"
520 << "# The C and CXX include file regular expressions for "
521 << "this directory.\n";
522 infoFileStream
523 << "SET(CMAKE_C_INCLUDE_REGEX_SCAN ";
524 this->WriteCMakeArgument(infoFileStream,
525 this->Makefile->GetIncludeRegularExpression());
526 infoFileStream
527 << ")\n";
528 infoFileStream
529 << "SET(CMAKE_C_INCLUDE_REGEX_COMPLAIN ";
530 this->WriteCMakeArgument(infoFileStream,
531 this->Makefile->GetComplainRegularExpression());
532 infoFileStream
533 << ")\n";
534 infoFileStream
535 << "SET(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN})\n";
536 infoFileStream
537 << "SET(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN "
538 "${CMAKE_C_INCLUDE_REGEX_COMPLAIN})\n";
541 //----------------------------------------------------------------------------
542 std::string
543 cmLocalUnixMakefileGenerator3
544 ::ConvertToFullPath(const std::string& localPath)
546 std::string dir = this->Makefile->GetStartOutputDirectory();
547 dir += "/";
548 dir += localPath;
549 return dir;
553 const std::string &cmLocalUnixMakefileGenerator3::GetHomeRelativeOutputPath()
555 return this->HomeRelativeOutputPath;
559 //----------------------------------------------------------------------------
560 void
561 cmLocalUnixMakefileGenerator3
562 ::WriteMakeRule(std::ostream& os,
563 const char* comment,
564 const char* target,
565 const std::vector<std::string>& depends,
566 const std::vector<std::string>& commands,
567 bool symbolic,
568 bool in_help)
570 // Make sure there is a target.
571 if(!target || !*target)
573 cmSystemTools::Error("No target for WriteMakeRule! called with comment: ",
574 comment);
575 return;
578 std::string replace;
580 // Write the comment describing the rule in the makefile.
581 if(comment)
583 replace = comment;
584 std::string::size_type lpos = 0;
585 std::string::size_type rpos;
586 while((rpos = replace.find('\n', lpos)) != std::string::npos)
588 os << "# " << replace.substr(lpos, rpos-lpos) << "\n";
589 lpos = rpos+1;
591 os << "# " << replace.substr(lpos) << "\n";
594 // Construct the left hand side of the rule.
595 replace = target;
596 std::string tgt = this->Convert(replace.c_str(),HOME_OUTPUT,MAKEFILE);
597 const char* space = "";
598 if(tgt.size() == 1)
600 // Add a space before the ":" to avoid drive letter confusion on
601 // Windows.
602 space = " ";
605 // Mark the rule as symbolic if requested.
606 if(symbolic)
608 if(const char* sym =
609 this->Makefile->GetDefinition("CMAKE_MAKE_SYMBOLIC_RULE"))
611 os << tgt.c_str() << space << ": " << sym << "\n";
615 // Write the rule.
616 if(depends.empty())
618 // No dependencies. The commands will always run.
619 os << tgt.c_str() << space << ":\n";
621 else
623 // Split dependencies into multiple rule lines. This allows for
624 // very long dependency lists even on older make implementations.
625 for(std::vector<std::string>::const_iterator dep = depends.begin();
626 dep != depends.end(); ++dep)
628 replace = *dep;
629 replace = this->Convert(replace.c_str(),HOME_OUTPUT,MAKEFILE);
630 os << tgt.c_str() << space << ": " << replace.c_str() << "\n";
634 // Write the list of commands.
635 for(std::vector<std::string>::const_iterator i = commands.begin();
636 i != commands.end(); ++i)
638 replace = *i;
639 os << "\t" << replace.c_str() << "\n";
641 if(symbolic && !this->WatcomWMake)
643 os << ".PHONY : " << tgt.c_str() << "\n";
645 os << "\n";
646 // Add the output to the local help if requested.
647 if(in_help)
649 this->LocalHelp.push_back(target);
653 //----------------------------------------------------------------------------
654 void
655 cmLocalUnixMakefileGenerator3
656 ::WriteMakeVariables(std::ostream& makefileStream)
658 this->WriteDivider(makefileStream);
659 makefileStream
660 << "# Set environment variables for the build.\n"
661 << "\n";
662 if(this->DefineWindowsNULL)
664 makefileStream
665 << "!IF \"$(OS)\" == \"Windows_NT\"\n"
666 << "NULL=\n"
667 << "!ELSE\n"
668 << "NULL=nul\n"
669 << "!ENDIF\n";
671 if(this->WindowsShell)
673 makefileStream
674 << "SHELL = cmd.exe\n"
675 << "\n";
677 else
679 makefileStream
680 << "# The shell in which to execute make rules.\n"
681 << "SHELL = /bin/sh\n"
682 << "\n";
685 std::string cmakecommand =
686 this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
687 makefileStream
688 << "# The CMake executable.\n"
689 << "CMAKE_COMMAND = "
690 << this->Convert(cmakecommand.c_str(), FULL, SHELL).c_str()
691 << "\n"
692 << "\n";
693 makefileStream
694 << "# The command to remove a file.\n"
695 << "RM = "
696 << this->Convert(cmakecommand.c_str(),FULL,SHELL).c_str()
697 << " -E remove -f\n"
698 << "\n";
700 if(const char* edit_cmd =
701 this->Makefile->GetDefinition("CMAKE_EDIT_COMMAND"))
703 makefileStream
704 << "# The program to use to edit the cache.\n"
705 << "CMAKE_EDIT_COMMAND = "
706 << this->Convert(edit_cmd,FULL,SHELL) << "\n"
707 << "\n";
710 makefileStream
711 << "# The top-level source directory on which CMake was run.\n"
712 << "CMAKE_SOURCE_DIR = "
713 << this->Convert(this->Makefile->GetHomeDirectory(), FULL, SHELL)
714 << "\n"
715 << "\n";
716 makefileStream
717 << "# The top-level build directory on which CMake was run.\n"
718 << "CMAKE_BINARY_DIR = "
719 << this->Convert(this->Makefile->GetHomeOutputDirectory(), FULL, SHELL)
720 << "\n"
721 << "\n";
724 //----------------------------------------------------------------------------
725 void
726 cmLocalUnixMakefileGenerator3
727 ::WriteSpecialTargetsTop(std::ostream& makefileStream)
729 this->WriteDivider(makefileStream);
730 makefileStream
731 << "# Special targets provided by cmake.\n"
732 << "\n";
734 std::vector<std::string> no_commands;
735 std::vector<std::string> no_depends;
737 // Special target to cleanup operation of make tool.
738 // This should be the first target except for the default_target in
739 // the interface Makefile.
740 this->WriteMakeRule(
741 makefileStream, "Disable implicit rules so canoncical targets will work.",
742 ".SUFFIXES", no_depends, no_commands, false);
744 if(!this->NMake && !this->WatcomWMake && !this->BorlandMakeCurlyHack)
746 // turn off RCS and SCCS automatic stuff from gmake
747 makefileStream
748 << "# Remove some rules from gmake that .SUFFIXES does not remove.\n"
749 << "SUFFIXES =\n\n";
751 // Add a fake suffix to keep HP happy. Must be max 32 chars for SGI make.
752 std::vector<std::string> depends;
753 depends.push_back(".hpux_make_needs_suffix_list");
754 this->WriteMakeRule(makefileStream, 0,
755 ".SUFFIXES", depends, no_commands, false);
757 cmGlobalUnixMakefileGenerator3* gg =
758 static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
759 // Write special target to silence make output. This must be after
760 // the default target in case VERBOSE is set (which changes the
761 // name). The setting of CMAKE_VERBOSE_MAKEFILE to ON will cause a
762 // "VERBOSE=1" to be added as a make variable which will change the
763 // name of this special target. This gives a make-time choice to
764 // the user.
765 if((this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"))
766 || (gg->GetForceVerboseMakefiles()))
768 makefileStream
769 << "# Produce verbose output by default.\n"
770 << "VERBOSE = 1\n"
771 << "\n";
773 if(this->SilentNoColon)
775 makefileStream << "$(VERBOSE).SILENT\n";
777 else
779 this->WriteMakeRule(makefileStream,
780 "Suppress display of executed commands.",
781 "$(VERBOSE).SILENT",
782 no_depends,
783 no_commands, false);
786 // Work-around for makes that drop rules that have no dependencies
787 // or commands.
788 std::string hack = gg->GetEmptyRuleHackDepends();
789 if(!hack.empty())
791 no_depends.push_back(hack);
793 std::string hack_cmd = gg->GetEmptyRuleHackCommand();
794 if(!hack_cmd.empty())
796 no_commands.push_back(hack_cmd);
799 // Special symbolic target that never exists to force dependers to
800 // run their rules.
801 this->WriteMakeRule
802 (makefileStream,
803 "A target that is always out of date.",
804 "cmake_force", no_depends, no_commands, true);
806 // Variables for reference by other rules.
807 this->WriteMakeVariables(makefileStream);
810 //----------------------------------------------------------------------------
811 void cmLocalUnixMakefileGenerator3
812 ::WriteSpecialTargetsBottom(std::ostream& makefileStream)
814 this->WriteDivider(makefileStream);
815 makefileStream
816 << "# Special targets to cleanup operation of make.\n"
817 << "\n";
819 // Write special "cmake_check_build_system" target to run cmake with
820 // the --check-build-system flag.
822 // Build command to run CMake to check if anything needs regenerating.
823 std::string cmakefileName = cmake::GetCMakeFilesDirectoryPostSlash();
824 cmakefileName += "Makefile.cmake";
825 std::string runRule =
826 "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
827 runRule += " --check-build-system ";
828 runRule += this->Convert(cmakefileName.c_str(),NONE,SHELL);
829 runRule += " 0";
831 std::vector<std::string> no_depends;
832 std::vector<std::string> commands;
833 commands.push_back(runRule);
834 if(this->Parent)
836 this->CreateCDCommand(commands,
837 this->Makefile->GetHomeOutputDirectory(),
838 cmLocalGenerator::START_OUTPUT);
840 this->WriteMakeRule(makefileStream,
841 "Special rule to run CMake to check the build system "
842 "integrity.\n"
843 "No rule that depends on this can have "
844 "commands that come from listfiles\n"
845 "because they might be regenerated.",
846 "cmake_check_build_system",
847 no_depends,
848 commands, true);
854 //----------------------------------------------------------------------------
855 void
856 cmLocalUnixMakefileGenerator3
857 ::WriteConvenienceRule(std::ostream& ruleFileStream,
858 const char* realTarget,
859 const char* helpTarget)
861 // A rule is only needed if the names are different.
862 if(strcmp(realTarget, helpTarget) != 0)
864 // The helper target depends on the real target.
865 std::vector<std::string> depends;
866 depends.push_back(realTarget);
868 // There are no commands.
869 std::vector<std::string> no_commands;
871 // Write the rule.
872 this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
873 helpTarget, depends, no_commands, true);
878 //----------------------------------------------------------------------------
879 std::string
880 cmLocalUnixMakefileGenerator3
881 ::GetRelativeTargetDirectory(cmTarget const& target)
883 std::string dir = this->HomeRelativeOutputPath;
884 dir += this->GetTargetDirectory(target);
885 return this->Convert(dir.c_str(),NONE,UNCHANGED);
890 //----------------------------------------------------------------------------
891 void cmLocalUnixMakefileGenerator3::AppendFlags(std::string& flags,
892 const char* newFlags)
894 if(this->WatcomWMake && newFlags && *newFlags)
896 std::string newf = newFlags;
897 if(newf.find("\\\"") != newf.npos)
899 cmSystemTools::ReplaceString(newf, "\\\"", "\"");
900 this->cmLocalGenerator::AppendFlags(flags, newf.c_str());
901 return;
904 this->cmLocalGenerator::AppendFlags(flags, newFlags);
907 //----------------------------------------------------------------------------
908 void
909 cmLocalUnixMakefileGenerator3
910 ::AppendRuleDepend(std::vector<std::string>& depends,
911 const char* ruleFileName)
913 // Add a dependency on the rule file itself unless an option to skip
914 // it is specifically enabled by the user or project.
915 const char* nodep =
916 this->Makefile->GetDefinition("CMAKE_SKIP_RULE_DEPENDENCY");
917 if(!nodep || cmSystemTools::IsOff(nodep))
919 depends.push_back(ruleFileName);
923 //----------------------------------------------------------------------------
924 void
925 cmLocalUnixMakefileGenerator3
926 ::AppendCustomDepends(std::vector<std::string>& depends,
927 const std::vector<cmCustomCommand>& ccs)
929 for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
930 i != ccs.end(); ++i)
932 this->AppendCustomDepend(depends, *i);
936 //----------------------------------------------------------------------------
937 void
938 cmLocalUnixMakefileGenerator3
939 ::AppendCustomDepend(std::vector<std::string>& depends,
940 const cmCustomCommand& cc)
942 for(std::vector<std::string>::const_iterator d = cc.GetDepends().begin();
943 d != cc.GetDepends().end(); ++d)
945 // Lookup the real name of the dependency in case it is a CMake target.
946 std::string dep = this->GetRealDependency
947 (d->c_str(), this->ConfigurationName.c_str());
948 depends.push_back(dep);
952 //----------------------------------------------------------------------------
953 void
954 cmLocalUnixMakefileGenerator3
955 ::AppendCustomCommands(std::vector<std::string>& commands,
956 const std::vector<cmCustomCommand>& ccs,
957 cmTarget* target,
958 cmLocalGenerator::RelativeRoot relative)
960 for(std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
961 i != ccs.end(); ++i)
963 this->AppendCustomCommand(commands, *i, target, true, relative);
967 //----------------------------------------------------------------------------
968 void
969 cmLocalUnixMakefileGenerator3
970 ::AppendCustomCommand(std::vector<std::string>& commands,
971 const cmCustomCommand& cc,
972 cmTarget* target,
973 bool echo_comment,
974 cmLocalGenerator::RelativeRoot relative,
975 std::ostream* content)
977 // Optionally create a command to display the custom command's
978 // comment text. This is used for pre-build, pre-link, and
979 // post-build command comments. Custom build step commands have
980 // their comments generated elsewhere.
981 if(echo_comment)
983 const char* comment = cc.GetComment();
984 if(comment && *comment)
986 this->AppendEcho(commands, comment,
987 cmLocalUnixMakefileGenerator3::EchoGenerate);
991 // if the command specified a working directory use it.
992 const char* dir = this->Makefile->GetStartOutputDirectory();
993 const char* workingDir = cc.GetWorkingDirectory();
994 if(workingDir)
996 dir = workingDir;
998 if(content)
1000 *content << dir;
1002 bool escapeOldStyle = cc.GetEscapeOldStyle();
1003 bool escapeAllowMakeVars = cc.GetEscapeAllowMakeVars();
1005 // Add each command line to the set of commands.
1006 std::vector<std::string> commands1;
1007 for(cmCustomCommandLines::const_iterator cl = cc.GetCommandLines().begin();
1008 cl != cc.GetCommandLines().end(); ++cl)
1010 // Build the command line in a single string.
1011 const cmCustomCommandLine& commandLine = *cl;
1012 std::string cmd = GetRealLocation(commandLine[0].c_str(),
1013 this->ConfigurationName.c_str());
1014 if (cmd.size())
1016 cmSystemTools::ReplaceString(cmd, "/./", "/");
1017 // Convert the command to a relative path only if the current
1018 // working directory will be the start-output directory.
1019 bool had_slash = cmd.find("/") != cmd.npos;
1020 if(!workingDir)
1022 cmd = this->Convert(cmd.c_str(),START_OUTPUT);
1024 bool has_slash = cmd.find("/") != cmd.npos;
1025 if(had_slash && !has_slash)
1027 // This command was specified as a path to a file in the
1028 // current directory. Add a leading "./" so it can run
1029 // without the current directory being in the search path.
1030 cmd = "./" + cmd;
1032 if(this->WatcomWMake &&
1033 cmSystemTools::FileIsFullPath(cmd.c_str()) &&
1034 cmd.find(" ") != cmd.npos)
1036 // On Watcom WMake use the windows short path for the command
1037 // name. This is needed to avoid funny quoting problems on
1038 // lines with shell redirection operators.
1039 std::string scmd;
1040 if(cmSystemTools::GetShortPath(cmd.c_str(), scmd))
1042 cmd = scmd;
1045 std::string launcher =
1046 this->MakeLauncher(cc, target, workingDir? NONE : START_OUTPUT);
1047 cmd = launcher + this->Convert(cmd.c_str(),NONE,SHELL);
1048 for(unsigned int j=1; j < commandLine.size(); ++j)
1050 cmd += " ";
1051 if(escapeOldStyle)
1053 cmd += this->EscapeForShellOldStyle(commandLine[j].c_str());
1055 else
1057 cmd += this->EscapeForShell(commandLine[j].c_str(),
1058 escapeAllowMakeVars);
1061 if(content)
1063 // Rule content does not include the launcher.
1064 *content << (cmd.c_str()+launcher.size());
1066 if(this->BorlandMakeCurlyHack)
1068 // Borland Make has a very strange bug. If the first curly
1069 // brace anywhere in the command string is a left curly, it
1070 // must be written {{} instead of just {. Otherwise some
1071 // curly braces are removed. The hack can be skipped if the
1072 // first curly brace is the last character.
1073 std::string::size_type lcurly = cmd.find("{");
1074 if(lcurly != cmd.npos && lcurly < (cmd.size()-1))
1076 std::string::size_type rcurly = cmd.find("}");
1077 if(rcurly == cmd.npos || rcurly > lcurly)
1079 // The first curly is a left curly. Use the hack.
1080 std::string hack_cmd = cmd.substr(0, lcurly);
1081 hack_cmd += "{{}";
1082 hack_cmd += cmd.substr(lcurly+1);
1083 cmd = hack_cmd;
1087 commands1.push_back(cmd);
1091 // Setup the proper working directory for the commands.
1092 this->CreateCDCommand(commands1, dir, relative);
1094 // push back the custom commands
1095 commands.insert(commands.end(), commands1.begin(), commands1.end());
1098 //----------------------------------------------------------------------------
1099 std::string
1100 cmLocalUnixMakefileGenerator3::MakeLauncher(const cmCustomCommand& cc,
1101 cmTarget* target,
1102 RelativeRoot relative)
1104 // Short-circuit if there is no launcher.
1105 const char* prop = "RULE_LAUNCH_CUSTOM";
1106 const char* val = this->GetRuleLauncher(target, prop);
1107 if(!(val && *val))
1109 return "";
1112 // Expand rules in the empty string. It may insert the launcher and
1113 // perform replacements.
1114 RuleVariables vars;
1115 vars.RuleLauncher = prop;
1116 vars.CMTarget = target;
1117 std::string output;
1118 const std::vector<std::string>& outputs = cc.GetOutputs();
1119 if(!outputs.empty())
1121 output = this->Convert(outputs[0].c_str(), relative, SHELL);
1123 vars.Output = output.c_str();
1125 std::string launcher;
1126 this->ExpandRuleVariables(launcher, vars);
1127 if(!launcher.empty())
1129 launcher += " ";
1131 return launcher;
1134 //----------------------------------------------------------------------------
1135 void
1136 cmLocalUnixMakefileGenerator3
1137 ::AppendCleanCommand(std::vector<std::string>& commands,
1138 const std::vector<std::string>& files,
1139 cmTarget& target, const char* filename)
1141 if(!files.empty())
1143 std::string cleanfile = this->Makefile->GetCurrentOutputDirectory();
1144 cleanfile += "/";
1145 cleanfile += this->GetTargetDirectory(target);
1146 cleanfile += "/cmake_clean";
1147 if(filename)
1149 cleanfile += "_";
1150 cleanfile += filename;
1152 cleanfile += ".cmake";
1153 std::string cleanfilePath = this->Convert(cleanfile.c_str(), FULL);
1154 std::ofstream fout(cleanfilePath.c_str());
1155 if(!fout)
1157 cmSystemTools::Error("Could not create ", cleanfilePath.c_str());
1159 fout << "FILE(REMOVE_RECURSE\n";
1160 std::string remove = "$(CMAKE_COMMAND) -P ";
1161 remove += this->Convert(cleanfile.c_str(), START_OUTPUT, SHELL);
1162 for(std::vector<std::string>::const_iterator f = files.begin();
1163 f != files.end(); ++f)
1165 std::string fc = this->Convert(f->c_str(),START_OUTPUT,UNCHANGED);
1166 fout << " " << this->EscapeForCMake(fc.c_str()) << "\n";
1168 fout << ")\n";
1169 commands.push_back(remove);
1171 // For the main clean rule add per-language cleaning.
1172 if(!filename)
1174 // Get the set of source languages in the target.
1175 std::set<cmStdString> languages;
1176 target.GetLanguages(languages);
1177 fout << "\n"
1178 << "# Per-language clean rules from dependency scanning.\n"
1179 << "FOREACH(lang";
1180 for(std::set<cmStdString>::const_iterator l = languages.begin();
1181 l != languages.end(); ++l)
1183 fout << " " << *l;
1185 fout << ")\n"
1186 << " INCLUDE(" << this->GetTargetDirectory(target)
1187 << "/cmake_clean_${lang}.cmake OPTIONAL)\n"
1188 << "ENDFOREACH(lang)\n";
1193 //----------------------------------------------------------------------------
1194 void
1195 cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
1196 const char* text,
1197 EchoColor color)
1199 // Choose the color for the text.
1200 std::string color_name;
1201 #ifdef CMAKE_BUILD_WITH_CMAKE
1202 if(this->GlobalGenerator->GetToolSupportsColor() && this->ColorMakefile)
1204 // See cmake::ExecuteEchoColor in cmake.cxx for these options.
1205 // This color set is readable on both black and white backgrounds.
1206 switch(color)
1208 case EchoNormal:
1209 break;
1210 case EchoDepend:
1211 color_name = "--magenta --bold ";
1212 break;
1213 case EchoBuild:
1214 color_name = "--green ";
1215 break;
1216 case EchoLink:
1217 color_name = "--red --bold ";
1218 break;
1219 case EchoGenerate:
1220 color_name = "--blue --bold ";
1221 break;
1222 case EchoGlobal:
1223 color_name = "--cyan ";
1224 break;
1227 #else
1228 (void)color;
1229 #endif
1231 // Echo one line at a time.
1232 std::string line;
1233 line.reserve(200);
1234 for(const char* c = text;; ++c)
1236 if(*c == '\n' || *c == '\0')
1238 // Avoid writing a blank last line on end-of-string.
1239 if(*c != '\0' || !line.empty())
1241 // Add a command to echo this line.
1242 std::string cmd;
1243 if(color_name.empty())
1245 // Use the native echo command.
1246 cmd = this->NativeEchoCommand;
1247 cmd += this->EscapeForShell(line.c_str(), false,
1248 this->NativeEchoWindows);
1250 else
1252 // Use cmake to echo the text in color.
1253 cmd = "@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) ";
1254 cmd += color_name;
1255 cmd += this->EscapeForShell(line.c_str());
1257 commands.push_back(cmd);
1260 // Reset the line to emtpy.
1261 line = "";
1263 // Terminate on end-of-string.
1264 if(*c == '\0')
1266 return;
1269 else if(*c != '\r')
1271 // Append this character to the current line.
1272 line += *c;
1277 //----------------------------------------------------------------------------
1278 std::string
1279 cmLocalUnixMakefileGenerator3
1280 ::CreateMakeVariable(const char* sin, const char* s2in)
1282 std::string s = sin;
1283 std::string s2 = s2in;
1284 std::string unmodified = s;
1285 unmodified += s2;
1286 // if there is no restriction on the length of make variables
1287 // and there are no "." charactors in the string, then return the
1288 // unmodified combination.
1289 if((!this->MakefileVariableSize && unmodified.find('.') == s.npos)
1290 && (!this->MakefileVariableSize && unmodified.find('-') == s.npos))
1292 return unmodified;
1295 // see if the variable has been defined before and return
1296 // the modified version of the variable
1297 std::map<cmStdString, cmStdString>::iterator i =
1298 this->MakeVariableMap.find(unmodified);
1299 if(i != this->MakeVariableMap.end())
1301 return i->second;
1303 // start with the unmodified variable
1304 std::string ret = unmodified;
1305 // if this there is no value for this->MakefileVariableSize then
1306 // the string must have bad characters in it
1307 if(!this->MakefileVariableSize)
1309 cmSystemTools::ReplaceString(ret, ".", "_");
1310 cmSystemTools::ReplaceString(ret, "-", "__");
1311 int ni = 0;
1312 char buffer[5];
1313 // make sure the _ version is not already used, if
1314 // it is used then add number to the end of the variable
1315 while(this->ShortMakeVariableMap.count(ret) && ni < 1000)
1317 ++ni;
1318 sprintf(buffer, "%04d", ni);
1319 ret = unmodified + buffer;
1321 this->ShortMakeVariableMap[ret] = "1";
1322 this->MakeVariableMap[unmodified] = ret;
1323 return ret;
1326 // if the string is greater the 32 chars it is an invalid vairable name
1327 // for borland make
1328 if(static_cast<int>(ret.size()) > this->MakefileVariableSize)
1330 int keep = this->MakefileVariableSize - 8;
1331 int size = keep + 3;
1332 std::string str1 = s;
1333 std::string str2 = s2;
1334 // we must shorten the combined string by 4 charactors
1335 // keep no more than 24 charactors from the second string
1336 if(static_cast<int>(str2.size()) > keep)
1338 str2 = str2.substr(0, keep);
1340 if(static_cast<int>(str1.size()) + static_cast<int>(str2.size()) > size)
1342 str1 = str1.substr(0, size - str2.size());
1344 char buffer[5];
1345 int ni = 0;
1346 sprintf(buffer, "%04d", ni);
1347 ret = str1 + str2 + buffer;
1348 while(this->ShortMakeVariableMap.count(ret) && ni < 1000)
1350 ++ni;
1351 sprintf(buffer, "%04d", ni);
1352 ret = str1 + str2 + buffer;
1354 if(ni == 1000)
1356 cmSystemTools::Error("Borland makefile variable length too long");
1357 return unmodified;
1359 // once an unused variable is found
1360 this->ShortMakeVariableMap[ret] = "1";
1362 // always make an entry into the unmodified to variable map
1363 this->MakeVariableMap[unmodified] = ret;
1364 return ret;
1367 //----------------------------------------------------------------------------
1368 bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
1369 bool verbose,
1370 bool color)
1372 // read in the target info file
1373 if(!this->Makefile->ReadListFile(0, tgtInfo) ||
1374 cmSystemTools::GetErrorOccuredFlag())
1376 cmSystemTools::Error("Target DependInfo.cmake file not found");
1379 // Check if any multiple output pairs have a missing file.
1380 this->CheckMultipleOutputs(verbose);
1382 std::string dir = cmSystemTools::GetFilenamePath(tgtInfo);
1383 std::string internalDependFile = dir + "/depend.internal";
1384 std::string dependFile = dir + "/depend.make";
1386 // If the target DependInfo.cmake file has changed since the last
1387 // time dependencies were scanned then force rescanning. This may
1388 // happen when a new source file is added and CMake regenerates the
1389 // project but no other sources were touched.
1390 bool needRescan = false;
1391 cmFileTimeComparison* ftc =
1392 this->GlobalGenerator->GetCMakeInstance()->GetFileComparison();
1394 int result;
1395 if(!ftc->FileTimeCompare(internalDependFile.c_str(), tgtInfo, &result) ||
1396 result < 0)
1398 if(verbose)
1400 cmOStringStream msg;
1401 msg << "Dependee \"" << tgtInfo
1402 << "\" is newer than depender \""
1403 << internalDependFile << "\"." << std::endl;
1404 cmSystemTools::Stdout(msg.str().c_str());
1406 needRescan = true;
1410 // Check the implicit dependencies to see if they are up to date.
1411 // The build.make file may have explicit dependencies for the object
1412 // files but these will not affect the scanning process so they need
1413 // not be considered.
1414 cmDependsC checker;
1415 checker.SetVerbose(verbose);
1416 checker.SetFileComparison(ftc);
1417 if(needRescan ||
1418 !checker.Check(dependFile.c_str(), internalDependFile.c_str()))
1420 // The dependencies must be regenerated.
1421 std::string targetName = cmSystemTools::GetFilenameName(dir);
1422 targetName = targetName.substr(0, targetName.length()-4);
1423 std::string message = "Scanning dependencies of target ";
1424 message += targetName;
1425 #ifdef CMAKE_BUILD_WITH_CMAKE
1426 cmSystemTools::MakefileColorEcho(
1427 cmsysTerminal_Color_ForegroundMagenta |
1428 cmsysTerminal_Color_ForegroundBold,
1429 message.c_str(), true, color);
1430 #else
1431 fprintf(stdout, "%s\n", message.c_str());
1432 #endif
1434 return this->ScanDependencies(dir.c_str());
1436 else
1438 // The dependencies are already up-to-date.
1439 return true;
1443 //----------------------------------------------------------------------------
1444 bool
1445 cmLocalUnixMakefileGenerator3
1446 ::ScanDependencies(const char* targetDir)
1448 // Read the directory information file.
1449 cmMakefile* mf = this->Makefile;
1450 bool haveDirectoryInfo = false;
1451 std::string dirInfoFile = this->Makefile->GetStartOutputDirectory();
1452 dirInfoFile += cmake::GetCMakeFilesDirectory();
1453 dirInfoFile += "/CMakeDirectoryInformation.cmake";
1454 if(mf->ReadListFile(0, dirInfoFile.c_str()) &&
1455 !cmSystemTools::GetErrorOccuredFlag())
1457 haveDirectoryInfo = true;
1460 // Lookup useful directory information.
1461 if(haveDirectoryInfo)
1463 // Test whether we need to force Unix paths.
1464 if(const char* force = mf->GetDefinition("CMAKE_FORCE_UNIX_PATHS"))
1466 if(!cmSystemTools::IsOff(force))
1468 cmSystemTools::SetForceUnixPaths(true);
1472 // Setup relative path top directories.
1473 this->RelativePathsConfigured = true;
1474 if(const char* relativePathTopSource =
1475 mf->GetDefinition("CMAKE_RELATIVE_PATH_TOP_SOURCE"))
1477 this->RelativePathTopSource = relativePathTopSource;
1479 if(const char* relativePathTopBinary =
1480 mf->GetDefinition("CMAKE_RELATIVE_PATH_TOP_BINARY"))
1482 this->RelativePathTopBinary = relativePathTopBinary;
1485 else
1487 cmSystemTools::Error("Directory Information file not found");
1490 // create the file stream for the depends file
1491 std::string dir = targetDir;
1493 // Open the make depends file. This should be copy-if-different
1494 // because the make tool may try to reload it needlessly otherwise.
1495 std::string ruleFileNameFull = dir;
1496 ruleFileNameFull += "/depend.make";
1497 cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
1498 ruleFileStream.SetCopyIfDifferent(true);
1499 if(!ruleFileStream)
1501 return false;
1504 // Open the cmake dependency tracking file. This should not be
1505 // copy-if-different because dependencies are re-scanned when it is
1506 // older than the DependInfo.cmake.
1507 std::string internalRuleFileNameFull = dir;
1508 internalRuleFileNameFull += "/depend.internal";
1509 cmGeneratedFileStream
1510 internalRuleFileStream(internalRuleFileNameFull.c_str());
1511 if(!internalRuleFileStream)
1513 return false;
1516 this->WriteDisclaimer(ruleFileStream);
1517 this->WriteDisclaimer(internalRuleFileStream);
1519 // for each language we need to scan, scan it
1520 const char *langStr = mf->GetSafeDefinition("CMAKE_DEPENDS_LANGUAGES");
1521 std::vector<std::string> langs;
1522 cmSystemTools::ExpandListArgument(langStr, langs);
1523 for (std::vector<std::string>::iterator li =
1524 langs.begin(); li != langs.end(); ++li)
1526 // construct the checker
1527 std::string lang = li->c_str();
1529 // Create the scanner for this language
1530 cmDepends *scanner = 0;
1531 if(lang == "C" || lang == "CXX" || lang == "RC")
1533 // TODO: Handle RC (resource files) dependencies correctly.
1534 scanner = new cmDependsC(this, targetDir, lang.c_str());
1536 #ifdef CMAKE_BUILD_WITH_CMAKE
1537 else if(lang == "Fortran")
1539 scanner = new cmDependsFortran(this);
1541 else if(lang == "Java")
1543 scanner = new cmDependsJava();
1545 #endif
1547 if (scanner)
1549 scanner->SetLocalGenerator(this);
1550 scanner->SetFileComparison
1551 (this->GlobalGenerator->GetCMakeInstance()->GetFileComparison());
1552 scanner->SetLanguage(lang.c_str());
1553 scanner->SetTargetDirectory(dir.c_str());
1554 scanner->Write(ruleFileStream, internalRuleFileStream);
1556 // free the scanner for this language
1557 delete scanner;
1561 return true;
1564 //----------------------------------------------------------------------------
1565 void cmLocalUnixMakefileGenerator3::CheckMultipleOutputs(bool verbose)
1567 cmMakefile* mf = this->Makefile;
1569 // Get the string listing the multiple output pairs.
1570 const char* pairs_string = mf->GetDefinition("CMAKE_MULTIPLE_OUTPUT_PAIRS");
1571 if(!pairs_string)
1573 return;
1576 // Convert the string to a list and preserve empty entries.
1577 std::vector<std::string> pairs;
1578 cmSystemTools::ExpandListArgument(pairs_string, pairs, true);
1579 for(std::vector<std::string>::const_iterator i = pairs.begin();
1580 i != pairs.end() && (i+1) != pairs.end();)
1582 const std::string& depender = *i++;
1583 const std::string& dependee = *i++;
1585 // If the depender is missing then delete the dependee to make
1586 // sure both will be regenerated.
1587 if(cmSystemTools::FileExists(dependee.c_str()) &&
1588 !cmSystemTools::FileExists(depender.c_str()))
1590 if(verbose)
1592 cmOStringStream msg;
1593 msg << "Deleting primary custom command output \"" << dependee
1594 << "\" because another output \""
1595 << depender << "\" does not exist." << std::endl;
1596 cmSystemTools::Stdout(msg.str().c_str());
1598 cmSystemTools::RemoveFile(dependee.c_str());
1603 //----------------------------------------------------------------------------
1604 void cmLocalUnixMakefileGenerator3
1605 ::WriteLocalAllRules(std::ostream& ruleFileStream)
1607 this->WriteDisclaimer(ruleFileStream);
1609 // Write the main entry point target. This must be the VERY first
1610 // target so that make with no arguments will run it.
1612 // Just depend on the all target to drive the build.
1613 std::vector<std::string> depends;
1614 std::vector<std::string> no_commands;
1615 depends.push_back("all");
1617 // Write the rule.
1618 this->WriteMakeRule(ruleFileStream,
1619 "Default target executed when no arguments are "
1620 "given to make.",
1621 "default_target",
1622 depends,
1623 no_commands, true);
1626 this->WriteSpecialTargetsTop(ruleFileStream);
1628 // Include the progress variables for the target.
1629 // Write all global targets
1630 this->WriteDivider(ruleFileStream);
1631 ruleFileStream
1632 << "# Targets provided globally by CMake.\n"
1633 << "\n";
1634 cmTargets* targets = &(this->Makefile->GetTargets());
1635 cmTargets::iterator glIt;
1636 for ( glIt = targets->begin(); glIt != targets->end(); ++ glIt )
1638 if ( glIt->second.GetType() == cmTarget::GLOBAL_TARGET )
1640 std::string targetString = "Special rule for the target " + glIt->first;
1641 std::vector<std::string> commands;
1642 std::vector<std::string> depends;
1644 const char* text = glIt->second.GetProperty("EchoString");
1645 if ( !text )
1647 text = "Running external command ...";
1649 std::set<cmStdString>::const_iterator dit;
1650 for ( dit = glIt->second.GetUtilities().begin();
1651 dit != glIt->second.GetUtilities().end();
1652 ++ dit )
1654 depends.push_back(dit->c_str());
1656 this->AppendEcho(commands, text,
1657 cmLocalUnixMakefileGenerator3::EchoGlobal);
1659 // Global targets store their rules in pre- and post-build commands.
1660 this->AppendCustomDepends(depends,
1661 glIt->second.GetPreBuildCommands());
1662 this->AppendCustomDepends(depends,
1663 glIt->second.GetPostBuildCommands());
1664 this->AppendCustomCommands(commands,
1665 glIt->second.GetPreBuildCommands(),
1666 &glIt->second,
1667 cmLocalGenerator::START_OUTPUT);
1668 this->AppendCustomCommands(commands,
1669 glIt->second.GetPostBuildCommands(),
1670 &glIt->second,
1671 cmLocalGenerator::START_OUTPUT);
1672 std::string targetName = glIt->second.GetName();
1673 this->WriteMakeRule(ruleFileStream, targetString.c_str(),
1674 targetName.c_str(), depends, commands, true);
1676 // Provide a "/fast" version of the target.
1677 depends.clear();
1678 if((targetName == "install")
1679 || (targetName == "install_local")
1680 || (targetName == "install_strip"))
1682 // Provide a fast install target that does not depend on all
1683 // but has the same command.
1684 depends.push_back("preinstall/fast");
1686 else
1688 // Just forward to the real target so at least it will work.
1689 depends.push_back(targetName);
1690 commands.clear();
1692 targetName += "/fast";
1693 this->WriteMakeRule(ruleFileStream, targetString.c_str(),
1694 targetName.c_str(), depends, commands, true);
1698 std::vector<std::string> depends;
1699 std::vector<std::string> commands;
1701 // Write the all rule.
1702 std::string dir;
1703 std::string recursiveTarget = this->Makefile->GetStartOutputDirectory();
1704 recursiveTarget += "/all";
1706 depends.push_back("cmake_check_build_system");
1708 std::string progressDir = this->Makefile->GetHomeOutputDirectory();
1709 progressDir += cmake::GetCMakeFilesDirectory();
1711 cmOStringStream progCmd;
1712 progCmd <<
1713 "$(CMAKE_COMMAND) -E cmake_progress_start ";
1714 progCmd << this->Convert(progressDir.c_str(),
1715 cmLocalGenerator::FULL,
1716 cmLocalGenerator::SHELL);
1718 std::string progressFile = cmake::GetCMakeFilesDirectory();
1719 progressFile += "/progress.make";
1720 std::string progressFileNameFull =
1721 this->ConvertToFullPath(progressFile.c_str());
1722 progCmd << " " << this->Convert(progressFileNameFull.c_str(),
1723 cmLocalGenerator::FULL,
1724 cmLocalGenerator::SHELL);
1725 commands.push_back(progCmd.str());
1727 std::string mf2Dir = cmake::GetCMakeFilesDirectoryPostSlash();
1728 mf2Dir += "Makefile2";
1729 commands.push_back(this->GetRecursiveMakeCall(mf2Dir.c_str(),
1730 recursiveTarget.c_str()));
1731 this->CreateCDCommand(commands,
1732 this->Makefile->GetHomeOutputDirectory(),
1733 cmLocalGenerator::START_OUTPUT);
1735 cmOStringStream progCmd;
1736 progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start "; // # 0
1737 progCmd << this->Convert(progressDir.c_str(),
1738 cmLocalGenerator::FULL,
1739 cmLocalGenerator::SHELL);
1740 progCmd << " 0";
1741 commands.push_back(progCmd.str());
1743 this->WriteMakeRule(ruleFileStream, "The main all target", "all",
1744 depends, commands, true);
1746 // Write the clean rule.
1747 recursiveTarget = this->Makefile->GetStartOutputDirectory();
1748 recursiveTarget += "/clean";
1749 commands.clear();
1750 depends.clear();
1751 commands.push_back(this->GetRecursiveMakeCall(mf2Dir.c_str(),
1752 recursiveTarget.c_str()));
1753 this->CreateCDCommand(commands,
1754 this->Makefile->GetHomeOutputDirectory(),
1755 cmLocalGenerator::START_OUTPUT);
1756 this->WriteMakeRule(ruleFileStream, "The main clean target", "clean",
1757 depends, commands, true);
1758 commands.clear();
1759 depends.clear();
1760 depends.push_back("clean");
1761 this->WriteMakeRule(ruleFileStream, "The main clean target", "clean/fast",
1762 depends, commands, true);
1764 // Write the preinstall rule.
1765 recursiveTarget = this->Makefile->GetStartOutputDirectory();
1766 recursiveTarget += "/preinstall";
1767 commands.clear();
1768 depends.clear();
1769 const char* noall =
1770 this->Makefile->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
1771 if(!noall || cmSystemTools::IsOff(noall))
1773 // Drive the build before installing.
1774 depends.push_back("all");
1776 else
1778 // At least make sure the build system is up to date.
1779 depends.push_back("cmake_check_build_system");
1781 commands.push_back
1782 (this->GetRecursiveMakeCall(mf2Dir.c_str(), recursiveTarget.c_str()));
1783 this->CreateCDCommand(commands,
1784 this->Makefile->GetHomeOutputDirectory(),
1785 cmLocalGenerator::START_OUTPUT);
1786 this->WriteMakeRule(ruleFileStream, "Prepare targets for installation.",
1787 "preinstall", depends, commands, true);
1788 depends.clear();
1789 this->WriteMakeRule(ruleFileStream, "Prepare targets for installation.",
1790 "preinstall/fast", depends, commands, true);
1792 // write the depend rule, really a recompute depends rule
1793 depends.clear();
1794 commands.clear();
1795 std::string cmakefileName = cmake::GetCMakeFilesDirectoryPostSlash();
1796 cmakefileName += "Makefile.cmake";
1797 std::string runRule =
1798 "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
1799 runRule += " --check-build-system ";
1800 runRule += this->Convert(cmakefileName.c_str(),cmLocalGenerator::NONE,
1801 cmLocalGenerator::SHELL);
1802 runRule += " 1";
1803 commands.push_back(runRule);
1804 this->CreateCDCommand(commands,
1805 this->Makefile->GetHomeOutputDirectory(),
1806 cmLocalGenerator::START_OUTPUT);
1807 this->WriteMakeRule(ruleFileStream, "clear depends",
1808 "depend",
1809 depends, commands, true);
1813 //----------------------------------------------------------------------------
1814 void cmLocalUnixMakefileGenerator3::ClearDependencies(cmMakefile* mf,
1815 bool verbose)
1817 // Get the list of target files to check
1818 const char* infoDef = mf->GetDefinition("CMAKE_DEPEND_INFO_FILES");
1819 if(!infoDef)
1821 return;
1823 std::vector<std::string> files;
1824 cmSystemTools::ExpandListArgument(infoDef, files);
1826 // Each depend information file corresponds to a target. Clear the
1827 // dependencies for that target.
1828 cmDepends clearer;
1829 clearer.SetVerbose(verbose);
1830 for(std::vector<std::string>::iterator l = files.begin();
1831 l != files.end(); ++l)
1833 std::string dir = cmSystemTools::GetFilenamePath(l->c_str());
1835 // Clear the implicit dependency makefile.
1836 std::string dependFile = dir + "/depend.make";
1837 clearer.Clear(dependFile.c_str());
1839 // Remove the internal dependency check file to force
1840 // regeneration.
1841 std::string internalDependFile = dir + "/depend.internal";
1842 cmSystemTools::RemoveFile(internalDependFile.c_str());
1847 void cmLocalUnixMakefileGenerator3
1848 ::WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &target)
1850 ImplicitDependLanguageMap const& implicitLangs =
1851 this->GetImplicitDepends(target);
1853 // list the languages
1854 cmakefileStream
1855 << "# The set of languages for which implicit dependencies are needed:\n";
1856 cmakefileStream
1857 << "SET(CMAKE_DEPENDS_LANGUAGES\n";
1858 for(ImplicitDependLanguageMap::const_iterator
1859 l = implicitLangs.begin(); l != implicitLangs.end(); ++l)
1861 cmakefileStream << " \"" << l->first.c_str() << "\"\n";
1863 cmakefileStream << " )\n";
1865 // now list the files for each language
1866 cmakefileStream
1867 << "# The set of files for implicit dependencies of each language:\n";
1868 for(ImplicitDependLanguageMap::const_iterator
1869 l = implicitLangs.begin(); l != implicitLangs.end(); ++l)
1871 cmakefileStream
1872 << "SET(CMAKE_DEPENDS_CHECK_" << l->first.c_str() << "\n";
1873 ImplicitDependFileMap const& implicitPairs = l->second;
1875 // for each file pair
1876 for(ImplicitDependFileMap::const_iterator pi = implicitPairs.begin();
1877 pi != implicitPairs.end(); ++pi)
1879 cmakefileStream << " \"" << pi->second << "\" ";
1880 cmakefileStream << "\"" << pi->first << "\"\n";
1882 cmakefileStream << " )\n";
1884 // Tell the dependency scanner what compiler is used.
1885 std::string cidVar = "CMAKE_";
1886 cidVar += l->first;
1887 cidVar += "_COMPILER_ID";
1888 const char* cid = this->Makefile->GetDefinition(cidVar.c_str());
1889 if(cid && *cid)
1891 cmakefileStream
1892 << "SET(CMAKE_" << l->first.c_str() << "_COMPILER_ID \""
1893 << cid << "\")\n";
1897 // Build a list of preprocessor definitions for the target.
1898 std::vector<std::string> defines;
1900 std::string defPropName = "COMPILE_DEFINITIONS_";
1901 defPropName += cmSystemTools::UpperCase(this->ConfigurationName);
1902 if(const char* ddefs = this->Makefile->GetProperty("COMPILE_DEFINITIONS"))
1904 cmSystemTools::ExpandListArgument(ddefs, defines);
1906 if(const char* cdefs = target.GetProperty("COMPILE_DEFINITIONS"))
1908 cmSystemTools::ExpandListArgument(cdefs, defines);
1910 if(const char* dcdefs = this->Makefile->GetProperty(defPropName.c_str()))
1912 cmSystemTools::ExpandListArgument(dcdefs, defines);
1914 if(const char* ccdefs = target.GetProperty(defPropName.c_str()))
1916 cmSystemTools::ExpandListArgument(ccdefs, defines);
1919 if(!defines.empty())
1921 cmakefileStream
1922 << "\n"
1923 << "# Preprocessor definitions for this target.\n"
1924 << "SET(CMAKE_TARGET_DEFINITIONS\n";
1925 for(std::vector<std::string>::const_iterator di = defines.begin();
1926 di != defines.end(); ++di)
1928 cmakefileStream
1929 << " " << this->EscapeForCMake(di->c_str()) << "\n";
1931 cmakefileStream
1932 << " )\n";
1935 // Store include transform rule properties. Write the directory
1936 // rules first because they may be overridden by later target rules.
1937 std::vector<std::string> transformRules;
1938 if(const char* xform =
1939 this->Makefile->GetProperty("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM"))
1941 cmSystemTools::ExpandListArgument(xform, transformRules);
1943 if(const char* xform =
1944 target.GetProperty("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM"))
1946 cmSystemTools::ExpandListArgument(xform, transformRules);
1948 if(!transformRules.empty())
1950 cmakefileStream
1951 << "SET(CMAKE_INCLUDE_TRANSFORMS\n";
1952 for(std::vector<std::string>::const_iterator tri = transformRules.begin();
1953 tri != transformRules.end(); ++tri)
1955 cmakefileStream << " " << this->EscapeForCMake(tri->c_str()) << "\n";
1957 cmakefileStream
1958 << " )\n";
1962 //----------------------------------------------------------------------------
1963 std::string
1964 cmLocalUnixMakefileGenerator3
1965 ::GetObjectFileName(cmTarget& target,
1966 const cmSourceFile& source,
1967 std::string* nameWithoutTargetDir,
1968 bool* hasSourceExtension)
1970 // Make sure we never hit this old case.
1971 if(source.GetProperty("MACOSX_PACKAGE_LOCATION"))
1973 std::string msg = "MACOSX_PACKAGE_LOCATION set on source file: ";
1974 msg += source.GetFullPath();
1975 this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR,
1976 msg.c_str());
1979 // Start with the target directory.
1980 std::string obj = this->GetTargetDirectory(target);
1981 obj += "/";
1983 // Get the object file name without the target directory.
1984 std::string dir_max;
1985 dir_max += this->Makefile->GetCurrentOutputDirectory();
1986 dir_max += "/";
1987 dir_max += obj;
1988 std::string objectName =
1989 this->GetObjectFileNameWithoutTarget(source, dir_max,
1990 hasSourceExtension);
1991 if(nameWithoutTargetDir)
1993 *nameWithoutTargetDir = objectName;
1996 // Append the object name to the target directory.
1997 obj += objectName;
1998 return obj;
2001 //----------------------------------------------------------------------------
2002 void cmLocalUnixMakefileGenerator3::WriteDisclaimer(std::ostream& os)
2005 << "# CMAKE generated file: DO NOT EDIT!\n"
2006 << "# Generated by \"" << this->GlobalGenerator->GetName() << "\""
2007 << " Generator, CMake Version "
2008 << cmVersion::GetMajorVersion() << "."
2009 << cmVersion::GetMinorVersion() << "\n\n";
2012 //----------------------------------------------------------------------------
2013 std::string
2014 cmLocalUnixMakefileGenerator3
2015 ::GetRecursiveMakeCall(const char *makefile, const char* tgt)
2017 // Call make on the given file.
2018 std::string cmd;
2019 cmd += "$(MAKE) -f ";
2020 cmd += this->Convert(makefile,NONE,SHELL);
2021 cmd += " ";
2023 // Pass down verbosity level.
2024 if(this->GetMakeSilentFlag().size())
2026 cmd += this->GetMakeSilentFlag();
2027 cmd += " ";
2030 // Most unix makes will pass the command line flags to make down to
2031 // sub-invoked makes via an environment variable. However, some
2032 // makes do not support that, so you have to pass the flags
2033 // explicitly.
2034 if(this->GetPassMakeflags())
2036 cmd += "-$(MAKEFLAGS) ";
2039 // Add the target.
2040 if (tgt && tgt[0] != '\0')
2042 // The make target is always relative to the top of the build tree.
2043 std::string tgt2 = this->Convert(tgt, HOME_OUTPUT);
2045 // The target may have been written with windows paths.
2046 cmSystemTools::ConvertToOutputSlashes(tgt2);
2048 // Escape one extra time if the make tool requires it.
2049 if(this->MakeCommandEscapeTargetTwice)
2051 tgt2 = this->EscapeForShell(tgt2.c_str(), true, false);
2054 // The target name is now a string that should be passed verbatim
2055 // on the command line.
2056 cmd += this->EscapeForShell(tgt2.c_str(), true, false);
2058 return cmd;
2061 //----------------------------------------------------------------------------
2062 void cmLocalUnixMakefileGenerator3::WriteDivider(std::ostream& os)
2065 << "#======================================"
2066 << "=======================================\n";
2069 //----------------------------------------------------------------------------
2070 void
2071 cmLocalUnixMakefileGenerator3
2072 ::WriteCMakeArgument(std::ostream& os, const char* s)
2074 // Write the given string to the stream with escaping to get it back
2075 // into CMake through the lexical scanner.
2076 os << "\"";
2077 for(const char* c = s; *c; ++c)
2079 if(*c == '\\')
2081 os << "\\\\";
2083 else if(*c == '"')
2085 os << "\\\"";
2087 else
2089 os << *c;
2092 os << "\"";
2095 //----------------------------------------------------------------------------
2096 std::string
2097 cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p)
2100 // Split the path into its components.
2101 std::vector<std::string> components;
2102 cmSystemTools::SplitPath(p, components);
2104 // Return an empty path if there are no components.
2105 if(components.empty())
2107 return "\"\"";
2110 // Choose a slash direction and fix root component.
2111 const char* slash = "/";
2112 #if defined(_WIN32) && !defined(__CYGWIN__)
2113 if(!cmSystemTools::GetForceUnixPaths())
2115 slash = "\\";
2116 for(std::string::iterator i = components[0].begin();
2117 i != components[0].end(); ++i)
2119 if(*i == '/')
2121 *i = '\\';
2125 #endif
2127 // Begin the quoted result with the root component.
2128 std::string result = "\"";
2129 result += components[0];
2131 // Now add the rest of the components separated by the proper slash
2132 // direction for this platform.
2133 bool first = true;
2134 for(unsigned int i=1; i < components.size(); ++i)
2136 // Only the last component can be empty to avoid double slashes.
2137 if(components[i].length() > 0 || (i == (components.size()-1)))
2139 if(!first)
2141 result += slash;
2143 result += components[i];
2144 first = false;
2148 // Close the quoted result.
2149 result += "\"";
2151 return result;
2154 //----------------------------------------------------------------------------
2155 std::string
2156 cmLocalUnixMakefileGenerator3
2157 ::GetTargetDirectory(cmTarget const& target) const
2159 std::string dir = cmake::GetCMakeFilesDirectoryPostSlash();
2160 dir += target.GetName();
2161 dir += ".dir";
2162 return dir;
2165 //----------------------------------------------------------------------------
2166 cmLocalUnixMakefileGenerator3::ImplicitDependLanguageMap const&
2167 cmLocalUnixMakefileGenerator3::GetImplicitDepends(cmTarget const& tgt)
2169 return this->ImplicitDepends[tgt.GetName()];
2172 //----------------------------------------------------------------------------
2173 void
2174 cmLocalUnixMakefileGenerator3::AddImplicitDepends(cmTarget const& tgt,
2175 const char* lang,
2176 const char* obj,
2177 const char* src)
2179 this->ImplicitDepends[tgt.GetName()][lang][obj] = src;
2182 //----------------------------------------------------------------------------
2183 void cmLocalUnixMakefileGenerator3
2184 ::CreateCDCommand(std::vector<std::string>& commands, const char *tgtDir,
2185 cmLocalGenerator::RelativeRoot relRetDir)
2187 const char* retDir = this->GetRelativeRootPath(relRetDir);
2189 // do we need to cd?
2190 if (!strcmp(tgtDir,retDir))
2192 return;
2195 if(!this->UnixCD)
2197 // On Windows we must perform each step separately and then change
2198 // back because the shell keeps the working directory between
2199 // commands.
2200 std::string cmd = "cd ";
2201 cmd += this->ConvertToOutputForExisting(tgtDir, relRetDir);
2202 commands.insert(commands.begin(),cmd);
2204 // Change back to the starting directory.
2205 cmd = "cd ";
2206 cmd += this->ConvertToOutputForExisting(relRetDir, tgtDir);
2207 commands.push_back(cmd);
2209 else
2211 // On UNIX we must construct a single shell command to change
2212 // directory and build because make resets the directory between
2213 // each command.
2214 std::vector<std::string>::iterator i = commands.begin();
2215 for (; i != commands.end(); ++i)
2217 std::string cmd = "cd ";
2218 cmd += this->ConvertToOutputForExisting(tgtDir, relRetDir);
2219 cmd += " && ";
2220 cmd += *i;
2221 *i = cmd;
2227 void cmLocalUnixMakefileGenerator3
2228 ::GetTargetObjectFileDirectories(cmTarget* target,
2229 std::vector<std::string>& dirs)
2231 std::string dir = this->Makefile->GetCurrentOutputDirectory();
2232 dir += "/";
2233 dir += this->GetTargetDirectory(*target);
2234 dirs.push_back(dir);