ENH: Link runtime libraries of all languages
This adds implicit libraries and search directories for languages linked into a target other than the linker language to its link line. For example, when linking an executable containing both C++ and Fortran code the C++ linker is used but we need to add the Fortran libraries. The variables CMAKE_<LANG>_IMPLICIT_LINK_LIBRARIES CMAKE_<LANG>_IMPLICIT_LINK_DIRECTORIES contain the implicit libraries and directories for each language. Entries for the linker language are known to be implicit in the generated link line. Entries for other languages that do not appear in the known implicit set are listed explicitly at the end of the link line.
This commit is contained in:
parent
0afa7a95f2
commit
0de8be8b49
|
@ -552,6 +552,47 @@ bool cmComputeLinkInformation::Compute()
|
|||
return false;
|
||||
}
|
||||
|
||||
// Add implicit language runtime libraries and directories.
|
||||
cmTarget::LinkClosure const* lc=this->Target->GetLinkClosure(this->Config);
|
||||
for(std::vector<std::string>::const_iterator li = lc->Languages.begin();
|
||||
li != lc->Languages.end(); ++li)
|
||||
{
|
||||
// Skip those of the linker language. They are implicit.
|
||||
if(*li != this->LinkLanguage)
|
||||
{
|
||||
// Add libraries for this language that are not implied by the
|
||||
// linker language.
|
||||
std::string libVar = "CMAKE_";
|
||||
libVar += *li;
|
||||
libVar += "_IMPLICIT_LINK_LIBRARIES";
|
||||
if(const char* libs = this->Makefile->GetDefinition(libVar.c_str()))
|
||||
{
|
||||
std::vector<std::string> libsVec;
|
||||
cmSystemTools::ExpandListArgument(libs, libsVec);
|
||||
for(std::vector<std::string>::const_iterator i = libsVec.begin();
|
||||
i != libsVec.end(); ++i)
|
||||
{
|
||||
if(this->ImplicitLinkLibs.find(*i) == this->ImplicitLinkLibs.end())
|
||||
{
|
||||
this->AddItem(i->c_str(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add linker search paths for this language that are not
|
||||
// implied by the linker language.
|
||||
std::string dirVar = "CMAKE_";
|
||||
dirVar += *li;
|
||||
dirVar += "_IMPLICIT_LINK_DIRECTORIES";
|
||||
if(const char* dirs = this->Makefile->GetDefinition(dirVar.c_str()))
|
||||
{
|
||||
std::vector<std::string> dirsVec;
|
||||
cmSystemTools::ExpandListArgument(dirs, dirsVec);
|
||||
this->OrderLinkerSearchPath->AddLanguageDirectories(dirsVec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1551,12 +1592,40 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo()
|
|||
cmSystemTools::ExpandListArgument(implicitLinks, implicitDirVec);
|
||||
}
|
||||
|
||||
// Get language-specific implicit directories.
|
||||
std::string implicitDirVar = "CMAKE_";
|
||||
implicitDirVar += this->LinkLanguage;
|
||||
implicitDirVar += "_IMPLICIT_LINK_DIRECTORIES";
|
||||
if(const char* implicitDirs =
|
||||
this->Makefile->GetDefinition(implicitDirVar.c_str()))
|
||||
{
|
||||
cmSystemTools::ExpandListArgument(implicitDirs, implicitDirVec);
|
||||
}
|
||||
|
||||
// Store implicit link directories.
|
||||
for(std::vector<std::string>::const_iterator i = implicitDirVec.begin();
|
||||
i != implicitDirVec.end(); ++i)
|
||||
{
|
||||
this->ImplicitLinkDirs.insert(*i);
|
||||
}
|
||||
|
||||
// Get language-specific implicit libraries.
|
||||
std::vector<std::string> implicitLibVec;
|
||||
std::string implicitLibVar = "CMAKE_";
|
||||
implicitLibVar += this->LinkLanguage;
|
||||
implicitLibVar += "_IMPLICIT_LINK_LIBRARIES";
|
||||
if(const char* implicitLibs =
|
||||
this->Makefile->GetDefinition(implicitLibVar.c_str()))
|
||||
{
|
||||
cmSystemTools::ExpandListArgument(implicitLibs, implicitLibVec);
|
||||
}
|
||||
|
||||
// Store implicit link libraries.
|
||||
for(std::vector<std::string>::const_iterator i = implicitLibVec.begin();
|
||||
i != implicitLibVec.end(); ++i)
|
||||
{
|
||||
this->ImplicitLinkLibs.insert(*i);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
@ -160,8 +160,11 @@ private:
|
|||
cmOrderDirectories* OrderLinkerSearchPath;
|
||||
bool FinishLinkerSearchDirectories();
|
||||
void PrintLinkPolicyDiagnosis(std::ostream&);
|
||||
|
||||
// Implicit link libraries and directories for linker language.
|
||||
void LoadImplicitLinkInfo();
|
||||
std::set<cmStdString> ImplicitLinkDirs;
|
||||
std::set<cmStdString> ImplicitLinkLibs;
|
||||
|
||||
// Linker search path compatibility mode.
|
||||
std::set<cmStdString> OldLinkDirMask;
|
||||
|
|
|
@ -369,6 +369,15 @@ cmOrderDirectories
|
|||
extra.begin(), extra.end());
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void
|
||||
cmOrderDirectories
|
||||
::AddLanguageDirectories(std::vector<std::string> const& dirs)
|
||||
{
|
||||
this->LanguageDirectories.insert(this->LanguageDirectories.end(),
|
||||
dirs.begin(), dirs.end());
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void
|
||||
cmOrderDirectories
|
||||
|
@ -400,6 +409,9 @@ void cmOrderDirectories::CollectOriginalDirectories()
|
|||
{
|
||||
this->ConstraintEntries[i]->AddDirectory();
|
||||
}
|
||||
|
||||
// Add language runtime directories last.
|
||||
this->AddOriginalDirectories(this->LanguageDirectories);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
void AddRuntimeLibrary(std::string const& fullPath, const char* soname = 0);
|
||||
void AddLinkLibrary(std::string const& fullPath);
|
||||
void AddUserDirectories(std::vector<std::string> const& extra);
|
||||
void AddLanguageDirectories(std::vector<std::string> const& dirs);
|
||||
void SetImplicitDirectories(std::set<cmStdString> const& implicitDirs);
|
||||
void SetLinkExtensionInfo(std::vector<std::string> const& linkExtensions,
|
||||
std::string const& removeExtRegex);
|
||||
|
@ -56,6 +57,7 @@ private:
|
|||
std::vector<cmOrderDirectoriesConstraint*> ConstraintEntries;
|
||||
std::vector<cmOrderDirectoriesConstraint*> ImplicitDirEntries;
|
||||
std::vector<std::string> UserDirectories;
|
||||
std::vector<std::string> LanguageDirectories;
|
||||
cmsys::RegularExpression RemoveLibraryExtension;
|
||||
std::vector<std::string> LinkExtensions;
|
||||
std::set<cmStdString> ImplicitDirectories;
|
||||
|
|
Loading…
Reference in New Issue