diff options
Diffstat (limited to 'Source/cmTargetLinkLibrariesCommand.cxx')
-rw-r--r-- | Source/cmTargetLinkLibrariesCommand.cxx | 77 |
1 files changed, 73 insertions, 4 deletions
diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index 73bb5a5..21acf80 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -40,17 +40,39 @@ bool cmTargetLinkLibrariesCommand return true; } + // Lookup the target for which libraries are specified. + this->Target = + this->Makefile->GetCMakeInstance() + ->GetGlobalGenerator()->FindTarget(0, args[0].c_str()); + if(!this->Target) + { + cmOStringStream e; + e << "Cannot specify link libraries for target \"" << args[0] << "\" " + << "which is not built by this project."; + this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + cmSystemTools::SetFatalErrorOccured(); + return true; + } + // Keep track of link configuration specifiers. cmTarget::LinkLibraryType llt = cmTarget::GENERAL; bool haveLLT = false; + // Start with primary linking and switch to link interface + // specification when the keyword is encountered. + this->DoingInterface = false; + // add libraries, nothe that there is an optional prefix // of debug and optimized than can be used std::vector<std::string>::const_iterator i = args.begin(); for(++i; i != args.end(); ++i) { - if(*i == "debug") + if(*i == "INTERFACE") + { + this->DoingInterface = true; + } + else if(*i == "debug") { if(haveLLT) { @@ -81,8 +103,7 @@ bool cmTargetLinkLibrariesCommand { // The link type was specified by the previous argument. haveLLT = false; - this->Makefile->AddLinkLibraryForTarget(args[0].c_str(), - i->c_str(), llt); + this->HandleLibrary(i->c_str(), llt); } else { @@ -108,7 +129,7 @@ bool cmTargetLinkLibrariesCommand llt = cmTarget::OPTIMIZED; } } - this->Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),llt); + this->HandleLibrary(i->c_str(), llt); } } @@ -122,6 +143,15 @@ bool cmTargetLinkLibrariesCommand cmSystemTools::SetFatalErrorOccured(); } + // If the INTERFACE option was given, make sure the + // LINK_INTERFACE_LIBRARIES property exists. This allows the + // command to be used to specify an empty link interface. + if(this->DoingInterface && + !this->Target->GetProperty("LINK_INTERFACE_LIBRARIES")) + { + this->Target->SetProperty("LINK_INTERFACE_LIBRARIES", ""); + } + return true; } @@ -137,3 +167,42 @@ cmTargetLinkLibrariesCommand << "The first specifier will be ignored."; this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); } + +//---------------------------------------------------------------------------- +void +cmTargetLinkLibrariesCommand::HandleLibrary(const char* lib, + cmTarget::LinkLibraryType llt) +{ + // Handle normal case first. + if(!this->DoingInterface) + { + this->Makefile + ->AddLinkLibraryForTarget(this->Target->GetName(), lib, llt); + return; + } + + // Include this library in the link interface for the target. + if(llt == cmTarget::DEBUG) + { + // Put in only the DEBUG configuration interface. + this->Target->AppendProperty("LINK_INTERFACE_LIBRARIES_DEBUG", lib); + } + else if(llt == cmTarget::OPTIMIZED) + { + // Put in only the non-DEBUG configuration interface. + this->Target->AppendProperty("LINK_INTERFACE_LIBRARIES", lib); + + // Make sure the DEBUG configuration interface exists so that this + // one will not be used as a fall-back. + if(!this->Target->GetProperty("LINK_INTERFACE_LIBRARIES_DEBUG")) + { + this->Target->SetProperty("LINK_INTERFACE_LIBRARIES_DEBUG", ""); + } + } + else + { + // Put in both the DEBUG and non-DEBUG configuration interfaces. + this->Target->AppendProperty("LINK_INTERFACE_LIBRARIES", lib); + this->Target->AppendProperty("LINK_INTERFACE_LIBRARIES_DEBUG", lib); + } +} |