1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmLocalGenerator.cxx,v $
6 Date: $Date: 2009-09-18 19:16:33 $
7 Version: $Revision: 1.313 $
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"
29 #include "cmTestGenerator.h"
30 #include "cmVersion.h"
33 #if defined(CMAKE_BUILD_WITH_CMAKE)
34 # define CM_LG_ENCODE_OBJECT_NAMES
35 # include <cmsys/MD5.h>
38 #include <cmsys/System.h>
40 #include <ctype.h> // for isalpha
44 cmLocalGenerator::cmLocalGenerator()
46 this->Makefile
= 0; // moved to after set on global
48 this->WindowsShell
= false;
49 this->WindowsVSIDE
= false;
50 this->WatcomWMake
= false;
51 this->MinGWMake
= false;
53 this->MSYSShell
= false;
54 this->LinkScriptShell
= false;
55 this->IgnoreLibPrefix
= false;
56 this->UseRelativePaths
= false;
57 this->Configured
= false;
58 this->EmitUniversalBinaryFlags
= true;
59 this->IsMakefileGenerator
= false;
60 this->RelativePathsConfigured
= false;
61 this->PathConversionsSetup
= false;
62 this->BackwardsCompatibility
= 0;
63 this->BackwardsCompatibilityFinal
= false;
66 cmLocalGenerator::~cmLocalGenerator()
68 delete this->Makefile
;
71 //----------------------------------------------------------------------------
72 class cmLocalGeneratorCurrent
74 cmGlobalGenerator
* GG
;
77 cmLocalGeneratorCurrent(cmLocalGenerator
* lg
)
79 this->GG
= lg
->GetGlobalGenerator();
80 this->LG
= this->GG
->GetCurrentLocalGenerator();
81 this->GG
->SetCurrentLocalGenerator(lg
);
83 ~cmLocalGeneratorCurrent()
85 this->GG
->SetCurrentLocalGenerator(this->LG
);
89 //----------------------------------------------------------------------------
90 void cmLocalGenerator::Configure()
92 // Manage the global generator's current local generator.
93 cmLocalGeneratorCurrent
clg(this);
94 static_cast<void>(clg
);
96 // make sure the CMakeFiles dir is there
97 std::string filesDir
= this->Makefile
->GetStartOutputDirectory();
98 filesDir
+= cmake::GetCMakeFilesDirectory();
99 cmSystemTools::MakeDirectory(filesDir
.c_str());
101 // find & read the list file
102 this->ReadInputFile();
104 // at the end of the ReadListFile handle any old style subdirs
105 // first get all the subdirectories
106 std::vector
<cmLocalGenerator
*> subdirs
= this->GetChildren();
108 // for each subdir recurse
109 std::vector
<cmLocalGenerator
*>::iterator sdi
= subdirs
.begin();
110 for (; sdi
!= subdirs
.end(); ++sdi
)
112 if (!(*sdi
)->Configured
)
114 this->Makefile
->ConfigureSubDirectory(*sdi
);
118 // Check whether relative paths should be used for optionally
120 this->UseRelativePaths
= this->Makefile
->IsOn("CMAKE_USE_RELATIVE_PATHS");
122 this->ComputeObjectMaxPath();
124 this->Configured
= true;
127 //----------------------------------------------------------------------------
128 void cmLocalGenerator::ComputeObjectMaxPath()
130 // Choose a maximum object file name length.
131 #if defined(_WIN32) || defined(__CYGWIN__)
132 this->ObjectPathMax
= 250;
134 this->ObjectPathMax
= 1000;
136 const char* plen
= this->Makefile
->GetDefinition("CMAKE_OBJECT_PATH_MAX");
140 if(sscanf(plen
, "%u", &pmax
) == 1)
144 this->ObjectPathMax
= pmax
;
149 w
<< "CMAKE_OBJECT_PATH_MAX is set to " << pmax
150 << ", which is less than the minimum of 128. "
151 << "The value will be ignored.";
152 this->Makefile
->IssueMessage(cmake::AUTHOR_WARNING
, w
.str());
158 w
<< "CMAKE_OBJECT_PATH_MAX is set to \"" << plen
159 << "\", which fails to parse as a positive integer. "
160 << "The value will be ignored.";
161 this->Makefile
->IssueMessage(cmake::AUTHOR_WARNING
, w
.str());
164 this->ObjectMaxPathViolations
.clear();
167 //----------------------------------------------------------------------------
168 void cmLocalGenerator::ReadInputFile()
170 // Look for the CMakeLists.txt file.
171 std::string currentStart
= this->Makefile
->GetStartDirectory();
172 currentStart
+= "/CMakeLists.txt";
173 if(cmSystemTools::FileExists(currentStart
.c_str(), true))
175 this->Makefile
->ReadListFile(currentStart
.c_str());
184 // The file is missing. Check policy CMP0014.
185 cmMakefile
* mf
= this->Parent
->GetMakefile();
187 e
<< "The source directory\n"
188 << " " << this->Makefile
->GetStartDirectory() << "\n"
189 << "does not contain a CMakeLists.txt file.";
190 switch (mf
->GetPolicyStatus(cmPolicies::CMP0014
))
192 case cmPolicies::WARN
:
193 // Print the warning.
195 << "CMake does not support this case but it used "
196 << "to work accidentally and is being allowed for "
199 << mf
->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0014
);
200 mf
->IssueMessage(cmake::AUTHOR_WARNING
, e
.str());
201 case cmPolicies::OLD
:
202 // OLD behavior does not warn.
204 case cmPolicies::REQUIRED_IF_USED
:
205 case cmPolicies::REQUIRED_ALWAYS
:
207 << mf
->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP0014
);
208 case cmPolicies::NEW
:
209 // NEW behavior prints the error.
210 mf
->IssueMessage(cmake::FATAL_ERROR
, e
.str());
215 void cmLocalGenerator::SetupPathConversions()
217 // Setup the current output directory components for use by
221 cmSystemTools::CollapseFullPath(this->Makefile
->GetHomeDirectory());
222 cmSystemTools::SplitPath(outdir
.c_str(), this->HomeDirectoryComponents
);
224 cmSystemTools::CollapseFullPath(this->Makefile
->GetStartDirectory());
225 cmSystemTools::SplitPath(outdir
.c_str(), this->StartDirectoryComponents
);
227 outdir
= cmSystemTools::CollapseFullPath
228 (this->Makefile
->GetHomeOutputDirectory());
229 cmSystemTools::SplitPath(outdir
.c_str(),
230 this->HomeOutputDirectoryComponents
);
232 outdir
= cmSystemTools::CollapseFullPath
233 (this->Makefile
->GetStartOutputDirectory());
234 cmSystemTools::SplitPath(outdir
.c_str(),
235 this->StartOutputDirectoryComponents
);
239 void cmLocalGenerator::SetGlobalGenerator(cmGlobalGenerator
*gg
)
241 this->GlobalGenerator
= gg
;
242 this->Makefile
= new cmMakefile
;
243 this->Makefile
->SetLocalGenerator(this);
245 // setup the home directories
246 this->Makefile
->GetProperties().SetCMakeInstance(gg
->GetCMakeInstance());
247 this->Makefile
->SetHomeDirectory(
248 gg
->GetCMakeInstance()->GetHomeDirectory());
249 this->Makefile
->SetHomeOutputDirectory(
250 gg
->GetCMakeInstance()->GetHomeOutputDirectory());
253 void cmLocalGenerator::ConfigureFinalPass()
255 this->Makefile
->ConfigureFinalPass();
258 void cmLocalGenerator::TraceDependencies()
260 // Generate the rule files for each target.
261 cmTargets
& targets
= this->Makefile
->GetTargets();
262 for(cmTargets::iterator t
= targets
.begin(); t
!= targets
.end(); ++t
)
264 const char* projectFilename
= 0;
265 if (this->IsMakefileGenerator
== false) // only use of this variable
267 projectFilename
= t
->second
.GetName();
269 t
->second
.TraceDependencies(projectFilename
);
273 void cmLocalGenerator::GenerateTestFiles()
275 if ( !this->Makefile
->IsOn("CMAKE_TESTING_ENABLED") )
280 // Compute the set of configurations.
281 std::vector
<std::string
> configurationTypes
;
282 if(const char* types
=
283 this->Makefile
->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
285 cmSystemTools::ExpandListArgument(types
, configurationTypes
);
287 const char* config
= 0;
288 if(configurationTypes
.empty())
290 config
= this->Makefile
->GetDefinition("CMAKE_BUILD_TYPE");
293 std::string file
= this->Makefile
->GetStartOutputDirectory();
295 file
+= "CTestTestfile.cmake";
297 cmGeneratedFileStream
fout(file
.c_str());
298 fout
.SetCopyIfDifferent(true);
300 fout
<< "# CMake generated Testfile for " << std::endl
301 << "# Source directory: "
302 << this->Makefile
->GetStartDirectory() << std::endl
303 << "# Build directory: "
304 << this->Makefile
->GetStartOutputDirectory() << std::endl
306 << "# This file includes the relevent testing commands "
307 << "required for " << std::endl
308 << "# testing this directory and lists subdirectories to "
309 << "be tested as well." << std::endl
;
311 const char* testIncludeFile
=
312 this->Makefile
->GetProperty("TEST_INCLUDE_FILE");
313 if ( testIncludeFile
)
315 fout
<< "INCLUDE(\"" << testIncludeFile
<< "\")" << std::endl
;
318 // Ask each test generator to write its code.
319 std::vector
<cmTestGenerator
*> const&
320 testers
= this->Makefile
->GetTestGenerators();
321 for(std::vector
<cmTestGenerator
*>::const_iterator gi
= testers
.begin();
322 gi
!= testers
.end(); ++gi
)
324 (*gi
)->Generate(fout
, config
, configurationTypes
);
326 if ( this->Children
.size())
329 for(i
= 0; i
< this->Children
.size(); ++i
)
333 this->Children
[i
]->GetMakefile()->GetStartOutputDirectory();
334 fout
<< this->Convert(outP
.c_str(),START_OUTPUT
);
335 fout
<< ")" << std::endl
;
340 //----------------------------------------------------------------------------
341 void cmLocalGenerator::GenerateInstallRules()
343 // Compute the install prefix.
344 const char* prefix
= this->Makefile
->GetDefinition("CMAKE_INSTALL_PREFIX");
345 #if defined(_WIN32) && !defined(__CYGWIN__)
346 std::string prefix_win32
;
349 if(!cmSystemTools::GetEnv("SystemDrive", prefix_win32
))
353 const char* project_name
= this->Makefile
->GetDefinition("PROJECT_NAME");
354 if(project_name
&& project_name
[0])
356 prefix_win32
+= "/Program Files/";
357 prefix_win32
+= project_name
;
361 prefix_win32
+= "/InstalledCMakeProject";
363 prefix
= prefix_win32
.c_str();
368 prefix
= "/usr/local";
372 // Compute the set of configurations.
373 std::vector
<std::string
> configurationTypes
;
374 if(const char* types
=
375 this->Makefile
->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
377 cmSystemTools::ExpandListArgument(types
, configurationTypes
);
379 const char* config
= 0;
380 if(configurationTypes
.empty())
382 config
= this->Makefile
->GetDefinition("CMAKE_BUILD_TYPE");
385 // Choose a default install configuration.
386 const char* default_config
= config
;
387 const char* default_order
[] = {"RELEASE", "MINSIZEREL",
388 "RELWITHDEBINFO", "DEBUG", 0};
389 for(const char** c
= default_order
; *c
&& !default_config
; ++c
)
391 for(std::vector
<std::string
>::iterator i
= configurationTypes
.begin();
392 i
!= configurationTypes
.end(); ++i
)
394 if(cmSystemTools::UpperCase(*i
) == *c
)
396 default_config
= i
->c_str();
400 if(!default_config
&& !configurationTypes
.empty())
402 default_config
= configurationTypes
[0].c_str();
406 default_config
= "Release";
409 // Create the install script file.
410 std::string file
= this->Makefile
->GetStartOutputDirectory();
411 std::string homedir
= this->Makefile
->GetHomeOutputDirectory();
412 std::string currdir
= this->Makefile
->GetCurrentOutputDirectory();
413 cmSystemTools::ConvertToUnixSlashes(file
);
414 cmSystemTools::ConvertToUnixSlashes(homedir
);
415 cmSystemTools::ConvertToUnixSlashes(currdir
);
416 int toplevel_install
= 0;
417 if ( currdir
== homedir
)
419 toplevel_install
= 1;
421 file
+= "/cmake_install.cmake";
422 cmGeneratedFileStream
fout(file
.c_str());
423 fout
.SetCopyIfDifferent(true);
426 fout
<< "# Install script for directory: "
427 << this->Makefile
->GetCurrentDirectory() << std::endl
<< std::endl
;
428 fout
<< "# Set the install prefix" << std::endl
429 << "IF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
430 << " SET(CMAKE_INSTALL_PREFIX \"" << prefix
<< "\")" << std::endl
431 << "ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
432 << "STRING(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
433 << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
436 // Write support code for generating per-configuration install rules.
438 "# Set the install configuration name.\n"
439 "IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
441 " STRING(REGEX REPLACE \"^[^A-Za-z0-9_]+\" \"\"\n"
442 " CMAKE_INSTALL_CONFIG_NAME \"${BUILD_TYPE}\")\n"
443 " ELSE(BUILD_TYPE)\n"
444 " SET(CMAKE_INSTALL_CONFIG_NAME \"" << default_config
<< "\")\n"
445 " ENDIF(BUILD_TYPE)\n"
446 " MESSAGE(STATUS \"Install configuration: "
447 "\\\"${CMAKE_INSTALL_CONFIG_NAME}\\\"\")\n"
448 "ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)\n"
451 // Write support code for dealing with component-specific installs.
453 "# Set the component getting installed.\n"
454 "IF(NOT CMAKE_INSTALL_COMPONENT)\n"
456 " MESSAGE(STATUS \"Install component: \\\"${COMPONENT}\\\"\")\n"
457 " SET(CMAKE_INSTALL_COMPONENT \"${COMPONENT}\")\n"
459 " SET(CMAKE_INSTALL_COMPONENT)\n"
460 " ENDIF(COMPONENT)\n"
461 "ENDIF(NOT CMAKE_INSTALL_COMPONENT)\n"
464 // Copy user-specified install options to the install code.
465 if(const char* so_no_exe
=
466 this->Makefile
->GetDefinition("CMAKE_INSTALL_SO_NO_EXE"))
469 "# Install shared libraries without execute permission?\n"
470 "IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
471 " SET(CMAKE_INSTALL_SO_NO_EXE \"" << so_no_exe
<< "\")\n"
472 "ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)\n"
476 // Ask each install generator to write its code.
477 std::vector
<cmInstallGenerator
*> const& installers
=
478 this->Makefile
->GetInstallGenerators();
479 for(std::vector
<cmInstallGenerator
*>::const_iterator
480 gi
= installers
.begin();
481 gi
!= installers
.end(); ++gi
)
483 (*gi
)->Generate(fout
, config
, configurationTypes
);
486 // Write rules from old-style specification stored in targets.
487 this->GenerateTargetInstallRules(fout
, config
, configurationTypes
);
489 // Include install scripts from subdirectories.
490 if(!this->Children
.empty())
492 fout
<< "IF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
493 fout
<< " # Include the install script for each subdirectory.\n";
494 for(std::vector
<cmLocalGenerator
*>::const_iterator
495 ci
= this->Children
.begin(); ci
!= this->Children
.end(); ++ci
)
497 if(!(*ci
)->GetMakefile()->GetPropertyAsBool("EXCLUDE_FROM_ALL"))
499 std::string odir
= (*ci
)->GetMakefile()->GetStartOutputDirectory();
500 cmSystemTools::ConvertToUnixSlashes(odir
);
501 fout
<< " INCLUDE(\"" << odir
.c_str()
502 << "/cmake_install.cmake\")" << std::endl
;
506 fout
<< "ENDIF(NOT CMAKE_INSTALL_LOCAL_ONLY)\n\n";
509 // Record the install manifest.
510 if ( toplevel_install
)
513 "IF(CMAKE_INSTALL_COMPONENT)\n"
514 " SET(CMAKE_INSTALL_MANIFEST \"install_manifest_"
515 "${CMAKE_INSTALL_COMPONENT}.txt\")\n"
516 "ELSE(CMAKE_INSTALL_COMPONENT)\n"
517 " SET(CMAKE_INSTALL_MANIFEST \"install_manifest.txt\")\n"
518 "ENDIF(CMAKE_INSTALL_COMPONENT)\n\n";
521 << homedir
.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
522 << "\"\")" << std::endl
;
524 << "FOREACH(file ${CMAKE_INSTALL_MANIFEST_FILES})" << std::endl
526 << homedir
.c_str() << "/${CMAKE_INSTALL_MANIFEST}\" "
527 << "\"${file}\\n\")" << std::endl
528 << "ENDFOREACH(file)" << std::endl
;
532 //----------------------------------------------------------------------------
533 void cmLocalGenerator::GenerateTargetManifest()
535 // Collect the set of configuration types.
536 std::vector
<std::string
> configNames
;
537 if(const char* configurationTypes
=
538 this->Makefile
->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
540 cmSystemTools::ExpandListArgument(configurationTypes
, configNames
);
542 else if(const char* buildType
=
543 this->Makefile
->GetDefinition("CMAKE_BUILD_TYPE"))
547 configNames
.push_back(buildType
);
551 // Add our targets to the manifest for each configuration.
552 cmTargets
& targets
= this->Makefile
->GetTargets();
553 for(cmTargets::iterator t
= targets
.begin(); t
!= targets
.end(); ++t
)
555 cmTarget
& target
= t
->second
;
556 if(configNames
.empty())
558 target
.GenerateTargetManifest(0);
562 for(std::vector
<std::string
>::iterator ci
= configNames
.begin();
563 ci
!= configNames
.end(); ++ci
)
565 const char* config
= ci
->c_str();
566 target
.GenerateTargetManifest(config
);
572 void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname
,
574 cmSourceFile
& source
,
577 std::string objectDir
= cmSystemTools::GetFilenamePath(std::string(ofname
));
578 objectDir
= this->Convert(objectDir
.c_str(),START_OUTPUT
,SHELL
);
579 std::string objectFile
= this->Convert(ofname
,START_OUTPUT
,SHELL
);
580 std::string sourceFile
=
581 this->Convert(source
.GetFullPath().c_str(),START_OUTPUT
,SHELL
,true);
582 std::string varString
= "CMAKE_";
584 varString
+= "_COMPILE_OBJECT";
585 std::vector
<std::string
> rules
;
586 rules
.push_back(this->Makefile
->GetRequiredDefinition(varString
.c_str()));
587 varString
= "CMAKE_";
589 varString
+= "_FLAGS";
591 flags
+= this->Makefile
->GetSafeDefinition(varString
.c_str());
593 flags
+= this->GetIncludeFlags(lang
);
595 // Construct the command lines.
596 cmCustomCommandLines commandLines
;
597 std::vector
<std::string
> commands
;
598 cmSystemTools::ExpandList(rules
, commands
);
599 cmLocalGenerator::RuleVariables vars
;
600 vars
.Language
= lang
;
601 vars
.Source
= sourceFile
.c_str();
602 vars
.Object
= objectFile
.c_str();
603 vars
.ObjectDir
= objectDir
.c_str();
604 vars
.Flags
= flags
.c_str();
605 for(std::vector
<std::string
>::iterator i
= commands
.begin();
606 i
!= commands
.end(); ++i
)
608 // Expand the full command line string.
609 this->ExpandRuleVariables(*i
, vars
);
611 // Parse the string to get the custom command line.
612 cmCustomCommandLine commandLine
;
613 std::vector
<cmStdString
> cmd
= cmSystemTools::ParseArguments(i
->c_str());
614 for(std::vector
<cmStdString
>::iterator a
= cmd
.begin();
617 commandLine
.push_back(*a
);
620 // Store this command line.
621 commandLines
.push_back(commandLine
);
624 // Check for extra object-file dependencies.
625 std::vector
<std::string
> depends
;
626 const char* additionalDeps
= source
.GetProperty("OBJECT_DEPENDS");
629 cmSystemTools::ExpandListArgument(additionalDeps
, depends
);
632 // Generate a meaningful comment for the command.
633 std::string comment
= "Building ";
635 comment
+= " object ";
636 comment
+= this->Convert(ofname
, START_OUTPUT
);
638 // Add the custom command to build the object file.
639 this->Makefile
->AddCustomCommandToOutput(
642 source
.GetFullPath().c_str(),
645 this->Makefile
->GetStartOutputDirectory()
649 void cmLocalGenerator::AddBuildTargetRule(const char* llang
, cmTarget
& target
)
652 std::vector
<std::string
> objVector
;
653 // Add all the sources outputs to the depends of the target
654 std::vector
<cmSourceFile
*> const& classes
= target
.GetSourceFiles();
655 for(std::vector
<cmSourceFile
*>::const_iterator i
= classes
.begin();
656 i
!= classes
.end(); ++i
)
658 cmSourceFile
* sf
= *i
;
659 if(!sf
->GetCustomCommand() &&
660 !sf
->GetPropertyAsBool("HEADER_FILE_ONLY") &&
661 !sf
->GetPropertyAsBool("EXTERNAL_OBJECT"))
664 dir_max
+= this->Makefile
->GetCurrentOutputDirectory();
666 std::string obj
= this->GetObjectFileNameWithoutTarget(*sf
, dir_max
);
669 std::string ofname
= this->Makefile
->GetCurrentOutputDirectory();
672 objVector
.push_back(ofname
);
673 this->AddCustomCommandToCreateObject(ofname
.c_str(),
674 llang
, *(*i
), target
);
675 objs
+= this->Convert(ofname
.c_str(),START_OUTPUT
,MAKEFILE
);
680 std::string createRule
= "CMAKE_";
682 createRule
+= target
.GetCreateRuleVariable();
683 std::string targetName
= target
.GetFullName();
688 std::string linkLibs
; // should be set
689 std::string flags
; // should be set
690 std::string linkFlags
; // should be set
691 this->GetTargetFlags(linkLibs
, flags
, linkFlags
, target
);
692 cmLocalGenerator::RuleVariables vars
;
693 vars
.Language
= llang
;
694 vars
.Objects
= objs
.c_str();
695 vars
.ObjectDir
= ".";
696 vars
.Target
= targetName
.c_str();
697 vars
.LinkLibraries
= linkLibs
.c_str();
698 vars
.Flags
= flags
.c_str();
699 vars
.LinkFlags
= linkFlags
.c_str();
701 std::string langFlags
;
702 this->AddLanguageFlags(langFlags
, llang
, 0);
703 vars
.LanguageCompileFlags
= langFlags
.c_str();
705 cmCustomCommandLines commandLines
;
706 std::vector
<std::string
> rules
;
707 rules
.push_back(this->Makefile
->GetRequiredDefinition(createRule
.c_str()));
708 std::vector
<std::string
> commands
;
709 cmSystemTools::ExpandList(rules
, commands
);
710 for(std::vector
<std::string
>::iterator i
= commands
.begin();
711 i
!= commands
.end(); ++i
)
713 // Expand the full command line string.
714 this->ExpandRuleVariables(*i
, vars
);
715 // Parse the string to get the custom command line.
716 cmCustomCommandLine commandLine
;
717 std::vector
<cmStdString
> cmd
= cmSystemTools::ParseArguments(i
->c_str());
718 for(std::vector
<cmStdString
>::iterator a
= cmd
.begin();
721 commandLine
.push_back(*a
);
724 // Store this command line.
725 commandLines
.push_back(commandLine
);
727 std::string targetFullPath
= target
.GetFullPath();
728 // Generate a meaningful comment for the command.
729 std::string comment
= "Linking ";
731 comment
+= " target ";
732 comment
+= this->Convert(targetFullPath
.c_str(), START_OUTPUT
);
733 this->Makefile
->AddCustomCommandToOutput(
734 targetFullPath
.c_str(),
739 this->Makefile
->GetStartOutputDirectory()
742 (this->Makefile
->GetSource(targetFullPath
.c_str()));
746 void cmLocalGenerator
747 ::CreateCustomTargetsAndCommands(std::set
<cmStdString
> const& lang
)
749 cmTargets
&tgts
= this->Makefile
->GetTargets();
750 for(cmTargets::iterator l
= tgts
.begin();
751 l
!= tgts
.end(); l
++)
753 cmTarget
& target
= l
->second
;
754 switch(target
.GetType())
756 case cmTarget::STATIC_LIBRARY
:
757 case cmTarget::SHARED_LIBRARY
:
758 case cmTarget::MODULE_LIBRARY
:
759 case cmTarget::EXECUTABLE
:
761 const char* llang
= target
.GetLinkerLanguage();
765 ("CMake can not determine linker language for target:",
769 // if the language is not in the set lang then create custom
770 // commands to build the target
771 if(lang
.count(llang
) == 0)
773 this->AddBuildTargetRule(llang
, target
);
783 // List of variables that are replaced when
784 // rules are expanced. These variables are
785 // replaced in the form <var> with GetSafeDefinition(var).
786 // ${LANG} is replaced in the variable first with all enabled
788 static const char* ruleReplaceVars
[] =
790 "CMAKE_${LANG}_COMPILER",
791 "CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
792 "CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
793 "CMAKE_SHARED_MODULE_${LANG}_FLAGS",
794 "CMAKE_SHARED_LIBRARY_${LANG}_FLAGS",
795 "CMAKE_${LANG}_LINK_FLAGS",
796 "CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
797 "CMAKE_${LANG}_ARCHIVE",
799 "CMAKE_CURRENT_SOURCE_DIR",
800 "CMAKE_CURRENT_BINARY_DIR",
807 cmLocalGenerator::ExpandRuleVariable(std::string
const& variable
,
808 const RuleVariables
& replaceValues
)
810 if(replaceValues
.LinkFlags
)
812 if(variable
== "LINK_FLAGS")
814 return replaceValues
.LinkFlags
;
817 if(replaceValues
.Flags
)
819 if(variable
== "FLAGS")
821 return replaceValues
.Flags
;
825 if(replaceValues
.Source
)
827 if(variable
== "SOURCE")
829 return replaceValues
.Source
;
832 if(replaceValues
.PreprocessedSource
)
834 if(variable
== "PREPROCESSED_SOURCE")
836 return replaceValues
.PreprocessedSource
;
839 if(replaceValues
.AssemblySource
)
841 if(variable
== "ASSEMBLY_SOURCE")
843 return replaceValues
.AssemblySource
;
846 if(replaceValues
.Object
)
848 if(variable
== "OBJECT")
850 return replaceValues
.Object
;
853 if(replaceValues
.ObjectDir
)
855 if(variable
== "OBJECT_DIR")
857 return replaceValues
.ObjectDir
;
860 if(replaceValues
.Objects
)
862 if(variable
== "OBJECTS")
864 return replaceValues
.Objects
;
867 if(replaceValues
.ObjectsQuoted
)
869 if(variable
== "OBJECTS_QUOTED")
871 return replaceValues
.ObjectsQuoted
;
874 if(replaceValues
.Defines
&& variable
== "DEFINES")
876 return replaceValues
.Defines
;
878 if(replaceValues
.TargetPDB
)
880 if(variable
== "TARGET_PDB")
882 return replaceValues
.TargetPDB
;
886 if(replaceValues
.Target
)
888 if(variable
== "TARGET_QUOTED")
890 std::string targetQuoted
= replaceValues
.Target
;
891 if(targetQuoted
.size() && targetQuoted
[0] != '\"')
894 targetQuoted
+= replaceValues
.Target
;
895 targetQuoted
+= '\"';
899 if(replaceValues
.LanguageCompileFlags
)
901 if(variable
== "LANGUAGE_COMPILE_FLAGS")
903 return replaceValues
.LanguageCompileFlags
;
906 if(replaceValues
.Target
)
908 if(variable
== "TARGET")
910 return replaceValues
.Target
;
913 if(variable
== "TARGET_IMPLIB")
915 return this->TargetImplib
;
917 if(variable
== "TARGET_VERSION_MAJOR")
919 if(replaceValues
.TargetVersionMajor
)
921 return replaceValues
.TargetVersionMajor
;
928 if(variable
== "TARGET_VERSION_MINOR")
930 if(replaceValues
.TargetVersionMinor
)
932 return replaceValues
.TargetVersionMinor
;
939 if(replaceValues
.Target
)
941 if(variable
== "TARGET_BASE")
943 // Strip the last extension off the target name.
944 std::string targetBase
= replaceValues
.Target
;
945 std::string::size_type pos
= targetBase
.rfind(".");
946 if(pos
!= targetBase
.npos
)
948 return targetBase
.substr(0, pos
);
957 if(replaceValues
.TargetSOName
)
959 if(variable
== "TARGET_SONAME")
961 if(replaceValues
.Language
)
963 std::string name
= "CMAKE_SHARED_LIBRARY_SONAME_";
964 name
+= replaceValues
.Language
;
966 if(this->Makefile
->GetDefinition(name
.c_str()))
968 return replaceValues
.TargetSOName
;
974 if(replaceValues
.TargetInstallNameDir
)
976 if(variable
== "TARGET_INSTALLNAME_DIR")
978 return replaceValues
.TargetInstallNameDir
;
981 if(replaceValues
.LinkLibraries
)
983 if(variable
== "LINK_LIBRARIES")
985 return replaceValues
.LinkLibraries
;
988 if(replaceValues
.Language
)
990 if(variable
== "LANGUAGE")
992 return replaceValues
.Language
;
995 if(replaceValues
.CMTarget
)
997 if(variable
== "TARGET_NAME")
999 return replaceValues
.CMTarget
->GetName();
1001 if(variable
== "TARGET_TYPE")
1003 return cmTarget::TargetTypeNames
[replaceValues
.CMTarget
->GetType()];
1006 if(replaceValues
.Output
)
1008 if(variable
== "OUTPUT")
1010 return replaceValues
.Output
;
1013 if(variable
== "CMAKE_COMMAND")
1015 const char* cmcommand
=
1016 this->GetMakefile()->GetDefinition("CMAKE_COMMAND");
1017 return this->Convert(cmcommand
, FULL
, SHELL
);
1019 std::vector
<std::string
> enabledLanguages
;
1020 this->GlobalGenerator
->GetEnabledLanguages(enabledLanguages
);
1021 // loop over language specific replace variables
1023 while(ruleReplaceVars
[pos
])
1025 for(std::vector
<std::string
>::iterator i
= enabledLanguages
.begin();
1026 i
!= enabledLanguages
.end(); ++i
)
1028 const char* lang
= i
->c_str();
1029 std::string actualReplace
= ruleReplaceVars
[pos
];
1030 // If this is the compiler then look for the extra variable
1031 // _COMPILER_ARG1 which must be the first argument to the compiler
1032 const char* compilerArg1
= 0;
1033 if(actualReplace
== "CMAKE_${LANG}_COMPILER")
1035 std::string arg1
= actualReplace
+ "_ARG1";
1036 cmSystemTools::ReplaceString(arg1
, "${LANG}", lang
);
1037 compilerArg1
= this->Makefile
->GetDefinition(arg1
.c_str());
1039 if(actualReplace
.find("${LANG}") != actualReplace
.npos
)
1041 cmSystemTools::ReplaceString(actualReplace
, "${LANG}", lang
);
1043 if(actualReplace
== variable
)
1045 std::string replace
=
1046 this->Makefile
->GetSafeDefinition(variable
.c_str());
1047 // if the variable is not a FLAG then treat it like a path
1048 if(variable
.find("_FLAG") == variable
.npos
)
1050 std::string ret
= this->ConvertToOutputForExisting(replace
.c_str());
1051 // if there is a required first argument to the compiler add it
1052 // to the compiler string
1056 ret
+= compilerArg1
;
1070 cmLocalGenerator::ExpandRuleVariables(std::string
& s
,
1071 const RuleVariables
& replaceValues
)
1073 std::vector
<std::string
> enabledLanguages
;
1074 this->GlobalGenerator
->GetEnabledLanguages(enabledLanguages
);
1075 this->InsertRuleLauncher(s
, replaceValues
.CMTarget
,
1076 replaceValues
.RuleLauncher
);
1077 std::string::size_type start
= s
.find('<');
1078 // no variables to expand
1083 std::string::size_type pos
= 0;
1084 std::string expandedInput
;
1085 while(start
!= s
.npos
&& start
< s
.size()-2)
1087 std::string::size_type end
= s
.find('>', start
);
1088 // if we find a < with no > we are done
1093 char c
= s
[start
+1];
1094 // if the next char after the < is not A-Za-z then
1095 // skip it and try to find the next < in the string
1098 start
= s
.find('<', start
+1);
1103 std::string var
= s
.substr(start
+1, end
- start
-1);
1104 std::string replace
= this->ExpandRuleVariable(var
,
1106 expandedInput
+= s
.substr(pos
, start
-pos
);
1107 expandedInput
+= replace
;
1109 start
= s
.find('<', start
+var
.size()+2);
1113 // add the rest of the input
1114 expandedInput
+= s
.substr(pos
, s
.size()-pos
);
1118 //----------------------------------------------------------------------------
1119 const char* cmLocalGenerator::GetRuleLauncher(cmTarget
* target
,
1124 return target
->GetProperty(prop
);
1128 return this->Makefile
->GetProperty(prop
);
1132 //----------------------------------------------------------------------------
1133 void cmLocalGenerator::InsertRuleLauncher(std::string
& s
, cmTarget
* target
,
1136 if(const char* val
= this->GetRuleLauncher(target
, prop
))
1138 cmOStringStream wrapped
;
1139 wrapped
<< val
<< " " << s
;
1144 //----------------------------------------------------------------------------
1146 cmLocalGenerator::ConvertToOutputForExistingCommon(const char* remote
,
1147 std::string
const& result
)
1149 // If this is a windows shell, the result has a space, and the path
1150 // already exists, we can use a short-path to reference it without a
1152 if(this->WindowsShell
&& result
.find(' ') != result
.npos
&&
1153 cmSystemTools::FileExists(remote
))
1156 if(cmSystemTools::GetShortPath(remote
, tmp
))
1158 return this->Convert(tmp
.c_str(), NONE
, SHELL
, true);
1162 // Otherwise, leave it unchanged.
1166 //----------------------------------------------------------------------------
1168 cmLocalGenerator::ConvertToOutputForExisting(const char* remote
,
1171 // Perform standard conversion.
1172 std::string result
= this->Convert(remote
, local
, SHELL
, true);
1174 // Consider short-path.
1175 return this->ConvertToOutputForExistingCommon(remote
, result
);
1178 //----------------------------------------------------------------------------
1180 cmLocalGenerator::ConvertToOutputForExisting(RelativeRoot remote
,
1183 // Perform standard conversion.
1184 std::string result
= this->Convert(remote
, local
, SHELL
, true);
1186 // Consider short-path.
1187 const char* remotePath
= this->GetRelativeRootPath(remote
);
1188 return this->ConvertToOutputForExistingCommon(remotePath
, result
);
1191 //----------------------------------------------------------------------------
1192 const char* cmLocalGenerator::GetIncludeFlags(const char* lang
)
1198 if(this->LanguageToIncludeFlags
.count(lang
))
1200 return this->LanguageToIncludeFlags
[lang
].c_str();
1203 cmOStringStream includeFlags
;
1204 std::vector
<std::string
> includes
;
1205 this->GetIncludeDirectories(includes
, lang
);
1206 std::vector
<std::string
>::iterator i
;
1208 std::string flagVar
= "CMAKE_INCLUDE_FLAG_";
1210 const char* includeFlag
=
1211 this->Makefile
->GetSafeDefinition(flagVar
.c_str());
1212 flagVar
= "CMAKE_INCLUDE_FLAG_SEP_";
1214 const char* sep
= this->Makefile
->GetDefinition(flagVar
.c_str());
1215 bool quotePaths
= false;
1216 if(this->Makefile
->GetDefinition("CMAKE_QUOTE_INCLUDE_PATHS"))
1220 bool repeatFlag
= true;
1221 // should the include flag be repeated like ie. -IA -IB
1228 // if there is a separator then the flag is not repeated but is only
1229 // given once i.e. -classpath a:b:c
1233 // Support special system include flag if it is available and the
1234 // normal flag is repeated for each directory.
1235 std::string sysFlagVar
= "CMAKE_INCLUDE_SYSTEM_FLAG_";
1237 const char* sysIncludeFlag
= 0;
1240 sysIncludeFlag
= this->Makefile
->GetDefinition(sysFlagVar
.c_str());
1243 bool flagUsed
= false;
1244 std::set
<cmStdString
> emitted
;
1246 emitted
.insert("/System/Library/Frameworks");
1248 for(i
= includes
.begin(); i
!= includes
.end(); ++i
)
1251 if(cmSystemTools::IsPathToFramework(i
->c_str()))
1253 std::string frameworkDir
= *i
;
1254 frameworkDir
+= "/../";
1255 frameworkDir
= cmSystemTools::CollapseFullPath(frameworkDir
.c_str());
1256 if(emitted
.insert(frameworkDir
).second
)
1259 << "-F" << this->Convert(frameworkDir
.c_str(),
1260 cmLocalGenerator::START_OUTPUT
,
1261 cmLocalGenerator::SHELL
, true)
1267 std::string include
= *i
;
1268 if(!flagUsed
|| repeatFlag
)
1270 if(sysIncludeFlag
&&
1271 this->Makefile
->IsSystemIncludeDirectory(i
->c_str()))
1273 includeFlags
<< sysIncludeFlag
;
1277 includeFlags
<< includeFlag
;
1281 std::string includePath
= this->ConvertToOutputForExisting(i
->c_str());
1282 if(quotePaths
&& includePath
.size() && includePath
[0] != '\"')
1284 includeFlags
<< "\"";
1286 includeFlags
<< includePath
;
1287 if(quotePaths
&& includePath
.size() && includePath
[0] != '\"')
1289 includeFlags
<< "\"";
1291 includeFlags
<< sep
;
1293 std::string flags
= includeFlags
.str();
1294 // remove trailing separators
1295 if((sep
[0] != ' ') && flags
.size()>0 && flags
[flags
.size()-1] == sep
[0])
1297 flags
[flags
.size()-1] = ' ';
1299 std::string defineFlags
= this->Makefile
->GetDefineFlags();
1300 flags
+= defineFlags
;
1301 this->LanguageToIncludeFlags
[lang
] = flags
;
1303 // Use this temorary variable for the return value to work-around a
1304 // bogus GCC 2.95 warning.
1305 const char* ret
= this->LanguageToIncludeFlags
[lang
].c_str();
1309 //----------------------------------------------------------------------------
1310 void cmLocalGenerator::GetIncludeDirectories(std::vector
<std::string
>& dirs
,
1313 // Need to decide whether to automatically include the source and
1314 // binary directories at the beginning of the include path.
1315 bool includeSourceDir
= false;
1316 bool includeBinaryDir
= false;
1318 // When automatic include directories are requested for a build then
1319 // include the source and binary directories at the beginning of the
1320 // include path to approximate include file behavior for an
1321 // in-source build. This does not account for the case of a source
1322 // file in a subdirectory of the current source directory but we
1323 // cannot fix this because not all native build tools support
1324 // per-source-file include paths.
1325 if(this->Makefile
->IsOn("CMAKE_INCLUDE_CURRENT_DIR"))
1327 includeSourceDir
= true;
1328 includeBinaryDir
= true;
1331 // CMake versions below 2.0 would add the source tree to the -I path
1332 // automatically. Preserve compatibility.
1333 if(this->NeedBackwardsCompatibility(1,9))
1335 includeSourceDir
= true;
1338 // Hack for VTK 4.0 - 4.4 which depend on the old behavior but do
1339 // not set the backwards compatibility level automatically.
1340 const char* vtkSourceDir
=
1341 this->Makefile
->GetDefinition("VTK_SOURCE_DIR");
1344 const char* vtk_major
=
1345 this->Makefile
->GetDefinition("VTK_MAJOR_VERSION");
1346 const char* vtk_minor
=
1347 this->Makefile
->GetDefinition("VTK_MINOR_VERSION");
1348 vtk_major
= vtk_major
? vtk_major
: "4";
1349 vtk_minor
= vtk_minor
? vtk_minor
: "4";
1352 if(sscanf(vtk_major
, "%d", &vmajor
) &&
1353 sscanf(vtk_minor
, "%d", &vminor
) && vmajor
== 4 && vminor
<= 4)
1355 includeSourceDir
= true;
1359 // Do not repeat an include path.
1360 std::set
<cmStdString
> emitted
;
1362 // Store the automatic include paths.
1363 if(includeBinaryDir
)
1365 dirs
.push_back(this->Makefile
->GetStartOutputDirectory());
1366 emitted
.insert(this->Makefile
->GetStartOutputDirectory());
1368 if(includeSourceDir
)
1370 if(emitted
.find(this->Makefile
->GetStartDirectory()) == emitted
.end())
1372 dirs
.push_back(this->Makefile
->GetStartDirectory());
1373 emitted
.insert(this->Makefile
->GetStartDirectory());
1377 // Load implicit include directories for this language.
1378 std::string impDirVar
= "CMAKE_";
1380 impDirVar
+= "_IMPLICIT_INCLUDE_DIRECTORIES";
1381 if(const char* value
= this->Makefile
->GetDefinition(impDirVar
.c_str()))
1383 std::vector
<std::string
> impDirVec
;
1384 cmSystemTools::ExpandListArgument(value
, impDirVec
);
1385 for(std::vector
<std::string
>::const_iterator i
= impDirVec
.begin();
1386 i
!= impDirVec
.end(); ++i
)
1392 // Get the project-specified include directories.
1393 std::vector
<std::string
>& includes
=
1394 this->Makefile
->GetIncludeDirectories();
1396 // Support putting all the in-project include directories first if
1397 // it is requested by the project.
1398 if(this->Makefile
->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"))
1400 const char* topSourceDir
= this->Makefile
->GetHomeDirectory();
1401 const char* topBinaryDir
= this->Makefile
->GetHomeOutputDirectory();
1402 for(std::vector
<std::string
>::iterator i
= includes
.begin();
1403 i
!= includes
.end(); ++i
)
1405 // Emit this directory only if it is a subdirectory of the
1406 // top-level source or binary tree.
1407 if(cmSystemTools::ComparePath(i
->c_str(), topSourceDir
) ||
1408 cmSystemTools::ComparePath(i
->c_str(), topBinaryDir
) ||
1409 cmSystemTools::IsSubDirectory(i
->c_str(), topSourceDir
) ||
1410 cmSystemTools::IsSubDirectory(i
->c_str(), topBinaryDir
))
1412 if(emitted
.insert(*i
).second
)
1420 // Construct the final ordered include directory list.
1421 for(std::vector
<std::string
>::iterator i
= includes
.begin();
1422 i
!= includes
.end(); ++i
)
1424 if(emitted
.insert(*i
).second
)
1431 void cmLocalGenerator::GetTargetFlags(std::string
& linkLibs
,
1433 std::string
& linkFlags
,
1436 std::string buildType
=
1437 this->Makefile
->GetSafeDefinition("CMAKE_BUILD_TYPE");
1438 buildType
= cmSystemTools::UpperCase(buildType
);
1439 const char* libraryLinkVariable
=
1440 "CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
1442 switch(target
.GetType())
1444 case cmTarget::STATIC_LIBRARY
:
1446 const char* targetLinkFlags
=
1447 target
.GetProperty("STATIC_LIBRARY_FLAGS");
1450 linkFlags
+= targetLinkFlags
;
1455 case cmTarget::MODULE_LIBRARY
:
1456 libraryLinkVariable
= "CMAKE_MODULE_LINKER_FLAGS";
1457 case cmTarget::SHARED_LIBRARY
:
1459 linkFlags
= this->Makefile
->GetSafeDefinition(libraryLinkVariable
);
1461 if(buildType
.size())
1463 std::string build
= libraryLinkVariable
;
1466 linkFlags
+= this->Makefile
->GetSafeDefinition(build
.c_str());
1469 if(this->Makefile
->IsOn("WIN32") &&
1470 !(this->Makefile
->IsOn("CYGWIN") || this->Makefile
->IsOn("MINGW")))
1472 const std::vector
<cmSourceFile
*>& sources
= target
.GetSourceFiles();
1473 for(std::vector
<cmSourceFile
*>::const_iterator i
= sources
.begin();
1474 i
!= sources
.end(); ++i
)
1476 cmSourceFile
* sf
= *i
;
1477 if(sf
->GetExtension() == "def")
1480 this->Makefile
->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
1481 linkFlags
+= this->Convert(sf
->GetFullPath().c_str(),
1482 START_OUTPUT
, SHELL
);
1487 const char* targetLinkFlags
= target
.GetProperty("LINK_FLAGS");
1490 linkFlags
+= targetLinkFlags
;
1492 std::string configLinkFlags
= targetLinkFlags
;
1493 configLinkFlags
+= buildType
;
1494 targetLinkFlags
= target
.GetProperty(configLinkFlags
.c_str());
1497 linkFlags
+= targetLinkFlags
;
1501 cmOStringStream linklibsStr
;
1502 this->OutputLinkLibraries(linklibsStr
, target
, false);
1503 linkLibs
= linklibsStr
.str();
1506 case cmTarget::EXECUTABLE
:
1509 this->Makefile
->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS");
1511 if(buildType
.size())
1513 std::string build
= "CMAKE_EXE_LINKER_FLAGS_";
1515 linkFlags
+= this->Makefile
->GetSafeDefinition(build
.c_str());
1518 const char* linkLanguage
= target
.GetLinkerLanguage();
1521 cmSystemTools::Error
1522 ("CMake can not determine linker language for target:",
1526 std::string langVar
= "CMAKE_";
1527 langVar
+= linkLanguage
;
1528 std::string flagsVar
= langVar
+ "_FLAGS";
1529 std::string sharedFlagsVar
= "CMAKE_SHARED_LIBRARY_";
1530 sharedFlagsVar
+= linkLanguage
;
1531 sharedFlagsVar
+= "_FLAGS";
1532 flags
+= this->Makefile
->GetSafeDefinition(flagsVar
.c_str());
1534 flags
+= this->Makefile
->GetSafeDefinition(sharedFlagsVar
.c_str());
1536 cmOStringStream linklibs
;
1537 this->OutputLinkLibraries(linklibs
, target
, false);
1538 linkLibs
= linklibs
.str();
1539 if(cmSystemTools::IsOn
1540 (this->Makefile
->GetDefinition("BUILD_SHARED_LIBS")))
1542 std::string sFlagVar
= std::string("CMAKE_SHARED_BUILD_")
1543 + linkLanguage
+ std::string("_FLAGS");
1544 linkFlags
+= this->Makefile
->GetSafeDefinition(sFlagVar
.c_str());
1547 if ( target
.GetPropertyAsBool("WIN32_EXECUTABLE") )
1550 this->Makefile
->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE");
1556 this->Makefile
->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE");
1559 const char* targetLinkFlags
= target
.GetProperty("LINK_FLAGS");
1562 linkFlags
+= targetLinkFlags
;
1564 std::string configLinkFlags
= targetLinkFlags
;
1565 configLinkFlags
+= buildType
;
1566 targetLinkFlags
= target
.GetProperty(configLinkFlags
.c_str());
1569 linkFlags
+= targetLinkFlags
;
1580 std::string
cmLocalGenerator::ConvertToLinkReference(std::string
const& lib
)
1582 #if defined(_WIN32) && !defined(__CYGWIN__)
1583 // Work-ardound command line parsing limitations in MSVC 6.0 and
1585 if(this->Makefile
->IsOn("MSVC60") || this->Makefile
->IsOn("WATCOM"))
1587 // Search for the last space.
1588 std::string::size_type pos
= lib
.rfind(' ');
1591 // Find the slash after the last space, if any.
1592 pos
= lib
.find('/', pos
);
1594 // Convert the portion of the path with a space to a short path.
1596 if(cmSystemTools::GetShortPath(lib
.substr(0, pos
).c_str(), sp
))
1598 // Append the rest of the path with no space.
1599 sp
+= lib
.substr(pos
);
1601 // Convert to an output path.
1602 return this->Convert(sp
.c_str(), NONE
, SHELL
);
1609 return this->Convert(lib
.c_str(), START_OUTPUT
, SHELL
);
1613 * Output the linking rules on a command line. For executables,
1614 * targetLibrary should be a NULL pointer. For libraries, it should point
1615 * to the name of the library. This will not link a library against itself.
1617 void cmLocalGenerator::OutputLinkLibraries(std::ostream
& fout
,
1621 const char* config
= this->Makefile
->GetDefinition("CMAKE_BUILD_TYPE");
1622 cmComputeLinkInformation
* pcli
= tgt
.GetLinkInformation(config
);
1627 cmComputeLinkInformation
& cli
= *pcli
;
1629 // Collect library linking flags command line options.
1630 std::string linkLibs
;
1632 const char* linkLanguage
= cli
.GetLinkLanguage();
1634 std::string libPathFlag
=
1635 this->Makefile
->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
1636 std::string libPathTerminator
=
1637 this->Makefile
->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
1639 // Flags to link an executable to shared libraries.
1640 std::string linkFlagsVar
= "CMAKE_SHARED_LIBRARY_LINK_";
1641 linkFlagsVar
+= linkLanguage
;
1642 linkFlagsVar
+= "_FLAGS";
1643 if( tgt
.GetType() == cmTarget::EXECUTABLE
)
1645 linkLibs
= this->Makefile
->GetSafeDefinition(linkFlagsVar
.c_str());
1649 // Append the framework search path flags.
1650 std::vector
<std::string
> const& fwDirs
= cli
.GetFrameworkPaths();
1651 for(std::vector
<std::string
>::const_iterator fdi
= fwDirs
.begin();
1652 fdi
!= fwDirs
.end(); ++fdi
)
1655 linkLibs
+= this->Convert(fdi
->c_str(), NONE
, SHELL
, false);
1659 // Append the library search path flags.
1660 std::vector
<std::string
> const& libDirs
= cli
.GetDirectories();
1661 for(std::vector
<std::string
>::const_iterator libDir
= libDirs
.begin();
1662 libDir
!= libDirs
.end(); ++libDir
)
1664 std::string libpath
= this->ConvertToOutputForExisting(libDir
->c_str());
1665 linkLibs
+= libPathFlag
;
1666 linkLibs
+= libpath
;
1667 linkLibs
+= libPathTerminator
;
1671 // Append the link items.
1672 typedef cmComputeLinkInformation::ItemVector ItemVector
;
1673 ItemVector
const& items
= cli
.GetItems();
1674 for(ItemVector::const_iterator li
= items
.begin(); li
!= items
.end(); ++li
)
1678 linkLibs
+= this->ConvertToLinkReference(li
->Value
);
1682 linkLibs
+= li
->Value
;
1687 // Write the library flags to the build rule.
1690 // Get the RPATH entries.
1691 std::vector
<std::string
> runtimeDirs
;
1692 cli
.GetRPath(runtimeDirs
, relink
);
1694 // Check what kind of rpath flags to use.
1695 if(cli
.GetRuntimeSep().empty())
1697 // Each rpath entry gets its own option ("-R a -R b -R c")
1699 for(std::vector
<std::string
>::iterator ri
= runtimeDirs
.begin();
1700 ri
!= runtimeDirs
.end(); ++ri
)
1702 rpath
+= cli
.GetRuntimeFlag();
1703 rpath
+= this->Convert(ri
->c_str(), NONE
, SHELL
, false);
1710 // All rpath entries are combined ("-Wl,-rpath,a:b:c").
1711 std::string rpath
= cli
.GetRPathString(relink
);
1713 // Store the rpath option in the stream.
1716 fout
<< cli
.GetRuntimeFlag();
1717 fout
<< this->EscapeForShell(rpath
.c_str(), true);
1722 // Add the linker runtime search path if any.
1723 std::string rpath_link
= cli
.GetRPathLinkString();
1724 if(!cli
.GetRPathLinkFlag().empty() && !rpath_link
.empty())
1726 fout
<< cli
.GetRPathLinkFlag();
1727 fout
<< this->EscapeForShell(rpath_link
.c_str(), true);
1731 // Add standard libraries for this language.
1732 std::string standardLibsVar
= "CMAKE_";
1733 standardLibsVar
+= cli
.GetLinkLanguage();
1734 standardLibsVar
+= "_STANDARD_LIBRARIES";
1735 if(const char* stdLibs
=
1736 this->Makefile
->GetDefinition(standardLibsVar
.c_str()))
1738 fout
<< stdLibs
<< " ";
1742 //----------------------------------------------------------------------------
1743 void cmLocalGenerator::AddLanguageFlags(std::string
& flags
,
1747 // Add language-specific flags.
1748 std::string flagsVar
= "CMAKE_";
1750 flagsVar
+= "_FLAGS";
1751 // Add special OSX flags
1753 if(this->EmitUniversalBinaryFlags
)
1755 const char* osxArch
=
1756 this->Makefile
->GetDefinition("CMAKE_OSX_ARCHITECTURES");
1757 const char* sysroot
=
1758 this->Makefile
->GetDefinition("CMAKE_OSX_SYSROOT");
1759 const char* sysrootDefault
=
1760 this->Makefile
->GetDefinition("CMAKE_OSX_SYSROOT_DEFAULT");
1761 const char* deploymentTarget
=
1762 this->Makefile
->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
1763 const char* gccHasIsysroot
=
1764 this->Makefile
->GetRequiredDefinition("CMAKE_OSX_GCC_SUPPORT_ISYSROOT");
1765 bool hasIsysroot
= true;
1766 if(cmSystemTools::IsOff(gccHasIsysroot
))
1768 hasIsysroot
= false;
1770 bool flagsUsed
= false;
1771 if(osxArch
&& sysroot
&& lang
&& (lang
[0] =='C' || lang
[0] == 'F'))
1773 std::vector
<std::string
> archs
;
1774 cmSystemTools::ExpandListArgument(std::string(osxArch
),
1776 bool addArchFlag
= false;
1777 if(archs
.size() >= 1)
1784 // if there is more than one arch add the -arch and
1785 // -isysroot flags, or if there is one arch flag, but
1786 // it is not the default -arch flag for the system, then
1787 // add it. Otherwize do not add -arch and -isysroot
1790 for( std::vector
<std::string
>::iterator i
= archs
.begin();
1791 i
!= archs
.end(); ++i
)
1798 flags
+= " -isysroot ";
1805 if(!flagsUsed
&& sysroot
&& sysrootDefault
&&
1806 strcmp(sysroot
, sysrootDefault
) != 0 && hasIsysroot
)
1808 flags
+= " -isysroot ";
1812 if (deploymentTarget
&& *deploymentTarget
&&
1813 lang
&& (lang
[0] =='C' || lang
[0] == 'F'))
1815 flags
+= " -mmacosx-version-min=";
1816 flags
+= deploymentTarget
;
1820 this->AddConfigVariableFlags(flags
, flagsVar
.c_str(), config
);
1823 //----------------------------------------------------------------------------
1824 std::string
cmLocalGenerator::GetRealDependency(const char* inName
,
1827 // Older CMake code may specify the dependency using the target
1828 // output file rather than the target name. Such code would have
1829 // been written before there was support for target properties that
1830 // modify the name so stripping down to just the file name should
1831 // produce the target name in this case.
1832 std::string name
= cmSystemTools::GetFilenameName(inName
);
1833 if(cmSystemTools::GetFilenameLastExtension(name
) == ".exe")
1835 name
= cmSystemTools::GetFilenameWithoutLastExtension(name
);
1838 // Look for a CMake target with the given name.
1839 if(cmTarget
* target
= this->Makefile
->FindTargetToUse(name
.c_str()))
1841 // make sure it is not just a coincidence that the target name
1842 // found is part of the inName
1843 if(cmSystemTools::FileIsFullPath(inName
))
1845 std::string tLocation
= target
->GetLocation(config
);
1846 tLocation
= cmSystemTools::GetFilenamePath(tLocation
);
1847 std::string depLocation
= cmSystemTools::GetFilenamePath(
1848 std::string(inName
));
1849 depLocation
= cmSystemTools::CollapseFullPath(depLocation
.c_str());
1850 tLocation
= cmSystemTools::CollapseFullPath(tLocation
.c_str());
1851 if(depLocation
!= tLocation
)
1853 // it is a full path to a depend that has the same name
1854 // as a target but is in a different location so do not use
1855 // the target as the depend
1859 switch (target
->GetType())
1861 case cmTarget::EXECUTABLE
:
1862 case cmTarget::STATIC_LIBRARY
:
1863 case cmTarget::SHARED_LIBRARY
:
1864 case cmTarget::MODULE_LIBRARY
:
1865 case cmTarget::UNKNOWN_LIBRARY
:
1867 // Get the location of the target's output file and depend on it.
1868 if(const char* location
= target
->GetLocation(config
))
1874 case cmTarget::UTILITY
:
1875 case cmTarget::GLOBAL_TARGET
:
1876 // Depending on a utility target may not work but just trust
1877 // the user to have given a valid name.
1879 case cmTarget::INSTALL_FILES
:
1880 case cmTarget::INSTALL_PROGRAMS
:
1881 case cmTarget::INSTALL_DIRECTORY
:
1886 // The name was not that of a CMake target. It must name a file.
1887 if(cmSystemTools::FileIsFullPath(inName
))
1889 // This is a full path. Return it as given.
1893 // Check for a source file in this directory that matches the
1895 if(cmSourceFile
* sf
= this->Makefile
->GetSource(inName
))
1897 name
= sf
->GetFullPath();
1901 // Treat the name as relative to the source directory in which it
1903 name
= this->Makefile
->GetCurrentDirectory();
1909 //----------------------------------------------------------------------------
1910 std::string
cmLocalGenerator::GetRealLocation(const char* inName
,
1913 std::string outName
=inName
;
1914 // Look for a CMake target with the given name, which is an executable
1915 // and which can be run
1916 cmTarget
* target
= this->Makefile
->FindTargetToUse(inName
);
1918 && (target
->GetType() == cmTarget::EXECUTABLE
)
1919 && ((this->Makefile
->IsOn("CMAKE_CROSSCOMPILING") == false)
1920 || (target
->IsImported() == true)))
1922 outName
= target
->GetLocation( config
);
1927 //----------------------------------------------------------------------------
1928 void cmLocalGenerator::AddSharedFlags(std::string
& flags
,
1932 std::string flagsVar
;
1934 // Add flags for dealing with shared libraries for this language.
1937 flagsVar
= "CMAKE_SHARED_LIBRARY_";
1939 flagsVar
+= "_FLAGS";
1940 this->AppendFlags(flags
, this->Makefile
->GetDefinition(flagsVar
.c_str()));
1943 // Add flags specific to shared builds.
1944 if(cmSystemTools::IsOn(this->Makefile
->GetDefinition("BUILD_SHARED_LIBS")))
1946 flagsVar
= "CMAKE_SHARED_BUILD_";
1948 flagsVar
+= "_FLAGS";
1949 this->AppendFlags(flags
, this->Makefile
->GetDefinition(flagsVar
.c_str()));
1953 //----------------------------------------------------------------------------
1954 void cmLocalGenerator::AddConfigVariableFlags(std::string
& flags
,
1958 // Add the flags from the variable itself.
1959 std::string flagsVar
= var
;
1960 this->AppendFlags(flags
, this->Makefile
->GetDefinition(flagsVar
.c_str()));
1961 // Add the flags from the build-type specific variable.
1962 if(config
&& *config
)
1965 flagsVar
+= cmSystemTools::UpperCase(config
);
1966 this->AppendFlags(flags
, this->Makefile
->GetDefinition(flagsVar
.c_str()));
1970 //----------------------------------------------------------------------------
1971 void cmLocalGenerator::AppendFlags(std::string
& flags
,
1972 const char* newFlags
)
1974 if(newFlags
&& *newFlags
)
1976 std::string newf
= newFlags
;
1985 //----------------------------------------------------------------------------
1986 void cmLocalGenerator::AppendDefines(std::string
& defines
,
1987 const char* defines_list
,
1990 // Short-circuit if there are no definitions.
1996 // Expand the list of definitions.
1997 std::vector
<std::string
> defines_vec
;
1998 cmSystemTools::ExpandListArgument(defines_list
, defines_vec
);
2000 // Short-circuit if there are no definitions.
2001 if(defines_vec
.empty())
2006 // Lookup the define flag for the current language.
2007 std::string dflag
= "-D";
2010 std::string defineFlagVar
= "CMAKE_";
2011 defineFlagVar
+= lang
;
2012 defineFlagVar
+= "_DEFINE_FLAG";
2013 const char* df
= this->Makefile
->GetDefinition(defineFlagVar
.c_str());
2020 // Add each definition to the command line with appropriate escapes.
2021 const char* dsep
= defines
.empty()? "" : " ";
2022 for(std::vector
<std::string
>::const_iterator di
= defines_vec
.begin();
2023 di
!= defines_vec
.end(); ++di
)
2025 // Skip unsupported definitions.
2026 if(!this->CheckDefinition(*di
))
2031 // Separate from previous definitions.
2035 // Append the definition with proper escaping.
2037 if(this->WatcomWMake
)
2039 // The Watcom compiler does its own command line parsing instead
2040 // of using the windows shell rules. Definitions are one of
2042 // -DNAME=<cpp-token>
2043 // -DNAME="c-string with spaces and other characters(?@#$)"
2045 // Watcom will properly parse each of these cases from the
2046 // command line without any escapes. However we still have to
2047 // get the '$' and '#' characters through WMake as '$$' and
2049 for(const char* c
= di
->c_str(); *c
; ++c
)
2051 if(*c
== '$' || *c
== '#')
2060 // Make the definition appear properly on the command line. Use
2061 // -DNAME="value" instead of -D"NAME=value" to help VS6 parser.
2062 std::string::size_type eq
= di
->find("=");
2063 defines
+= di
->substr(0, eq
);
2067 defines
+= this->EscapeForShell(di
->c_str() + eq
+ 1, true);
2073 //----------------------------------------------------------------------------
2075 cmLocalGenerator::ConstructComment(const cmCustomCommand
& cc
,
2076 const char* default_comment
)
2078 // Check for a comment provided with the command.
2081 return cc
.GetComment();
2084 // Construct a reasonable default comment if possible.
2085 if(!cc
.GetOutputs().empty())
2087 std::string comment
;
2088 comment
= "Generating ";
2089 const char* sep
= "";
2090 for(std::vector
<std::string
>::const_iterator o
= cc
.GetOutputs().begin();
2091 o
!= cc
.GetOutputs().end(); ++o
)
2094 comment
+= this->Convert(o
->c_str(), cmLocalGenerator::START_OUTPUT
);
2100 // Otherwise use the provided default.
2101 return default_comment
;
2104 //----------------------------------------------------------------------------
2106 cmLocalGenerator::ConvertToOptionallyRelativeOutputPath(const char* remote
)
2108 return this->Convert(remote
, START_OUTPUT
, SHELL
, true);
2111 //----------------------------------------------------------------------------
2112 const char* cmLocalGenerator::GetRelativeRootPath(RelativeRoot relroot
)
2116 case HOME
: return this->Makefile
->GetHomeDirectory();
2117 case START
: return this->Makefile
->GetStartDirectory();
2118 case HOME_OUTPUT
: return this->Makefile
->GetHomeOutputDirectory();
2119 case START_OUTPUT
: return this->Makefile
->GetStartOutputDirectory();
2125 //----------------------------------------------------------------------------
2126 std::string
cmLocalGenerator::Convert(const char* source
,
2127 RelativeRoot relative
,
2128 OutputFormat output
,
2131 // Make sure the relative path conversion components are set.
2132 if(!this->PathConversionsSetup
)
2134 this->SetupPathConversions();
2135 this->PathConversionsSetup
= true;
2138 // Convert the path to a relative path.
2139 std::string result
= source
;
2141 if (!optional
|| this->UseRelativePaths
)
2146 //result = cmSystemTools::CollapseFullPath(result.c_str());
2147 result
= this->ConvertToRelativePath(this->HomeDirectoryComponents
,
2151 //result = cmSystemTools::CollapseFullPath(result.c_str());
2152 result
= this->ConvertToRelativePath(this->StartDirectoryComponents
,
2156 //result = cmSystemTools::CollapseFullPath(result.c_str());
2158 this->ConvertToRelativePath(this->HomeOutputDirectoryComponents
,
2162 //result = cmSystemTools::CollapseFullPath(result.c_str());
2164 this->ConvertToRelativePath(this->StartOutputDirectoryComponents
,
2168 result
= cmSystemTools::CollapseFullPath(result
.c_str());
2174 return this->ConvertToOutputFormat(result
.c_str(), output
);
2177 //----------------------------------------------------------------------------
2178 std::string
cmLocalGenerator::ConvertToOutputFormat(const char* source
,
2179 OutputFormat output
)
2181 std::string result
= source
;
2182 // Convert it to an output path.
2183 if (output
== MAKEFILE
)
2185 result
= cmSystemTools::ConvertToOutputPath(result
.c_str());
2187 else if( output
== SHELL
)
2189 // For the MSYS shell convert drive letters to posix paths, so
2190 // that c:/some/path becomes /c/some/path. This is needed to
2191 // avoid problems with the shell path translation.
2192 if(this->MSYSShell
&& !this->LinkScriptShell
)
2194 if(result
.size() > 2 && result
[1] == ':')
2196 result
[1] = result
[0];
2200 if(this->WindowsShell
)
2202 std::string::size_type pos
= 0;
2203 while((pos
= result
.find('/', pos
)) != std::string::npos
)
2209 result
= this->EscapeForShell(result
.c_str(), true, false);
2214 //----------------------------------------------------------------------------
2215 std::string
cmLocalGenerator::Convert(RelativeRoot remote
,
2217 OutputFormat output
,
2220 const char* remotePath
= this->GetRelativeRootPath(remote
);
2222 // The relative root must have a path (i.e. not FULL or NONE)
2223 assert(remotePath
!= 0);
2225 if(local
&& (!optional
|| this->UseRelativePaths
))
2227 std::vector
<std::string
> components
;
2228 cmSystemTools::SplitPath(local
, components
);
2229 std::string result
= this->ConvertToRelativePath(components
, remotePath
);
2230 return this->ConvertToOutputFormat(result
.c_str(), output
);
2234 return this->ConvertToOutputFormat(remotePath
, output
);
2238 //----------------------------------------------------------------------------
2239 std::string
cmLocalGenerator::FindRelativePathTopSource()
2241 // Relative path conversion within a single tree managed by CMake is
2242 // safe. We can use our parent relative path top if and only if
2243 // this is a subdirectory of that top.
2244 if(cmLocalGenerator
* parent
= this->GetParent())
2246 std::string parentTop
= parent
->FindRelativePathTopSource();
2247 if(cmSystemTools::IsSubDirectory(
2248 this->Makefile
->GetStartDirectory(), parentTop
.c_str()))
2254 // Otherwise this directory itself is the new top.
2255 return this->Makefile
->GetStartDirectory();
2258 //----------------------------------------------------------------------------
2259 std::string
cmLocalGenerator::FindRelativePathTopBinary()
2261 // Relative path conversion within a single tree managed by CMake is
2262 // safe. We can use our parent relative path top if and only if
2263 // this is a subdirectory of that top.
2264 if(cmLocalGenerator
* parent
= this->GetParent())
2266 std::string parentTop
= parent
->FindRelativePathTopBinary();
2267 if(cmSystemTools::IsSubDirectory(
2268 this->Makefile
->GetStartOutputDirectory(), parentTop
.c_str()))
2274 // Otherwise this directory itself is the new top.
2275 return this->Makefile
->GetStartOutputDirectory();
2278 //----------------------------------------------------------------------------
2279 void cmLocalGenerator::ConfigureRelativePaths()
2281 // Relative path conversion inside the source tree is not used to
2282 // construct relative paths passed to build tools so it is safe to
2283 // even when the source is a network path.
2284 std::string source
= this->FindRelativePathTopSource();
2285 this->RelativePathTopSource
= source
;
2287 // The current working directory on Windows cannot be a network
2288 // path. Therefore relative paths cannot work when the binary tree
2289 // is a network path.
2290 std::string binary
= this->FindRelativePathTopBinary();
2291 if(binary
.size() < 2 || binary
.substr(0, 2) != "//")
2293 this->RelativePathTopBinary
= binary
;
2297 this->RelativePathTopBinary
= "";
2301 //----------------------------------------------------------------------------
2302 static bool cmLocalGeneratorNotAbove(const char* a
, const char* b
)
2304 return (cmSystemTools::ComparePath(a
, b
) ||
2305 cmSystemTools::IsSubDirectory(a
, b
));
2308 //----------------------------------------------------------------------------
2310 cmLocalGenerator::ConvertToRelativePath(const std::vector
<std::string
>& local
,
2311 const char* in_remote
)
2313 // The path should never be quoted.
2314 assert(in_remote
[0] != '\"');
2316 // The local path should never have a trailing slash.
2317 assert(local
.size() > 0 && !(local
[local
.size()-1] == ""));
2319 // If the path is already relative then just return the path.
2320 if(!cmSystemTools::FileIsFullPath(in_remote
))
2325 // Make sure relative path conversion is configured.
2326 if(!this->RelativePathsConfigured
)
2328 this->ConfigureRelativePaths();
2329 this->RelativePathsConfigured
= true;
2332 // Skip conversion if the path and local are not both in the source
2333 // or both in the binary tree.
2334 std::string local_path
= cmSystemTools::JoinPath(local
);
2335 if(!((cmLocalGeneratorNotAbove(local_path
.c_str(),
2336 this->RelativePathTopBinary
.c_str()) &&
2337 cmLocalGeneratorNotAbove(in_remote
,
2338 this->RelativePathTopBinary
.c_str())) ||
2339 (cmLocalGeneratorNotAbove(local_path
.c_str(),
2340 this->RelativePathTopSource
.c_str()) &&
2341 cmLocalGeneratorNotAbove(in_remote
,
2342 this->RelativePathTopSource
.c_str()))))
2347 // Identify the longest shared path component between the remote
2348 // path and the local path.
2349 std::vector
<std::string
> remote
;
2350 cmSystemTools::SplitPath(in_remote
, remote
);
2351 unsigned int common
=0;
2352 while(common
< remote
.size() &&
2353 common
< local
.size() &&
2354 cmSystemTools::ComparePath(remote
[common
].c_str(),
2355 local
[common
].c_str()))
2360 // If no part of the path is in common then return the full path.
2366 // If the entire path is in common then just return a ".".
2367 if(common
== remote
.size() &&
2368 common
== local
.size())
2373 // If the entire path is in common except for a trailing slash then
2374 // just return a "./".
2375 if(common
+1 == remote
.size() &&
2376 remote
[common
].size() == 0 &&
2377 common
== local
.size())
2382 // Construct the relative path.
2383 std::string relative
;
2385 // First add enough ../ to get up to the level of the shared portion
2386 // of the path. Leave off the trailing slash. Note that the last
2387 // component of local will never be empty because local should never
2388 // have a trailing slash.
2389 for(unsigned int i
=common
; i
< local
.size(); ++i
)
2392 if(i
< local
.size()-1)
2398 // Now add the portion of the destination path that is not included
2399 // in the shared portion of the path. Add a slash the first time
2400 // only if there was already something in the path. If there was a
2401 // trailing slash in the input then the last iteration of the loop
2402 // will add a slash followed by an empty string which will preserve
2403 // the trailing slash in the output.
2404 for(unsigned int i
=common
; i
< remote
.size(); ++i
)
2406 if(relative
.size() > 0)
2410 relative
+= remote
[i
];
2413 // Finally return the path.
2417 //----------------------------------------------------------------------------
2420 ::GenerateTargetInstallRules(
2421 std::ostream
& os
, const char* config
,
2422 std::vector
<std::string
> const& configurationTypes
)
2424 // Convert the old-style install specification from each target to
2425 // an install generator and run it.
2426 cmTargets
& tgts
= this->Makefile
->GetTargets();
2427 for(cmTargets::iterator l
= tgts
.begin(); l
!= tgts
.end(); ++l
)
2429 // Include the user-specified pre-install script for this target.
2430 if(const char* preinstall
= l
->second
.GetProperty("PRE_INSTALL_SCRIPT"))
2432 cmInstallScriptGenerator
g(preinstall
, false, 0);
2433 g
.Generate(os
, config
, configurationTypes
);
2436 // Install this target if a destination is given.
2437 if(l
->second
.GetInstallPath() != "")
2439 // Compute the full install destination. Note that converting
2440 // to unix slashes also removes any trailing slash.
2441 // We also skip over the leading slash given by the user.
2442 std::string destination
= l
->second
.GetInstallPath().substr(1);
2443 cmSystemTools::ConvertToUnixSlashes(destination
);
2444 if(destination
.empty())
2449 // Generate the proper install generator for this target type.
2450 switch(l
->second
.GetType())
2452 case cmTarget::EXECUTABLE
:
2453 case cmTarget::STATIC_LIBRARY
:
2454 case cmTarget::MODULE_LIBRARY
:
2456 // Use a target install generator.
2457 cmInstallTargetGenerator
g(l
->second
, destination
.c_str(), false);
2458 g
.Generate(os
, config
, configurationTypes
);
2461 case cmTarget::SHARED_LIBRARY
:
2463 #if defined(_WIN32) || defined(__CYGWIN__)
2464 // Special code to handle DLL. Install the import library
2465 // to the normal destination and the DLL to the runtime
2467 cmInstallTargetGenerator
g1(l
->second
, destination
.c_str(), true);
2468 g1
.Generate(os
, config
, configurationTypes
);
2469 // We also skip over the leading slash given by the user.
2470 destination
= l
->second
.GetRuntimeInstallPath().substr(1);
2471 cmSystemTools::ConvertToUnixSlashes(destination
);
2472 cmInstallTargetGenerator
g2(l
->second
, destination
.c_str(), false);
2473 g2
.Generate(os
, config
, configurationTypes
);
2475 // Use a target install generator.
2476 cmInstallTargetGenerator
g(l
->second
, destination
.c_str(), false);
2477 g
.Generate(os
, config
, configurationTypes
);
2486 // Include the user-specified post-install script for this target.
2487 if(const char* postinstall
= l
->second
.GetProperty("POST_INSTALL_SCRIPT"))
2489 cmInstallScriptGenerator
g(postinstall
, false, 0);
2490 g
.Generate(os
, config
, configurationTypes
);
2495 #if defined(CM_LG_ENCODE_OBJECT_NAMES)
2496 static std::string
cmLocalGeneratorMD5(const char* input
)
2499 cmsysMD5
* md5
= cmsysMD5_New();
2500 cmsysMD5_Initialize(md5
);
2501 cmsysMD5_Append(md5
, reinterpret_cast<unsigned char const*>(input
), -1);
2502 cmsysMD5_FinalizeHex(md5
, md5out
);
2503 cmsysMD5_Delete(md5
);
2504 return std::string(md5out
, 32);
2508 cmLocalGeneratorShortenObjectName(std::string
& objName
,
2509 std::string::size_type max_len
)
2511 // Replace the beginning of the path portion of the object name with
2513 std::string::size_type pos
= objName
.find('/', objName
.size()-max_len
+32);
2514 if(pos
!= objName
.npos
)
2516 std::string md5name
= cmLocalGeneratorMD5(objName
.substr(0, pos
).c_str());
2517 md5name
+= objName
.substr(pos
);
2520 // The object name is now short enough.
2525 // The object name could not be shortened enough.
2531 bool cmLocalGeneratorCheckObjectName(std::string
& objName
,
2532 std::string::size_type dir_len
,
2533 std::string::size_type max_total_len
)
2535 // Enforce the maximum file name length if possible.
2536 std::string::size_type max_obj_len
= max_total_len
;
2537 if(dir_len
< max_total_len
)
2539 max_obj_len
= max_total_len
- dir_len
;
2540 if(objName
.size() > max_obj_len
)
2542 // The current object file name is too long. Try to shorten it.
2543 return cmLocalGeneratorShortenObjectName(objName
, max_obj_len
);
2547 // The object file name is short enough.
2553 // The build directory in which the object will be stored is
2554 // already too deep.
2560 //----------------------------------------------------------------------------
2563 ::CreateSafeUniqueObjectFileName(const char* sin
,
2564 std::string
const& dir_max
)
2566 // Look for an existing mapped name for this object file.
2567 std::map
<cmStdString
,cmStdString
>::iterator it
=
2568 this->UniqueObjectNamesMap
.find(sin
);
2570 // If no entry exists create one.
2571 if(it
== this->UniqueObjectNamesMap
.end())
2573 // Start with the original name.
2574 std::string ssin
= sin
;
2576 // Avoid full paths by removing leading slashes.
2577 std::string::size_type pos
= 0;
2578 for(;pos
< ssin
.size() && ssin
[pos
] == '/'; ++pos
)
2581 ssin
= ssin
.substr(pos
);
2583 // Avoid full paths by removing colons.
2584 cmSystemTools::ReplaceString(ssin
, ":", "_");
2586 // Avoid relative paths that go up the tree.
2587 cmSystemTools::ReplaceString(ssin
, "../", "__/");
2590 cmSystemTools::ReplaceString(ssin
, " ", "_");
2592 // Mangle the name if necessary.
2593 if(this->Makefile
->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
2598 sprintf(rpstr
, "_p_");
2599 cmSystemTools::ReplaceString(ssin
, "+", rpstr
);
2600 std::string sssin
= sin
;
2604 for ( it
= this->UniqueObjectNamesMap
.begin();
2605 it
!= this->UniqueObjectNamesMap
.end();
2608 if ( it
->second
== ssin
)
2618 cmSystemTools::ReplaceString(ssin
, "_p_", rpstr
);
2619 sprintf(rpstr
, "_p%d_", cc
++);
2624 #if defined(CM_LG_ENCODE_OBJECT_NAMES)
2625 if(!cmLocalGeneratorCheckObjectName(ssin
, dir_max
.size(),
2626 this->ObjectPathMax
))
2628 // Warn if this is the first time the path has been seen.
2629 if(this->ObjectMaxPathViolations
.insert(dir_max
).second
)
2632 m
<< "The object file directory\n"
2633 << " " << dir_max
<< "\n"
2634 << "has " << dir_max
.size() << " characters. "
2635 << "The maximum full path to an object file is "
2636 << this->ObjectPathMax
<< " characters "
2637 << "(see CMAKE_OBJECT_PATH_MAX). "
2639 << " " << ssin
<< "\n"
2640 << "cannot be safely placed under this directory. "
2641 << "The build may not work correctly.";
2642 this->Makefile
->IssueMessage(cmake::WARNING
, m
.str());
2649 // Insert the newly mapped object file name.
2650 std::map
<cmStdString
, cmStdString
>::value_type
e(sin
, ssin
);
2651 it
= this->UniqueObjectNamesMap
.insert(e
).first
;
2654 // Return the map entry.
2658 //----------------------------------------------------------------------------
2661 ::GetObjectFileNameWithoutTarget(const cmSourceFile
& source
,
2662 std::string
const& dir_max
,
2663 bool* hasSourceExtension
)
2665 // Construct the object file name using the full path to the source
2666 // file which is its only unique identification.
2667 const char* fullPath
= source
.GetFullPath().c_str();
2669 // Try referencing the source relative to the source tree.
2670 std::string relFromSource
= this->Convert(fullPath
, START
);
2671 assert(!relFromSource
.empty());
2672 bool relSource
= !cmSystemTools::FileIsFullPath(relFromSource
.c_str());
2673 bool subSource
= relSource
&& relFromSource
[0] != '.';
2675 // Try referencing the source relative to the binary tree.
2676 std::string relFromBinary
= this->Convert(fullPath
, START_OUTPUT
);
2677 assert(!relFromBinary
.empty());
2678 bool relBinary
= !cmSystemTools::FileIsFullPath(relFromBinary
.c_str());
2679 bool subBinary
= relBinary
&& relFromBinary
[0] != '.';
2681 // Select a nice-looking reference to the source file to construct
2682 // the object file name.
2683 std::string objectName
;
2684 if((relSource
&& !relBinary
) || (subSource
&& !subBinary
))
2686 objectName
= relFromSource
;
2688 else if((relBinary
&& !relSource
) || (subBinary
&& !subSource
))
2690 objectName
= relFromBinary
;
2692 else if(relFromBinary
.length() < relFromSource
.length())
2694 objectName
= relFromBinary
;
2698 objectName
= relFromSource
;
2701 // if it is still a full path check for the try compile case
2702 // try compile never have in source sources, and should not
2703 // have conflicting source file names in the same target
2704 if(cmSystemTools::FileIsFullPath(objectName
.c_str()))
2706 if(this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile())
2708 objectName
= cmSystemTools::GetFilenameName(source
.GetFullPath());
2712 // Replace the original source file extension with the object file
2714 bool keptSourceExtension
= true;
2715 if(!source
.GetPropertyAsBool("KEEP_EXTENSION"))
2717 // Decide whether this language wants to replace the source
2718 // extension with the object extension. For CMake 2.4
2719 // compatibility do this by default.
2720 bool replaceExt
= this->NeedBackwardsCompatibility(2, 4);
2723 std::string repVar
= "CMAKE_";
2724 repVar
+= source
.GetLanguage();
2725 repVar
+= "_OUTPUT_EXTENSION_REPLACE";
2726 replaceExt
= this->Makefile
->IsOn(repVar
.c_str());
2729 // Remove the source extension if it is to be replaced.
2732 keptSourceExtension
= false;
2733 std::string::size_type dot_pos
= objectName
.rfind(".");
2734 if(dot_pos
!= std::string::npos
)
2736 objectName
= objectName
.substr(0, dot_pos
);
2740 // Store the new extension.
2742 this->GlobalGenerator
->GetLanguageOutputExtension(source
);
2744 if(hasSourceExtension
)
2746 *hasSourceExtension
= keptSourceExtension
;
2749 // Convert to a safe name.
2750 return this->CreateSafeUniqueObjectFileName(objectName
.c_str(), dir_max
);
2753 //----------------------------------------------------------------------------
2756 ::GetSourceFileLanguage(const cmSourceFile
& source
)
2758 return source
.GetLanguage();
2761 //----------------------------------------------------------------------------
2762 std::string
cmLocalGenerator::EscapeForShellOldStyle(const char* str
)
2765 bool forceOn
= cmSystemTools::GetForceUnixPaths();
2766 if(forceOn
&& this->WindowsShell
)
2768 cmSystemTools::SetForceUnixPaths(false);
2770 result
= cmSystemTools::EscapeSpaces(str
);
2771 if(forceOn
&& this->WindowsShell
)
2773 cmSystemTools::SetForceUnixPaths(true);
2778 //----------------------------------------------------------------------------
2779 static bool cmLocalGeneratorIsShellOperator(const char* str
)
2781 if(strcmp(str
, "<") == 0 ||
2782 strcmp(str
, ">") == 0 ||
2783 strcmp(str
, "<<") == 0 ||
2784 strcmp(str
, ">>") == 0 ||
2785 strcmp(str
, "|") == 0 ||
2786 strcmp(str
, "||") == 0 ||
2787 strcmp(str
, "&&") == 0 ||
2788 strcmp(str
, "&>") == 0 ||
2789 strcmp(str
, "1>") == 0 ||
2790 strcmp(str
, "2>") == 0 ||
2791 strcmp(str
, "2>&1") == 0 ||
2792 strcmp(str
, "1>&2") == 0)
2799 //----------------------------------------------------------------------------
2800 std::string
cmLocalGenerator::EscapeForShell(const char* str
, bool makeVars
,
2803 // Do not escape shell operators.
2804 if(cmLocalGeneratorIsShellOperator(str
))
2809 // Compute the flags for the target shell environment.
2811 if(this->WindowsVSIDE
)
2813 flags
|= cmsysSystem_Shell_Flag_VSIDE
;
2815 else if(!this->LinkScriptShell
)
2817 flags
|= cmsysSystem_Shell_Flag_Make
;
2821 flags
|= cmsysSystem_Shell_Flag_AllowMakeVariables
;
2825 flags
|= cmsysSystem_Shell_Flag_EchoWindows
;
2827 if(this->WatcomWMake
)
2829 flags
|= cmsysSystem_Shell_Flag_WatcomWMake
;
2833 flags
|= cmsysSystem_Shell_Flag_MinGWMake
;
2837 flags
|= cmsysSystem_Shell_Flag_NMake
;
2840 // Compute the buffer size needed.
2841 int size
= (this->WindowsShell
?
2842 cmsysSystem_Shell_GetArgumentSizeForWindows(str
, flags
) :
2843 cmsysSystem_Shell_GetArgumentSizeForUnix(str
, flags
));
2845 // Compute the shell argument itself.
2846 std::vector
<char> arg(size
);
2847 if(this->WindowsShell
)
2849 cmsysSystem_Shell_GetArgumentForWindows(str
, &arg
[0], flags
);
2853 cmsysSystem_Shell_GetArgumentForUnix(str
, &arg
[0], flags
);
2855 return std::string(&arg
[0]);
2858 //----------------------------------------------------------------------------
2859 std::string
cmLocalGenerator::EscapeForCMake(const char* str
)
2861 // Always double-quote the argument to take care of most escapes.
2862 std::string result
= "\"";
2863 for(const char* c
= str
; *c
; ++c
)
2867 // Escape the double quote to avoid ending the argument.
2872 // Escape the dollar to avoid expanding variables.
2877 // Escape the backslash to avoid other escapes.
2882 // Other characters will be parsed correctly.
2890 //----------------------------------------------------------------------------
2892 cmLocalGenerator::GetTargetDirectory(cmTarget
const&) const
2894 cmSystemTools::Error("GetTargetDirectory"
2895 " called on cmLocalGenerator");
2900 //----------------------------------------------------------------------------
2902 cmLocalGenerator::GetTargetObjectFileDirectories(cmTarget
* ,
2903 std::vector
<std::string
>&
2906 cmSystemTools::Error("GetTargetObjectFileDirectories"
2907 " called on cmLocalGenerator");
2910 //----------------------------------------------------------------------------
2911 unsigned int cmLocalGenerator::GetBackwardsCompatibility()
2913 // The computed version may change until the project is fully
2915 if(!this->BackwardsCompatibilityFinal
)
2917 unsigned int major
= 0;
2918 unsigned int minor
= 0;
2919 unsigned int patch
= 0;
2920 if(const char* value
2921 = this->Makefile
->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"))
2923 switch(sscanf(value
, "%u.%u.%u", &major
, &minor
, &patch
))
2925 case 2: patch
= 0; break;
2926 case 1: minor
= 0; patch
= 0; break;
2930 this->BackwardsCompatibility
= CMake_VERSION_ENCODE(major
, minor
, patch
);
2931 this->BackwardsCompatibilityFinal
= this->Configured
;
2934 return this->BackwardsCompatibility
;
2937 //----------------------------------------------------------------------------
2938 bool cmLocalGenerator::NeedBackwardsCompatibility(unsigned int major
,
2942 // Check the policy to decide whether to pay attention to this
2944 switch(this->Makefile
->GetPolicyStatus(cmPolicies::CMP0001
))
2946 case cmPolicies::WARN
:
2947 // WARN is just OLD without warning because user code does not
2948 // always affect whether this check is done.
2949 case cmPolicies::OLD
:
2950 // Old behavior is to check the variable.
2952 case cmPolicies::NEW
:
2953 // New behavior is to ignore the variable.
2955 case cmPolicies::REQUIRED_IF_USED
:
2956 case cmPolicies::REQUIRED_ALWAYS
:
2957 // This will never be the case because the only way to require
2958 // the setting is to require the user to specify version policy
2959 // 2.6 or higher. Once we add that requirement then this whole
2960 // method can be removed anyway.
2964 // Compatibility is needed if CMAKE_BACKWARDS_COMPATIBILITY is set
2965 // equal to or lower than the given version.
2966 unsigned int actual_compat
= this->GetBackwardsCompatibility();
2967 return (actual_compat
&&
2968 actual_compat
<= CMake_VERSION_ENCODE(major
, minor
, patch
));
2971 //----------------------------------------------------------------------------
2972 bool cmLocalGenerator::CheckDefinition(std::string
const& define
) const
2974 // Many compilers do not support -DNAME(arg)=sdf so we disable it.
2975 bool function_style
= false;
2976 for(const char* c
= define
.c_str(); *c
&& *c
!= '='; ++c
)
2980 function_style
= true;
2987 e
<< "WARNING: Function-style preprocessor definitions may not be "
2988 << "passed on the compiler command line because many compilers "
2989 << "do not support it.\n"
2990 << "CMake is dropping a preprocessor definition: " << define
<< "\n"
2991 << "Consider defining the macro in a (configured) header file.\n";
2992 cmSystemTools::Message(e
.str().c_str());
2996 // Many compilers do not support # in the value so we disable it.
2997 if(define
.find_first_of("#") != define
.npos
)
3000 e
<< "WARNING: Peprocessor definitions containing '#' may not be "
3001 << "passed on the compiler command line because many compilers "
3002 << "do not support it.\n"
3003 << "CMake is dropping a preprocessor definition: " << define
<< "\n"
3004 << "Consider defining the macro in a (configured) header file.\n";
3005 cmSystemTools::Message(e
.str().c_str());
3009 // Assume it is supported.
3013 //----------------------------------------------------------------------------
3014 static void cmLGInfoProp(cmMakefile
* mf
, cmTarget
* target
, const char* prop
)
3016 if(const char* val
= target
->GetProperty(prop
))
3018 mf
->AddDefinition(prop
, val
);
3022 //----------------------------------------------------------------------------
3023 void cmLocalGenerator::GenerateAppleInfoPList(cmTarget
* target
,
3024 const char* targetName
,
3027 // Find the Info.plist template.
3028 const char* in
= target
->GetProperty("MACOSX_BUNDLE_INFO_PLIST");
3029 std::string inFile
= (in
&& *in
)? in
: "MacOSXBundleInfo.plist.in";
3030 if(!cmSystemTools::FileIsFullPath(inFile
.c_str()))
3032 std::string inMod
= this->Makefile
->GetModulesFile(inFile
.c_str());
3038 if(!cmSystemTools::FileExists(inFile
.c_str(), true))
3041 e
<< "Target " << target
->GetName() << " Info.plist template \""
3042 << inFile
<< "\" could not be found.";
3043 cmSystemTools::Error(e
.str().c_str());
3047 // Convert target properties to variables in an isolated makefile
3048 // scope to configure the file. If properties are set they will
3049 // override user make variables. If not the configuration will fall
3050 // back to the directory-level values set by the user.
3051 cmMakefile
* mf
= this->Makefile
;
3053 mf
->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", targetName
);
3054 cmLGInfoProp(mf
, target
, "MACOSX_BUNDLE_INFO_STRING");
3055 cmLGInfoProp(mf
, target
, "MACOSX_BUNDLE_ICON_FILE");
3056 cmLGInfoProp(mf
, target
, "MACOSX_BUNDLE_GUI_IDENTIFIER");
3057 cmLGInfoProp(mf
, target
, "MACOSX_BUNDLE_LONG_VERSION_STRING");
3058 cmLGInfoProp(mf
, target
, "MACOSX_BUNDLE_BUNDLE_NAME");
3059 cmLGInfoProp(mf
, target
, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
3060 cmLGInfoProp(mf
, target
, "MACOSX_BUNDLE_BUNDLE_VERSION");
3061 cmLGInfoProp(mf
, target
, "MACOSX_BUNDLE_COPYRIGHT");
3062 mf
->ConfigureFile(inFile
.c_str(), fname
, false, false, false);
3066 //----------------------------------------------------------------------------
3067 void cmLocalGenerator::GenerateFrameworkInfoPList(cmTarget
* target
,
3068 const char* targetName
,
3071 // Find the Info.plist template.
3072 const char* in
= target
->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST");
3073 std::string inFile
= (in
&& *in
)? in
: "MacOSXFrameworkInfo.plist.in";
3074 if(!cmSystemTools::FileIsFullPath(inFile
.c_str()))
3076 std::string inMod
= this->Makefile
->GetModulesFile(inFile
.c_str());
3082 if(!cmSystemTools::FileExists(inFile
.c_str(), true))
3085 e
<< "Target " << target
->GetName() << " Info.plist template \""
3086 << inFile
<< "\" could not be found.";
3087 cmSystemTools::Error(e
.str().c_str());
3091 // Convert target properties to variables in an isolated makefile
3092 // scope to configure the file. If properties are set they will
3093 // override user make variables. If not the configuration will fall
3094 // back to the directory-level values set by the user.
3095 cmMakefile
* mf
= this->Makefile
;
3097 mf
->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName
);
3098 cmLGInfoProp(mf
, target
, "MACOSX_FRAMEWORK_ICON_FILE");
3099 cmLGInfoProp(mf
, target
, "MACOSX_FRAMEWORK_IDENTIFIER");
3100 cmLGInfoProp(mf
, target
, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING");
3101 cmLGInfoProp(mf
, target
, "MACOSX_FRAMEWORK_BUNDLE_VERSION");
3102 mf
->ConfigureFile(inFile
.c_str(), fname
, false, false, false);