diff options
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r-- | Source/cmMakefile.cxx | 163 |
1 files changed, 136 insertions, 27 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index cada13a..fd06a33 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -41,6 +41,7 @@ #include <stack> #include <ctype.h> // for isspace +#include <assert.h> class cmMakefile::Internals { @@ -149,6 +150,7 @@ cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals) this->Initialize(); this->CheckSystemVars = mf.CheckSystemVars; this->ListFileStack = mf.ListFileStack; + this->OutputToSource = mf.OutputToSource; } //---------------------------------------------------------------------------- @@ -1045,11 +1047,32 @@ cmMakefile::AddCustomCommandToOutput(const std::vector<std::string>& outputs, cc->SetEscapeOldStyle(escapeOldStyle); cc->SetEscapeAllowMakeVars(true); file->SetCustomCommand(cc); + this->UpdateOutputToSourceMap(outputs, file); } return file; } //---------------------------------------------------------------------------- +void +cmMakefile::UpdateOutputToSourceMap(std::vector<std::string> const& outputs, + cmSourceFile* source) +{ + for(std::vector<std::string>::const_iterator o = outputs.begin(); + o != outputs.end(); ++o) + { + this->UpdateOutputToSourceMap(*o, source); + } +} + +//---------------------------------------------------------------------------- +void +cmMakefile::UpdateOutputToSourceMap(std::string const& output, + cmSourceFile* source) +{ + this->OutputToSource[output] = source; +} + +//---------------------------------------------------------------------------- cmSourceFile* cmMakefile::AddCustomCommandToOutput(const char* output, const std::vector<std::string>& depends, @@ -1473,6 +1496,14 @@ void cmMakefile::AddLinkDirectoryForTarget(const char *target, cmTargets::iterator i = this->Targets.find(target); if ( i != this->Targets.end()) { + if(this->IsAlias(target)) + { + cmOStringStream e; + e << "ALIAS target \"" << target << "\" " + << "may not be linked into another target."; + this->IssueMessage(cmake::FATAL_ERROR, e.str().c_str()); + return; + } i->second.AddLinkDirectory( d ); } else @@ -1541,6 +1572,12 @@ void cmMakefile::InitializeFromParent() parentOptions.begin(), parentOptions.end()); + const std::vector<cmValueWithOrigin> parentDefines = + parent->GetCompileDefinitionsEntries(); + this->CompileDefinitionsEntries.insert(this->CompileDefinitionsEntries.end(), + parentDefines.begin(), + parentDefines.end()); + this->SystemIncludeDirectories = parent->SystemIncludeDirectories; // define flags @@ -1711,27 +1748,13 @@ cmMakefile::AddSystemIncludeDirectories(const std::set<cmStdString> &incs) { this->SystemIncludeDirectories.insert(*li); } -} -//---------------------------------------------------------------------------- -bool cmMakefile::IsSystemIncludeDirectory(const char* dir, const char *config) -{ - for (std::set<cmStdString>::const_iterator - it = this->SystemIncludeDirectories.begin(); - it != this->SystemIncludeDirectories.end(); ++it) + for (cmTargets::iterator l = this->Targets.begin(); + l != this->Targets.end(); ++l) { - cmListFileBacktrace lfbt; - cmGeneratorExpression ge(lfbt); - - std::vector<std::string> incs; - cmSystemTools::ExpandListArgument(ge.Parse(*it) - ->Evaluate(this, config, false), incs); - if (std::find(incs.begin(), incs.end(), dir) != incs.end()) - { - return true; - } + cmTarget &t = l->second; + t.AddSystemIncludeDirectories(incs); } - return false; } void cmMakefile::AddDefinition(const char* name, const char* value) @@ -1967,6 +1990,12 @@ void cmMakefile::AddGlobalLinkInformation(const char* name, cmTarget& target) } +void cmMakefile::AddAlias(const char* lname, cmTarget *tgt) +{ + this->AliasTargets[lname] = tgt; + this->LocalGenerator->GetGlobalGenerator()->AddAlias(lname, tgt); +} + cmTarget* cmMakefile::AddLibrary(const char* lname, cmTarget::TargetType type, const std::vector<std::string> &srcs, bool excludeFromAll) @@ -2023,7 +2052,7 @@ cmMakefile::AddNewTarget(cmTarget::TargetType type, const char* name) return &it->second; } -cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname) +cmSourceFile *cmMakefile::LinearGetSourceFileWithOutput(const char *cname) { std::string name = cname; std::string out; @@ -2059,6 +2088,25 @@ cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname) return 0; } +cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname) +{ + std::string name = cname; + + // If the queried path is not absolute we use the backward compatible + // linear-time search for an output with a matching suffix. + if(!cmSystemTools::FileIsFullPath(cname)) + { + return LinearGetSourceFileWithOutput(cname); + } + // Otherwise we use an efficient lookup map. + OutputToSourceMap::iterator o = this->OutputToSource.find(name); + if (o != this->OutputToSource.end()) + { + return (*o).second; + } + return 0; +} + #if defined(CMAKE_BUILD_WITH_CMAKE) cmSourceGroup* cmMakefile::GetSourceGroup(const std::vector<std::string>&name) { @@ -2828,7 +2876,7 @@ bool cmMakefile::ExpandArguments( // If the argument is quoted, it should be one argument. // Otherwise, it may be a list of arguments. - if(i->Quoted) + if(i->Delim == cmListFileArgument::Quoted) { outArgs.push_back(value); } @@ -3534,6 +3582,19 @@ void cmMakefile::SetProperty(const char* prop, const char* value) this->CompileOptionsEntries.push_back(cmValueWithOrigin(value, lfbt)); return; } + if (propname == "COMPILE_DEFINITIONS") + { + this->CompileDefinitionsEntries.clear(); + if (!value) + { + return; + } + cmListFileBacktrace lfbt; + this->GetBacktrace(lfbt); + cmValueWithOrigin entry(value, lfbt); + this->CompileDefinitionsEntries.push_back(entry); + return; + } if ( propname == "INCLUDE_REGULAR_EXPRESSION" ) { @@ -3581,6 +3642,14 @@ void cmMakefile::AppendProperty(const char* prop, const char* value, cmValueWithOrigin(value, lfbt)); return; } + if (propname == "COMPILE_DEFINITIONS") + { + cmListFileBacktrace lfbt; + this->GetBacktrace(lfbt); + this->CompileDefinitionsEntries.push_back( + cmValueWithOrigin(value, lfbt)); + return; + } if ( propname == "LINK_DIRECTORIES" ) { std::vector<std::string> varArgsExpanded; @@ -3720,6 +3789,20 @@ const char *cmMakefile::GetProperty(const char* prop, } return output.c_str(); } + else if (!strcmp("COMPILE_DEFINITIONS",prop)) + { + std::string sep; + for (std::vector<cmValueWithOrigin>::const_iterator + it = this->CompileDefinitionsEntries.begin(), + end = this->CompileDefinitionsEntries.end(); + it != end; ++it) + { + output += sep; + output += it->Value; + sep = ";"; + } + return output.c_str(); + } bool chain = false; const char *retVal = @@ -3768,8 +3851,17 @@ const char* cmMakefile::GetFeature(const char* feature, const char* config) return 0; } -cmTarget* cmMakefile::FindTarget(const char* name) +cmTarget* cmMakefile::FindTarget(const char* name, bool excludeAliases) { + if (!excludeAliases) + { + std::map<std::string, cmTarget*>::iterator i + = this->AliasTargets.find(name); + if (i != this->AliasTargets.end()) + { + return i->second; + } + } cmTargets& tgts = this->GetTargets(); cmTargets::iterator i = tgts.find ( name ); @@ -4095,14 +4187,13 @@ void cmMakefile::DefineProperties(cmake *cm) "List of options to pass to the compiler.", "This property specifies the list of directories given " "so far for this property. " - "This property exists on directories and targets. " + "This property exists on directories and targets." "\n" "The target property values are used by the generators to set " "the options for the compiler.\n" "Contents of COMPILE_OPTIONS may use \"generator expressions\" with " "the syntax \"$<...>\". " - CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS - CM_DOCUMENT_LANGUAGE_GENERATOR_EXPRESSIONS); + CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS); cm->DefineProperty ("LINK_DIRECTORIES", cmProperty::DIRECTORY, @@ -4195,7 +4286,7 @@ cmMakefile::AddImportedTarget(const char* name, cmTarget::TargetType type, } //---------------------------------------------------------------------------- -cmTarget* cmMakefile::FindTargetToUse(const char* name) +cmTarget* cmMakefile::FindTargetToUse(const char* name, bool excludeAliases) { // Look for an imported target. These take priority because they // are more local in scope and do not have to be globally unique. @@ -4207,15 +4298,25 @@ cmTarget* cmMakefile::FindTargetToUse(const char* name) } // Look for a target built in this directory. - if(cmTarget* t = this->FindTarget(name)) + if(cmTarget* t = this->FindTarget(name, excludeAliases)) { return t; } // Look for a target built in this project. - return this->LocalGenerator->GetGlobalGenerator()->FindTarget(0, name); + return this->LocalGenerator->GetGlobalGenerator()->FindTarget(0, name, + excludeAliases); } +//---------------------------------------------------------------------------- +bool cmMakefile::IsAlias(const char *name) +{ + if (this->AliasTargets.find(name) != this->AliasTargets.end()) + return true; + return this->GetLocalGenerator()->GetGlobalGenerator()->IsAlias(name); +} + +//---------------------------------------------------------------------------- cmGeneratorTarget* cmMakefile::FindGeneratorTargetToUse(const char* name) { cmTarget *t = this->FindTargetToUse(name); @@ -4226,6 +4327,14 @@ cmGeneratorTarget* cmMakefile::FindGeneratorTargetToUse(const char* name) bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg, bool isCustom) { + if(this->IsAlias(name.c_str())) + { + cmOStringStream e; + e << "cannot create target \"" << name + << "\" because an alias with the same name already exists."; + msg = e.str(); + return false; + } if(cmTarget* existing = this->FindTargetToUse(name.c_str())) { // The name given conflicts with an existing target. Produce an |