Introduce "generator expressions" to add_test()
[cmake.git] / Source / cmLocalGenerator.cxx
blob25fe761d201db6305f6b3aefbcf14240ddc376d7
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmLocalGenerator.cxx,v $
5 Language: C++
6 Date: $Date: 2009-08-04 19:41:57 $
7 Version: $Revision: 1.305 $
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 void cmLocalGenerator::Configure()
73 cmLocalGenerator* previousLg =
74 this->GetGlobalGenerator()->GetCurrentLocalGenerator();
75 this->GetGlobalGenerator()->SetCurrentLocalGenerator(this);
77 // make sure the CMakeFiles dir is there
78 std::string filesDir = this->Makefile->GetStartOutputDirectory();
79 filesDir += cmake::GetCMakeFilesDirectory();
80 cmSystemTools::MakeDirectory(filesDir.c_str());
82 // find & read the list file
83 std::string currentStart = this->Makefile->GetStartDirectory();
84 currentStart += "/CMakeLists.txt";
85 this->Makefile->ReadListFile(currentStart.c_str());
87 // at the end of the ReadListFile handle any old style subdirs
88 // first get all the subdirectories
89 std::vector<cmLocalGenerator *> subdirs = this->GetChildren();
91 // for each subdir recurse
92 std::vector<cmLocalGenerator *>::iterator sdi = subdirs.begin();
93 for (; sdi != subdirs.end(); ++sdi)
95 if (!(*sdi)->Configured)
97 this->Makefile->ConfigureSubDirectory(*sdi);
101 // Check whether relative paths should be used for optionally
102 // relative paths.
103 this->UseRelativePaths = this->Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS");
105 // Choose a maximum object file name length.
107 #if defined(_WIN32) || defined(__CYGWIN__)
108 this->ObjectPathMax = 250;
109 #else
110 this->ObjectPathMax = 1000;
111 #endif
112 const char* plen = this->Makefile->GetDefinition("CMAKE_OBJECT_PATH_MAX");
113 if(plen && *plen)
115 unsigned int pmax;
116 if(sscanf(plen, "%u", &pmax) == 1)
118 if(pmax >= 128)
120 this->ObjectPathMax = pmax;
122 else
124 cmOStringStream w;
125 w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax
126 << ", which is less than the minimum of 128. "
127 << "The value will be ignored.";
128 this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
131 else
133 cmOStringStream w;
134 w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen
135 << "\", which fails to parse as a positive integer. "
136 << "The value will be ignored.";
137 this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
140 this->ObjectMaxPathViolations.clear();
143 this->Configured = true;
145 this->GetGlobalGenerator()->SetCurrentLocalGenerator(previousLg);
148 void cmLocalGenerator::SetupPathConversions()
150 // Setup the current output directory components for use by
151 // Convert
152 std::string outdir;
153 outdir =
154 cmSystemTools::CollapseFullPath(this->Makefile->GetHomeDirectory());
155 cmSystemTools::SplitPath(outdir.c_str(), this->HomeDirectoryComponents);
156 outdir =
157 cmSystemTools::CollapseFullPath(this->Makefile->GetStartDirectory());
158 cmSystemTools::SplitPath(outdir.c_str(), this->StartDirectoryComponents);
160 outdir = cmSystemTools::CollapseFullPath
161 (this->Makefile->GetHomeOutputDirectory());
162 cmSystemTools::SplitPath(outdir.c_str(),
163 this->HomeOutputDirectoryComponents);
165 outdir = cmSystemTools::CollapseFullPath
166 (this->Makefile->GetStartOutputDirectory());
167 cmSystemTools::SplitPath(outdir.c_str(),
168 this->StartOutputDirectoryComponents);
172 void cmLocalGenerator::SetGlobalGenerator(cmGlobalGenerator *gg)
174 this->GlobalGenerator = gg;
175 this->Makefile = new cmMakefile;
176 this->Makefile->SetLocalGenerator(this);
178 // setup the home directories
179 this->Makefile->GetProperties().SetCMakeInstance(gg->GetCMakeInstance());
180 this->Makefile->SetHomeDirectory(
181 gg->GetCMakeInstance()->GetHomeDirectory());
182 this->Makefile->SetHomeOutputDirectory(
183 gg->GetCMakeInstance()->GetHomeOutputDirectory());
186 void cmLocalGenerator::ConfigureFinalPass()
188 this->Makefile->ConfigureFinalPass();
191 void cmLocalGenerator::TraceDependencies()
193 // Generate the rule files for each target.
194 cmTargets& targets = this->Makefile->GetTargets();
195 for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
197 const char* projectFilename = 0;
198 if (this->IsMakefileGenerator == false) // only use of this variable
200 projectFilename = t->second.GetName();
202 t->second.TraceDependencies(projectFilename);
206 void cmLocalGenerator::GenerateTestFiles()
208 if ( !this->Makefile->IsOn("CMAKE_TESTING_ENABLED") )
210 return;
213 // Compute the set of configurations.
214 std::vector<std::string> configurationTypes;
215 if(const char* types =
216 this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
218 cmSystemTools::ExpandListArgument(types, configurationTypes);
220 const char* config = 0;
221 if(configurationTypes.empty())
223 config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
226 std::string file = this->Makefile->GetStartOutputDirectory();
227 file += "/";
228 file += "CTestTestfile.cmake";
230 cmGeneratedFileStream fout(file.c_str());
231 fout.SetCopyIfDifferent(true);
233 fout << "# CMake generated Testfile for " << std::endl
234 << "# Source directory: "
235 << this->Makefile->GetStartDirectory() << std::endl
236 << "# Build directory: "
237 << this->Makefile->GetStartOutputDirectory() << std::endl
238 << "# " << std::endl
239 << "# This file includes the relevent testing commands "
240 << "required for " << std::endl
241 << "# testing this directory and lists subdirectories to "
242 << "be tested as well." << std::endl;
244 const char* testIncludeFile =
245 this->Makefile->GetProperty("TEST_INCLUDE_FILE");
246 if ( testIncludeFile )
248 fout << "INCLUDE(\"" << testIncludeFile << "\")" << std::endl;
251 // Ask each test generator to write its code.
252 std::vector<cmTestGenerator*> const&
253 testers = this->Makefile->GetTestGenerators();
254 for(std::vector<cmTestGenerator*>::const_iterator gi = testers.begin();
255 gi != testers.end(); ++gi)
257 (*gi)->Generate(fout, config, configurationTypes);
259 if ( this->Children.size())
261 size_t i;
262 for(i = 0; i < this->Children.size(); ++i)
264 fout << "SUBDIRS(";
265 std::string outP =
266 this->Children[i]->GetMakefile()->GetStartOutputDirectory();
267 fout << this->Convert(outP.c_str(),START_OUTPUT);
268 fout << ")" << std::endl;
273 //----------------------------------------------------------------------------
274 void cmLocalGenerator::GenerateInstallRules()
276 // Compute the install prefix.
277 const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
278 #if defined(_WIN32) && !defined(__CYGWIN__)
279 std::string prefix_win32;
280 if(!prefix)
282 if(!cmSystemTools::GetEnv("SystemDrive", prefix_win32))
284 prefix_win32 = "C:";
286 const char* project_name = this->Makefile->GetDefinition("PROJECT_NAME");
287 if(project_name && project_name[0])
289 prefix_win32 += "/Program Files/";
290 prefix_win32 += project_name;
292 else
294 prefix_win32 += "/InstalledCMakeProject";
296 prefix = prefix_win32.c_str();
298 #else
299 if (!prefix)
301 prefix = "/usr/local";
303 #endif
305 // Compute the set of configurations.
306 std::vector<std::string> configurationTypes;
307 if(const char* types =
308 this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
310 cmSystemTools::ExpandListArgument(types, configurationTypes);
312 const char* config = 0;
313 if(configurationTypes.empty())
315 config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
318 // Choose a default install configuration.
319 const char* default_config = config;
320 const char* default_order[] = {"RELEASE", "MINSIZEREL",
321 "RELWITHDEBINFO", "DEBUG", 0};
322 for(const char** c = default_order; *c && !default_config; ++c)
324 for(std::vector<std::string>::iterator i = configurationTypes.begin();
325 i != configurationTypes.end(); ++i)
327 if(cmSystemTools::UpperCase(*i) == *c)
329 default_config = i->c_str();
333 if(!default_config && !configurationTypes.empty())
335 default_config = configurationTypes[0].c_str();
337 if(!default_config)
339 default_config = "Release";
342 // Create the install script file.
343 std::string file = this->Makefile->GetStartOutputDirectory();
344 std::string homedir = this->Makefile->GetHomeOutputDirectory();
345 std::string currdir = this->Makefile->GetCurrentOutputDirectory();
346 cmSystemTools::ConvertToUnixSlashes(file);
347 cmSystemTools::ConvertToUnixSlashes(homedir);
348 cmSystemTools::ConvertToUnixSlashes(currdir);
349 int toplevel_install = 0;
350 if ( currdir == homedir )
352 toplevel_install = 1;
354 file += "/cmake_install.cmake";
355 cmGeneratedFileStream fout(file.c_str());
356 fout.SetCopyIfDifferent(true);
358 // Write the header.
359 fout << "# Install script for directory: "
360 << this->Makefile->GetCurrentDirectory() << std::endl << std::endl;
361 fout << "# Set the install prefix" << std::endl
362 << "IF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
363 << " SET(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
364 << "ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
365 << "STRING(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
366 << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
367 << std::endl;
369 // Write support code for generating per-configuration install rules.
370 fout <<
371 "# Set the install configuration name.\n"
372 "IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
373 " IF(BUILD_TYPE)\n"
374 " STRING(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
375 " CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
376 " ELSE(BUILD_TYPE)\n"
377 " SET(CMAKE_INSTALL_CONFIG_NAME \"" << default_config << "\")\n"
378 " ENDIF(BUILD_TYPE)\n"
379 " MESSAGE(STATUS \"Install configuration: "
380 "\\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
381 "ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
382 "\n";
384 // Write support code for dealing with component-specific installs.
385 fout <<
386 "# Set the component getting installed.\n"
387 "IF(NOT CMAKE_INSTALL_COMPONENT)\n"
388 " IF(COMPONENT)\n"
389 " MESSAGE(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
390 " SET(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
391 " ELSE(COMPONENT)\n"
392 " SET(CMAKE_INSTALL_COMPONENT)\n"
393 " ENDIF(COMPONENT)\n"
394 "ENDIF(NOT CMAKE_INSTALL_COMPONENT)\n"
395 "\n";
397 // Copy user-specified install options to the install code.
398 if(const char* so_no_exe =
399 this->Makefile->GetDefinition("CMAKE_INSTALL_SO_NO_EXE"))
401 fout <<
402 "# Install shared libraries without execute permission?\n"
403 "IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
404 " SET(CMAKE_INSTALL_SO_NO_EXE \"" << so_no_exe << "\")\n"
405 "ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
406 "\n";
409 // Ask each install generator to write its code.
410 std::vector<cmInstallGenerator*> const& installers =
411 this->Makefile->GetInstallGenerators();
412 for(std::vector<cmInstallGenerator*>::const_iterator
413 gi = installers.begin();
414 gi != installers.end(); ++gi)
416 (*gi)->Generate(fout, config, configurationTypes);
419 // Write rules from old-style specification stored in targets.
420 this->GenerateTargetInstallRules(fout, config, configurationTypes);
422 // Include install scripts from subdirectories.
423 if(!this->Children.empty())
425 fout << "IF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
426 fout << " # Include the install script for each subdirectory.\n";
427 for(std::vector<cmLocalGenerator*>::const_iterator
428 ci = this->Children.begin(); ci != this->Children.end(); ++ci)
430 if(!(*ci)->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
432 std::string odir = (*ci)->GetMakefile()->GetStartOutputDirectory();
433 cmSystemTools::ConvertToUnixSlashes(odir);
434 fout << " INCLUDE(\"" << odir.c_str()
435 << "/cmake_install.cmake\")" << std::endl;
438 fout << "\n";
439 fout << "ENDIF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n\n";
442 // Record the install manifest.
443 if ( toplevel_install )
445 fout <<
446 "IF(CMAKE_INSTALL_COMPONENT)\n"
447 " SET(CMAKE_INSTALL_MANIFEST \"install_manifest_"
448 "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
449 "ELSE(CMAKE_INSTALL_COMPONENT)\n"
450 " SET(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
451 "ENDIF(CMAKE_INSTALL_COMPONENT)\n\n";
452 fout
453 << "FILE(WRITE \""
454 << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
455 << "\"\")" << std::endl;
456 fout
457 << "FOREACH(file ${CMAKE_INSTALL_MANIFEST_FILES})" << std::endl
458 << " FILE(APPEND \""
459 << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
460 << "\"${file}\\n\")" << std::endl
461 << "ENDFOREACH(file)" << std::endl;
465 //----------------------------------------------------------------------------
466 void cmLocalGenerator::GenerateTargetManifest()
468 // Collect the set of configuration types.
469 std::vector<std::string> configNames;
470 if(const char* configurationTypes =
471 this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
473 cmSystemTools::ExpandListArgument(configurationTypes, configNames);
475 else if(const char* buildType =
476 this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"))
478 if(*buildType)
480 configNames.push_back(buildType);
484 // Add our targets to the manifest for each configuration.
485 cmTargets& targets = this->Makefile->GetTargets();
486 for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
488 cmTarget& target = t->second;
489 if(configNames.empty())
491 target.GenerateTargetManifest(0);
493 else
495 for(std::vector<std::string>::iterator ci = configNames.begin();
496 ci != configNames.end(); ++ci)
498 const char* config = ci->c_str();
499 target.GenerateTargetManifest(config);
505 void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
506 const char* lang,
507 cmSourceFile& source,
508 cmTarget& )
510 std::string objectDir = cmSystemTools::GetFilenamePath(std::string(ofname));
511 objectDir = this->Convert(objectDir.c_str(),START_OUTPUT,SHELL);
512 std::string objectFile = this->Convert(ofname,START_OUTPUT,SHELL);
513 std::string sourceFile =
514 this->Convert(source.GetFullPath().c_str(),START_OUTPUT,SHELL,true);
515 std::string varString = "CMAKE_";
516 varString += lang;
517 varString += "_COMPILE_OBJECT";
518 std::vector<std::string> rules;
519 rules.push_back(this->Makefile->GetRequiredDefinition(varString.c_str()));
520 varString = "CMAKE_";
521 varString += lang;
522 varString += "_FLAGS";
523 std::string flags;
524 flags += this->Makefile->GetSafeDefinition(varString.c_str());
525 flags += " ";
526 flags += this->GetIncludeFlags(lang);
528 // Construct the command lines.
529 cmCustomCommandLines commandLines;
530 std::vector<std::string> commands;
531 cmSystemTools::ExpandList(rules, commands);
532 cmLocalGenerator::RuleVariables vars;
533 vars.Language = lang;
534 vars.Source = sourceFile.c_str();
535 vars.Object = objectFile.c_str();
536 vars.ObjectDir = objectDir.c_str();
537 vars.Flags = flags.c_str();
538 for(std::vector<std::string>::iterator i = commands.begin();
539 i != commands.end(); ++i)
541 // Expand the full command line string.
542 this->ExpandRuleVariables(*i, vars);
544 // Parse the string to get the custom command line.
545 cmCustomCommandLine commandLine;
546 std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
547 for(std::vector<cmStdString>::iterator a = cmd.begin();
548 a != cmd.end(); ++a)
550 commandLine.push_back(*a);
553 // Store this command line.
554 commandLines.push_back(commandLine);
557 // Check for extra object-file dependencies.
558 std::vector<std::string> depends;
559 const char* additionalDeps = source.GetProperty("OBJECT_DEPENDS");
560 if(additionalDeps)
562 cmSystemTools::ExpandListArgument(additionalDeps, depends);
565 // Generate a meaningful comment for the command.
566 std::string comment = "Building ";
567 comment += lang;
568 comment += " object ";
569 comment += this->Convert(ofname, START_OUTPUT);
571 // Add the custom command to build the object file.
572 this->Makefile->AddCustomCommandToOutput(
573 ofname,
574 depends,
575 source.GetFullPath().c_str(),
576 commandLines,
577 comment.c_str(),
578 this->Makefile->GetStartOutputDirectory()
582 void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
584 cmStdString objs;
585 std::vector<std::string> objVector;
586 // Add all the sources outputs to the depends of the target
587 std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
588 for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
589 i != classes.end(); ++i)
591 cmSourceFile* sf = *i;
592 if(!sf->GetCustomCommand() &&
593 !sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
594 !sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
596 std::string dir_max;
597 dir_max += this->Makefile->GetCurrentOutputDirectory();
598 dir_max += "/";
599 std::string obj = this->GetObjectFileNameWithoutTarget(*sf, dir_max);
600 if(!obj.empty())
602 std::string ofname = this->Makefile->GetCurrentOutputDirectory();
603 ofname += "/";
604 ofname += obj;
605 objVector.push_back(ofname);
606 this->AddCustomCommandToCreateObject(ofname.c_str(),
607 llang, *(*i), target);
608 objs += this->Convert(ofname.c_str(),START_OUTPUT,MAKEFILE);
609 objs += " ";
613 std::string createRule = "CMAKE_";
614 createRule += llang;
615 createRule += target.GetCreateRuleVariable();
616 std::string targetName = target.GetFullName();
617 // Executable :
618 // Shared Library:
619 // Static Library:
620 // Shared Module:
621 std::string linkLibs; // should be set
622 std::string flags; // should be set
623 std::string linkFlags; // should be set
624 this->GetTargetFlags(linkLibs, flags, linkFlags, target);
625 cmLocalGenerator::RuleVariables vars;
626 vars.Language = llang;
627 vars.Objects = objs.c_str();
628 vars.ObjectDir = ".";
629 vars.Target = targetName.c_str();
630 vars.LinkLibraries = linkLibs.c_str();
631 vars.Flags = flags.c_str();
632 vars.LinkFlags = linkFlags.c_str();
634 std::string langFlags;
635 this->AddLanguageFlags(langFlags, llang, 0);
636 vars.LanguageCompileFlags = langFlags.c_str();
638 cmCustomCommandLines commandLines;
639 std::vector<std::string> rules;
640 rules.push_back(this->Makefile->GetRequiredDefinition(createRule.c_str()));
641 std::vector<std::string> commands;
642 cmSystemTools::ExpandList(rules, commands);
643 for(std::vector<std::string>::iterator i = commands.begin();
644 i != commands.end(); ++i)
646 // Expand the full command line string.
647 this->ExpandRuleVariables(*i, vars);
648 // Parse the string to get the custom command line.
649 cmCustomCommandLine commandLine;
650 std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
651 for(std::vector<cmStdString>::iterator a = cmd.begin();
652 a != cmd.end(); ++a)
654 commandLine.push_back(*a);
657 // Store this command line.
658 commandLines.push_back(commandLine);
660 std::string targetFullPath = target.GetFullPath();
661 // Generate a meaningful comment for the command.
662 std::string comment = "Linking ";
663 comment += llang;
664 comment += " target ";
665 comment += this->Convert(targetFullPath.c_str(), START_OUTPUT);
666 this->Makefile->AddCustomCommandToOutput(
667 targetFullPath.c_str(),
668 objVector,
670 commandLines,
671 comment.c_str(),
672 this->Makefile->GetStartOutputDirectory()
674 target.AddSourceFile
675 (this->Makefile->GetSource(targetFullPath.c_str()));
679 void cmLocalGenerator
680 ::CreateCustomTargetsAndCommands(std::set<cmStdString> const& lang)
682 cmTargets &tgts = this->Makefile->GetTargets();
683 for(cmTargets::iterator l = tgts.begin();
684 l != tgts.end(); l++)
686 cmTarget& target = l->second;
687 switch(target.GetType())
689 case cmTarget::STATIC_LIBRARY:
690 case cmTarget::SHARED_LIBRARY:
691 case cmTarget::MODULE_LIBRARY:
692 case cmTarget::EXECUTABLE:
694 const char* llang = target.GetLinkerLanguage();
695 if(!llang)
697 cmSystemTools::Error
698 ("CMake can not determine linker language for target:",
699 target.GetName());
700 return;
702 // if the language is not in the set lang then create custom
703 // commands to build the target
704 if(lang.count(llang) == 0)
706 this->AddBuildTargetRule(llang, target);
709 break;
710 default:
711 break;
716 // List of variables that are replaced when
717 // rules are expanced. These variables are
718 // replaced in the form <var> with GetSafeDefinition(var).
719 // ${LANG} is replaced in the variable first with all enabled
720 // languages.
721 static const char* ruleReplaceVars[] =
723 "CMAKE_${LANG}_COMPILER",
724 "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
725 "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
726 "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
727 "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
728 "CMAKE_${LANG}_LINK_FLAGS",
729 "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
730 "CMAKE_${LANG}_ARCHIVE",
731 "CMAKE_AR",
732 "CMAKE_CURRENT_SOURCE_DIR",
733 "CMAKE_CURRENT_BINARY_DIR",
734 "CMAKE_RANLIB",
735 "CMAKE_LINKER",
739 std::string
740 cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
741 const RuleVariables& replaceValues)
743 if(replaceValues.LinkFlags)
745 if(variable == "LINK_FLAGS")
747 return replaceValues.LinkFlags;
750 if(replaceValues.Flags)
752 if(variable == "FLAGS")
754 return replaceValues.Flags;
758 if(replaceValues.Source)
760 if(variable == "SOURCE")
762 return replaceValues.Source;
765 if(replaceValues.PreprocessedSource)
767 if(variable == "PREPROCESSED_SOURCE")
769 return replaceValues.PreprocessedSource;
772 if(replaceValues.AssemblySource)
774 if(variable == "ASSEMBLY_SOURCE")
776 return replaceValues.AssemblySource;
779 if(replaceValues.Object)
781 if(variable == "OBJECT")
783 return replaceValues.Object;
786 if(replaceValues.ObjectDir)
788 if(variable == "OBJECT_DIR")
790 return replaceValues.ObjectDir;
793 if(replaceValues.Objects)
795 if(variable == "OBJECTS")
797 return replaceValues.Objects;
800 if(replaceValues.ObjectsQuoted)
802 if(variable == "OBJECTS_QUOTED")
804 return replaceValues.ObjectsQuoted;
807 if(replaceValues.Defines && variable == "DEFINES")
809 return replaceValues.Defines;
811 if(replaceValues.TargetPDB )
813 if(variable == "TARGET_PDB")
815 return replaceValues.TargetPDB;
819 if(replaceValues.Target)
821 if(variable == "TARGET_QUOTED")
823 std::string targetQuoted = replaceValues.Target;
824 if(targetQuoted.size() && targetQuoted[0] != '\"')
826 targetQuoted = '\"';
827 targetQuoted += replaceValues.Target;
828 targetQuoted += '\"';
830 return targetQuoted;
832 if(replaceValues.LanguageCompileFlags)
834 if(variable == "LANGUAGE_COMPILE_FLAGS")
836 return replaceValues.LanguageCompileFlags;
839 if(replaceValues.Target)
841 if(variable == "TARGET")
843 return replaceValues.Target;
846 if(variable == "TARGET_IMPLIB")
848 return this->TargetImplib;
850 if(variable == "TARGET_VERSION_MAJOR")
852 if(replaceValues.TargetVersionMajor)
854 return replaceValues.TargetVersionMajor;
856 else
858 return "0";
861 if(variable == "TARGET_VERSION_MINOR")
863 if(replaceValues.TargetVersionMinor)
865 return replaceValues.TargetVersionMinor;
867 else
869 return "0";
872 if(replaceValues.Target)
874 if(variable == "TARGET_BASE")
876 // Strip the last extension off the target name.
877 std::string targetBase = replaceValues.Target;
878 std::string::size_type pos = targetBase.rfind(".");
879 if(pos != targetBase.npos)
881 return targetBase.substr(0, pos);
883 else
885 return targetBase;
890 if(replaceValues.TargetSOName)
892 if(variable == "TARGET_SONAME")
894 if(replaceValues.Language)
896 std::string name = "CMAKE_SHARED_LIBRARY_SONAME_";
897 name += replaceValues.Language;
898 name += "_FLAG";
899 if(this->Makefile->GetDefinition(name.c_str()))
901 return replaceValues.TargetSOName;
904 return "";
907 if(replaceValues.TargetInstallNameDir)
909 if(variable == "TARGET_INSTALLNAME_DIR")
911 return replaceValues.TargetInstallNameDir;
914 if(replaceValues.LinkLibraries)
916 if(variable == "LINK_LIBRARIES")
918 return replaceValues.LinkLibraries;
921 if(replaceValues.Language)
923 if(variable == "LANGUAGE")
925 return replaceValues.Language;
928 if(replaceValues.CMTarget)
930 if(variable == "TARGET_NAME")
932 return replaceValues.CMTarget->GetName();
934 if(variable == "TARGET_TYPE")
936 return cmTarget::TargetTypeNames[replaceValues.CMTarget->GetType()];
939 if(replaceValues.Output)
941 if(variable == "OUTPUT")
943 return replaceValues.Output;
946 if(variable == "CMAKE_COMMAND")
948 const char* cmcommand =
949 this->GetMakefile()->GetDefinition("CMAKE_COMMAND");
950 return this->Convert(cmcommand, FULL, SHELL);
952 std::vector<std::string> enabledLanguages;
953 this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
954 // loop over language specific replace variables
955 int pos = 0;
956 while(ruleReplaceVars[pos])
958 for(std::vector<std::string>::iterator i = enabledLanguages.begin();
959 i != enabledLanguages.end(); ++i)
961 const char* lang = i->c_str();
962 std::string actualReplace = ruleReplaceVars[pos];
963 // If this is the compiler then look for the extra variable
964 // _COMPILER_ARG1 which must be the first argument to the compiler
965 const char* compilerArg1 = 0;
966 if(actualReplace == "CMAKE_${LANG}_COMPILER")
968 std::string arg1 = actualReplace + "_ARG1";
969 cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
970 compilerArg1 = this->Makefile->GetDefinition(arg1.c_str());
972 if(actualReplace.find("${LANG}") != actualReplace.npos)
974 cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
976 if(actualReplace == variable)
978 std::string replace =
979 this->Makefile->GetSafeDefinition(variable.c_str());
980 // if the variable is not a FLAG then treat it like a path
981 if(variable.find("_FLAG") == variable.npos)
983 std::string ret = this->ConvertToOutputForExisting(replace.c_str());
984 // if there is a required first argument to the compiler add it
985 // to the compiler string
986 if(compilerArg1)
988 ret += " ";
989 ret += compilerArg1;
991 return ret;
993 return replace;
996 pos++;
998 return variable;
1002 void
1003 cmLocalGenerator::ExpandRuleVariables(std::string& s,
1004 const RuleVariables& replaceValues)
1006 std::vector<std::string> enabledLanguages;
1007 this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
1008 this->InsertRuleLauncher(s, replaceValues.CMTarget,
1009 replaceValues.RuleLauncher);
1010 std::string::size_type start = s.find('<');
1011 // no variables to expand
1012 if(start == s.npos)
1014 return;
1016 std::string::size_type pos = 0;
1017 std::string expandedInput;
1018 while(start != s.npos && start < s.size()-2)
1020 std::string::size_type end = s.find('>', start);
1021 // if we find a < with no > we are done
1022 if(end == s.npos)
1024 return;
1026 char c = s[start+1];
1027 // if the next char after the < is not A-Za-z then
1028 // skip it and try to find the next < in the string
1029 if(!isalpha(c))
1031 start = s.find('<', start+1);
1033 else
1035 // extract the var
1036 std::string var = s.substr(start+1, end - start-1);
1037 std::string replace = this->ExpandRuleVariable(var,
1038 replaceValues);
1039 expandedInput += s.substr(pos, start-pos);
1040 expandedInput += replace;
1041 // move to next one
1042 start = s.find('<', start+var.size()+2);
1043 pos = end+1;
1046 // add the rest of the input
1047 expandedInput += s.substr(pos, s.size()-pos);
1048 s = expandedInput;
1051 //----------------------------------------------------------------------------
1052 const char* cmLocalGenerator::GetRuleLauncher(cmTarget* target,
1053 const char* prop)
1055 if(target)
1057 return target->GetProperty(prop);
1059 else
1061 return this->Makefile->GetProperty(prop);
1065 //----------------------------------------------------------------------------
1066 void cmLocalGenerator::InsertRuleLauncher(std::string& s, cmTarget* target,
1067 const char* prop)
1069 if(const char* val = this->GetRuleLauncher(target, prop))
1071 cmOStringStream wrapped;
1072 wrapped << val << " " << s;
1073 s = wrapped.str();
1077 //----------------------------------------------------------------------------
1078 std::string
1079 cmLocalGenerator::ConvertToOutputForExistingCommon(const char* remote,
1080 std::string const& result)
1082 // If this is a windows shell, the result has a space, and the path
1083 // already exists, we can use a short-path to reference it without a
1084 // space.
1085 if(this->WindowsShell && result.find(' ') != result.npos &&
1086 cmSystemTools::FileExists(remote))
1088 std::string tmp;
1089 if(cmSystemTools::GetShortPath(remote, tmp))
1091 return this->Convert(tmp.c_str(), NONE, SHELL, true);
1095 // Otherwise, leave it unchanged.
1096 return result;
1099 //----------------------------------------------------------------------------
1100 std::string
1101 cmLocalGenerator::ConvertToOutputForExisting(const char* remote,
1102 RelativeRoot local)
1104 // Perform standard conversion.
1105 std::string result = this->Convert(remote, local, SHELL, true);
1107 // Consider short-path.
1108 return this->ConvertToOutputForExistingCommon(remote, result);
1111 //----------------------------------------------------------------------------
1112 std::string
1113 cmLocalGenerator::ConvertToOutputForExisting(RelativeRoot remote,
1114 const char* local)
1116 // Perform standard conversion.
1117 std::string result = this->Convert(remote, local, SHELL, true);
1119 // Consider short-path.
1120 const char* remotePath = this->GetRelativeRootPath(remote);
1121 return this->ConvertToOutputForExistingCommon(remotePath, result);
1124 //----------------------------------------------------------------------------
1125 const char* cmLocalGenerator::GetIncludeFlags(const char* lang)
1127 if(!lang)
1129 return "";
1131 if(this->LanguageToIncludeFlags.count(lang))
1133 return this->LanguageToIncludeFlags[lang].c_str();
1136 cmOStringStream includeFlags;
1137 std::vector<std::string> includes;
1138 this->GetIncludeDirectories(includes, lang);
1139 std::vector<std::string>::iterator i;
1141 std::string flagVar = "CMAKE_INCLUDE_FLAG_";
1142 flagVar += lang;
1143 const char* includeFlag =
1144 this->Makefile->GetSafeDefinition(flagVar.c_str());
1145 flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
1146 flagVar += lang;
1147 const char* sep = this->Makefile->GetDefinition(flagVar.c_str());
1148 bool quotePaths = false;
1149 if(this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS"))
1151 quotePaths = true;
1153 bool repeatFlag = true;
1154 // should the include flag be repeated like ie. -IA -IB
1155 if(!sep)
1157 sep = " ";
1159 else
1161 // if there is a separator then the flag is not repeated but is only
1162 // given once i.e. -classpath a:b:c
1163 repeatFlag = false;
1166 // Support special system include flag if it is available and the
1167 // normal flag is repeated for each directory.
1168 std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
1169 sysFlagVar += lang;
1170 const char* sysIncludeFlag = 0;
1171 if(repeatFlag)
1173 sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar.c_str());
1176 bool flagUsed = false;
1177 std::set<cmStdString> emitted;
1178 #ifdef __APPLE__
1179 emitted.insert("/System/Library/Frameworks");
1180 #endif
1181 for(i = includes.begin(); i != includes.end(); ++i)
1183 #ifdef __APPLE__
1184 if(cmSystemTools::IsPathToFramework(i->c_str()))
1186 std::string frameworkDir = *i;
1187 frameworkDir += "/../";
1188 frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
1189 if(emitted.insert(frameworkDir).second)
1191 includeFlags
1192 << "-F" << this->Convert(frameworkDir.c_str(),
1193 cmLocalGenerator::START_OUTPUT,
1194 cmLocalGenerator::SHELL, true)
1195 << " ";
1197 continue;
1199 #endif
1200 std::string include = *i;
1201 if(!flagUsed || repeatFlag)
1203 if(sysIncludeFlag &&
1204 this->Makefile->IsSystemIncludeDirectory(i->c_str()))
1206 includeFlags << sysIncludeFlag;
1208 else
1210 includeFlags << includeFlag;
1212 flagUsed = true;
1214 std::string includePath = this->ConvertToOutputForExisting(i->c_str());
1215 if(quotePaths && includePath.size() && includePath[0] != '\"')
1217 includeFlags << "\"";
1219 includeFlags << includePath;
1220 if(quotePaths && includePath.size() && includePath[0] != '\"')
1222 includeFlags << "\"";
1224 includeFlags << sep;
1226 std::string flags = includeFlags.str();
1227 // remove trailing separators
1228 if((sep[0] != ' ') && flags.size()>0 && flags[flags.size()-1] == sep[0])
1230 flags[flags.size()-1] = ' ';
1232 std::string defineFlags = this->Makefile->GetDefineFlags();
1233 flags += defineFlags;
1234 this->LanguageToIncludeFlags[lang] = flags;
1236 // Use this temorary variable for the return value to work-around a
1237 // bogus GCC 2.95 warning.
1238 const char* ret = this->LanguageToIncludeFlags[lang].c_str();
1239 return ret;
1242 //----------------------------------------------------------------------------
1243 void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
1244 const char* lang)
1246 // Need to decide whether to automatically include the source and
1247 // binary directories at the beginning of the include path.
1248 bool includeSourceDir = false;
1249 bool includeBinaryDir = false;
1251 // When automatic include directories are requested for a build then
1252 // include the source and binary directories at the beginning of the
1253 // include path to approximate include file behavior for an
1254 // in-source build. This does not account for the case of a source
1255 // file in a subdirectory of the current source directory but we
1256 // cannot fix this because not all native build tools support
1257 // per-source-file include paths.
1258 if(this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR"))
1260 includeSourceDir = true;
1261 includeBinaryDir = true;
1264 // CMake versions below 2.0 would add the source tree to the -I path
1265 // automatically. Preserve compatibility.
1266 if(this->NeedBackwardsCompatibility(1,9))
1268 includeSourceDir = true;
1271 // Hack for VTK 4.0 - 4.4 which depend on the old behavior but do
1272 // not set the backwards compatibility level automatically.
1273 const char* vtkSourceDir =
1274 this->Makefile->GetDefinition("VTK_SOURCE_DIR");
1275 if(vtkSourceDir)
1277 const char* vtk_major =
1278 this->Makefile->GetDefinition("VTK_MAJOR_VERSION");
1279 const char* vtk_minor =
1280 this->Makefile->GetDefinition("VTK_MINOR_VERSION");
1281 vtk_major = vtk_major? vtk_major : "4";
1282 vtk_minor = vtk_minor? vtk_minor : "4";
1283 int vmajor = 0;
1284 int vminor = 0;
1285 if(sscanf(vtk_major, "%d", &vmajor) &&
1286 sscanf(vtk_minor, "%d", &vminor) && vmajor == 4 && vminor <= 4)
1288 includeSourceDir = true;
1292 // Do not repeat an include path.
1293 std::set<cmStdString> emitted;
1295 // Store the automatic include paths.
1296 if(includeBinaryDir)
1298 dirs.push_back(this->Makefile->GetStartOutputDirectory());
1299 emitted.insert(this->Makefile->GetStartOutputDirectory());
1301 if(includeSourceDir)
1303 if(emitted.find(this->Makefile->GetStartDirectory()) == emitted.end())
1305 dirs.push_back(this->Makefile->GetStartDirectory());
1306 emitted.insert(this->Makefile->GetStartDirectory());
1310 // Load implicit include directories for this language.
1311 std::string impDirVar = "CMAKE_";
1312 impDirVar += lang;
1313 impDirVar += "_IMPLICIT_INCLUDE_DIRECTORIES";
1314 if(const char* value = this->Makefile->GetDefinition(impDirVar.c_str()))
1316 std::vector<std::string> impDirVec;
1317 cmSystemTools::ExpandListArgument(value, impDirVec);
1318 for(std::vector<std::string>::const_iterator i = impDirVec.begin();
1319 i != impDirVec.end(); ++i)
1321 emitted.insert(*i);
1325 // Get the project-specified include directories.
1326 std::vector<std::string>& includes =
1327 this->Makefile->GetIncludeDirectories();
1329 // Support putting all the in-project include directories first if
1330 // it is requested by the project.
1331 if(this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"))
1333 const char* topSourceDir = this->Makefile->GetHomeDirectory();
1334 const char* topBinaryDir = this->Makefile->GetHomeOutputDirectory();
1335 for(std::vector<std::string>::iterator i = includes.begin();
1336 i != includes.end(); ++i)
1338 // Emit this directory only if it is a subdirectory of the
1339 // top-level source or binary tree.
1340 if(cmSystemTools::ComparePath(i->c_str(), topSourceDir) ||
1341 cmSystemTools::ComparePath(i->c_str(), topBinaryDir) ||
1342 cmSystemTools::IsSubDirectory(i->c_str(), topSourceDir) ||
1343 cmSystemTools::IsSubDirectory(i->c_str(), topBinaryDir))
1345 if(emitted.insert(*i).second)
1347 dirs.push_back(*i);
1353 // Construct the final ordered include directory list.
1354 for(std::vector<std::string>::iterator i = includes.begin();
1355 i != includes.end(); ++i)
1357 if(emitted.insert(*i).second)
1359 dirs.push_back(*i);
1364 void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
1365 std::string& flags,
1366 std::string& linkFlags,
1367 cmTarget& target)
1369 std::string buildType =
1370 this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
1371 buildType = cmSystemTools::UpperCase(buildType);
1372 const char* libraryLinkVariable =
1373 "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
1375 switch(target.GetType())
1377 case cmTarget::STATIC_LIBRARY:
1379 const char* targetLinkFlags =
1380 target.GetProperty("STATIC_LIBRARY_FLAGS");
1381 if(targetLinkFlags)
1383 linkFlags += targetLinkFlags;
1384 linkFlags += " ";
1387 break;
1388 case cmTarget::MODULE_LIBRARY:
1389 libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
1390 case cmTarget::SHARED_LIBRARY:
1392 linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
1393 linkFlags += " ";
1394 if(buildType.size())
1396 std::string build = libraryLinkVariable;
1397 build += "_";
1398 build += buildType;
1399 linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
1400 linkFlags += " ";
1402 if(this->Makefile->IsOn("WIN32") &&
1403 !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")))
1405 const std::vector<cmSourceFile*>& sources = target.GetSourceFiles();
1406 for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
1407 i != sources.end(); ++i)
1409 cmSourceFile* sf = *i;
1410 if(sf->GetExtension() == "def")
1412 linkFlags +=
1413 this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
1414 linkFlags += this->Convert(sf->GetFullPath().c_str(),
1415 START_OUTPUT, SHELL);
1416 linkFlags += " ";
1420 const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
1421 if(targetLinkFlags)
1423 linkFlags += targetLinkFlags;
1424 linkFlags += " ";
1425 std::string configLinkFlags = targetLinkFlags;
1426 configLinkFlags += buildType;
1427 targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
1428 if(targetLinkFlags)
1430 linkFlags += targetLinkFlags;
1431 linkFlags += " ";
1434 cmOStringStream linklibsStr;
1435 this->OutputLinkLibraries(linklibsStr, target, false);
1436 linkLibs = linklibsStr.str();
1438 break;
1439 case cmTarget::EXECUTABLE:
1441 linkFlags +=
1442 this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
1443 linkFlags += " ";
1444 if(buildType.size())
1446 std::string build = "CMAKE_EXE_LINKER_FLAGS_";
1447 build += buildType;
1448 linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
1449 linkFlags += " ";
1451 const char* linkLanguage = target.GetLinkerLanguage();
1452 if(!linkLanguage)
1454 cmSystemTools::Error
1455 ("CMake can not determine linker language for target:",
1456 target.GetName());
1457 return;
1459 std::string langVar = "CMAKE_";
1460 langVar += linkLanguage;
1461 std::string flagsVar = langVar + "_FLAGS";
1462 std::string sharedFlagsVar = "CMAKE_SHARED_LIBRARY_";
1463 sharedFlagsVar += linkLanguage;
1464 sharedFlagsVar += "_FLAGS";
1465 flags += this->Makefile->GetSafeDefinition(flagsVar.c_str());
1466 flags += " ";
1467 flags += this->Makefile->GetSafeDefinition(sharedFlagsVar.c_str());
1468 flags += " ";
1469 cmOStringStream linklibs;
1470 this->OutputLinkLibraries(linklibs, target, false);
1471 linkLibs = linklibs.str();
1472 if(cmSystemTools::IsOn
1473 (this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
1475 std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_")
1476 + linkLanguage + std::string("_FLAGS");
1477 linkFlags += this->Makefile->GetSafeDefinition(sFlagVar.c_str());
1478 linkFlags += " ";
1480 if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
1482 linkFlags +=
1483 this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
1484 linkFlags += " ";
1486 else
1488 linkFlags +=
1489 this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
1490 linkFlags += " ";
1492 const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
1493 if(targetLinkFlags)
1495 linkFlags += targetLinkFlags;
1496 linkFlags += " ";
1497 std::string configLinkFlags = targetLinkFlags;
1498 configLinkFlags += buildType;
1499 targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
1500 if(targetLinkFlags)
1502 linkFlags += targetLinkFlags;
1503 linkFlags += " ";
1507 break;
1508 default:
1509 break;
1513 std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib)
1515 #if defined(_WIN32) && !defined(__CYGWIN__)
1516 // Work-ardound command line parsing limitations in MSVC 6.0 and
1517 // Watcom.
1518 if(this->Makefile->IsOn("MSVC60") || this->Makefile->IsOn("WATCOM"))
1520 // Search for the last space.
1521 std::string::size_type pos = lib.rfind(' ');
1522 if(pos != lib.npos)
1524 // Find the slash after the last space, if any.
1525 pos = lib.find('/', pos);
1527 // Convert the portion of the path with a space to a short path.
1528 std::string sp;
1529 if(cmSystemTools::GetShortPath(lib.substr(0, pos).c_str(), sp))
1531 // Append the rest of the path with no space.
1532 sp += lib.substr(pos);
1534 // Convert to an output path.
1535 return this->Convert(sp.c_str(), NONE, SHELL);
1539 #endif
1541 // Normal behavior.
1542 return this->Convert(lib.c_str(), START_OUTPUT, SHELL);
1546 * Output the linking rules on a command line. For executables,
1547 * targetLibrary should be a NULL pointer. For libraries, it should point
1548 * to the name of the library. This will not link a library against itself.
1550 void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout,
1551 cmTarget& tgt,
1552 bool relink)
1554 const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
1555 cmComputeLinkInformation* pcli = tgt.GetLinkInformation(config);
1556 if(!pcli)
1558 return;
1560 cmComputeLinkInformation& cli = *pcli;
1562 // Collect library linking flags command line options.
1563 std::string linkLibs;
1565 const char* linkLanguage = cli.GetLinkLanguage();
1567 std::string libPathFlag =
1568 this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
1569 std::string libPathTerminator =
1570 this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
1572 // Flags to link an executable to shared libraries.
1573 std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
1574 linkFlagsVar += linkLanguage;
1575 linkFlagsVar += "_FLAGS";
1576 if( tgt.GetType() == cmTarget::EXECUTABLE )
1578 linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar.c_str());
1579 linkLibs += " ";
1582 // Append the framework search path flags.
1583 std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
1584 for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
1585 fdi != fwDirs.end(); ++fdi)
1587 linkLibs += "-F";
1588 linkLibs += this->Convert(fdi->c_str(), NONE, SHELL, false);
1589 linkLibs += " ";
1592 // Append the library search path flags.
1593 std::vector<std::string> const& libDirs = cli.GetDirectories();
1594 for(std::vector<std::string>::const_iterator libDir = libDirs.begin();
1595 libDir != libDirs.end(); ++libDir)
1597 std::string libpath = this->ConvertToOutputForExisting(libDir->c_str());
1598 linkLibs += libPathFlag;
1599 linkLibs += libpath;
1600 linkLibs += libPathTerminator;
1601 linkLibs += " ";
1604 // Append the link items.
1605 typedef cmComputeLinkInformation::ItemVector ItemVector;
1606 ItemVector const& items = cli.GetItems();
1607 for(ItemVector::const_iterator li = items.begin(); li != items.end(); ++li)
1609 if(li->IsPath)
1611 linkLibs += this->ConvertToLinkReference(li->Value);
1613 else
1615 linkLibs += li->Value;
1617 linkLibs += " ";
1620 // Write the library flags to the build rule.
1621 fout << linkLibs;
1623 // Get the RPATH entries.
1624 std::vector<std::string> runtimeDirs;
1625 cli.GetRPath(runtimeDirs, relink);
1627 // Check what kind of rpath flags to use.
1628 if(cli.GetRuntimeSep().empty())
1630 // Each rpath entry gets its own option ("-R a -R b -R c")
1631 std::string rpath;
1632 for(std::vector<std::string>::iterator ri = runtimeDirs.begin();
1633 ri != runtimeDirs.end(); ++ri)
1635 rpath += cli.GetRuntimeFlag();
1636 rpath += this->Convert(ri->c_str(), NONE, SHELL, false);
1637 rpath += " ";
1639 fout << rpath;
1641 else
1643 // All rpath entries are combined ("-Wl,-rpath,a:b:c").
1644 std::string rpath = cli.GetRPathString(relink);
1646 // Store the rpath option in the stream.
1647 if(!rpath.empty())
1649 fout << cli.GetRuntimeFlag();
1650 fout << this->EscapeForShell(rpath.c_str(), true);
1651 fout << " ";
1655 // Add the linker runtime search path if any.
1656 std::string rpath_link = cli.GetRPathLinkString();
1657 if(!cli.GetRPathLinkFlag().empty() && !rpath_link.empty())
1659 fout << cli.GetRPathLinkFlag();
1660 fout << this->EscapeForShell(rpath_link.c_str(), true);
1661 fout << " ";
1664 // Add standard libraries for this language.
1665 std::string standardLibsVar = "CMAKE_";
1666 standardLibsVar += cli.GetLinkLanguage();
1667 standardLibsVar += "_STANDARD_LIBRARIES";
1668 if(const char* stdLibs =
1669 this->Makefile->GetDefinition(standardLibsVar.c_str()))
1671 fout << stdLibs << " ";
1675 //----------------------------------------------------------------------------
1676 void cmLocalGenerator::AddLanguageFlags(std::string& flags,
1677 const char* lang,
1678 const char* config)
1680 // Add language-specific flags.
1681 std::string flagsVar = "CMAKE_";
1682 flagsVar += lang;
1683 flagsVar += "_FLAGS";
1685 if(this->EmitUniversalBinaryFlags)
1687 const char* osxArch =
1688 this->Makefile->GetDefinition("CMAKE_OSX_ARCHITECTURES");
1689 const char* sysroot =
1690 this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
1691 const char* sysrootDefault =
1692 this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT_DEFAULT");
1693 const char* deploymentTarget =
1694 this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
1696 bool flagsUsed = false;
1698 if(osxArch && sysroot && lang && (lang[0] =='C' || lang[0] == 'F'))
1700 std::vector<std::string> archs;
1701 cmSystemTools::ExpandListArgument(std::string(osxArch),
1702 archs);
1703 bool addArchFlag = true;
1704 if(archs.size() == 1)
1706 const char* archOrig =
1707 this->Makefile->GetSafeDefinition("CMAKE_OSX_ARCHITECTURES_DEFAULT");
1709 if(archs[0] == archOrig)
1711 addArchFlag = false;
1714 // if there is more than one arch add the -arch and
1715 // -isysroot flags, or if there is one arch flag, but
1716 // it is not the default -arch flag for the system, then
1717 // add it. Otherwize do not add -arch and -isysroot
1718 if(addArchFlag)
1720 for( std::vector<std::string>::iterator i = archs.begin();
1721 i != archs.end(); ++i)
1723 flags += " -arch ";
1724 flags += *i;
1727 flags += " -isysroot ";
1728 flags += sysroot;
1730 flagsUsed = true;
1734 if(!flagsUsed && sysroot && sysrootDefault &&
1735 strcmp(sysroot, sysrootDefault) != 0)
1737 flags += " -isysroot ";
1738 flags += sysroot;
1741 if (deploymentTarget && *deploymentTarget &&
1742 lang && (lang[0] =='C' || lang[0] == 'F'))
1744 flags += " -mmacosx-version-min=";
1745 flags += deploymentTarget;
1749 this->AddConfigVariableFlags(flags, flagsVar.c_str(), config);
1752 //----------------------------------------------------------------------------
1753 std::string cmLocalGenerator::GetRealDependency(const char* inName,
1754 const char* config)
1756 // Older CMake code may specify the dependency using the target
1757 // output file rather than the target name. Such code would have
1758 // been written before there was support for target properties that
1759 // modify the name so stripping down to just the file name should
1760 // produce the target name in this case.
1761 std::string name = cmSystemTools::GetFilenameName(inName);
1762 if(cmSystemTools::GetFilenameLastExtension(name) == ".exe")
1764 name = cmSystemTools::GetFilenameWithoutLastExtension(name);
1767 // Look for a CMake target with the given name.
1768 if(cmTarget* target = this->Makefile->FindTargetToUse(name.c_str()))
1770 // make sure it is not just a coincidence that the target name
1771 // found is part of the inName
1772 if(cmSystemTools::FileIsFullPath(inName))
1774 std::string tLocation = target->GetLocation(config);
1775 tLocation = cmSystemTools::GetFilenamePath(tLocation);
1776 std::string depLocation = cmSystemTools::GetFilenamePath(
1777 std::string(inName));
1778 depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
1779 tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
1780 if(depLocation != tLocation)
1782 // it is a full path to a depend that has the same name
1783 // as a target but is in a different location so do not use
1784 // the target as the depend
1785 return inName;
1788 switch (target->GetType())
1790 case cmTarget::EXECUTABLE:
1791 case cmTarget::STATIC_LIBRARY:
1792 case cmTarget::SHARED_LIBRARY:
1793 case cmTarget::MODULE_LIBRARY:
1794 case cmTarget::UNKNOWN_LIBRARY:
1796 // Get the location of the target's output file and depend on it.
1797 if(const char* location = target->GetLocation(config))
1799 return location;
1802 break;
1803 case cmTarget::UTILITY:
1804 case cmTarget::GLOBAL_TARGET:
1805 // Depending on a utility target may not work but just trust
1806 // the user to have given a valid name.
1807 return inName;
1808 case cmTarget::INSTALL_FILES:
1809 case cmTarget::INSTALL_PROGRAMS:
1810 case cmTarget::INSTALL_DIRECTORY:
1811 break;
1815 // The name was not that of a CMake target. It must name a file.
1816 if(cmSystemTools::FileIsFullPath(inName))
1818 // This is a full path. Return it as given.
1819 return inName;
1822 // Check for a source file in this directory that matches the
1823 // dependency.
1824 if(cmSourceFile* sf = this->Makefile->GetSource(inName))
1826 name = sf->GetFullPath();
1827 return name;
1830 // Treat the name as relative to the source directory in which it
1831 // was given.
1832 name = this->Makefile->GetCurrentDirectory();
1833 name += "/";
1834 name += inName;
1835 return name;
1838 //----------------------------------------------------------------------------
1839 std::string cmLocalGenerator::GetRealLocation(const char* inName,
1840 const char* config)
1842 std::string outName=inName;
1843 // Look for a CMake target with the given name, which is an executable
1844 // and which can be run
1845 cmTarget* target = this->Makefile->FindTargetToUse(inName);
1846 if ((target != 0)
1847 && (target->GetType() == cmTarget::EXECUTABLE)
1848 && ((this->Makefile->IsOn("CMAKE_CROSSCOMPILING") == false)
1849 || (target->IsImported() == true)))
1851 outName = target->GetLocation( config );
1853 return outName;
1856 //----------------------------------------------------------------------------
1857 void cmLocalGenerator::AddSharedFlags(std::string& flags,
1858 const char* lang,
1859 bool shared)
1861 std::string flagsVar;
1863 // Add flags for dealing with shared libraries for this language.
1864 if(shared)
1866 flagsVar = "CMAKE_SHARED_LIBRARY_";
1867 flagsVar += lang;
1868 flagsVar += "_FLAGS";
1869 this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
1872 // Add flags specific to shared builds.
1873 if(cmSystemTools::IsOn(this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
1875 flagsVar = "CMAKE_SHARED_BUILD_";
1876 flagsVar += lang;
1877 flagsVar += "_FLAGS";
1878 this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
1882 //----------------------------------------------------------------------------
1883 void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
1884 const char* var,
1885 const char* config)
1887 // Add the flags from the variable itself.
1888 std::string flagsVar = var;
1889 this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
1890 // Add the flags from the build-type specific variable.
1891 if(config && *config)
1893 flagsVar += "_";
1894 flagsVar += cmSystemTools::UpperCase(config);
1895 this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
1899 //----------------------------------------------------------------------------
1900 void cmLocalGenerator::AppendFlags(std::string& flags,
1901 const char* newFlags)
1903 if(newFlags && *newFlags)
1905 std::string newf = newFlags;
1906 if(flags.size())
1908 flags += " ";
1910 flags += newFlags;
1914 //----------------------------------------------------------------------------
1915 void cmLocalGenerator::AppendDefines(std::string& defines,
1916 const char* defines_list,
1917 const char* lang)
1919 // Short-circuit if there are no definitions.
1920 if(!defines_list)
1922 return;
1925 // Expand the list of definitions.
1926 std::vector<std::string> defines_vec;
1927 cmSystemTools::ExpandListArgument(defines_list, defines_vec);
1929 // Short-circuit if there are no definitions.
1930 if(defines_vec.empty())
1932 return;
1935 // Lookup the define flag for the current language.
1936 std::string dflag = "-D";
1937 if(lang)
1939 std::string defineFlagVar = "CMAKE_";
1940 defineFlagVar += lang;
1941 defineFlagVar += "_DEFINE_FLAG";
1942 const char* df = this->Makefile->GetDefinition(defineFlagVar.c_str());
1943 if(df && *df)
1945 dflag = df;
1949 // Add each definition to the command line with appropriate escapes.
1950 const char* dsep = defines.empty()? "" : " ";
1951 for(std::vector<std::string>::const_iterator di = defines_vec.begin();
1952 di != defines_vec.end(); ++di)
1954 // Skip unsupported definitions.
1955 if(!this->CheckDefinition(*di))
1957 continue;
1960 // Separate from previous definitions.
1961 defines += dsep;
1962 dsep = " ";
1964 // Append the definition with proper escaping.
1965 defines += dflag;
1966 if(this->WatcomWMake)
1968 // The Watcom compiler does its own command line parsing instead
1969 // of using the windows shell rules. Definitions are one of
1970 // -DNAME
1971 // -DNAME=<cpp-token>
1972 // -DNAME="c-string with spaces and other characters(?@#$)"
1974 // Watcom will properly parse each of these cases from the
1975 // command line without any escapes. However we still have to
1976 // get the '$' and '#' characters through WMake as '$$' and
1977 // '$#'.
1978 for(const char* c = di->c_str(); *c; ++c)
1980 if(*c == '$' || *c == '#')
1982 defines += '$';
1984 defines += *c;
1987 else
1989 // Make the definition appear properly on the command line. Use
1990 // -DNAME="value" instead of -D"NAME=value" to help VS6 parser.
1991 std::string::size_type eq = di->find("=");
1992 defines += di->substr(0, eq);
1993 if(eq != di->npos)
1995 defines += "=";
1996 defines += this->EscapeForShell(di->c_str() + eq + 1, true);
2002 //----------------------------------------------------------------------------
2003 std::string
2004 cmLocalGenerator::ConstructComment(const cmCustomCommand& cc,
2005 const char* default_comment)
2007 // Check for a comment provided with the command.
2008 if(cc.GetComment())
2010 return cc.GetComment();
2013 // Construct a reasonable default comment if possible.
2014 if(!cc.GetOutputs().empty())
2016 std::string comment;
2017 comment = "Generating ";
2018 const char* sep = "";
2019 for(std::vector<std::string>::const_iterator o = cc.GetOutputs().begin();
2020 o != cc.GetOutputs().end(); ++o)
2022 comment += sep;
2023 comment += this->Convert(o->c_str(), cmLocalGenerator::START_OUTPUT);
2024 sep = ", ";
2026 return comment;
2029 // Otherwise use the provided default.
2030 return default_comment;
2033 //----------------------------------------------------------------------------
2034 std::string
2035 cmLocalGenerator::ConvertToOptionallyRelativeOutputPath(const char* remote)
2037 return this->Convert(remote, START_OUTPUT, SHELL, true);
2040 //----------------------------------------------------------------------------
2041 const char* cmLocalGenerator::GetRelativeRootPath(RelativeRoot relroot)
2043 switch (relroot)
2045 case HOME: return this->Makefile->GetHomeDirectory();
2046 case START: return this->Makefile->GetStartDirectory();
2047 case HOME_OUTPUT: return this->Makefile->GetHomeOutputDirectory();
2048 case START_OUTPUT: return this->Makefile->GetStartOutputDirectory();
2049 default: break;
2051 return 0;
2054 //----------------------------------------------------------------------------
2055 std::string cmLocalGenerator::Convert(const char* source,
2056 RelativeRoot relative,
2057 OutputFormat output,
2058 bool optional)
2060 // Make sure the relative path conversion components are set.
2061 if(!this->PathConversionsSetup)
2063 this->SetupPathConversions();
2064 this->PathConversionsSetup = true;
2067 // Convert the path to a relative path.
2068 std::string result = source;
2070 if (!optional || this->UseRelativePaths)
2072 switch (relative)
2074 case HOME:
2075 //result = cmSystemTools::CollapseFullPath(result.c_str());
2076 result = this->ConvertToRelativePath(this->HomeDirectoryComponents,
2077 result.c_str());
2078 break;
2079 case START:
2080 //result = cmSystemTools::CollapseFullPath(result.c_str());
2081 result = this->ConvertToRelativePath(this->StartDirectoryComponents,
2082 result.c_str());
2083 break;
2084 case HOME_OUTPUT:
2085 //result = cmSystemTools::CollapseFullPath(result.c_str());
2086 result =
2087 this->ConvertToRelativePath(this->HomeOutputDirectoryComponents,
2088 result.c_str());
2089 break;
2090 case START_OUTPUT:
2091 //result = cmSystemTools::CollapseFullPath(result.c_str());
2092 result =
2093 this->ConvertToRelativePath(this->StartOutputDirectoryComponents,
2094 result.c_str());
2095 break;
2096 case FULL:
2097 result = cmSystemTools::CollapseFullPath(result.c_str());
2098 break;
2099 case NONE:
2100 break;
2103 return this->ConvertToOutputFormat(result.c_str(), output);
2106 //----------------------------------------------------------------------------
2107 std::string cmLocalGenerator::ConvertToOutputFormat(const char* source,
2108 OutputFormat output)
2110 std::string result = source;
2111 // Convert it to an output path.
2112 if (output == MAKEFILE)
2114 result = cmSystemTools::ConvertToOutputPath(result.c_str());
2116 else if( output == SHELL)
2118 // For the MSYS shell convert drive letters to posix paths, so
2119 // that c:/some/path becomes /c/some/path. This is needed to
2120 // avoid problems with the shell path translation.
2121 if(this->MSYSShell && !this->LinkScriptShell)
2123 if(result.size() > 2 && result[1] == ':')
2125 result[1] = result[0];
2126 result[0] = '/';
2129 if(this->WindowsShell)
2131 std::string::size_type pos = 0;
2132 while((pos = result.find('/', pos)) != std::string::npos)
2134 result[pos] = '\\';
2135 pos++;
2138 result = this->EscapeForShell(result.c_str(), true, false);
2140 return result;
2143 //----------------------------------------------------------------------------
2144 std::string cmLocalGenerator::Convert(RelativeRoot remote,
2145 const char* local,
2146 OutputFormat output,
2147 bool optional)
2149 const char* remotePath = this->GetRelativeRootPath(remote);
2151 // The relative root must have a path (i.e. not FULL or NONE)
2152 assert(remotePath != 0);
2154 if(local && (!optional || this->UseRelativePaths))
2156 std::vector<std::string> components;
2157 cmSystemTools::SplitPath(local, components);
2158 std::string result = this->ConvertToRelativePath(components, remotePath);
2159 return this->ConvertToOutputFormat(result.c_str(), output);
2161 else
2163 return this->ConvertToOutputFormat(remotePath, output);
2167 //----------------------------------------------------------------------------
2168 std::string cmLocalGenerator::FindRelativePathTopSource()
2170 // Relative path conversion within a single tree managed by CMake is
2171 // safe. We can use our parent relative path top if and only if
2172 // this is a subdirectory of that top.
2173 if(cmLocalGenerator* parent = this->GetParent())
2175 std::string parentTop = parent->FindRelativePathTopSource();
2176 if(cmSystemTools::IsSubDirectory(
2177 this->Makefile->GetStartDirectory(), parentTop.c_str()))
2179 return parentTop;
2183 // Otherwise this directory itself is the new top.
2184 return this->Makefile->GetStartDirectory();
2187 //----------------------------------------------------------------------------
2188 std::string cmLocalGenerator::FindRelativePathTopBinary()
2190 // Relative path conversion within a single tree managed by CMake is
2191 // safe. We can use our parent relative path top if and only if
2192 // this is a subdirectory of that top.
2193 if(cmLocalGenerator* parent = this->GetParent())
2195 std::string parentTop = parent->FindRelativePathTopBinary();
2196 if(cmSystemTools::IsSubDirectory(
2197 this->Makefile->GetStartOutputDirectory(), parentTop.c_str()))
2199 return parentTop;
2203 // Otherwise this directory itself is the new top.
2204 return this->Makefile->GetStartOutputDirectory();
2207 //----------------------------------------------------------------------------
2208 void cmLocalGenerator::ConfigureRelativePaths()
2210 // Relative path conversion inside the source tree is not used to
2211 // construct relative paths passed to build tools so it is safe to
2212 // even when the source is a network path.
2213 std::string source = this->FindRelativePathTopSource();
2214 this->RelativePathTopSource = source;
2216 // The current working directory on Windows cannot be a network
2217 // path. Therefore relative paths cannot work when the binary tree
2218 // is a network path.
2219 std::string binary = this->FindRelativePathTopBinary();
2220 if(binary.size() < 2 || binary.substr(0, 2) != "//")
2222 this->RelativePathTopBinary = binary;
2224 else
2226 this->RelativePathTopBinary = "";
2230 //----------------------------------------------------------------------------
2231 static bool cmLocalGeneratorNotAbove(const char* a, const char* b)
2233 return (cmSystemTools::ComparePath(a, b) ||
2234 cmSystemTools::IsSubDirectory(a, b));
2237 //----------------------------------------------------------------------------
2238 std::string
2239 cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
2240 const char* in_remote)
2242 // The path should never be quoted.
2243 assert(in_remote[0] != '\"');
2245 // The local path should never have a trailing slash.
2246 assert(local.size() > 0 && !(local[local.size()-1] == ""));
2248 // If the path is already relative then just return the path.
2249 if(!cmSystemTools::FileIsFullPath(in_remote))
2251 return in_remote;
2254 // Make sure relative path conversion is configured.
2255 if(!this->RelativePathsConfigured)
2257 this->ConfigureRelativePaths();
2258 this->RelativePathsConfigured = true;
2261 // Skip conversion if the path and local are not both in the source
2262 // or both in the binary tree.
2263 std::string local_path = cmSystemTools::JoinPath(local);
2264 if(!((cmLocalGeneratorNotAbove(local_path.c_str(),
2265 this->RelativePathTopBinary.c_str()) &&
2266 cmLocalGeneratorNotAbove(in_remote,
2267 this->RelativePathTopBinary.c_str())) ||
2268 (cmLocalGeneratorNotAbove(local_path.c_str(),
2269 this->RelativePathTopSource.c_str()) &&
2270 cmLocalGeneratorNotAbove(in_remote,
2271 this->RelativePathTopSource.c_str()))))
2273 return in_remote;
2276 // Identify the longest shared path component between the remote
2277 // path and the local path.
2278 std::vector<std::string> remote;
2279 cmSystemTools::SplitPath(in_remote, remote);
2280 unsigned int common=0;
2281 while(common < remote.size() &&
2282 common < local.size() &&
2283 cmSystemTools::ComparePath(remote[common].c_str(),
2284 local[common].c_str()))
2286 ++common;
2289 // If no part of the path is in common then return the full path.
2290 if(common == 0)
2292 return in_remote;
2295 // If the entire path is in common then just return a ".".
2296 if(common == remote.size() &&
2297 common == local.size())
2299 return ".";
2302 // If the entire path is in common except for a trailing slash then
2303 // just return a "./".
2304 if(common+1 == remote.size() &&
2305 remote[common].size() == 0 &&
2306 common == local.size())
2308 return "./";
2311 // Construct the relative path.
2312 std::string relative;
2314 // First add enough ../ to get up to the level of the shared portion
2315 // of the path. Leave off the trailing slash. Note that the last
2316 // component of local will never be empty because local should never
2317 // have a trailing slash.
2318 for(unsigned int i=common; i < local.size(); ++i)
2320 relative += "..";
2321 if(i < local.size()-1)
2323 relative += "/";
2327 // Now add the portion of the destination path that is not included
2328 // in the shared portion of the path. Add a slash the first time
2329 // only if there was already something in the path. If there was a
2330 // trailing slash in the input then the last iteration of the loop
2331 // will add a slash followed by an empty string which will preserve
2332 // the trailing slash in the output.
2333 for(unsigned int i=common; i < remote.size(); ++i)
2335 if(relative.size() > 0)
2337 relative += "/";
2339 relative += remote[i];
2342 // Finally return the path.
2343 return relative;
2346 //----------------------------------------------------------------------------
2347 void
2348 cmLocalGenerator
2349 ::GenerateTargetInstallRules(
2350 std::ostream& os, const char* config,
2351 std::vector<std::string> const& configurationTypes)
2353 // Convert the old-style install specification from each target to
2354 // an install generator and run it.
2355 cmTargets& tgts = this->Makefile->GetTargets();
2356 for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
2358 // Include the user-specified pre-install script for this target.
2359 if(const char* preinstall = l->second.GetProperty("PRE_INSTALL_SCRIPT"))
2361 cmInstallScriptGenerator g(preinstall, false, 0);
2362 g.Generate(os, config, configurationTypes);
2365 // Install this target if a destination is given.
2366 if(l->second.GetInstallPath() != "")
2368 // Compute the full install destination. Note that converting
2369 // to unix slashes also removes any trailing slash.
2370 // We also skip over the leading slash given by the user.
2371 std::string destination = l->second.GetInstallPath().substr(1);
2372 cmSystemTools::ConvertToUnixSlashes(destination);
2373 if(destination.empty())
2375 destination = ".";
2378 // Generate the proper install generator for this target type.
2379 switch(l->second.GetType())
2381 case cmTarget::EXECUTABLE:
2382 case cmTarget::STATIC_LIBRARY:
2383 case cmTarget::MODULE_LIBRARY:
2385 // Use a target install generator.
2386 cmInstallTargetGenerator g(l->second, destination.c_str(), false);
2387 g.Generate(os, config, configurationTypes);
2389 break;
2390 case cmTarget::SHARED_LIBRARY:
2392 #if defined(_WIN32) || defined(__CYGWIN__)
2393 // Special code to handle DLL. Install the import library
2394 // to the normal destination and the DLL to the runtime
2395 // destination.
2396 cmInstallTargetGenerator g1(l->second, destination.c_str(), true);
2397 g1.Generate(os, config, configurationTypes);
2398 // We also skip over the leading slash given by the user.
2399 destination = l->second.GetRuntimeInstallPath().substr(1);
2400 cmSystemTools::ConvertToUnixSlashes(destination);
2401 cmInstallTargetGenerator g2(l->second, destination.c_str(), false);
2402 g2.Generate(os, config, configurationTypes);
2403 #else
2404 // Use a target install generator.
2405 cmInstallTargetGenerator g(l->second, destination.c_str(), false);
2406 g.Generate(os, config, configurationTypes);
2407 #endif
2409 break;
2410 default:
2411 break;
2415 // Include the user-specified post-install script for this target.
2416 if(const char* postinstall = l->second.GetProperty("POST_INSTALL_SCRIPT"))
2418 cmInstallScriptGenerator g(postinstall, false, 0);
2419 g.Generate(os, config, configurationTypes);
2424 #if defined(CM_LG_ENCODE_OBJECT_NAMES)
2425 static std::string cmLocalGeneratorMD5(const char* input)
2427 char md5out[32];
2428 cmsysMD5* md5 = cmsysMD5_New();
2429 cmsysMD5_Initialize(md5);
2430 cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
2431 cmsysMD5_FinalizeHex(md5, md5out);
2432 cmsysMD5_Delete(md5);
2433 return std::string(md5out, 32);
2436 static bool
2437 cmLocalGeneratorShortenObjectName(std::string& objName,
2438 std::string::size_type max_len)
2440 // Replace the beginning of the path portion of the object name with
2441 // its own md5 sum.
2442 std::string::size_type pos = objName.find('/', objName.size()-max_len+32);
2443 if(pos != objName.npos)
2445 std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
2446 md5name += objName.substr(pos);
2447 objName = md5name;
2449 // The object name is now short enough.
2450 return true;
2452 else
2454 // The object name could not be shortened enough.
2455 return false;
2459 static
2460 bool cmLocalGeneratorCheckObjectName(std::string& objName,
2461 std::string::size_type dir_len,
2462 std::string::size_type max_total_len)
2464 // Enforce the maximum file name length if possible.
2465 std::string::size_type max_obj_len = max_total_len;
2466 if(dir_len < max_total_len)
2468 max_obj_len = max_total_len - dir_len;
2469 if(objName.size() > max_obj_len)
2471 // The current object file name is too long. Try to shorten it.
2472 return cmLocalGeneratorShortenObjectName(objName, max_obj_len);
2474 else
2476 // The object file name is short enough.
2477 return true;
2480 else
2482 // The build directory in which the object will be stored is
2483 // already too deep.
2484 return false;
2487 #endif
2489 //----------------------------------------------------------------------------
2490 std::string&
2491 cmLocalGenerator
2492 ::CreateSafeUniqueObjectFileName(const char* sin,
2493 std::string const& dir_max)
2495 // Look for an existing mapped name for this object file.
2496 std::map<cmStdString,cmStdString>::iterator it =
2497 this->UniqueObjectNamesMap.find(sin);
2499 // If no entry exists create one.
2500 if(it == this->UniqueObjectNamesMap.end())
2502 // Start with the original name.
2503 std::string ssin = sin;
2505 // Avoid full paths by removing leading slashes.
2506 std::string::size_type pos = 0;
2507 for(;pos < ssin.size() && ssin[pos] == '/'; ++pos)
2510 ssin = ssin.substr(pos);
2512 // Avoid full paths by removing colons.
2513 cmSystemTools::ReplaceString(ssin, ":", "_");
2515 // Avoid relative paths that go up the tree.
2516 cmSystemTools::ReplaceString(ssin, "../", "__/");
2518 // Avoid spaces.
2519 cmSystemTools::ReplaceString(ssin, " ", "_");
2521 // Mangle the name if necessary.
2522 if(this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
2524 bool done;
2525 int cc = 0;
2526 char rpstr[100];
2527 sprintf(rpstr, "_p_");
2528 cmSystemTools::ReplaceString(ssin, "+", rpstr);
2529 std::string sssin = sin;
2532 done = true;
2533 for ( it = this->UniqueObjectNamesMap.begin();
2534 it != this->UniqueObjectNamesMap.end();
2535 ++ it )
2537 if ( it->second == ssin )
2539 done = false;
2542 if ( done )
2544 break;
2546 sssin = ssin;
2547 cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
2548 sprintf(rpstr, "_p%d_", cc++);
2550 while ( !done );
2553 #if defined(CM_LG_ENCODE_OBJECT_NAMES)
2554 if(!cmLocalGeneratorCheckObjectName(ssin, dir_max.size(),
2555 this->ObjectPathMax))
2557 // Warn if this is the first time the path has been seen.
2558 if(this->ObjectMaxPathViolations.insert(dir_max).second)
2560 cmOStringStream m;
2561 m << "The object file directory\n"
2562 << " " << dir_max << "\n"
2563 << "has " << dir_max.size() << " characters. "
2564 << "The maximum full path to an object file is "
2565 << this->ObjectPathMax << " characters "
2566 << "(see CMAKE_OBJECT_PATH_MAX). "
2567 << "Object file\n"
2568 << " " << ssin << "\n"
2569 << "cannot be safely placed under this directory. "
2570 << "The build may not work correctly.";
2571 this->Makefile->IssueMessage(cmake::WARNING, m.str());
2574 #else
2575 (void)dir_max;
2576 #endif
2578 // Insert the newly mapped object file name.
2579 std::map<cmStdString, cmStdString>::value_type e(sin, ssin);
2580 it = this->UniqueObjectNamesMap.insert(e).first;
2583 // Return the map entry.
2584 return it->second;
2587 //----------------------------------------------------------------------------
2588 std::string
2589 cmLocalGenerator
2590 ::GetObjectFileNameWithoutTarget(const cmSourceFile& source,
2591 std::string const& dir_max,
2592 bool* hasSourceExtension)
2594 // Construct the object file name using the full path to the source
2595 // file which is its only unique identification.
2596 const char* fullPath = source.GetFullPath().c_str();
2598 // Try referencing the source relative to the source tree.
2599 std::string relFromSource = this->Convert(fullPath, START);
2600 assert(!relFromSource.empty());
2601 bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
2602 bool subSource = relSource && relFromSource[0] != '.';
2604 // Try referencing the source relative to the binary tree.
2605 std::string relFromBinary = this->Convert(fullPath, START_OUTPUT);
2606 assert(!relFromBinary.empty());
2607 bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
2608 bool subBinary = relBinary && relFromBinary[0] != '.';
2610 // Select a nice-looking reference to the source file to construct
2611 // the object file name.
2612 std::string objectName;
2613 if((relSource && !relBinary) || (subSource && !subBinary))
2615 objectName = relFromSource;
2617 else if((relBinary && !relSource) || (subBinary && !subSource))
2619 objectName = relFromBinary;
2621 else if(relFromBinary.length() < relFromSource.length())
2623 objectName = relFromBinary;
2625 else
2627 objectName = relFromSource;
2630 // if it is still a full path check for the try compile case
2631 // try compile never have in source sources, and should not
2632 // have conflicting source file names in the same target
2633 if(cmSystemTools::FileIsFullPath(objectName.c_str()))
2635 if(this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile())
2637 objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
2641 // Replace the original source file extension with the object file
2642 // extension.
2643 bool keptSourceExtension = true;
2644 if(!source.GetPropertyAsBool("KEEP_EXTENSION"))
2646 // Decide whether this language wants to replace the source
2647 // extension with the object extension. For CMake 2.4
2648 // compatibility do this by default.
2649 bool replaceExt = this->NeedBackwardsCompatibility(2, 4);
2650 if(!replaceExt)
2652 std::string repVar = "CMAKE_";
2653 repVar += source.GetLanguage();
2654 repVar += "_OUTPUT_EXTENSION_REPLACE";
2655 replaceExt = this->Makefile->IsOn(repVar.c_str());
2658 // Remove the source extension if it is to be replaced.
2659 if(replaceExt)
2661 keptSourceExtension = false;
2662 std::string::size_type dot_pos = objectName.rfind(".");
2663 if(dot_pos != std::string::npos)
2665 objectName = objectName.substr(0, dot_pos);
2669 // Store the new extension.
2670 objectName +=
2671 this->GlobalGenerator->GetLanguageOutputExtension(source);
2673 if(hasSourceExtension)
2675 *hasSourceExtension = keptSourceExtension;
2678 // Convert to a safe name.
2679 return this->CreateSafeUniqueObjectFileName(objectName.c_str(), dir_max);
2682 //----------------------------------------------------------------------------
2683 const char*
2684 cmLocalGenerator
2685 ::GetSourceFileLanguage(const cmSourceFile& source)
2687 return source.GetLanguage();
2690 //----------------------------------------------------------------------------
2691 std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str)
2693 std::string result;
2694 bool forceOn = cmSystemTools::GetForceUnixPaths();
2695 if(forceOn && this->WindowsShell)
2697 cmSystemTools::SetForceUnixPaths(false);
2699 result = cmSystemTools::EscapeSpaces(str);
2700 if(forceOn && this->WindowsShell)
2702 cmSystemTools::SetForceUnixPaths(true);
2704 return result;
2707 //----------------------------------------------------------------------------
2708 static bool cmLocalGeneratorIsShellOperator(const char* str)
2710 if(strcmp(str, "<") == 0 ||
2711 strcmp(str, ">") == 0 ||
2712 strcmp(str, "<<") == 0 ||
2713 strcmp(str, ">>") == 0 ||
2714 strcmp(str, "|") == 0 ||
2715 strcmp(str, "||") == 0 ||
2716 strcmp(str, "&&") == 0 ||
2717 strcmp(str, "&>") == 0 ||
2718 strcmp(str, "1>") == 0 ||
2719 strcmp(str, "2>") == 0 ||
2720 strcmp(str, "2>&1") == 0 ||
2721 strcmp(str, "1>&2") == 0)
2723 return true;
2725 return false;
2728 //----------------------------------------------------------------------------
2729 std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars,
2730 bool forEcho)
2732 // Do not escape shell operators.
2733 if(cmLocalGeneratorIsShellOperator(str))
2735 return str;
2738 // Compute the flags for the target shell environment.
2739 int flags = 0;
2740 if(this->WindowsVSIDE)
2742 flags |= cmsysSystem_Shell_Flag_VSIDE;
2744 else if(!this->LinkScriptShell)
2746 flags |= cmsysSystem_Shell_Flag_Make;
2748 if(makeVars)
2750 flags |= cmsysSystem_Shell_Flag_AllowMakeVariables;
2752 if(forEcho)
2754 flags |= cmsysSystem_Shell_Flag_EchoWindows;
2756 if(this->WatcomWMake)
2758 flags |= cmsysSystem_Shell_Flag_WatcomWMake;
2760 if(this->MinGWMake)
2762 flags |= cmsysSystem_Shell_Flag_MinGWMake;
2764 if(this->NMake)
2766 flags |= cmsysSystem_Shell_Flag_NMake;
2769 // Compute the buffer size needed.
2770 int size = (this->WindowsShell ?
2771 cmsysSystem_Shell_GetArgumentSizeForWindows(str, flags) :
2772 cmsysSystem_Shell_GetArgumentSizeForUnix(str, flags));
2774 // Compute the shell argument itself.
2775 std::vector<char> arg(size);
2776 if(this->WindowsShell)
2778 cmsysSystem_Shell_GetArgumentForWindows(str, &arg[0], flags);
2780 else
2782 cmsysSystem_Shell_GetArgumentForUnix(str, &arg[0], flags);
2784 return std::string(&arg[0]);
2787 //----------------------------------------------------------------------------
2788 std::string cmLocalGenerator::EscapeForCMake(const char* str)
2790 // Always double-quote the argument to take care of most escapes.
2791 std::string result = "\"";
2792 for(const char* c = str; *c; ++c)
2794 if(*c == '"')
2796 // Escape the double quote to avoid ending the argument.
2797 result += "\\\"";
2799 else if(*c == '$')
2801 // Escape the dollar to avoid expanding variables.
2802 result += "\\$";
2804 else if(*c == '\\')
2806 // Escape the backslash to avoid other escapes.
2807 result += "\\\\";
2809 else
2811 // Other characters will be parsed correctly.
2812 result += *c;
2815 result += "\"";
2816 return result;
2819 //----------------------------------------------------------------------------
2820 std::string
2821 cmLocalGenerator::GetTargetDirectory(cmTarget const&) const
2823 cmSystemTools::Error("GetTargetDirectory"
2824 " called on cmLocalGenerator");
2825 return "";
2829 //----------------------------------------------------------------------------
2830 void
2831 cmLocalGenerator::GetTargetObjectFileDirectories(cmTarget* ,
2832 std::vector<std::string>&
2835 cmSystemTools::Error("GetTargetObjectFileDirectories"
2836 " called on cmLocalGenerator");
2839 //----------------------------------------------------------------------------
2840 unsigned int cmLocalGenerator::GetBackwardsCompatibility()
2842 // The computed version may change until the project is fully
2843 // configured.
2844 if(!this->BackwardsCompatibilityFinal)
2846 unsigned int major = 0;
2847 unsigned int minor = 0;
2848 unsigned int patch = 0;
2849 if(const char* value
2850 = this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"))
2852 switch(sscanf(value, "%u.%u.%u", &major, &minor, &patch))
2854 case 2: patch = 0; break;
2855 case 1: minor = 0; patch = 0; break;
2856 default: break;
2859 this->BackwardsCompatibility = CMake_VERSION_ENCODE(major, minor, patch);
2860 this->BackwardsCompatibilityFinal = this->Configured;
2863 return this->BackwardsCompatibility;
2866 //----------------------------------------------------------------------------
2867 bool cmLocalGenerator::NeedBackwardsCompatibility(unsigned int major,
2868 unsigned int minor,
2869 unsigned int patch)
2871 // Check the policy to decide whether to pay attention to this
2872 // variable.
2873 switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0001))
2875 case cmPolicies::WARN:
2876 // WARN is just OLD without warning because user code does not
2877 // always affect whether this check is done.
2878 case cmPolicies::OLD:
2879 // Old behavior is to check the variable.
2880 break;
2881 case cmPolicies::NEW:
2882 // New behavior is to ignore the variable.
2883 return false;
2884 case cmPolicies::REQUIRED_IF_USED:
2885 case cmPolicies::REQUIRED_ALWAYS:
2886 // This will never be the case because the only way to require
2887 // the setting is to require the user to specify version policy
2888 // 2.6 or higher. Once we add that requirement then this whole
2889 // method can be removed anyway.
2890 return false;
2893 // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set
2894 // equal to or lower than the given version.
2895 unsigned int actual_compat = this->GetBackwardsCompatibility();
2896 return (actual_compat &&
2897 actual_compat <= CMake_VERSION_ENCODE(major, minor, patch));
2900 //----------------------------------------------------------------------------
2901 bool cmLocalGenerator::CheckDefinition(std::string const& define) const
2903 // Many compilers do not support -DNAME(arg)=sdf so we disable it.
2904 bool function_style = false;
2905 for(const char* c = define.c_str(); *c && *c != '='; ++c)
2907 if(*c == '(')
2909 function_style = true;
2910 break;
2913 if(function_style)
2915 cmOStringStream e;
2916 e << "WARNING: Function-style preprocessor definitions may not be "
2917 << "passed on the compiler command line because many compilers "
2918 << "do not support it.\n"
2919 << "CMake is dropping a preprocessor definition: " << define << "\n"
2920 << "Consider defining the macro in a (configured) header file.\n";
2921 cmSystemTools::Message(e.str().c_str());
2922 return false;
2925 // Many compilers do not support # in the value so we disable it.
2926 if(define.find_first_of("#") != define.npos)
2928 cmOStringStream e;
2929 e << "WARNING: Peprocessor definitions containing '#' may not be "
2930 << "passed on the compiler command line because many compilers "
2931 << "do not support it.\n"
2932 << "CMake is dropping a preprocessor definition: " << define << "\n"
2933 << "Consider defining the macro in a (configured) header file.\n";
2934 cmSystemTools::Message(e.str().c_str());
2935 return false;
2938 // Assume it is supported.
2939 return true;
2942 //----------------------------------------------------------------------------
2943 static void cmLGInfoProp(cmMakefile* mf, cmTarget* target, const char* prop)
2945 if(const char* val = target->GetProperty(prop))
2947 mf->AddDefinition(prop, val);
2951 //----------------------------------------------------------------------------
2952 void cmLocalGenerator::GenerateAppleInfoPList(cmTarget* target,
2953 const char* targetName,
2954 const char* fname)
2956 // Find the Info.plist template.
2957 const char* in = target->GetProperty("MACOSX_BUNDLE_INFO_PLIST");
2958 std::string inFile = (in && *in)? in : "MacOSXBundleInfo.plist.in";
2959 if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
2961 std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
2962 if(!inMod.empty())
2964 inFile = inMod;
2967 if(!cmSystemTools::FileExists(inFile.c_str(), true))
2969 cmOStringStream e;
2970 e << "Target " << target->GetName() << " Info.plist template \""
2971 << inFile << "\" could not be found.";
2972 cmSystemTools::Error(e.str().c_str());
2973 return;
2976 // Convert target properties to variables in an isolated makefile
2977 // scope to configure the file. If properties are set they will
2978 // override user make variables. If not the configuration will fall
2979 // back to the directory-level values set by the user.
2980 cmMakefile* mf = this->Makefile;
2981 mf->PushScope();
2982 mf->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName);
2983 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_INFO_STRING");
2984 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_ICON_FILE");
2985 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_GUI_IDENTIFIER");
2986 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_LONG_VERSION_STRING");
2987 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_NAME");
2988 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
2989 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION");
2990 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT");
2991 mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
2992 mf->PopScope();
2995 //----------------------------------------------------------------------------
2996 void cmLocalGenerator::GenerateFrameworkInfoPList(cmTarget* target,
2997 const char* targetName,
2998 const char* fname)
3000 // Find the Info.plist template.
3001 const char* in = target->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST");
3002 std::string inFile = (in && *in)? in : "MacOSXFrameworkInfo.plist.in";
3003 if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
3005 std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
3006 if(!inMod.empty())
3008 inFile = inMod;
3011 if(!cmSystemTools::FileExists(inFile.c_str(), true))
3013 cmOStringStream e;
3014 e << "Target " << target->GetName() << " Info.plist template \""
3015 << inFile << "\" could not be found.";
3016 cmSystemTools::Error(e.str().c_str());
3017 return;
3020 // Convert target properties to variables in an isolated makefile
3021 // scope to configure the file. If properties are set they will
3022 // override user make variables. If not the configuration will fall
3023 // back to the directory-level values set by the user.
3024 cmMakefile* mf = this->Makefile;
3025 mf->PushScope();
3026 mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName);
3027 cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_ICON_FILE");
3028 cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER");
3029 cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
3030 cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
3031 mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
3032 mf->PopScope();