KWSys Nightly Date Stamp
[cmake.git] / Source / cmLocalGenerator.cxx
blob267eedea4713735cc53e3e8cba56873e1f3cec95
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmLocalGenerator.cxx,v $
5 Language: C++
6 Date: $Date: 2009-09-22 20:16:55 $
7 Version: $Revision: 1.315 $
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 "cmLocalGenerator.h"
19 #include "cmComputeLinkInformation.h"
20 #include "cmGeneratedFileStream.h"
21 #include "cmGlobalGenerator.h"
22 #include "cmInstallGenerator.h"
23 #include "cmInstallFilesGenerator.h"
24 #include "cmInstallScriptGenerator.h"
25 #include "cmInstallTargetGenerator.h"
26 #include "cmMakefile.h"
27 #include "cmSourceFile.h"
28 #include "cmTest.h"
29 #include "cmTestGenerator.h"
30 #include "cmVersion.h"
31 #include "cmake.h"
33 #if defined(CMAKE_BUILD_WITH_CMAKE)
34 # define CM_LG_ENCODE_OBJECT_NAMES
35 # include <cmsys/MD5.h>
36 #endif
38 #include <cmsys/System.h>
40 #include <ctype.h> // for isalpha
42 #include <assert.h>
44 cmLocalGenerator::cmLocalGenerator()
46 this->Makefile = 0; // moved to after set on global
47 this->Parent = 0;
48 this->WindowsShell = false;
49 this->WindowsVSIDE = false;
50 this->WatcomWMake = false;
51 this->MinGWMake = false;
52 this->NMake = false;
53 this->MSYSShell = false;
54 this->LinkScriptShell = false;
55 this->IgnoreLibPrefix = false;
56 this->UseRelativePaths = false;
57 this->Configured = false;
58 this->EmitUniversalBinaryFlags = true;
59 this->IsMakefileGenerator = false;
60 this->RelativePathsConfigured = false;
61 this->PathConversionsSetup = false;
62 this->BackwardsCompatibility = 0;
63 this->BackwardsCompatibilityFinal = false;
66 cmLocalGenerator::~cmLocalGenerator()
68 delete this->Makefile;
71 //----------------------------------------------------------------------------
72 class cmLocalGeneratorCurrent
74 cmGlobalGenerator* GG;
75 cmLocalGenerator* LG;
76 public:
77 cmLocalGeneratorCurrent(cmLocalGenerator* lg)
79 this->GG = lg->GetGlobalGenerator();
80 this->LG = this->GG->GetCurrentLocalGenerator();
81 this->GG->SetCurrentLocalGenerator(lg);
83 ~cmLocalGeneratorCurrent()
85 this->GG->SetCurrentLocalGenerator(this->LG);
89 //----------------------------------------------------------------------------
90 void cmLocalGenerator::Configure()
92 // Manage the global generator's current local generator.
93 cmLocalGeneratorCurrent clg(this);
94 static_cast<void>(clg);
96 // make sure the CMakeFiles dir is there
97 std::string filesDir = this->Makefile->GetStartOutputDirectory();
98 filesDir += cmake::GetCMakeFilesDirectory();
99 cmSystemTools::MakeDirectory(filesDir.c_str());
101 // find & read the list file
102 this->ReadInputFile();
104 // at the end of the ReadListFile handle any old style subdirs
105 // first get all the subdirectories
106 std::vector<cmLocalGenerator *> subdirs = this->GetChildren();
108 // for each subdir recurse
109 std::vector<cmLocalGenerator *>::iterator sdi = subdirs.begin();
110 for (; sdi != subdirs.end(); ++sdi)
112 if (!(*sdi)->Configured)
114 this->Makefile->ConfigureSubDirectory(*sdi);
118 // Check whether relative paths should be used for optionally
119 // relative paths.
120 this->UseRelativePaths = this->Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS");
122 this->ComputeObjectMaxPath();
124 this->Configured = true;
127 //----------------------------------------------------------------------------
128 void cmLocalGenerator::ComputeObjectMaxPath()
130 // Choose a maximum object file name length.
131 #if defined(_WIN32) || defined(__CYGWIN__)
132 this->ObjectPathMax = 250;
133 #else
134 this->ObjectPathMax = 1000;
135 #endif
136 const char* plen = this->Makefile->GetDefinition("CMAKE_OBJECT_PATH_MAX");
137 if(plen && *plen)
139 unsigned int pmax;
140 if(sscanf(plen, "%u", &pmax) == 1)
142 if(pmax >= 128)
144 this->ObjectPathMax = pmax;
146 else
148 cmOStringStream w;
149 w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax
150 << ", which is less than the minimum of 128. "
151 << "The value will be ignored.";
152 this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
155 else
157 cmOStringStream w;
158 w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen
159 << "\", which fails to parse as a positive integer. "
160 << "The value will be ignored.";
161 this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
164 this->ObjectMaxPathViolations.clear();
167 //----------------------------------------------------------------------------
168 void cmLocalGenerator::ReadInputFile()
170 // Look for the CMakeLists.txt file.
171 std::string currentStart = this->Makefile->GetStartDirectory();
172 currentStart += "/CMakeLists.txt";
173 if(cmSystemTools::FileExists(currentStart.c_str(), true))
175 this->Makefile->ReadListFile(currentStart.c_str());
176 return;
179 if(!this->Parent)
181 return;
184 // The file is missing. Check policy CMP0014.
185 cmMakefile* mf = this->Parent->GetMakefile();
186 cmOStringStream e;
187 e << "The source directory\n"
188 << " " << this->Makefile->GetStartDirectory() << "\n"
189 << "does not contain a CMakeLists.txt file.";
190 switch (mf->GetPolicyStatus(cmPolicies::CMP0014))
192 case cmPolicies::WARN:
193 // Print the warning.
194 e << "\n"
195 << "CMake does not support this case but it used "
196 << "to work accidentally and is being allowed for "
197 << "compatibility."
198 << "\n"
199 << mf->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0014);
200 mf->IssueMessage(cmake::AUTHOR_WARNING, e.str());
201 case cmPolicies::OLD:
202 // OLD behavior does not warn.
203 return;
204 case cmPolicies::REQUIRED_IF_USED:
205 case cmPolicies::REQUIRED_ALWAYS:
206 e << "\n"
207 << mf->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP0014);
208 case cmPolicies::NEW:
209 // NEW behavior prints the error.
210 mf->IssueMessage(cmake::FATAL_ERROR, e.str());
211 break;
215 void cmLocalGenerator::SetupPathConversions()
217 // Setup the current output directory components for use by
218 // Convert
219 std::string outdir;
220 outdir =
221 cmSystemTools::CollapseFullPath(this->Makefile->GetHomeDirectory());
222 cmSystemTools::SplitPath(outdir.c_str(), this->HomeDirectoryComponents);
223 outdir =
224 cmSystemTools::CollapseFullPath(this->Makefile->GetStartDirectory());
225 cmSystemTools::SplitPath(outdir.c_str(), this->StartDirectoryComponents);
227 outdir = cmSystemTools::CollapseFullPath
228 (this->Makefile->GetHomeOutputDirectory());
229 cmSystemTools::SplitPath(outdir.c_str(),
230 this->HomeOutputDirectoryComponents);
232 outdir = cmSystemTools::CollapseFullPath
233 (this->Makefile->GetStartOutputDirectory());
234 cmSystemTools::SplitPath(outdir.c_str(),
235 this->StartOutputDirectoryComponents);
239 void cmLocalGenerator::SetGlobalGenerator(cmGlobalGenerator *gg)
241 this->GlobalGenerator = gg;
242 this->Makefile = new cmMakefile;
243 this->Makefile->SetLocalGenerator(this);
245 // setup the home directories
246 this->Makefile->GetProperties().SetCMakeInstance(gg->GetCMakeInstance());
247 this->Makefile->SetHomeDirectory(
248 gg->GetCMakeInstance()->GetHomeDirectory());
249 this->Makefile->SetHomeOutputDirectory(
250 gg->GetCMakeInstance()->GetHomeOutputDirectory());
253 void cmLocalGenerator::ConfigureFinalPass()
255 this->Makefile->ConfigureFinalPass();
258 void cmLocalGenerator::TraceDependencies()
260 // Generate the rule files for each target.
261 cmTargets& targets = this->Makefile->GetTargets();
262 for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
264 const char* projectFilename = 0;
265 if (this->IsMakefileGenerator == false) // only use of this variable
267 projectFilename = t->second.GetName();
269 t->second.TraceDependencies(projectFilename);
273 void cmLocalGenerator::GenerateTestFiles()
275 if ( !this->Makefile->IsOn("CMAKE_TESTING_ENABLED") )
277 return;
280 // Compute the set of configurations.
281 std::vector<std::string> configurationTypes;
282 if(const char* types =
283 this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
285 cmSystemTools::ExpandListArgument(types, configurationTypes);
287 const char* config = 0;
288 if(configurationTypes.empty())
290 config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
293 std::string file = this->Makefile->GetStartOutputDirectory();
294 file += "/";
295 file += "CTestTestfile.cmake";
297 cmGeneratedFileStream fout(file.c_str());
298 fout.SetCopyIfDifferent(true);
300 fout << "# CMake generated Testfile for " << std::endl
301 << "# Source directory: "
302 << this->Makefile->GetStartDirectory() << std::endl
303 << "# Build directory: "
304 << this->Makefile->GetStartOutputDirectory() << std::endl
305 << "# " << std::endl
306 << "# This file includes the relevent testing commands "
307 << "required for " << std::endl
308 << "# testing this directory and lists subdirectories to "
309 << "be tested as well." << std::endl;
311 const char* testIncludeFile =
312 this->Makefile->GetProperty("TEST_INCLUDE_FILE");
313 if ( testIncludeFile )
315 fout << "INCLUDE(\"" << testIncludeFile << "\")" << std::endl;
318 // Ask each test generator to write its code.
319 std::vector<cmTestGenerator*> const&
320 testers = this->Makefile->GetTestGenerators();
321 for(std::vector<cmTestGenerator*>::const_iterator gi = testers.begin();
322 gi != testers.end(); ++gi)
324 (*gi)->Generate(fout, config, configurationTypes);
326 if ( this->Children.size())
328 size_t i;
329 for(i = 0; i < this->Children.size(); ++i)
331 fout << "SUBDIRS(";
332 std::string outP =
333 this->Children[i]->GetMakefile()->GetStartOutputDirectory();
334 fout << this->Convert(outP.c_str(),START_OUTPUT);
335 fout << ")" << std::endl;
340 //----------------------------------------------------------------------------
341 void cmLocalGenerator::GenerateInstallRules()
343 // Compute the install prefix.
344 const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
345 #if defined(_WIN32) && !defined(__CYGWIN__)
346 std::string prefix_win32;
347 if(!prefix)
349 if(!cmSystemTools::GetEnv("SystemDrive", prefix_win32))
351 prefix_win32 = "C:";
353 const char* project_name = this->Makefile->GetDefinition("PROJECT_NAME");
354 if(project_name && project_name[0])
356 prefix_win32 += "/Program Files/";
357 prefix_win32 += project_name;
359 else
361 prefix_win32 += "/InstalledCMakeProject";
363 prefix = prefix_win32.c_str();
365 #else
366 if (!prefix)
368 prefix = "/usr/local";
370 #endif
372 // Compute the set of configurations.
373 std::vector<std::string> configurationTypes;
374 if(const char* types =
375 this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
377 cmSystemTools::ExpandListArgument(types, configurationTypes);
379 const char* config = 0;
380 if(configurationTypes.empty())
382 config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
385 // Choose a default install configuration.
386 const char* default_config = config;
387 const char* default_order[] = {"RELEASE", "MINSIZEREL",
388 "RELWITHDEBINFO", "DEBUG", 0};
389 for(const char** c = default_order; *c && !default_config; ++c)
391 for(std::vector<std::string>::iterator i = configurationTypes.begin();
392 i != configurationTypes.end(); ++i)
394 if(cmSystemTools::UpperCase(*i) == *c)
396 default_config = i->c_str();
400 if(!default_config && !configurationTypes.empty())
402 default_config = configurationTypes[0].c_str();
404 if(!default_config)
406 default_config = "Release";
409 // Create the install script file.
410 std::string file = this->Makefile->GetStartOutputDirectory();
411 std::string homedir = this->Makefile->GetHomeOutputDirectory();
412 std::string currdir = this->Makefile->GetCurrentOutputDirectory();
413 cmSystemTools::ConvertToUnixSlashes(file);
414 cmSystemTools::ConvertToUnixSlashes(homedir);
415 cmSystemTools::ConvertToUnixSlashes(currdir);
416 int toplevel_install = 0;
417 if ( currdir == homedir )
419 toplevel_install = 1;
421 file += "/cmake_install.cmake";
422 cmGeneratedFileStream fout(file.c_str());
423 fout.SetCopyIfDifferent(true);
425 // Write the header.
426 fout << "# Install script for directory: "
427 << this->Makefile->GetCurrentDirectory() << std::endl << std::endl;
428 fout << "# Set the install prefix" << std::endl
429 << "IF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
430 << " SET(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
431 << "ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
432 << "STRING(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
433 << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
434 << std::endl;
436 // Write support code for generating per-configuration install rules.
437 fout <<
438 "# Set the install configuration name.\n"
439 "IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
440 " IF(BUILD_TYPE)\n"
441 " STRING(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
442 " CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
443 " ELSE(BUILD_TYPE)\n"
444 " SET(CMAKE_INSTALL_CONFIG_NAME \"" << default_config << "\")\n"
445 " ENDIF(BUILD_TYPE)\n"
446 " MESSAGE(STATUS \"Install configuration: "
447 "\\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
448 "ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
449 "\n";
451 // Write support code for dealing with component-specific installs.
452 fout <<
453 "# Set the component getting installed.\n"
454 "IF(NOT CMAKE_INSTALL_COMPONENT)\n"
455 " IF(COMPONENT)\n"
456 " MESSAGE(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
457 " SET(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
458 " ELSE(COMPONENT)\n"
459 " SET(CMAKE_INSTALL_COMPONENT)\n"
460 " ENDIF(COMPONENT)\n"
461 "ENDIF(NOT CMAKE_INSTALL_COMPONENT)\n"
462 "\n";
464 // Copy user-specified install options to the install code.
465 if(const char* so_no_exe =
466 this->Makefile->GetDefinition("CMAKE_INSTALL_SO_NO_EXE"))
468 fout <<
469 "# Install shared libraries without execute permission?\n"
470 "IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
471 " SET(CMAKE_INSTALL_SO_NO_EXE \"" << so_no_exe << "\")\n"
472 "ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
473 "\n";
476 // Ask each install generator to write its code.
477 std::vector<cmInstallGenerator*> const& installers =
478 this->Makefile->GetInstallGenerators();
479 for(std::vector<cmInstallGenerator*>::const_iterator
480 gi = installers.begin();
481 gi != installers.end(); ++gi)
483 (*gi)->Generate(fout, config, configurationTypes);
486 // Write rules from old-style specification stored in targets.
487 this->GenerateTargetInstallRules(fout, config, configurationTypes);
489 // Include install scripts from subdirectories.
490 if(!this->Children.empty())
492 fout << "IF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
493 fout << " # Include the install script for each subdirectory.\n";
494 for(std::vector<cmLocalGenerator*>::const_iterator
495 ci = this->Children.begin(); ci != this->Children.end(); ++ci)
497 if(!(*ci)->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
499 std::string odir = (*ci)->GetMakefile()->GetStartOutputDirectory();
500 cmSystemTools::ConvertToUnixSlashes(odir);
501 fout << " INCLUDE(\"" << odir.c_str()
502 << "/cmake_install.cmake\")" << std::endl;
505 fout << "\n";
506 fout << "ENDIF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n\n";
509 // Record the install manifest.
510 if ( toplevel_install )
512 fout <<
513 "IF(CMAKE_INSTALL_COMPONENT)\n"
514 " SET(CMAKE_INSTALL_MANIFEST \"install_manifest_"
515 "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
516 "ELSE(CMAKE_INSTALL_COMPONENT)\n"
517 " SET(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
518 "ENDIF(CMAKE_INSTALL_COMPONENT)\n\n";
519 fout
520 << "FILE(WRITE \""
521 << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
522 << "\"\")" << std::endl;
523 fout
524 << "FOREACH(file ${CMAKE_INSTALL_MANIFEST_FILES})" << std::endl
525 << " FILE(APPEND \""
526 << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
527 << "\"${file}\\n\")" << std::endl
528 << "ENDFOREACH(file)" << std::endl;
532 //----------------------------------------------------------------------------
533 void cmLocalGenerator::GenerateTargetManifest()
535 // Collect the set of configuration types.
536 std::vector<std::string> configNames;
537 if(const char* configurationTypes =
538 this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
540 cmSystemTools::ExpandListArgument(configurationTypes, configNames);
542 else if(const char* buildType =
543 this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"))
545 if(*buildType)
547 configNames.push_back(buildType);
551 // Add our targets to the manifest for each configuration.
552 cmTargets& targets = this->Makefile->GetTargets();
553 for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
555 cmTarget& target = t->second;
556 if(configNames.empty())
558 target.GenerateTargetManifest(0);
560 else
562 for(std::vector<std::string>::iterator ci = configNames.begin();
563 ci != configNames.end(); ++ci)
565 const char* config = ci->c_str();
566 target.GenerateTargetManifest(config);
572 void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
573 const char* lang,
574 cmSourceFile& source,
575 cmTarget& )
577 std::string objectDir = cmSystemTools::GetFilenamePath(std::string(ofname));
578 objectDir = this->Convert(objectDir.c_str(),START_OUTPUT,SHELL);
579 std::string objectFile = this->Convert(ofname,START_OUTPUT,SHELL);
580 std::string sourceFile =
581 this->Convert(source.GetFullPath().c_str(),START_OUTPUT,SHELL,true);
582 std::string varString = "CMAKE_";
583 varString += lang;
584 varString += "_COMPILE_OBJECT";
585 std::vector<std::string> rules;
586 rules.push_back(this->Makefile->GetRequiredDefinition(varString.c_str()));
587 varString = "CMAKE_";
588 varString += lang;
589 varString += "_FLAGS";
590 std::string flags;
591 flags += this->Makefile->GetSafeDefinition(varString.c_str());
592 flags += " ";
593 flags += this->GetIncludeFlags(lang);
595 // Construct the command lines.
596 cmCustomCommandLines commandLines;
597 std::vector<std::string> commands;
598 cmSystemTools::ExpandList(rules, commands);
599 cmLocalGenerator::RuleVariables vars;
600 vars.Language = lang;
601 vars.Source = sourceFile.c_str();
602 vars.Object = objectFile.c_str();
603 vars.ObjectDir = objectDir.c_str();
604 vars.Flags = flags.c_str();
605 for(std::vector<std::string>::iterator i = commands.begin();
606 i != commands.end(); ++i)
608 // Expand the full command line string.
609 this->ExpandRuleVariables(*i, vars);
611 // Parse the string to get the custom command line.
612 cmCustomCommandLine commandLine;
613 std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
614 for(std::vector<cmStdString>::iterator a = cmd.begin();
615 a != cmd.end(); ++a)
617 commandLine.push_back(*a);
620 // Store this command line.
621 commandLines.push_back(commandLine);
624 // Check for extra object-file dependencies.
625 std::vector<std::string> depends;
626 const char* additionalDeps = source.GetProperty("OBJECT_DEPENDS");
627 if(additionalDeps)
629 cmSystemTools::ExpandListArgument(additionalDeps, depends);
632 // Generate a meaningful comment for the command.
633 std::string comment = "Building ";
634 comment += lang;
635 comment += " object ";
636 comment += this->Convert(ofname, START_OUTPUT);
638 // Add the custom command to build the object file.
639 this->Makefile->AddCustomCommandToOutput(
640 ofname,
641 depends,
642 source.GetFullPath().c_str(),
643 commandLines,
644 comment.c_str(),
645 this->Makefile->GetStartOutputDirectory()
649 void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
651 cmStdString objs;
652 std::vector<std::string> objVector;
653 // Add all the sources outputs to the depends of the target
654 std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
655 for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
656 i != classes.end(); ++i)
658 cmSourceFile* sf = *i;
659 if(!sf->GetCustomCommand() &&
660 !sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
661 !sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
663 std::string dir_max;
664 dir_max += this->Makefile->GetCurrentOutputDirectory();
665 dir_max += "/";
666 std::string obj = this->GetObjectFileNameWithoutTarget(*sf, dir_max);
667 if(!obj.empty())
669 std::string ofname = this->Makefile->GetCurrentOutputDirectory();
670 ofname += "/";
671 ofname += obj;
672 objVector.push_back(ofname);
673 this->AddCustomCommandToCreateObject(ofname.c_str(),
674 llang, *(*i), target);
675 objs += this->Convert(ofname.c_str(),START_OUTPUT,MAKEFILE);
676 objs += " ";
680 std::string createRule = "CMAKE_";
681 createRule += llang;
682 createRule += target.GetCreateRuleVariable();
683 std::string targetName = target.GetFullName();
684 // Executable :
685 // Shared Library:
686 // Static Library:
687 // Shared Module:
688 std::string linkLibs; // should be set
689 std::string flags; // should be set
690 std::string linkFlags; // should be set
691 this->GetTargetFlags(linkLibs, flags, linkFlags, target);
692 cmLocalGenerator::RuleVariables vars;
693 vars.Language = llang;
694 vars.Objects = objs.c_str();
695 vars.ObjectDir = ".";
696 vars.Target = targetName.c_str();
697 vars.LinkLibraries = linkLibs.c_str();
698 vars.Flags = flags.c_str();
699 vars.LinkFlags = linkFlags.c_str();
701 std::string langFlags;
702 this->AddLanguageFlags(langFlags, llang, 0);
703 vars.LanguageCompileFlags = langFlags.c_str();
705 cmCustomCommandLines commandLines;
706 std::vector<std::string> rules;
707 rules.push_back(this->Makefile->GetRequiredDefinition(createRule.c_str()));
708 std::vector<std::string> commands;
709 cmSystemTools::ExpandList(rules, commands);
710 for(std::vector<std::string>::iterator i = commands.begin();
711 i != commands.end(); ++i)
713 // Expand the full command line string.
714 this->ExpandRuleVariables(*i, vars);
715 // Parse the string to get the custom command line.
716 cmCustomCommandLine commandLine;
717 std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
718 for(std::vector<cmStdString>::iterator a = cmd.begin();
719 a != cmd.end(); ++a)
721 commandLine.push_back(*a);
724 // Store this command line.
725 commandLines.push_back(commandLine);
727 std::string targetFullPath = target.GetFullPath();
728 // Generate a meaningful comment for the command.
729 std::string comment = "Linking ";
730 comment += llang;
731 comment += " target ";
732 comment += this->Convert(targetFullPath.c_str(), START_OUTPUT);
733 this->Makefile->AddCustomCommandToOutput(
734 targetFullPath.c_str(),
735 objVector,
737 commandLines,
738 comment.c_str(),
739 this->Makefile->GetStartOutputDirectory()
741 target.AddSourceFile
742 (this->Makefile->GetSource(targetFullPath.c_str()));
746 void cmLocalGenerator
747 ::CreateCustomTargetsAndCommands(std::set<cmStdString> const& lang)
749 cmTargets &tgts = this->Makefile->GetTargets();
750 for(cmTargets::iterator l = tgts.begin();
751 l != tgts.end(); l++)
753 cmTarget& target = l->second;
754 switch(target.GetType())
756 case cmTarget::STATIC_LIBRARY:
757 case cmTarget::SHARED_LIBRARY:
758 case cmTarget::MODULE_LIBRARY:
759 case cmTarget::EXECUTABLE:
761 const char* llang = target.GetLinkerLanguage();
762 if(!llang)
764 cmSystemTools::Error
765 ("CMake can not determine linker language for target:",
766 target.GetName());
767 return;
769 // if the language is not in the set lang then create custom
770 // commands to build the target
771 if(lang.count(llang) == 0)
773 this->AddBuildTargetRule(llang, target);
776 break;
777 default:
778 break;
783 // List of variables that are replaced when
784 // rules are expanced. These variables are
785 // replaced in the form <var> with GetSafeDefinition(var).
786 // ${LANG} is replaced in the variable first with all enabled
787 // languages.
788 static const char* ruleReplaceVars[] =
790 "CMAKE_${LANG}_COMPILER",
791 "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
792 "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
793 "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
794 "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
795 "CMAKE_${LANG}_LINK_FLAGS",
796 "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
797 "CMAKE_${LANG}_ARCHIVE",
798 "CMAKE_AR",
799 "CMAKE_CURRENT_SOURCE_DIR",
800 "CMAKE_CURRENT_BINARY_DIR",
801 "CMAKE_RANLIB",
802 "CMAKE_LINKER",
806 std::string
807 cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
808 const RuleVariables& replaceValues)
810 if(replaceValues.LinkFlags)
812 if(variable == "LINK_FLAGS")
814 return replaceValues.LinkFlags;
817 if(replaceValues.Flags)
819 if(variable == "FLAGS")
821 return replaceValues.Flags;
825 if(replaceValues.Source)
827 if(variable == "SOURCE")
829 return replaceValues.Source;
832 if(replaceValues.PreprocessedSource)
834 if(variable == "PREPROCESSED_SOURCE")
836 return replaceValues.PreprocessedSource;
839 if(replaceValues.AssemblySource)
841 if(variable == "ASSEMBLY_SOURCE")
843 return replaceValues.AssemblySource;
846 if(replaceValues.Object)
848 if(variable == "OBJECT")
850 return replaceValues.Object;
853 if(replaceValues.ObjectDir)
855 if(variable == "OBJECT_DIR")
857 return replaceValues.ObjectDir;
860 if(replaceValues.Objects)
862 if(variable == "OBJECTS")
864 return replaceValues.Objects;
867 if(replaceValues.ObjectsQuoted)
869 if(variable == "OBJECTS_QUOTED")
871 return replaceValues.ObjectsQuoted;
874 if(replaceValues.Defines && variable == "DEFINES")
876 return replaceValues.Defines;
878 if(replaceValues.TargetPDB )
880 if(variable == "TARGET_PDB")
882 return replaceValues.TargetPDB;
886 if(replaceValues.Target)
888 if(variable == "TARGET_QUOTED")
890 std::string targetQuoted = replaceValues.Target;
891 if(targetQuoted.size() && targetQuoted[0] != '\"')
893 targetQuoted = '\"';
894 targetQuoted += replaceValues.Target;
895 targetQuoted += '\"';
897 return targetQuoted;
899 if(replaceValues.LanguageCompileFlags)
901 if(variable == "LANGUAGE_COMPILE_FLAGS")
903 return replaceValues.LanguageCompileFlags;
906 if(replaceValues.Target)
908 if(variable == "TARGET")
910 return replaceValues.Target;
913 if(variable == "TARGET_IMPLIB")
915 return this->TargetImplib;
917 if(variable == "TARGET_VERSION_MAJOR")
919 if(replaceValues.TargetVersionMajor)
921 return replaceValues.TargetVersionMajor;
923 else
925 return "0";
928 if(variable == "TARGET_VERSION_MINOR")
930 if(replaceValues.TargetVersionMinor)
932 return replaceValues.TargetVersionMinor;
934 else
936 return "0";
939 if(replaceValues.Target)
941 if(variable == "TARGET_BASE")
943 // Strip the last extension off the target name.
944 std::string targetBase = replaceValues.Target;
945 std::string::size_type pos = targetBase.rfind(".");
946 if(pos != targetBase.npos)
948 return targetBase.substr(0, pos);
950 else
952 return targetBase;
957 if(replaceValues.TargetSOName)
959 if(variable == "TARGET_SONAME")
961 if(replaceValues.Language)
963 std::string name = "CMAKE_SHARED_LIBRARY_SONAME_";
964 name += replaceValues.Language;
965 name += "_FLAG";
966 if(this->Makefile->GetDefinition(name.c_str()))
968 return replaceValues.TargetSOName;
971 return "";
974 if(replaceValues.TargetInstallNameDir)
976 if(variable == "TARGET_INSTALLNAME_DIR")
978 return replaceValues.TargetInstallNameDir;
981 if(replaceValues.LinkLibraries)
983 if(variable == "LINK_LIBRARIES")
985 return replaceValues.LinkLibraries;
988 if(replaceValues.Language)
990 if(variable == "LANGUAGE")
992 return replaceValues.Language;
995 if(replaceValues.CMTarget)
997 if(variable == "TARGET_NAME")
999 return replaceValues.CMTarget->GetName();
1001 if(variable == "TARGET_TYPE")
1003 return cmTarget::TargetTypeNames[replaceValues.CMTarget->GetType()];
1006 if(replaceValues.Output)
1008 if(variable == "OUTPUT")
1010 return replaceValues.Output;
1013 if(variable == "CMAKE_COMMAND")
1015 const char* cmcommand =
1016 this->GetMakefile()->GetDefinition("CMAKE_COMMAND");
1017 return this->Convert(cmcommand, FULL, SHELL);
1019 std::vector<std::string> enabledLanguages;
1020 this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
1021 // loop over language specific replace variables
1022 int pos = 0;
1023 while(ruleReplaceVars[pos])
1025 for(std::vector<std::string>::iterator i = enabledLanguages.begin();
1026 i != enabledLanguages.end(); ++i)
1028 const char* lang = i->c_str();
1029 std::string actualReplace = ruleReplaceVars[pos];
1030 // If this is the compiler then look for the extra variable
1031 // _COMPILER_ARG1 which must be the first argument to the compiler
1032 const char* compilerArg1 = 0;
1033 if(actualReplace == "CMAKE_${LANG}_COMPILER")
1035 std::string arg1 = actualReplace + "_ARG1";
1036 cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
1037 compilerArg1 = this->Makefile->GetDefinition(arg1.c_str());
1039 if(actualReplace.find("${LANG}") != actualReplace.npos)
1041 cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
1043 if(actualReplace == variable)
1045 std::string replace =
1046 this->Makefile->GetSafeDefinition(variable.c_str());
1047 // if the variable is not a FLAG then treat it like a path
1048 if(variable.find("_FLAG") == variable.npos)
1050 std::string ret = this->ConvertToOutputForExisting(replace.c_str());
1051 // if there is a required first argument to the compiler add it
1052 // to the compiler string
1053 if(compilerArg1)
1055 ret += " ";
1056 ret += compilerArg1;
1058 return ret;
1060 return replace;
1063 pos++;
1065 return variable;
1069 void
1070 cmLocalGenerator::ExpandRuleVariables(std::string& s,
1071 const RuleVariables& replaceValues)
1073 std::vector<std::string> enabledLanguages;
1074 this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
1075 this->InsertRuleLauncher(s, replaceValues.CMTarget,
1076 replaceValues.RuleLauncher);
1077 std::string::size_type start = s.find('<');
1078 // no variables to expand
1079 if(start == s.npos)
1081 return;
1083 std::string::size_type pos = 0;
1084 std::string expandedInput;
1085 while(start != s.npos && start < s.size()-2)
1087 std::string::size_type end = s.find('>', start);
1088 // if we find a < with no > we are done
1089 if(end == s.npos)
1091 return;
1093 char c = s[start+1];
1094 // if the next char after the < is not A-Za-z then
1095 // skip it and try to find the next < in the string
1096 if(!isalpha(c))
1098 start = s.find('<', start+1);
1100 else
1102 // extract the var
1103 std::string var = s.substr(start+1, end - start-1);
1104 std::string replace = this->ExpandRuleVariable(var,
1105 replaceValues);
1106 expandedInput += s.substr(pos, start-pos);
1107 expandedInput += replace;
1108 // move to next one
1109 start = s.find('<', start+var.size()+2);
1110 pos = end+1;
1113 // add the rest of the input
1114 expandedInput += s.substr(pos, s.size()-pos);
1115 s = expandedInput;
1118 //----------------------------------------------------------------------------
1119 const char* cmLocalGenerator::GetRuleLauncher(cmTarget* target,
1120 const char* prop)
1122 if(target)
1124 return target->GetProperty(prop);
1126 else
1128 return this->Makefile->GetProperty(prop);
1132 //----------------------------------------------------------------------------
1133 void cmLocalGenerator::InsertRuleLauncher(std::string& s, cmTarget* target,
1134 const char* prop)
1136 if(const char* val = this->GetRuleLauncher(target, prop))
1138 cmOStringStream wrapped;
1139 wrapped << val << " " << s;
1140 s = wrapped.str();
1144 //----------------------------------------------------------------------------
1145 std::string
1146 cmLocalGenerator::ConvertToOutputForExistingCommon(const char* remote,
1147 std::string const& result)
1149 // If this is a windows shell, the result has a space, and the path
1150 // already exists, we can use a short-path to reference it without a
1151 // space.
1152 if(this->WindowsShell && result.find(' ') != result.npos &&
1153 cmSystemTools::FileExists(remote))
1155 std::string tmp;
1156 if(cmSystemTools::GetShortPath(remote, tmp))
1158 return this->Convert(tmp.c_str(), NONE, SHELL, true);
1162 // Otherwise, leave it unchanged.
1163 return result;
1166 //----------------------------------------------------------------------------
1167 std::string
1168 cmLocalGenerator::ConvertToOutputForExisting(const char* remote,
1169 RelativeRoot local)
1171 // Perform standard conversion.
1172 std::string result = this->Convert(remote, local, SHELL, true);
1174 // Consider short-path.
1175 return this->ConvertToOutputForExistingCommon(remote, result);
1178 //----------------------------------------------------------------------------
1179 std::string
1180 cmLocalGenerator::ConvertToOutputForExisting(RelativeRoot remote,
1181 const char* local)
1183 // Perform standard conversion.
1184 std::string result = this->Convert(remote, local, SHELL, true);
1186 // Consider short-path.
1187 const char* remotePath = this->GetRelativeRootPath(remote);
1188 return this->ConvertToOutputForExistingCommon(remotePath, result);
1191 //----------------------------------------------------------------------------
1192 const char* cmLocalGenerator::GetIncludeFlags(const char* lang)
1194 if(!lang)
1196 return "";
1198 if(this->LanguageToIncludeFlags.count(lang))
1200 return this->LanguageToIncludeFlags[lang].c_str();
1203 cmOStringStream includeFlags;
1204 std::vector<std::string> includes;
1205 this->GetIncludeDirectories(includes, lang);
1206 std::vector<std::string>::iterator i;
1208 std::string flagVar = "CMAKE_INCLUDE_FLAG_";
1209 flagVar += lang;
1210 const char* includeFlag =
1211 this->Makefile->GetSafeDefinition(flagVar.c_str());
1212 flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
1213 flagVar += lang;
1214 const char* sep = this->Makefile->GetDefinition(flagVar.c_str());
1215 bool quotePaths = false;
1216 if(this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS"))
1218 quotePaths = true;
1220 bool repeatFlag = true;
1221 // should the include flag be repeated like ie. -IA -IB
1222 if(!sep)
1224 sep = " ";
1226 else
1228 // if there is a separator then the flag is not repeated but is only
1229 // given once i.e. -classpath a:b:c
1230 repeatFlag = false;
1233 // Support special system include flag if it is available and the
1234 // normal flag is repeated for each directory.
1235 std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
1236 sysFlagVar += lang;
1237 const char* sysIncludeFlag = 0;
1238 if(repeatFlag)
1240 sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar.c_str());
1243 bool flagUsed = false;
1244 std::set<cmStdString> emitted;
1245 #ifdef __APPLE__
1246 emitted.insert("/System/Library/Frameworks");
1247 #endif
1248 for(i = includes.begin(); i != includes.end(); ++i)
1250 #ifdef __APPLE__
1251 if(cmSystemTools::IsPathToFramework(i->c_str()))
1253 std::string frameworkDir = *i;
1254 frameworkDir += "/../";
1255 frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
1256 if(emitted.insert(frameworkDir).second)
1258 includeFlags
1259 << "-F" << this->Convert(frameworkDir.c_str(),
1260 cmLocalGenerator::START_OUTPUT,
1261 cmLocalGenerator::SHELL, true)
1262 << " ";
1264 continue;
1266 #endif
1267 std::string include = *i;
1268 if(!flagUsed || repeatFlag)
1270 if(sysIncludeFlag &&
1271 this->Makefile->IsSystemIncludeDirectory(i->c_str()))
1273 includeFlags << sysIncludeFlag;
1275 else
1277 includeFlags << includeFlag;
1279 flagUsed = true;
1281 std::string includePath = this->ConvertToOutputForExisting(i->c_str());
1282 if(quotePaths && includePath.size() && includePath[0] != '\"')
1284 includeFlags << "\"";
1286 includeFlags << includePath;
1287 if(quotePaths && includePath.size() && includePath[0] != '\"')
1289 includeFlags << "\"";
1291 includeFlags << sep;
1293 std::string flags = includeFlags.str();
1294 // remove trailing separators
1295 if((sep[0] != ' ') && flags.size()>0 && flags[flags.size()-1] == sep[0])
1297 flags[flags.size()-1] = ' ';
1299 std::string defineFlags = this->Makefile->GetDefineFlags();
1300 flags += defineFlags;
1301 this->LanguageToIncludeFlags[lang] = flags;
1303 // Use this temorary variable for the return value to work-around a
1304 // bogus GCC 2.95 warning.
1305 const char* ret = this->LanguageToIncludeFlags[lang].c_str();
1306 return ret;
1309 //----------------------------------------------------------------------------
1310 void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
1311 const char* lang)
1313 // Need to decide whether to automatically include the source and
1314 // binary directories at the beginning of the include path.
1315 bool includeSourceDir = false;
1316 bool includeBinaryDir = false;
1318 // When automatic include directories are requested for a build then
1319 // include the source and binary directories at the beginning of the
1320 // include path to approximate include file behavior for an
1321 // in-source build. This does not account for the case of a source
1322 // file in a subdirectory of the current source directory but we
1323 // cannot fix this because not all native build tools support
1324 // per-source-file include paths.
1325 if(this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR"))
1327 includeSourceDir = true;
1328 includeBinaryDir = true;
1331 // CMake versions below 2.0 would add the source tree to the -I path
1332 // automatically. Preserve compatibility.
1333 if(this->NeedBackwardsCompatibility(1,9))
1335 includeSourceDir = true;
1338 // Hack for VTK 4.0 - 4.4 which depend on the old behavior but do
1339 // not set the backwards compatibility level automatically.
1340 const char* vtkSourceDir =
1341 this->Makefile->GetDefinition("VTK_SOURCE_DIR");
1342 if(vtkSourceDir)
1344 const char* vtk_major =
1345 this->Makefile->GetDefinition("VTK_MAJOR_VERSION");
1346 const char* vtk_minor =
1347 this->Makefile->GetDefinition("VTK_MINOR_VERSION");
1348 vtk_major = vtk_major? vtk_major : "4";
1349 vtk_minor = vtk_minor? vtk_minor : "4";
1350 int vmajor = 0;
1351 int vminor = 0;
1352 if(sscanf(vtk_major, "%d", &vmajor) &&
1353 sscanf(vtk_minor, "%d", &vminor) && vmajor == 4 && vminor <= 4)
1355 includeSourceDir = true;
1359 // Do not repeat an include path.
1360 std::set<cmStdString> emitted;
1362 // Store the automatic include paths.
1363 if(includeBinaryDir)
1365 dirs.push_back(this->Makefile->GetStartOutputDirectory());
1366 emitted.insert(this->Makefile->GetStartOutputDirectory());
1368 if(includeSourceDir)
1370 if(emitted.find(this->Makefile->GetStartDirectory()) == emitted.end())
1372 dirs.push_back(this->Makefile->GetStartDirectory());
1373 emitted.insert(this->Makefile->GetStartDirectory());
1377 // Load implicit include directories for this language.
1378 std::string impDirVar = "CMAKE_";
1379 impDirVar += lang;
1380 impDirVar += "_IMPLICIT_INCLUDE_DIRECTORIES";
1381 if(const char* value = this->Makefile->GetDefinition(impDirVar.c_str()))
1383 std::vector<std::string> impDirVec;
1384 cmSystemTools::ExpandListArgument(value, impDirVec);
1385 for(std::vector<std::string>::const_iterator i = impDirVec.begin();
1386 i != impDirVec.end(); ++i)
1388 emitted.insert(*i);
1392 // Get the project-specified include directories.
1393 std::vector<std::string>& includes =
1394 this->Makefile->GetIncludeDirectories();
1396 // Support putting all the in-project include directories first if
1397 // it is requested by the project.
1398 if(this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"))
1400 const char* topSourceDir = this->Makefile->GetHomeDirectory();
1401 const char* topBinaryDir = this->Makefile->GetHomeOutputDirectory();
1402 for(std::vector<std::string>::iterator i = includes.begin();
1403 i != includes.end(); ++i)
1405 // Emit this directory only if it is a subdirectory of the
1406 // top-level source or binary tree.
1407 if(cmSystemTools::ComparePath(i->c_str(), topSourceDir) ||
1408 cmSystemTools::ComparePath(i->c_str(), topBinaryDir) ||
1409 cmSystemTools::IsSubDirectory(i->c_str(), topSourceDir) ||
1410 cmSystemTools::IsSubDirectory(i->c_str(), topBinaryDir))
1412 if(emitted.insert(*i).second)
1414 dirs.push_back(*i);
1420 // Construct the final ordered include directory list.
1421 for(std::vector<std::string>::iterator i = includes.begin();
1422 i != includes.end(); ++i)
1424 if(emitted.insert(*i).second)
1426 dirs.push_back(*i);
1431 void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
1432 std::string& flags,
1433 std::string& linkFlags,
1434 cmTarget& target)
1436 std::string buildType =
1437 this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
1438 buildType = cmSystemTools::UpperCase(buildType);
1439 const char* libraryLinkVariable =
1440 "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
1442 switch(target.GetType())
1444 case cmTarget::STATIC_LIBRARY:
1446 const char* targetLinkFlags =
1447 target.GetProperty("STATIC_LIBRARY_FLAGS");
1448 if(targetLinkFlags)
1450 linkFlags += targetLinkFlags;
1451 linkFlags += " ";
1454 break;
1455 case cmTarget::MODULE_LIBRARY:
1456 libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
1457 case cmTarget::SHARED_LIBRARY:
1459 linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
1460 linkFlags += " ";
1461 if(buildType.size())
1463 std::string build = libraryLinkVariable;
1464 build += "_";
1465 build += buildType;
1466 linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
1467 linkFlags += " ";
1469 if(this->Makefile->IsOn("WIN32") &&
1470 !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")))
1472 const std::vector<cmSourceFile*>& sources = target.GetSourceFiles();
1473 for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
1474 i != sources.end(); ++i)
1476 cmSourceFile* sf = *i;
1477 if(sf->GetExtension() == "def")
1479 linkFlags +=
1480 this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
1481 linkFlags += this->Convert(sf->GetFullPath().c_str(),
1482 START_OUTPUT, SHELL);
1483 linkFlags += " ";
1487 const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
1488 if(targetLinkFlags)
1490 linkFlags += targetLinkFlags;
1491 linkFlags += " ";
1492 std::string configLinkFlags = targetLinkFlags;
1493 configLinkFlags += buildType;
1494 targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
1495 if(targetLinkFlags)
1497 linkFlags += targetLinkFlags;
1498 linkFlags += " ";
1501 cmOStringStream linklibsStr;
1502 this->OutputLinkLibraries(linklibsStr, target, false);
1503 linkLibs = linklibsStr.str();
1505 break;
1506 case cmTarget::EXECUTABLE:
1508 linkFlags +=
1509 this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
1510 linkFlags += " ";
1511 if(buildType.size())
1513 std::string build = "CMAKE_EXE_LINKER_FLAGS_";
1514 build += buildType;
1515 linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
1516 linkFlags += " ";
1518 const char* linkLanguage = target.GetLinkerLanguage();
1519 if(!linkLanguage)
1521 cmSystemTools::Error
1522 ("CMake can not determine linker language for target:",
1523 target.GetName());
1524 return;
1526 std::string langVar = "CMAKE_";
1527 langVar += linkLanguage;
1528 std::string flagsVar = langVar + "_FLAGS";
1529 std::string sharedFlagsVar = "CMAKE_SHARED_LIBRARY_";
1530 sharedFlagsVar += linkLanguage;
1531 sharedFlagsVar += "_FLAGS";
1532 flags += this->Makefile->GetSafeDefinition(flagsVar.c_str());
1533 flags += " ";
1534 flags += this->Makefile->GetSafeDefinition(sharedFlagsVar.c_str());
1535 flags += " ";
1536 cmOStringStream linklibs;
1537 this->OutputLinkLibraries(linklibs, target, false);
1538 linkLibs = linklibs.str();
1539 if(cmSystemTools::IsOn
1540 (this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
1542 std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_")
1543 + linkLanguage + std::string("_FLAGS");
1544 linkFlags += this->Makefile->GetSafeDefinition(sFlagVar.c_str());
1545 linkFlags += " ";
1547 if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
1549 linkFlags +=
1550 this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
1551 linkFlags += " ";
1553 else
1555 linkFlags +=
1556 this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
1557 linkFlags += " ";
1559 const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
1560 if(targetLinkFlags)
1562 linkFlags += targetLinkFlags;
1563 linkFlags += " ";
1564 std::string configLinkFlags = targetLinkFlags;
1565 configLinkFlags += buildType;
1566 targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
1567 if(targetLinkFlags)
1569 linkFlags += targetLinkFlags;
1570 linkFlags += " ";
1574 break;
1575 default:
1576 break;
1580 std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib)
1582 #if defined(_WIN32) && !defined(__CYGWIN__)
1583 // Work-ardound command line parsing limitations in MSVC 6.0 and
1584 // Watcom.
1585 if(this->Makefile->IsOn("MSVC60") || this->Makefile->IsOn("WATCOM"))
1587 // Search for the last space.
1588 std::string::size_type pos = lib.rfind(' ');
1589 if(pos != lib.npos)
1591 // Find the slash after the last space, if any.
1592 pos = lib.find('/', pos);
1594 // Convert the portion of the path with a space to a short path.
1595 std::string sp;
1596 if(cmSystemTools::GetShortPath(lib.substr(0, pos).c_str(), sp))
1598 // Append the rest of the path with no space.
1599 sp += lib.substr(pos);
1601 // Convert to an output path.
1602 return this->Convert(sp.c_str(), NONE, SHELL);
1606 #endif
1608 // Normal behavior.
1609 return this->Convert(lib.c_str(), START_OUTPUT, SHELL);
1613 * Output the linking rules on a command line. For executables,
1614 * targetLibrary should be a NULL pointer. For libraries, it should point
1615 * to the name of the library. This will not link a library against itself.
1617 void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout,
1618 cmTarget& tgt,
1619 bool relink)
1621 const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
1622 cmComputeLinkInformation* pcli = tgt.GetLinkInformation(config);
1623 if(!pcli)
1625 return;
1627 cmComputeLinkInformation& cli = *pcli;
1629 // Collect library linking flags command line options.
1630 std::string linkLibs;
1632 const char* linkLanguage = cli.GetLinkLanguage();
1634 std::string libPathFlag =
1635 this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
1636 std::string libPathTerminator =
1637 this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
1639 // Flags to link an executable to shared libraries.
1640 std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
1641 linkFlagsVar += linkLanguage;
1642 linkFlagsVar += "_FLAGS";
1643 if( tgt.GetType() == cmTarget::EXECUTABLE )
1645 linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar.c_str());
1646 linkLibs += " ";
1649 // Append the framework search path flags.
1650 std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
1651 for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
1652 fdi != fwDirs.end(); ++fdi)
1654 linkLibs += "-F";
1655 linkLibs += this->Convert(fdi->c_str(), NONE, SHELL, false);
1656 linkLibs += " ";
1659 // Append the library search path flags.
1660 std::vector<std::string> const& libDirs = cli.GetDirectories();
1661 for(std::vector<std::string>::const_iterator libDir = libDirs.begin();
1662 libDir != libDirs.end(); ++libDir)
1664 std::string libpath = this->ConvertToOutputForExisting(libDir->c_str());
1665 linkLibs += libPathFlag;
1666 linkLibs += libpath;
1667 linkLibs += libPathTerminator;
1668 linkLibs += " ";
1671 // Append the link items.
1672 typedef cmComputeLinkInformation::ItemVector ItemVector;
1673 ItemVector const& items = cli.GetItems();
1674 for(ItemVector::const_iterator li = items.begin(); li != items.end(); ++li)
1676 if(li->IsPath)
1678 linkLibs += this->ConvertToLinkReference(li->Value);
1680 else
1682 linkLibs += li->Value;
1684 linkLibs += " ";
1687 // Write the library flags to the build rule.
1688 fout << linkLibs;
1690 // Get the RPATH entries.
1691 std::vector<std::string> runtimeDirs;
1692 cli.GetRPath(runtimeDirs, relink);
1694 // Check what kind of rpath flags to use.
1695 if(cli.GetRuntimeSep().empty())
1697 // Each rpath entry gets its own option ("-R a -R b -R c")
1698 std::string rpath;
1699 for(std::vector<std::string>::iterator ri = runtimeDirs.begin();
1700 ri != runtimeDirs.end(); ++ri)
1702 rpath += cli.GetRuntimeFlag();
1703 rpath += this->Convert(ri->c_str(), NONE, SHELL, false);
1704 rpath += " ";
1706 fout << rpath;
1708 else
1710 // All rpath entries are combined ("-Wl,-rpath,a:b:c").
1711 std::string rpath = cli.GetRPathString(relink);
1713 // Store the rpath option in the stream.
1714 if(!rpath.empty())
1716 fout << cli.GetRuntimeFlag();
1717 fout << this->EscapeForShell(rpath.c_str(), true);
1718 fout << " ";
1722 // Add the linker runtime search path if any.
1723 std::string rpath_link = cli.GetRPathLinkString();
1724 if(!cli.GetRPathLinkFlag().empty() && !rpath_link.empty())
1726 fout << cli.GetRPathLinkFlag();
1727 fout << this->EscapeForShell(rpath_link.c_str(), true);
1728 fout << " ";
1731 // Add standard libraries for this language.
1732 std::string standardLibsVar = "CMAKE_";
1733 standardLibsVar += cli.GetLinkLanguage();
1734 standardLibsVar += "_STANDARD_LIBRARIES";
1735 if(const char* stdLibs =
1736 this->Makefile->GetDefinition(standardLibsVar.c_str()))
1738 fout << stdLibs << " ";
1742 //----------------------------------------------------------------------------
1743 void cmLocalGenerator::AddLanguageFlags(std::string& flags,
1744 const char* lang,
1745 const char* config)
1747 // Add language-specific flags.
1748 std::string flagsVar = "CMAKE_";
1749 flagsVar += lang;
1750 flagsVar += "_FLAGS";
1751 // Add special OSX flags
1752 #ifdef __APPLE__
1753 if(this->EmitUniversalBinaryFlags)
1755 const char* osxArch =
1756 this->Makefile->GetDefinition("CMAKE_OSX_ARCHITECTURES");
1757 const char* sysroot =
1758 this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
1759 const char* sysrootDefault =
1760 this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT_DEFAULT");
1761 const char* deploymentTarget =
1762 this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
1763 std::string isysrootVar = std::string("CMAKE_") + lang + "_HAS_ISYSROOT";
1764 bool hasIsysroot = this->Makefile->IsOn(isysrootVar.c_str());
1765 bool flagsUsed = false;
1766 if(osxArch && sysroot && lang && (lang[0] =='C' || lang[0] == 'F'))
1768 std::vector<std::string> archs;
1769 cmSystemTools::ExpandListArgument(std::string(osxArch),
1770 archs);
1771 bool addArchFlag = false;
1772 if(archs.size() >= 1)
1774 if(archs[0] != "")
1776 addArchFlag = true;
1779 // if there is more than one arch add the -arch and
1780 // -isysroot flags, or if there is one arch flag, but
1781 // it is not the default -arch flag for the system, then
1782 // add it. Otherwize do not add -arch and -isysroot
1783 if(addArchFlag)
1785 for( std::vector<std::string>::iterator i = archs.begin();
1786 i != archs.end(); ++i)
1788 flags += " -arch ";
1789 flags += *i;
1791 if(hasIsysroot)
1793 flags += " -isysroot ";
1794 flags += sysroot;
1796 flagsUsed = true;
1800 if(!flagsUsed && sysroot && sysrootDefault &&
1801 strcmp(sysroot, sysrootDefault) != 0 && hasIsysroot)
1803 flags += " -isysroot ";
1804 flags += sysroot;
1807 if (deploymentTarget && *deploymentTarget &&
1808 lang && (lang[0] =='C' || lang[0] == 'F'))
1810 flags += " -mmacosx-version-min=";
1811 flags += deploymentTarget;
1814 #endif
1815 this->AddConfigVariableFlags(flags, flagsVar.c_str(), config);
1818 //----------------------------------------------------------------------------
1819 std::string cmLocalGenerator::GetRealDependency(const char* inName,
1820 const char* config)
1822 // Older CMake code may specify the dependency using the target
1823 // output file rather than the target name. Such code would have
1824 // been written before there was support for target properties that
1825 // modify the name so stripping down to just the file name should
1826 // produce the target name in this case.
1827 std::string name = cmSystemTools::GetFilenameName(inName);
1828 if(cmSystemTools::GetFilenameLastExtension(name) == ".exe")
1830 name = cmSystemTools::GetFilenameWithoutLastExtension(name);
1833 // Look for a CMake target with the given name.
1834 if(cmTarget* target = this->Makefile->FindTargetToUse(name.c_str()))
1836 // make sure it is not just a coincidence that the target name
1837 // found is part of the inName
1838 if(cmSystemTools::FileIsFullPath(inName))
1840 std::string tLocation = target->GetLocation(config);
1841 tLocation = cmSystemTools::GetFilenamePath(tLocation);
1842 std::string depLocation = cmSystemTools::GetFilenamePath(
1843 std::string(inName));
1844 depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
1845 tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
1846 if(depLocation != tLocation)
1848 // it is a full path to a depend that has the same name
1849 // as a target but is in a different location so do not use
1850 // the target as the depend
1851 return inName;
1854 switch (target->GetType())
1856 case cmTarget::EXECUTABLE:
1857 case cmTarget::STATIC_LIBRARY:
1858 case cmTarget::SHARED_LIBRARY:
1859 case cmTarget::MODULE_LIBRARY:
1860 case cmTarget::UNKNOWN_LIBRARY:
1862 // Get the location of the target's output file and depend on it.
1863 if(const char* location = target->GetLocation(config))
1865 return location;
1868 break;
1869 case cmTarget::UTILITY:
1870 case cmTarget::GLOBAL_TARGET:
1871 // Depending on a utility target may not work but just trust
1872 // the user to have given a valid name.
1873 return inName;
1874 case cmTarget::INSTALL_FILES:
1875 case cmTarget::INSTALL_PROGRAMS:
1876 case cmTarget::INSTALL_DIRECTORY:
1877 break;
1881 // The name was not that of a CMake target. It must name a file.
1882 if(cmSystemTools::FileIsFullPath(inName))
1884 // This is a full path. Return it as given.
1885 return inName;
1888 // Check for a source file in this directory that matches the
1889 // dependency.
1890 if(cmSourceFile* sf = this->Makefile->GetSource(inName))
1892 name = sf->GetFullPath();
1893 return name;
1896 // Treat the name as relative to the source directory in which it
1897 // was given.
1898 name = this->Makefile->GetCurrentDirectory();
1899 name += "/";
1900 name += inName;
1901 return name;
1904 //----------------------------------------------------------------------------
1905 std::string cmLocalGenerator::GetRealLocation(const char* inName,
1906 const char* config)
1908 std::string outName=inName;
1909 // Look for a CMake target with the given name, which is an executable
1910 // and which can be run
1911 cmTarget* target = this->Makefile->FindTargetToUse(inName);
1912 if ((target != 0)
1913 && (target->GetType() == cmTarget::EXECUTABLE)
1914 && ((this->Makefile->IsOn("CMAKE_CROSSCOMPILING") == false)
1915 || (target->IsImported() == true)))
1917 outName = target->GetLocation( config );
1919 return outName;
1922 //----------------------------------------------------------------------------
1923 void cmLocalGenerator::AddSharedFlags(std::string& flags,
1924 const char* lang,
1925 bool shared)
1927 std::string flagsVar;
1929 // Add flags for dealing with shared libraries for this language.
1930 if(shared)
1932 flagsVar = "CMAKE_SHARED_LIBRARY_";
1933 flagsVar += lang;
1934 flagsVar += "_FLAGS";
1935 this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
1938 // Add flags specific to shared builds.
1939 if(cmSystemTools::IsOn(this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
1941 flagsVar = "CMAKE_SHARED_BUILD_";
1942 flagsVar += lang;
1943 flagsVar += "_FLAGS";
1944 this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
1948 //----------------------------------------------------------------------------
1949 void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
1950 const char* var,
1951 const char* config)
1953 // Add the flags from the variable itself.
1954 std::string flagsVar = var;
1955 this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
1956 // Add the flags from the build-type specific variable.
1957 if(config && *config)
1959 flagsVar += "_";
1960 flagsVar += cmSystemTools::UpperCase(config);
1961 this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
1965 //----------------------------------------------------------------------------
1966 void cmLocalGenerator::AppendFlags(std::string& flags,
1967 const char* newFlags)
1969 if(newFlags && *newFlags)
1971 std::string newf = newFlags;
1972 if(flags.size())
1974 flags += " ";
1976 flags += newFlags;
1980 //----------------------------------------------------------------------------
1981 void cmLocalGenerator::AppendDefines(std::string& defines,
1982 const char* defines_list,
1983 const char* lang)
1985 // Short-circuit if there are no definitions.
1986 if(!defines_list)
1988 return;
1991 // Expand the list of definitions.
1992 std::vector<std::string> defines_vec;
1993 cmSystemTools::ExpandListArgument(defines_list, defines_vec);
1995 // Short-circuit if there are no definitions.
1996 if(defines_vec.empty())
1998 return;
2001 // Lookup the define flag for the current language.
2002 std::string dflag = "-D";
2003 if(lang)
2005 std::string defineFlagVar = "CMAKE_";
2006 defineFlagVar += lang;
2007 defineFlagVar += "_DEFINE_FLAG";
2008 const char* df = this->Makefile->GetDefinition(defineFlagVar.c_str());
2009 if(df && *df)
2011 dflag = df;
2015 // Add each definition to the command line with appropriate escapes.
2016 const char* dsep = defines.empty()? "" : " ";
2017 for(std::vector<std::string>::const_iterator di = defines_vec.begin();
2018 di != defines_vec.end(); ++di)
2020 // Skip unsupported definitions.
2021 if(!this->CheckDefinition(*di))
2023 continue;
2026 // Separate from previous definitions.
2027 defines += dsep;
2028 dsep = " ";
2030 // Append the definition with proper escaping.
2031 defines += dflag;
2032 if(this->WatcomWMake)
2034 // The Watcom compiler does its own command line parsing instead
2035 // of using the windows shell rules. Definitions are one of
2036 // -DNAME
2037 // -DNAME=<cpp-token>
2038 // -DNAME="c-string with spaces and other characters(?@#$)"
2040 // Watcom will properly parse each of these cases from the
2041 // command line without any escapes. However we still have to
2042 // get the '$' and '#' characters through WMake as '$$' and
2043 // '$#'.
2044 for(const char* c = di->c_str(); *c; ++c)
2046 if(*c == '$' || *c == '#')
2048 defines += '$';
2050 defines += *c;
2053 else
2055 // Make the definition appear properly on the command line. Use
2056 // -DNAME="value" instead of -D"NAME=value" to help VS6 parser.
2057 std::string::size_type eq = di->find("=");
2058 defines += di->substr(0, eq);
2059 if(eq != di->npos)
2061 defines += "=";
2062 defines += this->EscapeForShell(di->c_str() + eq + 1, true);
2068 //----------------------------------------------------------------------------
2069 std::string
2070 cmLocalGenerator::ConstructComment(const cmCustomCommand& cc,
2071 const char* default_comment)
2073 // Check for a comment provided with the command.
2074 if(cc.GetComment())
2076 return cc.GetComment();
2079 // Construct a reasonable default comment if possible.
2080 if(!cc.GetOutputs().empty())
2082 std::string comment;
2083 comment = "Generating ";
2084 const char* sep = "";
2085 for(std::vector<std::string>::const_iterator o = cc.GetOutputs().begin();
2086 o != cc.GetOutputs().end(); ++o)
2088 comment += sep;
2089 comment += this->Convert(o->c_str(), cmLocalGenerator::START_OUTPUT);
2090 sep = ", ";
2092 return comment;
2095 // Otherwise use the provided default.
2096 return default_comment;
2099 //----------------------------------------------------------------------------
2100 std::string
2101 cmLocalGenerator::ConvertToOptionallyRelativeOutputPath(const char* remote)
2103 return this->Convert(remote, START_OUTPUT, SHELL, true);
2106 //----------------------------------------------------------------------------
2107 const char* cmLocalGenerator::GetRelativeRootPath(RelativeRoot relroot)
2109 switch (relroot)
2111 case HOME: return this->Makefile->GetHomeDirectory();
2112 case START: return this->Makefile->GetStartDirectory();
2113 case HOME_OUTPUT: return this->Makefile->GetHomeOutputDirectory();
2114 case START_OUTPUT: return this->Makefile->GetStartOutputDirectory();
2115 default: break;
2117 return 0;
2120 //----------------------------------------------------------------------------
2121 std::string cmLocalGenerator::Convert(const char* source,
2122 RelativeRoot relative,
2123 OutputFormat output,
2124 bool optional)
2126 // Make sure the relative path conversion components are set.
2127 if(!this->PathConversionsSetup)
2129 this->SetupPathConversions();
2130 this->PathConversionsSetup = true;
2133 // Convert the path to a relative path.
2134 std::string result = source;
2136 if (!optional || this->UseRelativePaths)
2138 switch (relative)
2140 case HOME:
2141 //result = cmSystemTools::CollapseFullPath(result.c_str());
2142 result = this->ConvertToRelativePath(this->HomeDirectoryComponents,
2143 result.c_str());
2144 break;
2145 case START:
2146 //result = cmSystemTools::CollapseFullPath(result.c_str());
2147 result = this->ConvertToRelativePath(this->StartDirectoryComponents,
2148 result.c_str());
2149 break;
2150 case HOME_OUTPUT:
2151 //result = cmSystemTools::CollapseFullPath(result.c_str());
2152 result =
2153 this->ConvertToRelativePath(this->HomeOutputDirectoryComponents,
2154 result.c_str());
2155 break;
2156 case START_OUTPUT:
2157 //result = cmSystemTools::CollapseFullPath(result.c_str());
2158 result =
2159 this->ConvertToRelativePath(this->StartOutputDirectoryComponents,
2160 result.c_str());
2161 break;
2162 case FULL:
2163 result = cmSystemTools::CollapseFullPath(result.c_str());
2164 break;
2165 case NONE:
2166 break;
2169 return this->ConvertToOutputFormat(result.c_str(), output);
2172 //----------------------------------------------------------------------------
2173 std::string cmLocalGenerator::ConvertToOutputFormat(const char* source,
2174 OutputFormat output)
2176 std::string result = source;
2177 // Convert it to an output path.
2178 if (output == MAKEFILE)
2180 result = cmSystemTools::ConvertToOutputPath(result.c_str());
2182 else if( output == SHELL)
2184 // For the MSYS shell convert drive letters to posix paths, so
2185 // that c:/some/path becomes /c/some/path. This is needed to
2186 // avoid problems with the shell path translation.
2187 if(this->MSYSShell && !this->LinkScriptShell)
2189 if(result.size() > 2 && result[1] == ':')
2191 result[1] = result[0];
2192 result[0] = '/';
2195 if(this->WindowsShell)
2197 std::string::size_type pos = 0;
2198 while((pos = result.find('/', pos)) != std::string::npos)
2200 result[pos] = '\\';
2201 pos++;
2204 result = this->EscapeForShell(result.c_str(), true, false);
2206 return result;
2209 //----------------------------------------------------------------------------
2210 std::string cmLocalGenerator::Convert(RelativeRoot remote,
2211 const char* local,
2212 OutputFormat output,
2213 bool optional)
2215 const char* remotePath = this->GetRelativeRootPath(remote);
2217 // The relative root must have a path (i.e. not FULL or NONE)
2218 assert(remotePath != 0);
2220 if(local && (!optional || this->UseRelativePaths))
2222 std::vector<std::string> components;
2223 cmSystemTools::SplitPath(local, components);
2224 std::string result = this->ConvertToRelativePath(components, remotePath);
2225 return this->ConvertToOutputFormat(result.c_str(), output);
2227 else
2229 return this->ConvertToOutputFormat(remotePath, output);
2233 //----------------------------------------------------------------------------
2234 std::string cmLocalGenerator::FindRelativePathTopSource()
2236 // Relative path conversion within a single tree managed by CMake is
2237 // safe. We can use our parent relative path top if and only if
2238 // this is a subdirectory of that top.
2239 if(cmLocalGenerator* parent = this->GetParent())
2241 std::string parentTop = parent->FindRelativePathTopSource();
2242 if(cmSystemTools::IsSubDirectory(
2243 this->Makefile->GetStartDirectory(), parentTop.c_str()))
2245 return parentTop;
2249 // Otherwise this directory itself is the new top.
2250 return this->Makefile->GetStartDirectory();
2253 //----------------------------------------------------------------------------
2254 std::string cmLocalGenerator::FindRelativePathTopBinary()
2256 // Relative path conversion within a single tree managed by CMake is
2257 // safe. We can use our parent relative path top if and only if
2258 // this is a subdirectory of that top.
2259 if(cmLocalGenerator* parent = this->GetParent())
2261 std::string parentTop = parent->FindRelativePathTopBinary();
2262 if(cmSystemTools::IsSubDirectory(
2263 this->Makefile->GetStartOutputDirectory(), parentTop.c_str()))
2265 return parentTop;
2269 // Otherwise this directory itself is the new top.
2270 return this->Makefile->GetStartOutputDirectory();
2273 //----------------------------------------------------------------------------
2274 void cmLocalGenerator::ConfigureRelativePaths()
2276 // Relative path conversion inside the source tree is not used to
2277 // construct relative paths passed to build tools so it is safe to
2278 // even when the source is a network path.
2279 std::string source = this->FindRelativePathTopSource();
2280 this->RelativePathTopSource = source;
2282 // The current working directory on Windows cannot be a network
2283 // path. Therefore relative paths cannot work when the binary tree
2284 // is a network path.
2285 std::string binary = this->FindRelativePathTopBinary();
2286 if(binary.size() < 2 || binary.substr(0, 2) != "//")
2288 this->RelativePathTopBinary = binary;
2290 else
2292 this->RelativePathTopBinary = "";
2296 //----------------------------------------------------------------------------
2297 static bool cmLocalGeneratorNotAbove(const char* a, const char* b)
2299 return (cmSystemTools::ComparePath(a, b) ||
2300 cmSystemTools::IsSubDirectory(a, b));
2303 //----------------------------------------------------------------------------
2304 std::string
2305 cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
2306 const char* in_remote, bool force)
2308 // The path should never be quoted.
2309 assert(in_remote[0] != '\"');
2311 // The local path should never have a trailing slash.
2312 assert(local.size() > 0 && !(local[local.size()-1] == ""));
2314 // If the path is already relative then just return the path.
2315 if(!cmSystemTools::FileIsFullPath(in_remote))
2317 return in_remote;
2320 // Make sure relative path conversion is configured.
2321 if(!this->RelativePathsConfigured)
2323 this->ConfigureRelativePaths();
2324 this->RelativePathsConfigured = true;
2327 if(!force)
2329 // Skip conversion if the path and local are not both in the source
2330 // or both in the binary tree.
2331 std::string local_path = cmSystemTools::JoinPath(local);
2332 if(!((cmLocalGeneratorNotAbove(local_path.c_str(),
2333 this->RelativePathTopBinary.c_str()) &&
2334 cmLocalGeneratorNotAbove(in_remote,
2335 this->RelativePathTopBinary.c_str())) ||
2336 (cmLocalGeneratorNotAbove(local_path.c_str(),
2337 this->RelativePathTopSource.c_str()) &&
2338 cmLocalGeneratorNotAbove(in_remote,
2339 this->RelativePathTopSource.c_str()))))
2341 return in_remote;
2345 // Identify the longest shared path component between the remote
2346 // path and the local path.
2347 std::vector<std::string> remote;
2348 cmSystemTools::SplitPath(in_remote, remote);
2349 unsigned int common=0;
2350 while(common < remote.size() &&
2351 common < local.size() &&
2352 cmSystemTools::ComparePath(remote[common].c_str(),
2353 local[common].c_str()))
2355 ++common;
2358 // If no part of the path is in common then return the full path.
2359 if(common == 0)
2361 return in_remote;
2364 // If the entire path is in common then just return a ".".
2365 if(common == remote.size() &&
2366 common == local.size())
2368 return ".";
2371 // If the entire path is in common except for a trailing slash then
2372 // just return a "./".
2373 if(common+1 == remote.size() &&
2374 remote[common].size() == 0 &&
2375 common == local.size())
2377 return "./";
2380 // Construct the relative path.
2381 std::string relative;
2383 // First add enough ../ to get up to the level of the shared portion
2384 // of the path. Leave off the trailing slash. Note that the last
2385 // component of local will never be empty because local should never
2386 // have a trailing slash.
2387 for(unsigned int i=common; i < local.size(); ++i)
2389 relative += "..";
2390 if(i < local.size()-1)
2392 relative += "/";
2396 // Now add the portion of the destination path that is not included
2397 // in the shared portion of the path. Add a slash the first time
2398 // only if there was already something in the path. If there was a
2399 // trailing slash in the input then the last iteration of the loop
2400 // will add a slash followed by an empty string which will preserve
2401 // the trailing slash in the output.
2402 for(unsigned int i=common; i < remote.size(); ++i)
2404 if(relative.size() > 0)
2406 relative += "/";
2408 relative += remote[i];
2411 // Finally return the path.
2412 return relative;
2415 //----------------------------------------------------------------------------
2416 void
2417 cmLocalGenerator
2418 ::GenerateTargetInstallRules(
2419 std::ostream& os, const char* config,
2420 std::vector<std::string> const& configurationTypes)
2422 // Convert the old-style install specification from each target to
2423 // an install generator and run it.
2424 cmTargets& tgts = this->Makefile->GetTargets();
2425 for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
2427 // Include the user-specified pre-install script for this target.
2428 if(const char* preinstall = l->second.GetProperty("PRE_INSTALL_SCRIPT"))
2430 cmInstallScriptGenerator g(preinstall, false, 0);
2431 g.Generate(os, config, configurationTypes);
2434 // Install this target if a destination is given.
2435 if(l->second.GetInstallPath() != "")
2437 // Compute the full install destination. Note that converting
2438 // to unix slashes also removes any trailing slash.
2439 // We also skip over the leading slash given by the user.
2440 std::string destination = l->second.GetInstallPath().substr(1);
2441 cmSystemTools::ConvertToUnixSlashes(destination);
2442 if(destination.empty())
2444 destination = ".";
2447 // Generate the proper install generator for this target type.
2448 switch(l->second.GetType())
2450 case cmTarget::EXECUTABLE:
2451 case cmTarget::STATIC_LIBRARY:
2452 case cmTarget::MODULE_LIBRARY:
2454 // Use a target install generator.
2455 cmInstallTargetGenerator g(l->second, destination.c_str(), false);
2456 g.Generate(os, config, configurationTypes);
2458 break;
2459 case cmTarget::SHARED_LIBRARY:
2461 #if defined(_WIN32) || defined(__CYGWIN__)
2462 // Special code to handle DLL. Install the import library
2463 // to the normal destination and the DLL to the runtime
2464 // destination.
2465 cmInstallTargetGenerator g1(l->second, destination.c_str(), true);
2466 g1.Generate(os, config, configurationTypes);
2467 // We also skip over the leading slash given by the user.
2468 destination = l->second.GetRuntimeInstallPath().substr(1);
2469 cmSystemTools::ConvertToUnixSlashes(destination);
2470 cmInstallTargetGenerator g2(l->second, destination.c_str(), false);
2471 g2.Generate(os, config, configurationTypes);
2472 #else
2473 // Use a target install generator.
2474 cmInstallTargetGenerator g(l->second, destination.c_str(), false);
2475 g.Generate(os, config, configurationTypes);
2476 #endif
2478 break;
2479 default:
2480 break;
2484 // Include the user-specified post-install script for this target.
2485 if(const char* postinstall = l->second.GetProperty("POST_INSTALL_SCRIPT"))
2487 cmInstallScriptGenerator g(postinstall, false, 0);
2488 g.Generate(os, config, configurationTypes);
2493 #if defined(CM_LG_ENCODE_OBJECT_NAMES)
2494 static std::string cmLocalGeneratorMD5(const char* input)
2496 char md5out[32];
2497 cmsysMD5* md5 = cmsysMD5_New();
2498 cmsysMD5_Initialize(md5);
2499 cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
2500 cmsysMD5_FinalizeHex(md5, md5out);
2501 cmsysMD5_Delete(md5);
2502 return std::string(md5out, 32);
2505 static bool
2506 cmLocalGeneratorShortenObjectName(std::string& objName,
2507 std::string::size_type max_len)
2509 // Replace the beginning of the path portion of the object name with
2510 // its own md5 sum.
2511 std::string::size_type pos = objName.find('/', objName.size()-max_len+32);
2512 if(pos != objName.npos)
2514 std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
2515 md5name += objName.substr(pos);
2516 objName = md5name;
2518 // The object name is now short enough.
2519 return true;
2521 else
2523 // The object name could not be shortened enough.
2524 return false;
2528 static
2529 bool cmLocalGeneratorCheckObjectName(std::string& objName,
2530 std::string::size_type dir_len,
2531 std::string::size_type max_total_len)
2533 // Enforce the maximum file name length if possible.
2534 std::string::size_type max_obj_len = max_total_len;
2535 if(dir_len < max_total_len)
2537 max_obj_len = max_total_len - dir_len;
2538 if(objName.size() > max_obj_len)
2540 // The current object file name is too long. Try to shorten it.
2541 return cmLocalGeneratorShortenObjectName(objName, max_obj_len);
2543 else
2545 // The object file name is short enough.
2546 return true;
2549 else
2551 // The build directory in which the object will be stored is
2552 // already too deep.
2553 return false;
2556 #endif
2558 //----------------------------------------------------------------------------
2559 std::string&
2560 cmLocalGenerator
2561 ::CreateSafeUniqueObjectFileName(const char* sin,
2562 std::string const& dir_max)
2564 // Look for an existing mapped name for this object file.
2565 std::map<cmStdString,cmStdString>::iterator it =
2566 this->UniqueObjectNamesMap.find(sin);
2568 // If no entry exists create one.
2569 if(it == this->UniqueObjectNamesMap.end())
2571 // Start with the original name.
2572 std::string ssin = sin;
2574 // Avoid full paths by removing leading slashes.
2575 std::string::size_type pos = 0;
2576 for(;pos < ssin.size() && ssin[pos] == '/'; ++pos)
2579 ssin = ssin.substr(pos);
2581 // Avoid full paths by removing colons.
2582 cmSystemTools::ReplaceString(ssin, ":", "_");
2584 // Avoid relative paths that go up the tree.
2585 cmSystemTools::ReplaceString(ssin, "../", "__/");
2587 // Avoid spaces.
2588 cmSystemTools::ReplaceString(ssin, " ", "_");
2590 // Mangle the name if necessary.
2591 if(this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
2593 bool done;
2594 int cc = 0;
2595 char rpstr[100];
2596 sprintf(rpstr, "_p_");
2597 cmSystemTools::ReplaceString(ssin, "+", rpstr);
2598 std::string sssin = sin;
2601 done = true;
2602 for ( it = this->UniqueObjectNamesMap.begin();
2603 it != this->UniqueObjectNamesMap.end();
2604 ++ it )
2606 if ( it->second == ssin )
2608 done = false;
2611 if ( done )
2613 break;
2615 sssin = ssin;
2616 cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
2617 sprintf(rpstr, "_p%d_", cc++);
2619 while ( !done );
2622 #if defined(CM_LG_ENCODE_OBJECT_NAMES)
2623 if(!cmLocalGeneratorCheckObjectName(ssin, dir_max.size(),
2624 this->ObjectPathMax))
2626 // Warn if this is the first time the path has been seen.
2627 if(this->ObjectMaxPathViolations.insert(dir_max).second)
2629 cmOStringStream m;
2630 m << "The object file directory\n"
2631 << " " << dir_max << "\n"
2632 << "has " << dir_max.size() << " characters. "
2633 << "The maximum full path to an object file is "
2634 << this->ObjectPathMax << " characters "
2635 << "(see CMAKE_OBJECT_PATH_MAX). "
2636 << "Object file\n"
2637 << " " << ssin << "\n"
2638 << "cannot be safely placed under this directory. "
2639 << "The build may not work correctly.";
2640 this->Makefile->IssueMessage(cmake::WARNING, m.str());
2643 #else
2644 (void)dir_max;
2645 #endif
2647 // Insert the newly mapped object file name.
2648 std::map<cmStdString, cmStdString>::value_type e(sin, ssin);
2649 it = this->UniqueObjectNamesMap.insert(e).first;
2652 // Return the map entry.
2653 return it->second;
2656 //----------------------------------------------------------------------------
2657 std::string
2658 cmLocalGenerator
2659 ::GetObjectFileNameWithoutTarget(const cmSourceFile& source,
2660 std::string const& dir_max,
2661 bool* hasSourceExtension)
2663 // Construct the object file name using the full path to the source
2664 // file which is its only unique identification.
2665 const char* fullPath = source.GetFullPath().c_str();
2667 // Try referencing the source relative to the source tree.
2668 std::string relFromSource = this->Convert(fullPath, START);
2669 assert(!relFromSource.empty());
2670 bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
2671 bool subSource = relSource && relFromSource[0] != '.';
2673 // Try referencing the source relative to the binary tree.
2674 std::string relFromBinary = this->Convert(fullPath, START_OUTPUT);
2675 assert(!relFromBinary.empty());
2676 bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
2677 bool subBinary = relBinary && relFromBinary[0] != '.';
2679 // Select a nice-looking reference to the source file to construct
2680 // the object file name.
2681 std::string objectName;
2682 if((relSource && !relBinary) || (subSource && !subBinary))
2684 objectName = relFromSource;
2686 else if((relBinary && !relSource) || (subBinary && !subSource))
2688 objectName = relFromBinary;
2690 else if(relFromBinary.length() < relFromSource.length())
2692 objectName = relFromBinary;
2694 else
2696 objectName = relFromSource;
2699 // if it is still a full path check for the try compile case
2700 // try compile never have in source sources, and should not
2701 // have conflicting source file names in the same target
2702 if(cmSystemTools::FileIsFullPath(objectName.c_str()))
2704 if(this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile())
2706 objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
2710 // Replace the original source file extension with the object file
2711 // extension.
2712 bool keptSourceExtension = true;
2713 if(!source.GetPropertyAsBool("KEEP_EXTENSION"))
2715 // Decide whether this language wants to replace the source
2716 // extension with the object extension. For CMake 2.4
2717 // compatibility do this by default.
2718 bool replaceExt = this->NeedBackwardsCompatibility(2, 4);
2719 if(!replaceExt)
2721 std::string repVar = "CMAKE_";
2722 repVar += source.GetLanguage();
2723 repVar += "_OUTPUT_EXTENSION_REPLACE";
2724 replaceExt = this->Makefile->IsOn(repVar.c_str());
2727 // Remove the source extension if it is to be replaced.
2728 if(replaceExt)
2730 keptSourceExtension = false;
2731 std::string::size_type dot_pos = objectName.rfind(".");
2732 if(dot_pos != std::string::npos)
2734 objectName = objectName.substr(0, dot_pos);
2738 // Store the new extension.
2739 objectName +=
2740 this->GlobalGenerator->GetLanguageOutputExtension(source);
2742 if(hasSourceExtension)
2744 *hasSourceExtension = keptSourceExtension;
2747 // Convert to a safe name.
2748 return this->CreateSafeUniqueObjectFileName(objectName.c_str(), dir_max);
2751 //----------------------------------------------------------------------------
2752 const char*
2753 cmLocalGenerator
2754 ::GetSourceFileLanguage(const cmSourceFile& source)
2756 return source.GetLanguage();
2759 //----------------------------------------------------------------------------
2760 std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str)
2762 std::string result;
2763 bool forceOn = cmSystemTools::GetForceUnixPaths();
2764 if(forceOn && this->WindowsShell)
2766 cmSystemTools::SetForceUnixPaths(false);
2768 result = cmSystemTools::EscapeSpaces(str);
2769 if(forceOn && this->WindowsShell)
2771 cmSystemTools::SetForceUnixPaths(true);
2773 return result;
2776 //----------------------------------------------------------------------------
2777 static bool cmLocalGeneratorIsShellOperator(const char* str)
2779 if(strcmp(str, "<") == 0 ||
2780 strcmp(str, ">") == 0 ||
2781 strcmp(str, "<<") == 0 ||
2782 strcmp(str, ">>") == 0 ||
2783 strcmp(str, "|") == 0 ||
2784 strcmp(str, "||") == 0 ||
2785 strcmp(str, "&&") == 0 ||
2786 strcmp(str, "&>") == 0 ||
2787 strcmp(str, "1>") == 0 ||
2788 strcmp(str, "2>") == 0 ||
2789 strcmp(str, "2>&1") == 0 ||
2790 strcmp(str, "1>&2") == 0)
2792 return true;
2794 return false;
2797 //----------------------------------------------------------------------------
2798 std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars,
2799 bool forEcho)
2801 // Do not escape shell operators.
2802 if(cmLocalGeneratorIsShellOperator(str))
2804 return str;
2807 // Compute the flags for the target shell environment.
2808 int flags = 0;
2809 if(this->WindowsVSIDE)
2811 flags |= cmsysSystem_Shell_Flag_VSIDE;
2813 else if(!this->LinkScriptShell)
2815 flags |= cmsysSystem_Shell_Flag_Make;
2817 if(makeVars)
2819 flags |= cmsysSystem_Shell_Flag_AllowMakeVariables;
2821 if(forEcho)
2823 flags |= cmsysSystem_Shell_Flag_EchoWindows;
2825 if(this->WatcomWMake)
2827 flags |= cmsysSystem_Shell_Flag_WatcomWMake;
2829 if(this->MinGWMake)
2831 flags |= cmsysSystem_Shell_Flag_MinGWMake;
2833 if(this->NMake)
2835 flags |= cmsysSystem_Shell_Flag_NMake;
2838 // Compute the buffer size needed.
2839 int size = (this->WindowsShell ?
2840 cmsysSystem_Shell_GetArgumentSizeForWindows(str, flags) :
2841 cmsysSystem_Shell_GetArgumentSizeForUnix(str, flags));
2843 // Compute the shell argument itself.
2844 std::vector<char> arg(size);
2845 if(this->WindowsShell)
2847 cmsysSystem_Shell_GetArgumentForWindows(str, &arg[0], flags);
2849 else
2851 cmsysSystem_Shell_GetArgumentForUnix(str, &arg[0], flags);
2853 return std::string(&arg[0]);
2856 //----------------------------------------------------------------------------
2857 std::string cmLocalGenerator::EscapeForCMake(const char* str)
2859 // Always double-quote the argument to take care of most escapes.
2860 std::string result = "\"";
2861 for(const char* c = str; *c; ++c)
2863 if(*c == '"')
2865 // Escape the double quote to avoid ending the argument.
2866 result += "\\\"";
2868 else if(*c == '$')
2870 // Escape the dollar to avoid expanding variables.
2871 result += "\\$";
2873 else if(*c == '\\')
2875 // Escape the backslash to avoid other escapes.
2876 result += "\\\\";
2878 else
2880 // Other characters will be parsed correctly.
2881 result += *c;
2884 result += "\"";
2885 return result;
2888 //----------------------------------------------------------------------------
2889 std::string
2890 cmLocalGenerator::GetTargetDirectory(cmTarget const&) const
2892 cmSystemTools::Error("GetTargetDirectory"
2893 " called on cmLocalGenerator");
2894 return "";
2898 //----------------------------------------------------------------------------
2899 void
2900 cmLocalGenerator::GetTargetObjectFileDirectories(cmTarget* ,
2901 std::vector<std::string>&
2904 cmSystemTools::Error("GetTargetObjectFileDirectories"
2905 " called on cmLocalGenerator");
2908 //----------------------------------------------------------------------------
2909 unsigned int cmLocalGenerator::GetBackwardsCompatibility()
2911 // The computed version may change until the project is fully
2912 // configured.
2913 if(!this->BackwardsCompatibilityFinal)
2915 unsigned int major = 0;
2916 unsigned int minor = 0;
2917 unsigned int patch = 0;
2918 if(const char* value
2919 = this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"))
2921 switch(sscanf(value, "%u.%u.%u", &major, &minor, &patch))
2923 case 2: patch = 0; break;
2924 case 1: minor = 0; patch = 0; break;
2925 default: break;
2928 this->BackwardsCompatibility = CMake_VERSION_ENCODE(major, minor, patch);
2929 this->BackwardsCompatibilityFinal = this->Configured;
2932 return this->BackwardsCompatibility;
2935 //----------------------------------------------------------------------------
2936 bool cmLocalGenerator::NeedBackwardsCompatibility(unsigned int major,
2937 unsigned int minor,
2938 unsigned int patch)
2940 // Check the policy to decide whether to pay attention to this
2941 // variable.
2942 switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0001))
2944 case cmPolicies::WARN:
2945 // WARN is just OLD without warning because user code does not
2946 // always affect whether this check is done.
2947 case cmPolicies::OLD:
2948 // Old behavior is to check the variable.
2949 break;
2950 case cmPolicies::NEW:
2951 // New behavior is to ignore the variable.
2952 return false;
2953 case cmPolicies::REQUIRED_IF_USED:
2954 case cmPolicies::REQUIRED_ALWAYS:
2955 // This will never be the case because the only way to require
2956 // the setting is to require the user to specify version policy
2957 // 2.6 or higher. Once we add that requirement then this whole
2958 // method can be removed anyway.
2959 return false;
2962 // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set
2963 // equal to or lower than the given version.
2964 unsigned int actual_compat = this->GetBackwardsCompatibility();
2965 return (actual_compat &&
2966 actual_compat <= CMake_VERSION_ENCODE(major, minor, patch));
2969 //----------------------------------------------------------------------------
2970 bool cmLocalGenerator::CheckDefinition(std::string const& define) const
2972 // Many compilers do not support -DNAME(arg)=sdf so we disable it.
2973 bool function_style = false;
2974 for(const char* c = define.c_str(); *c && *c != '='; ++c)
2976 if(*c == '(')
2978 function_style = true;
2979 break;
2982 if(function_style)
2984 cmOStringStream e;
2985 e << "WARNING: Function-style preprocessor definitions may not be "
2986 << "passed on the compiler command line because many compilers "
2987 << "do not support it.\n"
2988 << "CMake is dropping a preprocessor definition: " << define << "\n"
2989 << "Consider defining the macro in a (configured) header file.\n";
2990 cmSystemTools::Message(e.str().c_str());
2991 return false;
2994 // Many compilers do not support # in the value so we disable it.
2995 if(define.find_first_of("#") != define.npos)
2997 cmOStringStream e;
2998 e << "WARNING: Peprocessor definitions containing '#' may not be "
2999 << "passed on the compiler command line because many compilers "
3000 << "do not support it.\n"
3001 << "CMake is dropping a preprocessor definition: " << define << "\n"
3002 << "Consider defining the macro in a (configured) header file.\n";
3003 cmSystemTools::Message(e.str().c_str());
3004 return false;
3007 // Assume it is supported.
3008 return true;
3011 //----------------------------------------------------------------------------
3012 static void cmLGInfoProp(cmMakefile* mf, cmTarget* target, const char* prop)
3014 if(const char* val = target->GetProperty(prop))
3016 mf->AddDefinition(prop, val);
3020 //----------------------------------------------------------------------------
3021 void cmLocalGenerator::GenerateAppleInfoPList(cmTarget* target,
3022 const char* targetName,
3023 const char* fname)
3025 // Find the Info.plist template.
3026 const char* in = target->GetProperty("MACOSX_BUNDLE_INFO_PLIST");
3027 std::string inFile = (in && *in)? in : "MacOSXBundleInfo.plist.in";
3028 if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
3030 std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
3031 if(!inMod.empty())
3033 inFile = inMod;
3036 if(!cmSystemTools::FileExists(inFile.c_str(), true))
3038 cmOStringStream e;
3039 e << "Target " << target->GetName() << " Info.plist template \""
3040 << inFile << "\" could not be found.";
3041 cmSystemTools::Error(e.str().c_str());
3042 return;
3045 // Convert target properties to variables in an isolated makefile
3046 // scope to configure the file. If properties are set they will
3047 // override user make variables. If not the configuration will fall
3048 // back to the directory-level values set by the user.
3049 cmMakefile* mf = this->Makefile;
3050 mf->PushScope();
3051 mf->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName);
3052 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_INFO_STRING");
3053 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_ICON_FILE");
3054 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_GUI_IDENTIFIER");
3055 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_LONG_VERSION_STRING");
3056 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_NAME");
3057 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
3058 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION");
3059 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT");
3060 mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
3061 mf->PopScope();
3064 //----------------------------------------------------------------------------
3065 void cmLocalGenerator::GenerateFrameworkInfoPList(cmTarget* target,
3066 const char* targetName,
3067 const char* fname)
3069 // Find the Info.plist template.
3070 const char* in = target->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST");
3071 std::string inFile = (in && *in)? in : "MacOSXFrameworkInfo.plist.in";
3072 if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
3074 std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
3075 if(!inMod.empty())
3077 inFile = inMod;
3080 if(!cmSystemTools::FileExists(inFile.c_str(), true))
3082 cmOStringStream e;
3083 e << "Target " << target->GetName() << " Info.plist template \""
3084 << inFile << "\" could not be found.";
3085 cmSystemTools::Error(e.str().c_str());
3086 return;
3089 // Convert target properties to variables in an isolated makefile
3090 // scope to configure the file. If properties are set they will
3091 // override user make variables. If not the configuration will fall
3092 // back to the directory-level values set by the user.
3093 cmMakefile* mf = this->Makefile;
3094 mf->PushScope();
3095 mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName);
3096 cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_ICON_FILE");
3097 cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER");
3098 cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
3099 cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
3100 mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
3101 mf->PopScope();