ENH: Compress the library search directories so that each appears only once.

This commit is contained in:
Amitha Perera 2001-06-05 22:54:42 -04:00
parent 22270abae5
commit 84edcba848
1 changed files with 20 additions and 9 deletions

View File

@ -251,6 +251,9 @@ void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
const char* targetLibrary, const char* targetLibrary,
const cmTarget &tgt) const cmTarget &tgt)
{ {
// Try to emit each search path once
std::set<std::string> emitted;
// collect all the flags needed for linking libraries // collect all the flags needed for linking libraries
std::string linkLibs; std::string linkLibs;
std::vector<std::string>& libdirs = m_Makefile->GetLinkDirectories(); std::vector<std::string>& libdirs = m_Makefile->GetLinkDirectories();
@ -260,16 +263,20 @@ void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
std::string libpath = cmSystemTools::EscapeSpaces(libDir->c_str()); std::string libpath = cmSystemTools::EscapeSpaces(libDir->c_str());
if(libpath != "/usr/lib") if(libpath != "/usr/lib")
{ {
std::string::size_type pos = libDir->find("-L"); if(emitted.insert(libpath).second)
if((pos == std::string::npos || pos > 0)
&& libDir->find("${") == std::string::npos)
{ {
linkLibs += "-L"; std::string::size_type pos = libDir->find("-L");
if((pos == std::string::npos || pos > 0)
&& libDir->find("${") == std::string::npos)
{
linkLibs += "-L";
}
linkLibs += libpath;
linkLibs += " ";
} }
linkLibs += libpath;
linkLibs += " ";
} }
} }
std::string librariesLinked; std::string librariesLinked;
const cmTarget::LinkLibraries& libs = tgt.GetLinkLibraries(); const cmTarget::LinkLibraries& libs = tgt.GetLinkLibraries();
cmRegularExpression reg("lib(.*)(\\.so$|\\.a|\\.sl$)"); cmRegularExpression reg("lib(.*)(\\.so$|\\.a|\\.sl$)");
@ -294,9 +301,12 @@ void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
std::string libpath = cmSystemTools::EscapeSpaces(dir.c_str()); std::string libpath = cmSystemTools::EscapeSpaces(dir.c_str());
if(libpath != "/usr/lib") if(libpath != "/usr/lib")
{ {
linkLibs += "-L"; if(emitted.insert(libpath).second)
linkLibs += libpath; {
linkLibs += " "; linkLibs += "-L";
linkLibs += libpath;
linkLibs += " ";
}
} }
cmRegularExpression libname("lib(.*)\\.(.*)"); cmRegularExpression libname("lib(.*)\\.(.*)");
if(libname.find(file)) if(libname.find(file))
@ -318,6 +328,7 @@ void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
librariesLinked += " "; librariesLinked += " ";
} }
} }
linkLibs += librariesLinked; linkLibs += librariesLinked;
if(!targetLibrary) if(!targetLibrary)