1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmLocalGenerator.h"
14 #include "cmComputeLinkInformation.h"
15 #include "cmGeneratedFileStream.h"
16 #include "cmGlobalGenerator.h"
17 #include "cmInstallGenerator.h"
18 #include "cmInstallFilesGenerator.h"
19 #include "cmInstallScriptGenerator.h"
20 #include "cmInstallTargetGenerator.h"
21 #include "cmMakefile.h"
22 #include "cmSourceFile.h"
24 #include "cmTestGenerator.h"
25 #include "cmVersion.h"
28 #if defined(CMAKE_BUILD_WITH_CMAKE)
29 # define CM_LG_ENCODE_OBJECT_NAMES
30 # include <cmsys/MD5.h>
33 #include <cmsys/System.h>
35 #include <ctype.h> // for isalpha
39 #if defined(__HAIKU__)
40 #include <StorageKit.h>
43 cmLocalGenerator::cmLocalGenerator()
45 this->Makefile = 0; // moved to after set on global
47 this->WindowsShell = false;
48 this->WindowsVSIDE = false;
49 this->WatcomWMake = false;
50 this->MinGWMake = false;
52 this->MSYSShell = false;
53 this->LinkScriptShell = false;
54 this->IgnoreLibPrefix = false;
55 this->UseRelativePaths = false;
56 this->Configured = false;
57 this->EmitUniversalBinaryFlags = true;
58 this->RelativePathsConfigured = false;
59 this->PathConversionsSetup = false;
60 this->BackwardsCompatibility = 0;
61 this->BackwardsCompatibilityFinal = false;
64 cmLocalGenerator::~cmLocalGenerator()
66 delete this->Makefile;
69 //----------------------------------------------------------------------------
70 class cmLocalGeneratorCurrent
72 cmGlobalGenerator* GG;
75 cmLocalGeneratorCurrent(cmLocalGenerator* lg)
77 this->GG = lg->GetGlobalGenerator();
78 this->LG = this->GG->GetCurrentLocalGenerator();
79 this->GG->SetCurrentLocalGenerator(lg);
81 ~cmLocalGeneratorCurrent()
83 this->GG->SetCurrentLocalGenerator(this->LG);
87 //----------------------------------------------------------------------------
88 void cmLocalGenerator::Configure()
90 // Manage the global generator's current local generator.
91 cmLocalGeneratorCurrent clg(this);
92 static_cast<void>(clg);
94 // make sure the CMakeFiles dir is there
95 std::string filesDir = this->Makefile->GetStartOutputDirectory();
96 filesDir += cmake::GetCMakeFilesDirectory();
97 cmSystemTools::MakeDirectory(filesDir.c_str());
99 // find & read the list file
100 this->ReadInputFile();
102 // at the end of the ReadListFile handle any old style subdirs
103 // first get all the subdirectories
104 std::vector<cmLocalGenerator *> subdirs = this->GetChildren();
106 // for each subdir recurse
107 std::vector<cmLocalGenerator *>::iterator sdi = subdirs.begin();
108 for (; sdi != subdirs.end(); ++sdi)
110 if (!(*sdi)->Configured)
112 this->Makefile->ConfigureSubDirectory(*sdi);
116 // Check whether relative paths should be used for optionally
118 this->UseRelativePaths = this->Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS");
120 this->ComputeObjectMaxPath();
122 this->Configured = true;
125 //----------------------------------------------------------------------------
126 void cmLocalGenerator::ComputeObjectMaxPath()
128 // Choose a maximum object file name length.
129 #if defined(_WIN32) || defined(__CYGWIN__)
130 this->ObjectPathMax = 250;
132 this->ObjectPathMax = 1000;
134 const char* plen = this->Makefile->GetDefinition("CMAKE_OBJECT_PATH_MAX");
138 if(sscanf(plen, "%u", &pmax) == 1)
142 this->ObjectPathMax = pmax;
147 w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax
148 << ", which is less than the minimum of 128. "
149 << "The value will be ignored.";
150 this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
156 w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen
157 << "\", which fails to parse as a positive integer. "
158 << "The value will be ignored.";
159 this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
162 this->ObjectMaxPathViolations.clear();
165 //----------------------------------------------------------------------------
166 void cmLocalGenerator::ReadInputFile()
168 // Look for the CMakeLists.txt file.
169 std::string currentStart = this->Makefile->GetStartDirectory();
170 currentStart += "/CMakeLists.txt";
171 if(cmSystemTools::FileExists(currentStart.c_str(), true))
173 this->Makefile->ReadListFile(currentStart.c_str());
182 // The file is missing. Check policy CMP0014.
183 cmMakefile* mf = this->Parent->GetMakefile();
185 e << "The source directory\n"
186 << " " << this->Makefile->GetStartDirectory() << "\n"
187 << "does not contain a CMakeLists.txt file.";
188 switch (mf->GetPolicyStatus(cmPolicies::CMP0014))
190 case cmPolicies::WARN:
191 // Print the warning.
193 << "CMake does not support this case but it used "
194 << "to work accidentally and is being allowed for "
197 << mf->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0014);
198 mf->IssueMessage(cmake::AUTHOR_WARNING, e.str());
199 case cmPolicies::OLD:
200 // OLD behavior does not warn.
202 case cmPolicies::REQUIRED_IF_USED:
203 case cmPolicies::REQUIRED_ALWAYS:
205 << mf->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP0014);
206 case cmPolicies::NEW:
207 // NEW behavior prints the error.
208 mf->IssueMessage(cmake::FATAL_ERROR, e.str());
213 void cmLocalGenerator::SetupPathConversions()
215 // Setup the current output directory components for use by
219 cmSystemTools::CollapseFullPath(this->Makefile->GetHomeDirectory());
220 cmSystemTools::SplitPath(outdir.c_str(), this->HomeDirectoryComponents);
222 cmSystemTools::CollapseFullPath(this->Makefile->GetStartDirectory());
223 cmSystemTools::SplitPath(outdir.c_str(), this->StartDirectoryComponents);
225 outdir = cmSystemTools::CollapseFullPath
226 (this->Makefile->GetHomeOutputDirectory());
227 cmSystemTools::SplitPath(outdir.c_str(),
228 this->HomeOutputDirectoryComponents);
230 outdir = cmSystemTools::CollapseFullPath
231 (this->Makefile->GetStartOutputDirectory());
232 cmSystemTools::SplitPath(outdir.c_str(),
233 this->StartOutputDirectoryComponents);
237 void cmLocalGenerator::SetGlobalGenerator(cmGlobalGenerator *gg)
239 this->GlobalGenerator = gg;
240 this->Makefile = new cmMakefile;
241 this->Makefile->SetLocalGenerator(this);
243 // setup the home directories
244 this->Makefile->GetProperties().SetCMakeInstance(gg->GetCMakeInstance());
245 this->Makefile->SetHomeDirectory(
246 gg->GetCMakeInstance()->GetHomeDirectory());
247 this->Makefile->SetHomeOutputDirectory(
248 gg->GetCMakeInstance()->GetHomeOutputDirectory());
251 void cmLocalGenerator::ConfigureFinalPass()
253 this->Makefile->ConfigureFinalPass();
256 void cmLocalGenerator::TraceDependencies()
258 // Generate the rule files for each target.
259 cmTargets& targets = this->Makefile->GetTargets();
260 for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
262 t->second.TraceDependencies();
266 void cmLocalGenerator::GenerateTestFiles()
268 if ( !this->Makefile->IsOn("CMAKE_TESTING_ENABLED") )
273 // Compute the set of configurations.
274 std::vector<std::string> configurationTypes;
276 this->Makefile->GetConfigurations(configurationTypes, false);
278 std::string file = this->Makefile->GetStartOutputDirectory();
280 file += "CTestTestfile.cmake";
282 cmGeneratedFileStream fout(file.c_str());
283 fout.SetCopyIfDifferent(true);
285 fout << "# CMake generated Testfile for " << std::endl
286 << "# Source directory: "
287 << this->Makefile->GetStartDirectory() << std::endl
288 << "# Build directory: "
289 << this->Makefile->GetStartOutputDirectory() << std::endl
291 << "# This file includes the relevant testing commands "
292 << "required for " << std::endl
293 << "# testing this directory and lists subdirectories to "
294 << "be tested as well." << std::endl;
296 const char* testIncludeFile =
297 this->Makefile->GetProperty("TEST_INCLUDE_FILE");
298 if ( testIncludeFile )
300 fout << "INCLUDE(\"" << testIncludeFile << "\")" << std::endl;
303 // Ask each test generator to write its code.
304 std::vector<cmTestGenerator*> const&
305 testers = this->Makefile->GetTestGenerators();
306 for(std::vector<cmTestGenerator*>::const_iterator gi = testers.begin();
307 gi != testers.end(); ++gi)
309 (*gi)->Generate(fout, config, configurationTypes);
311 if ( this->Children.size())
314 for(i = 0; i < this->Children.size(); ++i)
318 this->Children[i]->GetMakefile()->GetStartOutputDirectory();
319 fout << this->Convert(outP.c_str(),START_OUTPUT);
320 fout << ")" << std::endl;
325 //----------------------------------------------------------------------------
326 void cmLocalGenerator::GenerateInstallRules()
328 // Compute the install prefix.
329 const char* prefix = this->Makefile->GetDefinition("CMAKE_INSTALL_PREFIX");
330 #if defined(_WIN32) && !defined(__CYGWIN__)
331 std::string prefix_win32;
334 if(!cmSystemTools::GetEnv("SystemDrive", prefix_win32))
338 const char* project_name = this->Makefile->GetDefinition("PROJECT_NAME");
339 if(project_name && project_name[0])
341 prefix_win32 += "/Program Files/";
342 prefix_win32 += project_name;
346 prefix_win32 += "/InstalledCMakeProject";
348 prefix = prefix_win32.c_str();
350 #elif defined(__HAIKU__)
354 if (find_directory(B_COMMON_DIRECTORY, &dir) == B_OK)
360 prefix = "/boot/common";
366 prefix = "/usr/local";
370 // Compute the set of configurations.
371 std::vector<std::string> configurationTypes;
373 this->Makefile->GetConfigurations(configurationTypes, false);
375 // Choose a default install configuration.
376 const char* default_config = config;
377 const char* default_order[] = {"RELEASE", "MINSIZEREL",
378 "RELWITHDEBINFO", "DEBUG", 0};
379 for(const char** c = default_order; *c && !default_config; ++c)
381 for(std::vector<std::string>::iterator i = configurationTypes.begin();
382 i != configurationTypes.end(); ++i)
384 if(cmSystemTools::UpperCase(*i) == *c)
386 default_config = i->c_str();
390 if(!default_config && !configurationTypes.empty())
392 default_config = configurationTypes[0].c_str();
396 default_config = "Release";
399 // Create the install script file.
400 std::string file = this->Makefile->GetStartOutputDirectory();
401 std::string homedir = this->Makefile->GetHomeOutputDirectory();
402 std::string currdir = this->Makefile->GetCurrentOutputDirectory();
403 cmSystemTools::ConvertToUnixSlashes(file);
404 cmSystemTools::ConvertToUnixSlashes(homedir);
405 cmSystemTools::ConvertToUnixSlashes(currdir);
406 int toplevel_install = 0;
407 if ( currdir == homedir )
409 toplevel_install = 1;
411 file += "/cmake_install.cmake";
412 cmGeneratedFileStream fout(file.c_str());
413 fout.SetCopyIfDifferent(true);
416 fout << "# Install script for directory: "
417 << this->Makefile->GetCurrentDirectory() << std::endl << std::endl;
418 fout << "# Set the install prefix" << std::endl
419 << "IF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
420 << " SET(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
421 << "ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
422 << "STRING(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
423 << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
426 // Write support code for generating per-configuration install rules.
428 "# Set the install configuration name.\n"
429 "IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
431 " STRING(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
432 " CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
433 " ELSE(BUILD_TYPE)\n"
434 " SET(CMAKE_INSTALL_CONFIG_NAME \"" << default_config << "\")\n"
435 " ENDIF(BUILD_TYPE)\n"
436 " MESSAGE(STATUS \"Install configuration: "
437 "\\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
438 "ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
441 // Write support code for dealing with component-specific installs.
443 "# Set the component getting installed.\n"
444 "IF(NOT CMAKE_INSTALL_COMPONENT)\n"
446 " MESSAGE(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
447 " SET(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
449 " SET(CMAKE_INSTALL_COMPONENT)\n"
450 " ENDIF(COMPONENT)\n"
451 "ENDIF(NOT CMAKE_INSTALL_COMPONENT)\n"
454 // Copy user-specified install options to the install code.
455 if(const char* so_no_exe =
456 this->Makefile->GetDefinition("CMAKE_INSTALL_SO_NO_EXE"))
459 "# Install shared libraries without execute permission?\n"
460 "IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
461 " SET(CMAKE_INSTALL_SO_NO_EXE \"" << so_no_exe << "\")\n"
462 "ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
466 // Ask each install generator to write its code.
467 std::vector<cmInstallGenerator*> const& installers =
468 this->Makefile->GetInstallGenerators();
469 for(std::vector<cmInstallGenerator*>::const_iterator
470 gi = installers.begin();
471 gi != installers.end(); ++gi)
473 (*gi)->Generate(fout, config, configurationTypes);
476 // Write rules from old-style specification stored in targets.
477 this->GenerateTargetInstallRules(fout, config, configurationTypes);
479 // Include install scripts from subdirectories.
480 if(!this->Children.empty())
482 fout << "IF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
483 fout << " # Include the install script for each subdirectory.\n";
484 for(std::vector<cmLocalGenerator*>::const_iterator
485 ci = this->Children.begin(); ci != this->Children.end(); ++ci)
487 if(!(*ci)->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
489 std::string odir = (*ci)->GetMakefile()->GetStartOutputDirectory();
490 cmSystemTools::ConvertToUnixSlashes(odir);
491 fout << " INCLUDE(\"" << odir.c_str()
492 << "/cmake_install.cmake\")" << std::endl;
496 fout << "ENDIF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n\n";
499 // Record the install manifest.
500 if ( toplevel_install )
503 "IF(CMAKE_INSTALL_COMPONENT)\n"
504 " SET(CMAKE_INSTALL_MANIFEST \"install_manifest_"
505 "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
506 "ELSE(CMAKE_INSTALL_COMPONENT)\n"
507 " SET(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
508 "ENDIF(CMAKE_INSTALL_COMPONENT)\n\n";
511 << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
512 << "\"\")" << std::endl;
514 << "FOREACH(file ${CMAKE_INSTALL_MANIFEST_FILES})" << std::endl
516 << homedir.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
517 << "\"${file}\\n\")" << std::endl
518 << "ENDFOREACH(file)" << std::endl;
522 //----------------------------------------------------------------------------
523 void cmLocalGenerator::GenerateTargetManifest()
525 // Collect the set of configuration types.
526 std::vector<std::string> configNames;
527 this->Makefile->GetConfigurations(configNames);
529 // Add our targets to the manifest for each configuration.
530 cmTargets& targets = this->Makefile->GetTargets();
531 for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
533 cmTarget& target = t->second;
534 if(configNames.empty())
536 target.GenerateTargetManifest(0);
540 for(std::vector<std::string>::iterator ci = configNames.begin();
541 ci != configNames.end(); ++ci)
543 const char* config = ci->c_str();
544 target.GenerateTargetManifest(config);
550 void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
552 cmSourceFile& source,
553 cmGeneratorTarget& target)
555 std::string objectDir = cmSystemTools::GetFilenamePath(std::string(ofname));
556 objectDir = this->Convert(objectDir.c_str(),START_OUTPUT,SHELL);
557 std::string objectFile = this->Convert(ofname,START_OUTPUT,SHELL);
558 std::string sourceFile =
559 this->Convert(source.GetFullPath().c_str(),START_OUTPUT,SHELL,true);
560 std::string varString = "CMAKE_";
562 varString += "_COMPILE_OBJECT";
563 std::vector<std::string> rules;
564 rules.push_back(this->Makefile->GetRequiredDefinition(varString.c_str()));
565 varString = "CMAKE_";
567 varString += "_FLAGS";
569 flags += this->Makefile->GetSafeDefinition(varString.c_str());
572 std::vector<std::string> includes;
573 this->GetIncludeDirectories(includes, &target, lang);
574 flags += this->GetIncludeFlags(includes, &target, lang);
576 flags += this->Makefile->GetDefineFlags();
578 // Construct the command lines.
579 cmCustomCommandLines commandLines;
580 std::vector<std::string> commands;
581 cmSystemTools::ExpandList(rules, commands);
582 cmLocalGenerator::RuleVariables vars;
583 vars.Language = lang;
584 vars.Source = sourceFile.c_str();
585 vars.Object = objectFile.c_str();
586 vars.ObjectDir = objectDir.c_str();
587 vars.Flags = flags.c_str();
588 for(std::vector<std::string>::iterator i = commands.begin();
589 i != commands.end(); ++i)
591 // Expand the full command line string.
592 this->ExpandRuleVariables(*i, vars);
594 // Parse the string to get the custom command line.
595 cmCustomCommandLine commandLine;
596 std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
597 for(std::vector<cmStdString>::iterator a = cmd.begin();
600 commandLine.push_back(*a);
603 // Store this command line.
604 commandLines.push_back(commandLine);
607 // Check for extra object-file dependencies.
608 std::vector<std::string> depends;
609 const char* additionalDeps = source.GetProperty("OBJECT_DEPENDS");
612 cmSystemTools::ExpandListArgument(additionalDeps, depends);
615 // Generate a meaningful comment for the command.
616 std::string comment = "Building ";
618 comment += " object ";
619 comment += this->Convert(ofname, START_OUTPUT);
621 // Add the custom command to build the object file.
622 this->Makefile->AddCustomCommandToOutput(
625 source.GetFullPath().c_str(),
628 this->Makefile->GetStartOutputDirectory()
632 void cmLocalGenerator::AddBuildTargetRule(const char* llang,
633 cmGeneratorTarget& target)
636 std::vector<std::string> objVector;
637 // Add all the sources outputs to the depends of the target
638 std::vector<cmSourceFile*> const& classes = target.GetSourceFiles();
639 for(std::vector<cmSourceFile*>::const_iterator i = classes.begin();
640 i != classes.end(); ++i)
642 cmSourceFile* sf = *i;
643 if(!sf->GetCustomCommand() &&
644 !sf->GetPropertyAsBool("HEADER_FILE_ONLY") &&
645 !sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
648 dir_max += this->Makefile->GetCurrentOutputDirectory();
650 std::string obj = this->GetObjectFileNameWithoutTarget(*sf, dir_max);
653 std::string ofname = this->Makefile->GetCurrentOutputDirectory();
656 objVector.push_back(ofname);
657 this->AddCustomCommandToCreateObject(ofname.c_str(),
658 llang, *(*i), target);
659 objs += this->Convert(ofname.c_str(),START_OUTPUT,MAKEFILE);
664 std::string createRule = "CMAKE_";
666 createRule += target.GetCreateRuleVariable();
667 std::string targetName = target.Target->GetFullName();
672 std::string linkLibs; // should be set
673 std::string frameworkPath;
674 std::string linkPath;
675 std::string flags; // should be set
676 std::string linkFlags; // should be set
677 this->GetTargetFlags(linkLibs, frameworkPath, linkPath, flags, linkFlags,
679 linkLibs = frameworkPath + linkPath + linkLibs;
680 cmLocalGenerator::RuleVariables vars;
681 vars.Language = llang;
682 vars.Objects = objs.c_str();
683 vars.ObjectDir = ".";
684 vars.Target = targetName.c_str();
685 vars.LinkLibraries = linkLibs.c_str();
686 vars.Flags = flags.c_str();
687 vars.LinkFlags = linkFlags.c_str();
689 std::string langFlags;
690 this->AddLanguageFlags(langFlags, llang, 0);
691 this->AddArchitectureFlags(langFlags, &target, llang, 0);
692 vars.LanguageCompileFlags = langFlags.c_str();
694 cmCustomCommandLines commandLines;
695 std::vector<std::string> rules;
696 rules.push_back(this->Makefile->GetRequiredDefinition(createRule.c_str()));
697 std::vector<std::string> commands;
698 cmSystemTools::ExpandList(rules, commands);
699 for(std::vector<std::string>::iterator i = commands.begin();
700 i != commands.end(); ++i)
702 // Expand the full command line string.
703 this->ExpandRuleVariables(*i, vars);
704 // Parse the string to get the custom command line.
705 cmCustomCommandLine commandLine;
706 std::vector<cmStdString> cmd = cmSystemTools::ParseArguments(i->c_str());
707 for(std::vector<cmStdString>::iterator a = cmd.begin();
710 commandLine.push_back(*a);
713 // Store this command line.
714 commandLines.push_back(commandLine);
716 std::string targetFullPath = target.Target->GetFullPath();
717 // Generate a meaningful comment for the command.
718 std::string comment = "Linking ";
720 comment += " target ";
721 comment += this->Convert(targetFullPath.c_str(), START_OUTPUT);
722 this->Makefile->AddCustomCommandToOutput(
723 targetFullPath.c_str(),
728 this->Makefile->GetStartOutputDirectory()
730 target.Target->AddSourceFile
731 (this->Makefile->GetSource(targetFullPath.c_str()));
735 void cmLocalGenerator
736 ::CreateCustomTargetsAndCommands(std::set<cmStdString> const& lang)
738 cmGeneratorTargetsType tgts = this->Makefile->GetGeneratorTargets();
739 for(cmGeneratorTargetsType::iterator l = tgts.begin();
740 l != tgts.end(); l++)
742 if (l->first->IsImported())
746 cmGeneratorTarget& target = *l->second;
747 switch(target.GetType())
749 case cmTarget::STATIC_LIBRARY:
750 case cmTarget::SHARED_LIBRARY:
751 case cmTarget::MODULE_LIBRARY:
752 case cmTarget::EXECUTABLE:
754 const char* llang = target.Target->GetLinkerLanguage();
758 ("CMake can not determine linker language for target: ",
759 target.Target->GetName());
762 // if the language is not in the set lang then create custom
763 // commands to build the target
764 if(lang.count(llang) == 0)
766 this->AddBuildTargetRule(llang, target);
776 // List of variables that are replaced when
777 // rules are expanced. These variables are
778 // replaced in the form <var> with GetSafeDefinition(var).
779 // ${LANG} is replaced in the variable first with all enabled
781 static const char* ruleReplaceVars[] =
783 "CMAKE_${LANG}_COMPILER",
784 "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
785 "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
786 "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
787 "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
788 "CMAKE_${LANG}_LINK_FLAGS",
789 "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
790 "CMAKE_${LANG}_ARCHIVE",
792 "CMAKE_CURRENT_SOURCE_DIR",
793 "CMAKE_CURRENT_BINARY_DIR",
800 cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
801 const RuleVariables& replaceValues)
803 if(replaceValues.LinkFlags)
805 if(variable == "LINK_FLAGS")
807 return replaceValues.LinkFlags;
810 if(replaceValues.Flags)
812 if(variable == "FLAGS")
814 return replaceValues.Flags;
818 if(replaceValues.Source)
820 if(variable == "SOURCE")
822 return replaceValues.Source;
825 if(replaceValues.PreprocessedSource)
827 if(variable == "PREPROCESSED_SOURCE")
829 return replaceValues.PreprocessedSource;
832 if(replaceValues.AssemblySource)
834 if(variable == "ASSEMBLY_SOURCE")
836 return replaceValues.AssemblySource;
839 if(replaceValues.Object)
841 if(variable == "OBJECT")
843 return replaceValues.Object;
846 if(replaceValues.ObjectDir)
848 if(variable == "OBJECT_DIR")
850 return replaceValues.ObjectDir;
853 if(replaceValues.Objects)
855 if(variable == "OBJECTS")
857 return replaceValues.Objects;
860 if(replaceValues.ObjectsQuoted)
862 if(variable == "OBJECTS_QUOTED")
864 return replaceValues.ObjectsQuoted;
867 if(replaceValues.Defines && variable == "DEFINES")
869 return replaceValues.Defines;
871 if(replaceValues.TargetPDB )
873 if(variable == "TARGET_PDB")
875 return replaceValues.TargetPDB;
878 if(replaceValues.DependencyFile )
880 if(variable == "DEP_FILE")
882 return replaceValues.DependencyFile;
886 if(replaceValues.Target)
888 if(variable == "TARGET_QUOTED")
890 std::string targetQuoted = replaceValues.Target;
891 if(targetQuoted.size() && targetQuoted[0] != '\"')
894 targetQuoted += replaceValues.Target;
895 targetQuoted += '\"';
899 if(variable == "TARGET_UNQUOTED")
901 std::string unquoted = replaceValues.Target;
902 std::string::size_type sz = unquoted.size();
903 if(sz > 2 && unquoted[0] == '\"' && unquoted[sz-1] == '\"')
905 unquoted = unquoted.substr(1, sz-2);
909 if(replaceValues.LanguageCompileFlags)
911 if(variable == "LANGUAGE_COMPILE_FLAGS")
913 return replaceValues.LanguageCompileFlags;
916 if(replaceValues.Target)
918 if(variable == "TARGET")
920 return replaceValues.Target;
923 if(variable == "TARGET_IMPLIB")
925 return this->TargetImplib;
927 if(variable == "TARGET_VERSION_MAJOR")
929 if(replaceValues.TargetVersionMajor)
931 return replaceValues.TargetVersionMajor;
938 if(variable == "TARGET_VERSION_MINOR")
940 if(replaceValues.TargetVersionMinor)
942 return replaceValues.TargetVersionMinor;
949 if(replaceValues.Target)
951 if(variable == "TARGET_BASE")
953 // Strip the last extension off the target name.
954 std::string targetBase = replaceValues.Target;
955 std::string::size_type pos = targetBase.rfind(".");
956 if(pos != targetBase.npos)
958 return targetBase.substr(0, pos);
967 if(variable == "TARGET_SONAME" || variable == "SONAME_FLAG" ||
968 variable == "TARGET_INSTALLNAME_DIR")
970 // All these variables depend on TargetSOName
971 if(replaceValues.TargetSOName)
973 if(variable == "TARGET_SONAME")
975 return replaceValues.TargetSOName;
977 if(variable == "SONAME_FLAG" && replaceValues.SONameFlag)
979 return replaceValues.SONameFlag;
981 if(replaceValues.TargetInstallNameDir &&
982 variable == "TARGET_INSTALLNAME_DIR")
984 return replaceValues.TargetInstallNameDir;
989 if(replaceValues.LinkLibraries)
991 if(variable == "LINK_LIBRARIES")
993 return replaceValues.LinkLibraries;
996 if(replaceValues.Language)
998 if(variable == "LANGUAGE")
1000 return replaceValues.Language;
1003 if(replaceValues.CMTarget)
1005 if(variable == "TARGET_NAME")
1007 return replaceValues.CMTarget->GetName();
1009 if(variable == "TARGET_TYPE")
1011 return cmTarget::GetTargetTypeName(replaceValues.CMTarget->GetType());
1014 if(replaceValues.Output)
1016 if(variable == "OUTPUT")
1018 return replaceValues.Output;
1021 if(variable == "CMAKE_COMMAND")
1023 const char* cmcommand =
1024 this->GetMakefile()->GetDefinition("CMAKE_COMMAND");
1025 return this->Convert(cmcommand, FULL, SHELL);
1027 std::vector<std::string> enabledLanguages;
1028 this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
1029 // loop over language specific replace variables
1031 while(ruleReplaceVars[pos])
1033 for(std::vector<std::string>::iterator i = enabledLanguages.begin();
1034 i != enabledLanguages.end(); ++i)
1036 const char* lang = i->c_str();
1037 std::string actualReplace = ruleReplaceVars[pos];
1038 // If this is the compiler then look for the extra variable
1039 // _COMPILER_ARG1 which must be the first argument to the compiler
1040 const char* compilerArg1 = 0;
1041 if(actualReplace == "CMAKE_${LANG}_COMPILER")
1043 std::string arg1 = actualReplace + "_ARG1";
1044 cmSystemTools::ReplaceString(arg1, "${LANG}", lang);
1045 compilerArg1 = this->Makefile->GetDefinition(arg1.c_str());
1047 if(actualReplace.find("${LANG}") != actualReplace.npos)
1049 cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
1051 if(actualReplace == variable)
1053 std::string replace =
1054 this->Makefile->GetSafeDefinition(variable.c_str());
1055 // if the variable is not a FLAG then treat it like a path
1056 if(variable.find("_FLAG") == variable.npos)
1058 std::string ret = this->ConvertToOutputForExisting(replace.c_str());
1059 // if there is a required first argument to the compiler add it
1060 // to the compiler string
1064 ret += compilerArg1;
1078 cmLocalGenerator::ExpandRuleVariables(std::string& s,
1079 const RuleVariables& replaceValues)
1081 this->InsertRuleLauncher(s, replaceValues.CMTarget,
1082 replaceValues.RuleLauncher);
1083 std::string::size_type start = s.find('<');
1084 // no variables to expand
1089 std::string::size_type pos = 0;
1090 std::string expandedInput;
1091 while(start != s.npos && start < s.size()-2)
1093 std::string::size_type end = s.find('>', start);
1094 // if we find a < with no > we are done
1099 char c = s[start+1];
1100 // if the next char after the < is not A-Za-z then
1101 // skip it and try to find the next < in the string
1104 start = s.find('<', start+1);
1109 std::string var = s.substr(start+1, end - start-1);
1110 std::string replace = this->ExpandRuleVariable(var,
1112 expandedInput += s.substr(pos, start-pos);
1113 expandedInput += replace;
1115 start = s.find('<', start+var.size()+2);
1119 // add the rest of the input
1120 expandedInput += s.substr(pos, s.size()-pos);
1124 //----------------------------------------------------------------------------
1125 const char* cmLocalGenerator::GetRuleLauncher(cmTarget* target,
1130 return target->GetProperty(prop);
1134 return this->Makefile->GetProperty(prop);
1138 //----------------------------------------------------------------------------
1139 void cmLocalGenerator::InsertRuleLauncher(std::string& s, cmTarget* target,
1142 if(const char* val = this->GetRuleLauncher(target, prop))
1144 cmOStringStream wrapped;
1145 wrapped << val << " " << s;
1150 //----------------------------------------------------------------------------
1152 cmLocalGenerator::ConvertToOutputForExistingCommon(const char* remote,
1153 std::string const& result)
1155 // If this is a windows shell, the result has a space, and the path
1156 // already exists, we can use a short-path to reference it without a
1158 if(this->WindowsShell && result.find(' ') != result.npos &&
1159 cmSystemTools::FileExists(remote))
1162 if(cmSystemTools::GetShortPath(remote, tmp))
1164 return this->Convert(tmp.c_str(), NONE, SHELL, true);
1168 // Otherwise, leave it unchanged.
1172 //----------------------------------------------------------------------------
1174 cmLocalGenerator::ConvertToOutputForExisting(const char* remote,
1177 // Perform standard conversion.
1178 std::string result = this->Convert(remote, local, SHELL, true);
1180 // Consider short-path.
1181 return this->ConvertToOutputForExistingCommon(remote, result);
1184 //----------------------------------------------------------------------------
1186 cmLocalGenerator::ConvertToOutputForExisting(RelativeRoot remote,
1189 // Perform standard conversion.
1190 std::string result = this->Convert(remote, local, SHELL, true);
1192 // Consider short-path.
1193 const char* remotePath = this->GetRelativeRootPath(remote);
1194 return this->ConvertToOutputForExistingCommon(remotePath, result);
1197 //----------------------------------------------------------------------------
1199 cmLocalGenerator::ConvertToIncludeReference(std::string const& path)
1201 return this->ConvertToOutputForExisting(path.c_str());
1204 //----------------------------------------------------------------------------
1205 std::string cmLocalGenerator::GetIncludeFlags(
1206 const std::vector<std::string> &includes,
1207 cmGeneratorTarget* target,
1208 const char* lang, bool forResponseFile,
1216 cmOStringStream includeFlags;
1218 std::string flagVar = "CMAKE_INCLUDE_FLAG_";
1220 const char* includeFlag =
1221 this->Makefile->GetSafeDefinition(flagVar.c_str());
1222 flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
1224 const char* sep = this->Makefile->GetDefinition(flagVar.c_str());
1225 bool quotePaths = false;
1226 if(this->Makefile->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS"))
1230 bool repeatFlag = true;
1231 // should the include flag be repeated like ie. -IA -IB
1238 // if there is a separator then the flag is not repeated but is only
1239 // given once i.e. -classpath a:b:c
1243 // Support special system include flag if it is available and the
1244 // normal flag is repeated for each directory.
1245 std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
1247 const char* sysIncludeFlag = 0;
1250 sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar.c_str());
1253 bool flagUsed = false;
1254 std::set<cmStdString> emitted;
1256 emitted.insert("/System/Library/Frameworks");
1258 std::vector<std::string>::const_iterator i;
1259 for(i = includes.begin(); i != includes.end(); ++i)
1261 if(this->Makefile->IsOn("APPLE")
1262 && cmSystemTools::IsPathToFramework(i->c_str()))
1264 std::string frameworkDir = *i;
1265 frameworkDir += "/../";
1266 frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
1267 if(emitted.insert(frameworkDir).second)
1269 OutputFormat format = forResponseFile? RESPONSE : SHELL;
1271 << "-F" << this->Convert(frameworkDir.c_str(),
1272 START_OUTPUT, format, true)
1278 if(!flagUsed || repeatFlag)
1280 if(sysIncludeFlag && target &&
1281 target->IsSystemIncludeDirectory(i->c_str(), config))
1283 includeFlags << sysIncludeFlag;
1287 includeFlags << includeFlag;
1291 std::string includePath;
1294 includePath = this->Convert(i->c_str(), START_OUTPUT,
1299 includePath = this->ConvertToIncludeReference(*i);
1301 if(quotePaths && includePath.size() && includePath[0] != '\"')
1303 includeFlags << "\"";
1305 includeFlags << includePath;
1306 if(quotePaths && includePath.size() && includePath[0] != '\"')
1308 includeFlags << "\"";
1310 includeFlags << sep;
1312 std::string flags = includeFlags.str();
1313 // remove trailing separators
1314 if((sep[0] != ' ') && flags.size()>0 && flags[flags.size()-1] == sep[0])
1316 flags[flags.size()-1] = ' ';
1321 //----------------------------------------------------------------------------
1322 void cmLocalGenerator::AddCompileDefinitions(std::set<std::string>& defines,
1326 std::vector<std::string> targetDefines;
1327 target->GetCompileDefinitions(targetDefines,
1329 this->AppendDefines(defines, targetDefines);
1332 //----------------------------------------------------------------------------
1333 void cmLocalGenerator::AddCompileOptions(
1334 std::string& flags, cmTarget* target,
1335 const char* lang, const char* config
1338 std::string langFlagRegexVar = std::string("CMAKE_")+lang+"_FLAG_REGEX";
1339 if(const char* langFlagRegexStr =
1340 this->Makefile->GetDefinition(langFlagRegexVar.c_str()))
1342 // Filter flags acceptable to this language.
1343 cmsys::RegularExpression r(langFlagRegexStr);
1344 std::vector<std::string> opts;
1345 if(const char* targetFlags = target->GetProperty("COMPILE_FLAGS"))
1347 cmSystemTools::ParseWindowsCommandLine(targetFlags, opts);
1349 target->GetCompileOptions(opts, config);
1350 for(std::vector<std::string>::const_iterator i = opts.begin();
1351 i != opts.end(); ++i)
1353 if(r.find(i->c_str()))
1355 // (Re-)Escape this flag. COMPILE_FLAGS were already parsed
1356 // as a command line above, and COMPILE_OPTIONS are escaped.
1357 this->AppendFlagEscape(flags, i->c_str());
1364 if(const char* targetFlags = target->GetProperty("COMPILE_FLAGS"))
1366 // COMPILE_FLAGS are not escaped for historical reasons.
1367 this->AppendFlags(flags, targetFlags);
1369 std::vector<std::string> opts;
1370 target->GetCompileOptions(opts, config);
1371 for(std::vector<std::string>::const_iterator i = opts.begin();
1372 i != opts.end(); ++i)
1374 // COMPILE_OPTIONS are escaped.
1375 this->AppendFlagEscape(flags, i->c_str());
1380 //----------------------------------------------------------------------------
1381 void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
1382 cmGeneratorTarget* target,
1385 bool stripImplicitInclDirs
1388 // Need to decide whether to automatically include the source and
1389 // binary directories at the beginning of the include path.
1390 bool includeSourceDir = false;
1391 bool includeBinaryDir = false;
1393 // When automatic include directories are requested for a build then
1394 // include the source and binary directories at the beginning of the
1395 // include path to approximate include file behavior for an
1396 // in-source build. This does not account for the case of a source
1397 // file in a subdirectory of the current source directory but we
1398 // cannot fix this because not all native build tools support
1399 // per-source-file include paths.
1400 if(this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR"))
1402 includeSourceDir = true;
1403 includeBinaryDir = true;
1406 // CMake versions below 2.0 would add the source tree to the -I path
1407 // automatically. Preserve compatibility.
1408 if(this->NeedBackwardsCompatibility(1,9))
1410 includeSourceDir = true;
1413 // Hack for VTK 4.0 - 4.4 which depend on the old behavior but do
1414 // not set the backwards compatibility level automatically.
1415 const char* vtkSourceDir =
1416 this->Makefile->GetDefinition("VTK_SOURCE_DIR");
1419 const char* vtk_major =
1420 this->Makefile->GetDefinition("VTK_MAJOR_VERSION");
1421 const char* vtk_minor =
1422 this->Makefile->GetDefinition("VTK_MINOR_VERSION");
1423 vtk_major = vtk_major? vtk_major : "4";
1424 vtk_minor = vtk_minor? vtk_minor : "4";
1427 if(sscanf(vtk_major, "%d", &vmajor) &&
1428 sscanf(vtk_minor, "%d", &vminor) && vmajor == 4 && vminor <= 4)
1430 includeSourceDir = true;
1434 // Do not repeat an include path.
1435 std::set<cmStdString> emitted;
1437 // Store the automatic include paths.
1438 if(includeBinaryDir)
1441 this->Makefile->GetStartOutputDirectory()) == emitted.end())
1443 dirs.push_back(this->Makefile->GetStartOutputDirectory());
1444 emitted.insert(this->Makefile->GetStartOutputDirectory());
1447 if(includeSourceDir)
1449 if(emitted.find(this->Makefile->GetStartDirectory()) == emitted.end())
1451 dirs.push_back(this->Makefile->GetStartDirectory());
1452 emitted.insert(this->Makefile->GetStartDirectory());
1461 std::vector<std::string> implicitDirs;
1462 // Load implicit include directories for this language.
1463 std::string impDirVar = "CMAKE_";
1465 impDirVar += "_IMPLICIT_INCLUDE_DIRECTORIES";
1466 if(const char* value = this->Makefile->GetDefinition(impDirVar.c_str()))
1468 std::vector<std::string> impDirVec;
1469 cmSystemTools::ExpandListArgument(value, impDirVec);
1470 for(std::vector<std::string>::const_iterator i = impDirVec.begin();
1471 i != impDirVec.end(); ++i)
1474 if (!stripImplicitInclDirs)
1476 implicitDirs.push_back(*i);
1481 // Get the target-specific include directories.
1482 std::vector<std::string> includes;
1484 includes = target->GetIncludeDirectories(config);
1486 // Support putting all the in-project include directories first if
1487 // it is requested by the project.
1488 if(this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"))
1490 const char* topSourceDir = this->Makefile->GetHomeDirectory();
1491 const char* topBinaryDir = this->Makefile->GetHomeOutputDirectory();
1492 for(std::vector<std::string>::const_iterator i = includes.begin();
1493 i != includes.end(); ++i)
1495 // Emit this directory only if it is a subdirectory of the
1496 // top-level source or binary tree.
1497 if(cmSystemTools::ComparePath(i->c_str(), topSourceDir) ||
1498 cmSystemTools::ComparePath(i->c_str(), topBinaryDir) ||
1499 cmSystemTools::IsSubDirectory(i->c_str(), topSourceDir) ||
1500 cmSystemTools::IsSubDirectory(i->c_str(), topBinaryDir))
1502 if(emitted.insert(*i).second)
1510 // Construct the final ordered include directory list.
1511 for(std::vector<std::string>::const_iterator i = includes.begin();
1512 i != includes.end(); ++i)
1514 if(emitted.insert(*i).second)
1520 for(std::vector<std::string>::const_iterator i = implicitDirs.begin();
1521 i != implicitDirs.end(); ++i)
1523 if(std::find(includes.begin(), includes.end(), *i) != includes.end())
1530 void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags,
1531 std::string const& config,
1534 this->AppendFlags(flags,
1535 this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS"));
1538 std::string name = "CMAKE_STATIC_LINKER_FLAGS_" + config;
1539 this->AppendFlags(flags, this->Makefile->GetSafeDefinition(name.c_str()));
1541 this->AppendFlags(flags, target->GetProperty("STATIC_LIBRARY_FLAGS"));
1544 std::string name = "STATIC_LIBRARY_FLAGS_" + config;
1545 this->AppendFlags(flags, target->GetProperty(name.c_str()));
1549 void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
1551 std::string& linkFlags,
1552 std::string& frameworkPath,
1553 std::string& linkPath,
1554 cmGeneratorTarget* target)
1556 std::string buildType =
1557 this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
1558 buildType = cmSystemTools::UpperCase(buildType);
1559 const char* libraryLinkVariable =
1560 "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
1562 switch(target->GetType())
1564 case cmTarget::STATIC_LIBRARY:
1565 this->GetStaticLibraryFlags(linkFlags, buildType, target->Target);
1567 case cmTarget::MODULE_LIBRARY:
1568 libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
1569 case cmTarget::SHARED_LIBRARY:
1571 linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
1573 if(!buildType.empty())
1575 std::string build = libraryLinkVariable;
1578 linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
1581 if(this->Makefile->IsOn("WIN32") &&
1582 !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")))
1584 const std::vector<cmSourceFile*>& sources = target->GetSourceFiles();
1585 for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
1586 i != sources.end(); ++i)
1588 cmSourceFile* sf = *i;
1589 if(sf->GetExtension() == "def")
1592 this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
1593 linkFlags += this->Convert(sf->GetFullPath().c_str(),
1599 const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
1602 linkFlags += targetLinkFlags;
1605 if(!buildType.empty())
1607 std::string configLinkFlags = "LINK_FLAGS_";
1608 configLinkFlags += buildType;
1609 targetLinkFlags = target->GetProperty(configLinkFlags.c_str());
1612 linkFlags += targetLinkFlags;
1616 this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath,
1620 case cmTarget::EXECUTABLE:
1623 this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
1625 if(!buildType.empty())
1627 std::string build = "CMAKE_EXE_LINKER_FLAGS_";
1629 linkFlags += this->Makefile->GetSafeDefinition(build.c_str());
1632 const char* linkLanguage = target->Target->GetLinkerLanguage();
1635 cmSystemTools::Error
1636 ("CMake can not determine linker language for target: ",
1637 target->Target->GetName());
1640 this->AddLanguageFlags(flags, linkLanguage, buildType.c_str());
1641 this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath,
1643 if(cmSystemTools::IsOn
1644 (this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
1646 std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_")
1647 + linkLanguage + std::string("_FLAGS");
1648 linkFlags += this->Makefile->GetSafeDefinition(sFlagVar.c_str());
1651 if ( target->GetPropertyAsBool("WIN32_EXECUTABLE") )
1654 this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
1660 this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
1663 if (target->Target->IsExecutableWithExports())
1665 std::string exportFlagVar = "CMAKE_EXE_EXPORTS_";
1666 exportFlagVar += linkLanguage;
1667 exportFlagVar += "_FLAG";
1670 this->Makefile->GetSafeDefinition(exportFlagVar.c_str());
1673 const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
1676 linkFlags += targetLinkFlags;
1679 if(!buildType.empty())
1681 std::string configLinkFlags = "LINK_FLAGS_";
1682 configLinkFlags += buildType;
1683 targetLinkFlags = target->GetProperty(configLinkFlags.c_str());
1686 linkFlags += targetLinkFlags;
1697 std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib)
1699 #if defined(_WIN32) && !defined(__CYGWIN__)
1700 // Work-ardound command line parsing limitations in MSVC 6.0 and
1702 if(this->Makefile->IsOn("MSVC60") || this->Makefile->IsOn("WATCOM"))
1704 // Search for the last space.
1705 std::string::size_type pos = lib.rfind(' ');
1708 // Find the slash after the last space, if any.
1709 pos = lib.find('/', pos);
1711 // Convert the portion of the path with a space to a short path.
1713 if(cmSystemTools::GetShortPath(lib.substr(0, pos).c_str(), sp))
1715 // Append the rest of the path with no space.
1716 sp += lib.substr(pos);
1718 // Convert to an output path.
1719 return this->Convert(sp.c_str(), NONE, SHELL);
1726 return this->Convert(lib.c_str(), START_OUTPUT, SHELL);
1730 * Output the linking rules on a command line. For executables,
1731 * targetLibrary should be a NULL pointer. For libraries, it should point
1732 * to the name of the library. This will not link a library against itself.
1734 void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
1735 std::string& frameworkPath,
1736 std::string& linkPath,
1737 cmGeneratorTarget &tgt,
1740 cmOStringStream fout;
1741 const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
1742 cmComputeLinkInformation* pcli = tgt.Target->GetLinkInformation(config);
1747 cmComputeLinkInformation& cli = *pcli;
1749 // Collect library linking flags command line options.
1750 std::string linkLibs;
1752 const char* linkLanguage = cli.GetLinkLanguage();
1754 std::string libPathFlag =
1755 this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
1756 std::string libPathTerminator =
1757 this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
1759 // Flags to link an executable to shared libraries.
1760 std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
1761 linkFlagsVar += linkLanguage;
1762 linkFlagsVar += "_FLAGS";
1763 if( tgt.GetType() == cmTarget::EXECUTABLE )
1765 linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar.c_str());
1769 // Append the framework search path flags.
1770 std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
1771 for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
1772 fdi != fwDirs.end(); ++fdi)
1774 frameworkPath += "-F";
1775 frameworkPath += this->Convert(fdi->c_str(), NONE, SHELL, false);
1776 frameworkPath += " ";
1779 // Append the library search path flags.
1780 std::vector<std::string> const& libDirs = cli.GetDirectories();
1781 for(std::vector<std::string>::const_iterator libDir = libDirs.begin();
1782 libDir != libDirs.end(); ++libDir)
1784 std::string libpath = this->ConvertToOutputForExisting(libDir->c_str());
1785 linkPath += " " + libPathFlag;
1786 linkPath += libpath;
1787 linkPath += libPathTerminator;
1791 // Append the link items.
1792 typedef cmComputeLinkInformation::ItemVector ItemVector;
1793 ItemVector const& items = cli.GetItems();
1794 for(ItemVector::const_iterator li = items.begin(); li != items.end(); ++li)
1798 linkLibs += this->ConvertToLinkReference(li->Value);
1802 linkLibs += li->Value;
1807 // Write the library flags to the build rule.
1810 // Get the RPATH entries.
1811 std::vector<std::string> runtimeDirs;
1812 cli.GetRPath(runtimeDirs, relink);
1814 // Check what kind of rpath flags to use.
1815 if(cli.GetRuntimeSep().empty())
1817 // Each rpath entry gets its own option ("-R a -R b -R c")
1819 for(std::vector<std::string>::iterator ri = runtimeDirs.begin();
1820 ri != runtimeDirs.end(); ++ri)
1822 rpath += cli.GetRuntimeFlag();
1823 rpath += this->Convert(ri->c_str(), NONE, SHELL, false);
1830 // All rpath entries are combined ("-Wl,-rpath,a:b:c").
1831 std::string rpath = cli.GetRPathString(relink);
1833 // Store the rpath option in the stream.
1836 fout << cli.GetRuntimeFlag();
1837 fout << this->EscapeForShell(rpath.c_str(), true);
1842 // Add the linker runtime search path if any.
1843 std::string rpath_link = cli.GetRPathLinkString();
1844 if(!cli.GetRPathLinkFlag().empty() && !rpath_link.empty())
1846 fout << cli.GetRPathLinkFlag();
1847 fout << this->EscapeForShell(rpath_link.c_str(), true);
1851 // Add standard libraries for this language.
1852 std::string standardLibsVar = "CMAKE_";
1853 standardLibsVar += cli.GetLinkLanguage();
1854 standardLibsVar += "_STANDARD_LIBRARIES";
1855 if(const char* stdLibs =
1856 this->Makefile->GetDefinition(standardLibsVar.c_str()))
1858 fout << stdLibs << " ";
1861 linkLibraries = fout.str();
1865 //----------------------------------------------------------------------------
1866 void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
1867 cmGeneratorTarget* target,
1871 // Only add Mac OS X specific flags on Darwin platforms (OSX and iphone):
1872 if(!this->Makefile->IsOn("APPLE"))
1877 if(this->EmitUniversalBinaryFlags)
1879 std::vector<std::string> archs;
1880 target->GetAppleArchs(config, archs);
1881 const char* sysroot = this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
1882 if(sysroot && sysroot[0] == '/' && !sysroot[1])
1884 std::string sysrootFlagVar =
1885 std::string("CMAKE_") + lang + "_SYSROOT_FLAG";
1886 const char* sysrootFlag =
1887 this->Makefile->GetDefinition(sysrootFlagVar.c_str());
1888 const char* deploymentTarget =
1889 this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
1890 std::string deploymentTargetFlagVar =
1891 std::string("CMAKE_") + lang + "_OSX_DEPLOYMENT_TARGET_FLAG";
1892 const char* deploymentTargetFlag =
1893 this->Makefile->GetDefinition(deploymentTargetFlagVar.c_str());
1894 if(!archs.empty() && lang && (lang[0] =='C' || lang[0] == 'F'))
1896 for(std::vector<std::string>::iterator i = archs.begin();
1897 i != archs.end(); ++i)
1904 if(sysrootFlag && *sysrootFlag && sysroot && *sysroot)
1907 flags += sysrootFlag;
1912 if (deploymentTargetFlag && *deploymentTargetFlag &&
1913 deploymentTarget && *deploymentTarget)
1916 flags += deploymentTargetFlag;
1917 flags += deploymentTarget;
1923 //----------------------------------------------------------------------------
1924 void cmLocalGenerator::AddLanguageFlags(std::string& flags,
1928 // Add language-specific flags.
1929 std::string flagsVar = "CMAKE_";
1931 flagsVar += "_FLAGS";
1932 this->AddConfigVariableFlags(flags, flagsVar.c_str(), config);
1935 //----------------------------------------------------------------------------
1936 bool cmLocalGenerator::GetRealDependency(const char* inName,
1940 // Older CMake code may specify the dependency using the target
1941 // output file rather than the target name. Such code would have
1942 // been written before there was support for target properties that
1943 // modify the name so stripping down to just the file name should
1944 // produce the target name in this case.
1945 std::string name = cmSystemTools::GetFilenameName(inName);
1947 // If the input name is the empty string, there is no real
1948 // dependency. Short-circuit the other checks:
1954 if(cmSystemTools::GetFilenameLastExtension(name) == ".exe")
1956 name = cmSystemTools::GetFilenameWithoutLastExtension(name);
1959 // Look for a CMake target with the given name.
1960 if(cmTarget* target = this->Makefile->FindTargetToUse(name.c_str()))
1962 // make sure it is not just a coincidence that the target name
1963 // found is part of the inName
1964 if(cmSystemTools::FileIsFullPath(inName))
1966 std::string tLocation;
1967 if(target->GetType() >= cmTarget::EXECUTABLE &&
1968 target->GetType() <= cmTarget::MODULE_LIBRARY)
1970 tLocation = target->GetLocation(config);
1971 tLocation = cmSystemTools::GetFilenamePath(tLocation);
1972 tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
1974 std::string depLocation = cmSystemTools::GetFilenamePath(
1975 std::string(inName));
1976 depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
1977 if(depLocation != tLocation)
1979 // it is a full path to a depend that has the same name
1980 // as a target but is in a different location so do not use
1981 // the target as the depend
1986 switch (target->GetType())
1988 case cmTarget::EXECUTABLE:
1989 case cmTarget::STATIC_LIBRARY:
1990 case cmTarget::SHARED_LIBRARY:
1991 case cmTarget::MODULE_LIBRARY:
1992 case cmTarget::UNKNOWN_LIBRARY:
1993 dep = target->GetLocation(config);
1995 case cmTarget::OBJECT_LIBRARY:
1996 // An object library has no single file on which to depend.
1997 // This was listed to get the target-level dependency.
1999 case cmTarget::UTILITY:
2000 case cmTarget::GLOBAL_TARGET:
2001 // A utility target has no file on which to depend. This was listed
2002 // only to get the target-level dependency.
2007 // The name was not that of a CMake target. It must name a file.
2008 if(cmSystemTools::FileIsFullPath(inName))
2010 // This is a full path. Return it as given.
2015 // Check for a source file in this directory that matches the
2017 if(cmSourceFile* sf = this->Makefile->GetSource(inName))
2019 dep = sf->GetFullPath();
2023 // Treat the name as relative to the source directory in which it
2025 dep = this->Makefile->GetCurrentDirectory();
2031 //----------------------------------------------------------------------------
2032 void cmLocalGenerator::AddSharedFlags(std::string& flags,
2036 std::string flagsVar;
2038 // Add flags for dealing with shared libraries for this language.
2041 flagsVar = "CMAKE_SHARED_LIBRARY_";
2043 flagsVar += "_FLAGS";
2044 this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
2048 static void AddVisibilityCompileOption(std::string &flags, cmTarget* target,
2049 cmLocalGenerator *lg, const char *lang)
2051 std::string l(lang);
2052 std::string compileOption = "CMAKE_" + l + "_COMPILE_OPTIONS_VISIBILITY";
2053 const char *opt = lg->GetMakefile()->GetDefinition(compileOption.c_str());
2058 std::string flagDefine = l + "_VISIBILITY_PRESET";
2060 const char *prop = target->GetProperty(flagDefine.c_str());
2065 if (strcmp(prop, "hidden") != 0
2066 && strcmp(prop, "default") != 0
2067 && strcmp(prop, "protected") != 0
2068 && strcmp(prop, "internal") != 0 )
2071 e << "Target " << target->GetName() << " uses unsupported value \""
2072 << prop << "\" for " << flagDefine << ".";
2073 cmSystemTools::Error(e.str().c_str());
2076 std::string option = std::string(opt) + prop;
2077 lg->AppendFlags(flags, option.c_str());
2080 static void AddInlineVisibilityCompileOption(std::string &flags,
2082 cmLocalGenerator *lg)
2084 std::string compileOption
2085 = "CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN";
2086 const char *opt = lg->GetMakefile()->GetDefinition(compileOption.c_str());
2092 bool prop = target->GetPropertyAsBool("VISIBILITY_INLINES_HIDDEN");
2097 lg->AppendFlags(flags, opt);
2100 //----------------------------------------------------------------------------
2101 void cmLocalGenerator
2102 ::AddVisibilityPresetFlags(std::string &flags, cmTarget* target,
2105 int targetType = target->GetType();
2106 bool suitableTarget = ((targetType == cmTarget::SHARED_LIBRARY)
2107 || (targetType == cmTarget::MODULE_LIBRARY)
2108 || (target->IsExecutableWithExports()));
2110 if (!suitableTarget)
2119 AddVisibilityCompileOption(flags, target, this, lang);
2120 AddInlineVisibilityCompileOption(flags, target, this);
2123 //----------------------------------------------------------------------------
2124 void cmLocalGenerator::AddCMP0018Flags(std::string &flags, cmTarget* target,
2125 std::string const& lang,
2128 int targetType = target->GetType();
2130 bool shared = ((targetType == cmTarget::SHARED_LIBRARY) ||
2131 (targetType == cmTarget::MODULE_LIBRARY));
2133 if (this->GetShouldUseOldFlags(shared, lang))
2135 this->AddSharedFlags(flags, lang.c_str(), shared);
2139 if (target->GetType() == cmTarget::OBJECT_LIBRARY)
2141 if (target->GetPropertyAsBool("POSITION_INDEPENDENT_CODE"))
2143 this->AddPositionIndependentFlags(flags, lang, targetType);
2148 if (target->GetLinkInterfaceDependentBoolProperty(
2149 "POSITION_INDEPENDENT_CODE",
2152 this->AddPositionIndependentFlags(flags, lang, targetType);
2156 this->AppendFeatureOptions(flags, lang.c_str(), "DLL");
2161 //----------------------------------------------------------------------------
2162 bool cmLocalGenerator::GetShouldUseOldFlags(bool shared,
2163 const std::string &lang) const
2165 std::string originalFlags =
2166 this->GlobalGenerator->GetSharedLibFlagsForLanguage(lang);
2169 std::string flagsVar = "CMAKE_SHARED_LIBRARY_";
2171 flagsVar += "_FLAGS";
2173 this->Makefile->GetSafeDefinition(flagsVar.c_str());
2175 if (flags && flags != originalFlags)
2177 switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0018))
2179 case cmPolicies::WARN:
2182 e << "Variable " << flagsVar << " has been modified. CMake "
2183 "will ignore the POSITION_INDEPENDENT_CODE target property for "
2184 "shared libraries and will use the " << flagsVar << " variable "
2185 "instead. This may cause errors if the original content of "
2186 << flagsVar << " was removed.\n"
2187 << this->Makefile->GetPolicies()->GetPolicyWarning(
2188 cmPolicies::CMP0018);
2190 this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
2191 // fall through to OLD behaviour
2193 case cmPolicies::OLD:
2195 case cmPolicies::REQUIRED_IF_USED:
2196 case cmPolicies::REQUIRED_ALWAYS:
2197 case cmPolicies::NEW:
2206 //----------------------------------------------------------------------------
2207 void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags,
2208 std::string const& lang,
2211 const char* picFlags = 0;
2213 if(targetType == cmTarget::EXECUTABLE)
2215 std::string flagsVar = "CMAKE_";
2217 flagsVar += "_COMPILE_OPTIONS_PIE";
2218 picFlags = this->Makefile->GetSafeDefinition(flagsVar.c_str());
2222 std::string flagsVar = "CMAKE_";
2224 flagsVar += "_COMPILE_OPTIONS_PIC";
2225 picFlags = this->Makefile->GetSafeDefinition(flagsVar.c_str());
2229 std::vector<std::string> options;
2230 cmSystemTools::ExpandListArgument(picFlags, options);
2231 for(std::vector<std::string>::const_iterator oi = options.begin();
2232 oi != options.end(); ++oi)
2234 this->AppendFlagEscape(flags, oi->c_str());
2239 //----------------------------------------------------------------------------
2240 void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
2244 // Add the flags from the variable itself.
2245 std::string flagsVar = var;
2246 this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
2247 // Add the flags from the build-type specific variable.
2248 if(config && *config)
2251 flagsVar += cmSystemTools::UpperCase(config);
2252 this->AppendFlags(flags, this->Makefile->GetDefinition(flagsVar.c_str()));
2256 //----------------------------------------------------------------------------
2257 void cmLocalGenerator::AppendFlags(std::string& flags,
2258 const char* newFlags)
2260 if(newFlags && *newFlags)
2262 std::string newf = newFlags;
2271 //----------------------------------------------------------------------------
2272 void cmLocalGenerator::AppendFlagEscape(std::string& flags,
2273 const char* rawFlag)
2275 this->AppendFlags(flags, this->EscapeForShell(rawFlag).c_str());
2278 //----------------------------------------------------------------------------
2279 void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
2280 const char* defines_list)
2282 // Short-circuit if there are no definitions.
2288 // Expand the list of definitions.
2289 std::vector<std::string> defines_vec;
2290 cmSystemTools::ExpandListArgument(defines_list, defines_vec);
2291 this->AppendDefines(defines, defines_vec);
2294 //----------------------------------------------------------------------------
2295 void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
2296 const std::vector<std::string> &defines_vec)
2298 for(std::vector<std::string>::const_iterator di = defines_vec.begin();
2299 di != defines_vec.end(); ++di)
2301 // Skip unsupported definitions.
2302 if(!this->CheckDefinition(*di))
2306 defines.insert(*di);
2310 //----------------------------------------------------------------------------
2311 void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines,
2312 std::string &definesString,
2315 // Lookup the define flag for the current language.
2316 std::string dflag = "-D";
2319 std::string defineFlagVar = "CMAKE_";
2320 defineFlagVar += lang;
2321 defineFlagVar += "_DEFINE_FLAG";
2322 const char* df = this->Makefile->GetDefinition(defineFlagVar.c_str());
2329 std::set<std::string>::const_iterator defineIt = defines.begin();
2330 const std::set<std::string>::const_iterator defineEnd = defines.end();
2331 const char* itemSeparator = definesString.empty() ? "" : " ";
2332 for( ; defineIt != defineEnd; ++defineIt)
2334 // Append the definition with proper escaping.
2335 std::string def = dflag;
2336 if(this->WatcomWMake)
2338 // The Watcom compiler does its own command line parsing instead
2339 // of using the windows shell rules. Definitions are one of
2341 // -DNAME=<cpp-token>
2342 // -DNAME="c-string with spaces and other characters(?@#$)"
2344 // Watcom will properly parse each of these cases from the
2345 // command line without any escapes. However we still have to
2346 // get the '$' and '#' characters through WMake as '$$' and
2348 for(const char* c = defineIt->c_str(); *c; ++c)
2350 if(*c == '$' || *c == '#')
2359 // Make the definition appear properly on the command line. Use
2360 // -DNAME="value" instead of -D"NAME=value" to help VS6 parser.
2361 std::string::size_type eq = defineIt->find("=");
2362 def += defineIt->substr(0, eq);
2363 if(eq != defineIt->npos)
2366 def += this->EscapeForShell(defineIt->c_str() + eq + 1, true);
2369 definesString += itemSeparator;
2370 itemSeparator = " ";
2371 definesString += def;
2375 //----------------------------------------------------------------------------
2376 void cmLocalGenerator::AppendFeatureOptions(
2377 std::string& flags, const char* lang, const char* feature)
2379 std::string optVar = "CMAKE_";
2381 optVar += "_COMPILE_OPTIONS_";
2383 if(const char* optionList = this->Makefile->GetDefinition(optVar.c_str()))
2385 std::vector<std::string> options;
2386 cmSystemTools::ExpandListArgument(optionList, options);
2387 for(std::vector<std::string>::const_iterator oi = options.begin();
2388 oi != options.end(); ++oi)
2390 this->AppendFlagEscape(flags, oi->c_str());
2395 //----------------------------------------------------------------------------
2397 cmLocalGenerator::ConstructComment(const cmCustomCommand& cc,
2398 const char* default_comment)
2400 // Check for a comment provided with the command.
2403 return cc.GetComment();
2406 // Construct a reasonable default comment if possible.
2407 if(!cc.GetOutputs().empty())
2409 std::string comment;
2410 comment = "Generating ";
2411 const char* sep = "";
2412 for(std::vector<std::string>::const_iterator o = cc.GetOutputs().begin();
2413 o != cc.GetOutputs().end(); ++o)
2416 comment += this->Convert(o->c_str(), cmLocalGenerator::START_OUTPUT);
2422 // Otherwise use the provided default.
2423 return default_comment;
2426 //----------------------------------------------------------------------------
2428 cmLocalGenerator::ConvertToOptionallyRelativeOutputPath(const char* remote)
2430 return this->Convert(remote, START_OUTPUT, SHELL, true);
2433 //----------------------------------------------------------------------------
2434 const char* cmLocalGenerator::GetRelativeRootPath(RelativeRoot relroot)
2438 case HOME: return this->Makefile->GetHomeDirectory();
2439 case START: return this->Makefile->GetStartDirectory();
2440 case HOME_OUTPUT: return this->Makefile->GetHomeOutputDirectory();
2441 case START_OUTPUT: return this->Makefile->GetStartOutputDirectory();
2447 //----------------------------------------------------------------------------
2448 std::string cmLocalGenerator::Convert(const char* source,
2449 RelativeRoot relative,
2450 OutputFormat output,
2453 // Make sure the relative path conversion components are set.
2454 if(!this->PathConversionsSetup)
2456 this->SetupPathConversions();
2457 this->PathConversionsSetup = true;
2460 // Convert the path to a relative path.
2461 std::string result = source;
2463 if (!optional || this->UseRelativePaths)
2468 //result = cmSystemTools::CollapseFullPath(result.c_str());
2469 result = this->ConvertToRelativePath(this->HomeDirectoryComponents,
2473 //result = cmSystemTools::CollapseFullPath(result.c_str());
2474 result = this->ConvertToRelativePath(this->StartDirectoryComponents,
2478 //result = cmSystemTools::CollapseFullPath(result.c_str());
2480 this->ConvertToRelativePath(this->HomeOutputDirectoryComponents,
2484 //result = cmSystemTools::CollapseFullPath(result.c_str());
2486 this->ConvertToRelativePath(this->StartOutputDirectoryComponents,
2490 result = cmSystemTools::CollapseFullPath(result.c_str());
2496 return this->ConvertToOutputFormat(result.c_str(), output);
2499 //----------------------------------------------------------------------------
2500 std::string cmLocalGenerator::ConvertToOutputFormat(const char* source,
2501 OutputFormat output)
2503 std::string result = source;
2504 // Convert it to an output path.
2505 if (output == MAKEFILE)
2507 result = cmSystemTools::ConvertToOutputPath(result.c_str());
2509 else if( output == SHELL)
2511 // For the MSYS shell convert drive letters to posix paths, so
2512 // that c:/some/path becomes /c/some/path. This is needed to
2513 // avoid problems with the shell path translation.
2514 if(this->MSYSShell && !this->LinkScriptShell)
2516 if(result.size() > 2 && result[1] == ':')
2518 result[1] = result[0];
2522 if(this->WindowsShell)
2524 std::string::size_type pos = 0;
2525 while((pos = result.find('/', pos)) != std::string::npos)
2531 result = this->EscapeForShell(result.c_str(), true, false);
2533 else if(output == RESPONSE)
2535 result = this->EscapeForShell(result.c_str(), false, false);
2540 //----------------------------------------------------------------------------
2541 std::string cmLocalGenerator::Convert(RelativeRoot remote,
2543 OutputFormat output,
2546 const char* remotePath = this->GetRelativeRootPath(remote);
2548 // The relative root must have a path (i.e. not FULL or NONE)
2549 assert(remotePath != 0);
2551 if(local && (!optional || this->UseRelativePaths))
2553 std::vector<std::string> components;
2554 cmSystemTools::SplitPath(local, components);
2555 std::string result = this->ConvertToRelativePath(components, remotePath);
2556 return this->ConvertToOutputFormat(result.c_str(), output);
2560 return this->ConvertToOutputFormat(remotePath, output);
2564 //----------------------------------------------------------------------------
2565 std::string cmLocalGenerator::FindRelativePathTopSource()
2567 // Relative path conversion within a single tree managed by CMake is
2568 // safe. We can use our parent relative path top if and only if
2569 // this is a subdirectory of that top.
2570 if(cmLocalGenerator* parent = this->GetParent())
2572 std::string parentTop = parent->FindRelativePathTopSource();
2573 if(cmSystemTools::IsSubDirectory(
2574 this->Makefile->GetStartDirectory(), parentTop.c_str()))
2580 // Otherwise this directory itself is the new top.
2581 return this->Makefile->GetStartDirectory();
2584 //----------------------------------------------------------------------------
2585 std::string cmLocalGenerator::FindRelativePathTopBinary()
2587 // Relative path conversion within a single tree managed by CMake is
2588 // safe. We can use our parent relative path top if and only if
2589 // this is a subdirectory of that top.
2590 if(cmLocalGenerator* parent = this->GetParent())
2592 std::string parentTop = parent->FindRelativePathTopBinary();
2593 if(cmSystemTools::IsSubDirectory(
2594 this->Makefile->GetStartOutputDirectory(), parentTop.c_str()))
2600 // Otherwise this directory itself is the new top.
2601 return this->Makefile->GetStartOutputDirectory();
2604 //----------------------------------------------------------------------------
2605 void cmLocalGenerator::ConfigureRelativePaths()
2607 // Relative path conversion inside the source tree is not used to
2608 // construct relative paths passed to build tools so it is safe to
2609 // even when the source is a network path.
2610 std::string source = this->FindRelativePathTopSource();
2611 this->RelativePathTopSource = source;
2613 // The current working directory on Windows cannot be a network
2614 // path. Therefore relative paths cannot work when the binary tree
2615 // is a network path.
2616 std::string binary = this->FindRelativePathTopBinary();
2617 if(binary.size() < 2 || binary.substr(0, 2) != "//")
2619 this->RelativePathTopBinary = binary;
2623 this->RelativePathTopBinary = "";
2627 //----------------------------------------------------------------------------
2628 static bool cmLocalGeneratorNotAbove(const char* a, const char* b)
2630 return (cmSystemTools::ComparePath(a, b) ||
2631 cmSystemTools::IsSubDirectory(a, b));
2634 //----------------------------------------------------------------------------
2636 cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
2637 const char* in_remote, bool force)
2639 // The path should never be quoted.
2640 assert(in_remote[0] != '\"');
2642 // The local path should never have a trailing slash.
2643 assert(local.size() > 0 && !(local[local.size()-1] == ""));
2645 // If the path is already relative then just return the path.
2646 if(!cmSystemTools::FileIsFullPath(in_remote))
2651 // Make sure relative path conversion is configured.
2652 if(!this->RelativePathsConfigured)
2654 this->ConfigureRelativePaths();
2655 this->RelativePathsConfigured = true;
2660 // Skip conversion if the path and local are not both in the source
2661 // or both in the binary tree.
2662 std::string local_path = cmSystemTools::JoinPath(local);
2663 if(!((cmLocalGeneratorNotAbove(local_path.c_str(),
2664 this->RelativePathTopBinary.c_str()) &&
2665 cmLocalGeneratorNotAbove(in_remote,
2666 this->RelativePathTopBinary.c_str())) ||
2667 (cmLocalGeneratorNotAbove(local_path.c_str(),
2668 this->RelativePathTopSource.c_str()) &&
2669 cmLocalGeneratorNotAbove(in_remote,
2670 this->RelativePathTopSource.c_str()))))
2676 // Identify the longest shared path component between the remote
2677 // path and the local path.
2678 std::vector<std::string> remote;
2679 cmSystemTools::SplitPath(in_remote, remote);
2680 unsigned int common=0;
2681 while(common < remote.size() &&
2682 common < local.size() &&
2683 cmSystemTools::ComparePath(remote[common].c_str(),
2684 local[common].c_str()))
2689 // If no part of the path is in common then return the full path.
2695 // If the entire path is in common then just return a ".".
2696 if(common == remote.size() &&
2697 common == local.size())
2702 // If the entire path is in common except for a trailing slash then
2703 // just return a "./".
2704 if(common+1 == remote.size() &&
2705 remote[common].size() == 0 &&
2706 common == local.size())
2711 // Construct the relative path.
2712 std::string relative;
2714 // First add enough ../ to get up to the level of the shared portion
2715 // of the path. Leave off the trailing slash. Note that the last
2716 // component of local will never be empty because local should never
2717 // have a trailing slash.
2718 for(unsigned int i=common; i < local.size(); ++i)
2721 if(i < local.size()-1)
2727 // Now add the portion of the destination path that is not included
2728 // in the shared portion of the path. Add a slash the first time
2729 // only if there was already something in the path. If there was a
2730 // trailing slash in the input then the last iteration of the loop
2731 // will add a slash followed by an empty string which will preserve
2732 // the trailing slash in the output.
2733 for(unsigned int i=common; i < remote.size(); ++i)
2735 if(relative.size() > 0)
2739 relative += remote[i];
2742 // Finally return the path.
2746 //----------------------------------------------------------------------------
2749 ::GenerateTargetInstallRules(
2750 std::ostream& os, const char* config,
2751 std::vector<std::string> const& configurationTypes)
2753 // Convert the old-style install specification from each target to
2754 // an install generator and run it.
2755 cmTargets& tgts = this->Makefile->GetTargets();
2756 for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
2758 // Include the user-specified pre-install script for this target.
2759 if(const char* preinstall = l->second.GetProperty("PRE_INSTALL_SCRIPT"))
2761 cmInstallScriptGenerator g(preinstall, false, 0);
2762 g.Generate(os, config, configurationTypes);
2765 // Install this target if a destination is given.
2766 if(l->second.GetInstallPath() != "")
2768 // Compute the full install destination. Note that converting
2769 // to unix slashes also removes any trailing slash.
2770 // We also skip over the leading slash given by the user.
2771 std::string destination = l->second.GetInstallPath().substr(1);
2772 cmSystemTools::ConvertToUnixSlashes(destination);
2773 if(destination.empty())
2778 // Generate the proper install generator for this target type.
2779 switch(l->second.GetType())
2781 case cmTarget::EXECUTABLE:
2782 case cmTarget::STATIC_LIBRARY:
2783 case cmTarget::MODULE_LIBRARY:
2785 // Use a target install generator.
2786 cmInstallTargetGenerator g(l->second, destination.c_str(), false);
2787 g.Generate(os, config, configurationTypes);
2790 case cmTarget::SHARED_LIBRARY:
2792 #if defined(_WIN32) || defined(__CYGWIN__)
2793 // Special code to handle DLL. Install the import library
2794 // to the normal destination and the DLL to the runtime
2796 cmInstallTargetGenerator g1(l->second, destination.c_str(), true);
2797 g1.Generate(os, config, configurationTypes);
2798 // We also skip over the leading slash given by the user.
2799 destination = l->second.GetRuntimeInstallPath().substr(1);
2800 cmSystemTools::ConvertToUnixSlashes(destination);
2801 cmInstallTargetGenerator g2(l->second, destination.c_str(), false);
2802 g2.Generate(os, config, configurationTypes);
2804 // Use a target install generator.
2805 cmInstallTargetGenerator g(l->second, destination.c_str(), false);
2806 g.Generate(os, config, configurationTypes);
2815 // Include the user-specified post-install script for this target.
2816 if(const char* postinstall = l->second.GetProperty("POST_INSTALL_SCRIPT"))
2818 cmInstallScriptGenerator g(postinstall, false, 0);
2819 g.Generate(os, config, configurationTypes);
2824 #if defined(CM_LG_ENCODE_OBJECT_NAMES)
2825 static std::string cmLocalGeneratorMD5(const char* input)
2828 cmsysMD5* md5 = cmsysMD5_New();
2829 cmsysMD5_Initialize(md5);
2830 cmsysMD5_Append(md5, reinterpret_cast<unsigned char const*>(input), -1);
2831 cmsysMD5_FinalizeHex(md5, md5out);
2832 cmsysMD5_Delete(md5);
2833 return std::string(md5out, 32);
2837 cmLocalGeneratorShortenObjectName(std::string& objName,
2838 std::string::size_type max_len)
2840 // Replace the beginning of the path portion of the object name with
2842 std::string::size_type pos = objName.find('/', objName.size()-max_len+32);
2843 if(pos != objName.npos)
2845 std::string md5name = cmLocalGeneratorMD5(objName.substr(0, pos).c_str());
2846 md5name += objName.substr(pos);
2849 // The object name is now short enough.
2854 // The object name could not be shortened enough.
2860 bool cmLocalGeneratorCheckObjectName(std::string& objName,
2861 std::string::size_type dir_len,
2862 std::string::size_type max_total_len)
2864 // Enforce the maximum file name length if possible.
2865 std::string::size_type max_obj_len = max_total_len;
2866 if(dir_len < max_total_len)
2868 max_obj_len = max_total_len - dir_len;
2869 if(objName.size() > max_obj_len)
2871 // The current object file name is too long. Try to shorten it.
2872 return cmLocalGeneratorShortenObjectName(objName, max_obj_len);
2876 // The object file name is short enough.
2882 // The build directory in which the object will be stored is
2883 // already too deep.
2889 //----------------------------------------------------------------------------
2892 ::CreateSafeUniqueObjectFileName(const char* sin,
2893 std::string const& dir_max)
2895 // Look for an existing mapped name for this object file.
2896 std::map<cmStdString,cmStdString>::iterator it =
2897 this->UniqueObjectNamesMap.find(sin);
2899 // If no entry exists create one.
2900 if(it == this->UniqueObjectNamesMap.end())
2902 // Start with the original name.
2903 std::string ssin = sin;
2905 // Avoid full paths by removing leading slashes.
2906 std::string::size_type pos = 0;
2907 for(;pos < ssin.size() && ssin[pos] == '/'; ++pos)
2910 ssin = ssin.substr(pos);
2912 // Avoid full paths by removing colons.
2913 cmSystemTools::ReplaceString(ssin, ":", "_");
2915 // Avoid relative paths that go up the tree.
2916 cmSystemTools::ReplaceString(ssin, "../", "__/");
2919 cmSystemTools::ReplaceString(ssin, " ", "_");
2921 // Mangle the name if necessary.
2922 if(this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
2927 sprintf(rpstr, "_p_");
2928 cmSystemTools::ReplaceString(ssin, "+", rpstr);
2929 std::string sssin = sin;
2933 for ( it = this->UniqueObjectNamesMap.begin();
2934 it != this->UniqueObjectNamesMap.end();
2937 if ( it->second == ssin )
2947 cmSystemTools::ReplaceString(ssin, "_p_", rpstr);
2948 sprintf(rpstr, "_p%d_", cc++);
2953 #if defined(CM_LG_ENCODE_OBJECT_NAMES)
2954 if(!cmLocalGeneratorCheckObjectName(ssin, dir_max.size(),
2955 this->ObjectPathMax))
2957 // Warn if this is the first time the path has been seen.
2958 if(this->ObjectMaxPathViolations.insert(dir_max).second)
2961 m << "The object file directory\n"
2962 << " " << dir_max << "\n"
2963 << "has " << dir_max.size() << " characters. "
2964 << "The maximum full path to an object file is "
2965 << this->ObjectPathMax << " characters "
2966 << "(see CMAKE_OBJECT_PATH_MAX). "
2968 << " " << ssin << "\n"
2969 << "cannot be safely placed under this directory. "
2970 << "The build may not work correctly.";
2971 this->Makefile->IssueMessage(cmake::WARNING, m.str());
2978 // Insert the newly mapped object file name.
2979 std::map<cmStdString, cmStdString>::value_type e(sin, ssin);
2980 it = this->UniqueObjectNamesMap.insert(e).first;
2983 // Return the map entry.
2987 //----------------------------------------------------------------------------
2990 ::GetObjectFileNameWithoutTarget(const cmSourceFile& source,
2991 std::string const& dir_max,
2992 bool* hasSourceExtension)
2994 // Construct the object file name using the full path to the source
2995 // file which is its only unique identification.
2996 const char* fullPath = source.GetFullPath().c_str();
2998 // Try referencing the source relative to the source tree.
2999 std::string relFromSource = this->Convert(fullPath, START);
3000 assert(!relFromSource.empty());
3001 bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
3002 bool subSource = relSource && relFromSource[0] != '.';
3004 // Try referencing the source relative to the binary tree.
3005 std::string relFromBinary = this->Convert(fullPath, START_OUTPUT);
3006 assert(!relFromBinary.empty());
3007 bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
3008 bool subBinary = relBinary && relFromBinary[0] != '.';
3010 // Select a nice-looking reference to the source file to construct
3011 // the object file name.
3012 std::string objectName;
3013 if((relSource && !relBinary) || (subSource && !subBinary))
3015 objectName = relFromSource;
3017 else if((relBinary && !relSource) || (subBinary && !subSource))
3019 objectName = relFromBinary;
3021 else if(relFromBinary.length() < relFromSource.length())
3023 objectName = relFromBinary;
3027 objectName = relFromSource;
3030 // if it is still a full path check for the try compile case
3031 // try compile never have in source sources, and should not
3032 // have conflicting source file names in the same target
3033 if(cmSystemTools::FileIsFullPath(objectName.c_str()))
3035 if(this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile())
3037 objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
3041 // Replace the original source file extension with the object file
3043 bool keptSourceExtension = true;
3044 if(!source.GetPropertyAsBool("KEEP_EXTENSION"))
3046 // Decide whether this language wants to replace the source
3047 // extension with the object extension. For CMake 2.4
3048 // compatibility do this by default.
3049 bool replaceExt = this->NeedBackwardsCompatibility(2, 4);
3052 if(const char* lang = source.GetLanguage())
3054 std::string repVar = "CMAKE_";
3056 repVar += "_OUTPUT_EXTENSION_REPLACE";
3057 replaceExt = this->Makefile->IsOn(repVar.c_str());
3061 // Remove the source extension if it is to be replaced.
3064 keptSourceExtension = false;
3065 std::string::size_type dot_pos = objectName.rfind(".");
3066 if(dot_pos != std::string::npos)
3068 objectName = objectName.substr(0, dot_pos);
3072 // Store the new extension.
3074 this->GlobalGenerator->GetLanguageOutputExtension(source);
3076 if(hasSourceExtension)
3078 *hasSourceExtension = keptSourceExtension;
3081 // Convert to a safe name.
3082 return this->CreateSafeUniqueObjectFileName(objectName.c_str(), dir_max);
3085 //----------------------------------------------------------------------------
3088 ::GetSourceFileLanguage(const cmSourceFile& source)
3090 return source.GetLanguage();
3093 //----------------------------------------------------------------------------
3094 std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str)
3097 #if defined(_WIN32) && !defined(__CYGWIN__)
3098 // if there are spaces
3099 std::string temp = str;
3100 if (temp.find(" ") != std::string::npos &&
3101 temp.find("\"")==std::string::npos)
3110 for(const char* ch = str; *ch != '\0'; ++ch)
3122 //----------------------------------------------------------------------------
3123 static bool cmLocalGeneratorIsShellOperator(const char* str)
3125 if(strcmp(str, "<") == 0 ||
3126 strcmp(str, ">") == 0 ||
3127 strcmp(str, "<<") == 0 ||
3128 strcmp(str, ">>") == 0 ||
3129 strcmp(str, "|") == 0 ||
3130 strcmp(str, "||") == 0 ||
3131 strcmp(str, "&&") == 0 ||
3132 strcmp(str, "&>") == 0 ||
3133 strcmp(str, "1>") == 0 ||
3134 strcmp(str, "2>") == 0 ||
3135 strcmp(str, "2>&1") == 0 ||
3136 strcmp(str, "1>&2") == 0)
3143 //----------------------------------------------------------------------------
3144 std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars,
3147 // Do not escape shell operators.
3148 if(cmLocalGeneratorIsShellOperator(str))
3153 // Compute the flags for the target shell environment.
3155 if(this->WindowsVSIDE)
3157 flags |= cmsysSystem_Shell_Flag_VSIDE;
3159 else if(!this->LinkScriptShell)
3161 flags |= cmsysSystem_Shell_Flag_Make;
3165 flags |= cmsysSystem_Shell_Flag_AllowMakeVariables;
3169 flags |= cmsysSystem_Shell_Flag_EchoWindows;
3171 if(this->WatcomWMake)
3173 flags |= cmsysSystem_Shell_Flag_WatcomWMake;
3177 flags |= cmsysSystem_Shell_Flag_MinGWMake;
3181 flags |= cmsysSystem_Shell_Flag_NMake;
3184 // Compute the buffer size needed.
3185 int size = (this->WindowsShell ?
3186 cmsysSystem_Shell_GetArgumentSizeForWindows(str, flags) :
3187 cmsysSystem_Shell_GetArgumentSizeForUnix(str, flags));
3189 // Compute the shell argument itself.
3190 std::vector<char> arg(size);
3191 if(this->WindowsShell)
3193 cmsysSystem_Shell_GetArgumentForWindows(str, &arg[0], flags);
3197 cmsysSystem_Shell_GetArgumentForUnix(str, &arg[0], flags);
3199 return std::string(&arg[0]);
3202 //----------------------------------------------------------------------------
3203 std::string cmLocalGenerator::EscapeForCMake(const char* str)
3205 // Always double-quote the argument to take care of most escapes.
3206 std::string result = "\"";
3207 for(const char* c = str; *c; ++c)
3211 // Escape the double quote to avoid ending the argument.
3216 // Escape the dollar to avoid expanding variables.
3221 // Escape the backslash to avoid other escapes.
3226 // Other characters will be parsed correctly.
3234 //----------------------------------------------------------------------------
3235 cmLocalGenerator::FortranFormat
3236 cmLocalGenerator::GetFortranFormat(const char* value)
3238 FortranFormat format = FortranFormatNone;
3241 std::vector<std::string> fmt;
3242 cmSystemTools::ExpandListArgument(value, fmt);
3243 for(std::vector<std::string>::iterator fi = fmt.begin();
3244 fi != fmt.end(); ++fi)
3248 format = FortranFormatFixed;
3252 format = FortranFormatFree;
3259 //----------------------------------------------------------------------------
3261 cmLocalGenerator::GetTargetDirectory(cmTarget const&) const
3263 cmSystemTools::Error("GetTargetDirectory"
3264 " called on cmLocalGenerator");
3268 //----------------------------------------------------------------------------
3269 unsigned int cmLocalGenerator::GetBackwardsCompatibility()
3271 // The computed version may change until the project is fully
3273 if(!this->BackwardsCompatibilityFinal)
3275 unsigned int major = 0;
3276 unsigned int minor = 0;
3277 unsigned int patch = 0;
3278 if(const char* value
3279 = this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"))
3281 switch(sscanf(value, "%u.%u.%u", &major, &minor, &patch))
3283 case 2: patch = 0; break;
3284 case 1: minor = 0; patch = 0; break;
3288 this->BackwardsCompatibility = CMake_VERSION_ENCODE(major, minor, patch);
3289 this->BackwardsCompatibilityFinal = this->Configured;
3292 return this->BackwardsCompatibility;
3295 //----------------------------------------------------------------------------
3296 bool cmLocalGenerator::NeedBackwardsCompatibility(unsigned int major,
3300 // Check the policy to decide whether to pay attention to this
3302 switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0001))
3304 case cmPolicies::WARN:
3305 // WARN is just OLD without warning because user code does not
3306 // always affect whether this check is done.
3307 case cmPolicies::OLD:
3308 // Old behavior is to check the variable.
3310 case cmPolicies::NEW:
3311 // New behavior is to ignore the variable.
3313 case cmPolicies::REQUIRED_IF_USED:
3314 case cmPolicies::REQUIRED_ALWAYS:
3315 // This will never be the case because the only way to require
3316 // the setting is to require the user to specify version policy
3317 // 2.6 or higher. Once we add that requirement then this whole
3318 // method can be removed anyway.
3322 // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set
3323 // equal to or lower than the given version.
3324 unsigned int actual_compat = this->GetBackwardsCompatibility();
3325 return (actual_compat &&
3326 actual_compat <= CMake_VERSION_ENCODE(major, minor, patch));
3329 //----------------------------------------------------------------------------
3330 bool cmLocalGenerator::CheckDefinition(std::string const& define) const
3332 // Many compilers do not support -DNAME(arg)=sdf so we disable it.
3333 bool function_style = false;
3334 for(const char* c = define.c_str(); *c && *c != '='; ++c)
3338 function_style = true;
3345 e << "WARNING: Function-style preprocessor definitions may not be "
3346 << "passed on the compiler command line because many compilers "
3347 << "do not support it.\n"
3348 << "CMake is dropping a preprocessor definition: " << define << "\n"
3349 << "Consider defining the macro in a (configured) header file.\n";
3350 cmSystemTools::Message(e.str().c_str());
3354 // Many compilers do not support # in the value so we disable it.
3355 if(define.find_first_of("#") != define.npos)
3358 e << "WARNING: Preprocessor definitions containing '#' may not be "
3359 << "passed on the compiler command line because many compilers "
3360 << "do not support it.\n"
3361 << "CMake is dropping a preprocessor definition: " << define << "\n"
3362 << "Consider defining the macro in a (configured) header file.\n";
3363 cmSystemTools::Message(e.str().c_str());
3367 // Assume it is supported.
3371 //----------------------------------------------------------------------------
3372 static void cmLGInfoProp(cmMakefile* mf, cmTarget* target, const char* prop)
3374 if(const char* val = target->GetProperty(prop))
3376 mf->AddDefinition(prop, val);
3380 //----------------------------------------------------------------------------
3381 void cmLocalGenerator::GenerateAppleInfoPList(cmTarget* target,
3382 const char* targetName,
3385 // Find the Info.plist template.
3386 const char* in = target->GetProperty("MACOSX_BUNDLE_INFO_PLIST");
3387 std::string inFile = (in && *in)? in : "MacOSXBundleInfo.plist.in";
3388 if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
3390 std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
3396 if(!cmSystemTools::FileExists(inFile.c_str(), true))
3399 e << "Target " << target->GetName() << " Info.plist template \""
3400 << inFile << "\" could not be found.";
3401 cmSystemTools::Error(e.str().c_str());
3405 // Convert target properties to variables in an isolated makefile
3406 // scope to configure the file. If properties are set they will
3407 // override user make variables. If not the configuration will fall
3408 // back to the directory-level values set by the user.
3409 cmMakefile* mf = this->Makefile;
3411 mf->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName);
3412 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_INFO_STRING");
3413 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_ICON_FILE");
3414 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_GUI_IDENTIFIER");
3415 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_LONG_VERSION_STRING");
3416 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_NAME");
3417 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
3418 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_BUNDLE_VERSION");
3419 cmLGInfoProp(mf, target, "MACOSX_BUNDLE_COPYRIGHT");
3420 mf->ConfigureFile(inFile.c_str(), fname, false, false, false);
3424 //----------------------------------------------------------------------------
3425 void cmLocalGenerator::GenerateFrameworkInfoPList(cmTarget* target,
3426 const char* targetName,
3429 // Find the Info.plist template.
3430 const char* in = target->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST");
3431 std::string inFile = (in && *in)? in : "MacOSXFrameworkInfo.plist.in";
3432 if(!cmSystemTools::FileIsFullPath(inFile.c_str()))
3434 std::string inMod = this->Makefile->GetModulesFile(inFile.c_str());
3440 if(!cmSystemTools::FileExists(inFile.c_str(), true))
3443 e << "Target " << target->GetName() << " Info.plist template \""
3444 << inFile << "\" could not be found.";
3445 cmSystemTools::Error(e.str().c_str());
3449 // Convert target properties to variables in an isolated makefile
3450 // scope to configure the file. If properties are set they will
3451 // override user make variables. If not the configuration will fall
3452 // back to the directory-level values set by the user.
3453 cmMakefile* mf = this->Makefile;
3455 mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName);
3456 cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_ICON_FILE");
3457 cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER");
3458 cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
3459 cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
3460 mf->ConfigureFile(inFile.c_str(), fname, false, false, false);