summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2001-04-12 13:55:08 (GMT)
committerBrad King <brad.king@kitware.com>2001-04-12 13:55:08 (GMT)
commitfb6c4b8710ea6023a2a55dddd7b0034c20f68705 (patch)
tree4ac20b05500ee44b1f28efc889f0d972b8f5e0d5 /Source
parente784f153cf93796b0386fec91e09607cf546ff73 (diff)
downloadCMake-fb6c4b8710ea6023a2a55dddd7b0034c20f68705.zip
CMake-fb6c4b8710ea6023a2a55dddd7b0034c20f68705.tar.gz
CMake-fb6c4b8710ea6023a2a55dddd7b0034c20f68705.tar.bz2
ENH: Added individual library linkage output so that shared libraries will not try to link against themselves.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmUnixMakefileGenerator.cxx40
-rw-r--r--Source/cmUnixMakefileGenerator.h2
2 files changed, 27 insertions, 15 deletions
diff --git a/Source/cmUnixMakefileGenerator.cxx b/Source/cmUnixMakefileGenerator.cxx
index 6ffed36..6d4bcd9 100644
--- a/Source/cmUnixMakefileGenerator.cxx
+++ b/Source/cmUnixMakefileGenerator.cxx
@@ -56,7 +56,7 @@ void cmUnixMakefileGenerator::OutputMakefile(const char* file)
this->OutputMakeFlags(fout);
this->OutputVerbatim(fout);
this->OutputTargetRules(fout);
- this->OutputLinkLibs(fout);
+ this->OutputDependencies(fout);
this->OutputTargets(fout);
this->OutputSubDirectoryRules(fout);
this->OutputObjectDepends(fout);
@@ -102,8 +102,14 @@ void cmUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
}
}
-// Output the rules for any targets
-void cmUnixMakefileGenerator::OutputLinkLibs(std::ostream& fout)
+
+/**
+ * Output the linking rules on a command line. For executables,
+ * targetLibrary should be a NULL pointer. For libraries, it should point
+ * to the name of the library. This will not link a library against itself.
+ */
+void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
+ const char* targetLibrary)
{
// collect all the flags needed for linking libraries
std::string linkLibs;
@@ -124,6 +130,8 @@ void cmUnixMakefileGenerator::OutputLinkLibs(std::ostream& fout)
std::vector<std::string>& libs = m_Makefile->GetLinkLibraries();
for(j = libs.begin(); j != libs.end(); ++j)
{
+ // Don't link the library against itself!
+ if(targetLibrary && (*j == targetLibrary)) continue;
std::string::size_type pos = (*j).find("-l");
if((pos == std::string::npos || pos > 0)
&& (*j).find("${") == std::string::npos)
@@ -133,9 +141,13 @@ void cmUnixMakefileGenerator::OutputLinkLibs(std::ostream& fout)
librariesLinked += *j;
librariesLinked += " ";
}
- // Add these in twice so order does not matter
- linkLibs += librariesLinked;
linkLibs += librariesLinked;
+
+ if(!targetLibrary)
+ {
+ // For executables, add these a second time so order does not matter
+ linkLibs += librariesLinked;
+ }
std::vector<std::string>& libsUnix = m_Makefile->GetLinkLibrariesUnix();
for(j = libsUnix.begin(); j != libsUnix.end(); ++j)
@@ -144,14 +156,10 @@ void cmUnixMakefileGenerator::OutputLinkLibs(std::ostream& fout)
linkLibs += " ";
}
linkLibs += " ${LOCAL_LINK_FLAGS} ";
- fout << "CMAKE_LINK_LIBS = " << linkLibs << "\n\n";
- // create and output a varible in the makefile that
- // each executable will depend on. This will have all the
- // libraries that the executable uses
- fout << "CMAKE_DEPEND_LIBS = ";
- this->OutputDependencies(fout);
+ fout << linkLibs;
}
+
void cmUnixMakefileGenerator::OutputTargets(std::ostream& fout)
{
// for each target
@@ -177,15 +185,18 @@ void cmUnixMakefileGenerator::OutputTargets(std::ostream& fout)
fout << "\t$(CXX) ${CXX_FLAGS} ${CMAKE_SHLIB_BUILD_FLAGS} -o \\\n";
fout << "\t lib" << l->first << "$(SHLIB_SUFFIX) \\\n";
fout << "\t ${KIT_OBJ} ${" << l->first <<
- "_SRC_OBJS} ${CMAKE_LINK_LIBS}\n\n";
+ "_SRC_OBJS} ";
+ this->OutputLinkLibraries(fout, l->first.c_str());
+ fout << "\n\n";
}
else
{
fout << l->first << ": ${" <<
l->first << "_SRC_OBJS} ${CMAKE_DEPEND_LIBS}\n";
fout << "\t${CXX} ${CXX_FLAGS} ${" <<
- l->first << "_SRC_OBJS} ${CMAKE_LINK_LIBS} -o "
- << l->first << "\n\n";
+ l->first << "_SRC_OBJS} ";
+ this->OutputLinkLibraries(fout, NULL);
+ fout << " -o " << l->first << "\n\n";
}
}
}
@@ -195,6 +206,7 @@ void cmUnixMakefileGenerator::OutputTargets(std::ostream& fout)
// in this makefile will depend on.
void cmUnixMakefileGenerator::OutputDependencies(std::ostream& fout)
{
+ fout << "CMAKE_DEPEND_LIBS = ";
std::vector<std::string>& libs = m_Makefile->GetLinkLibraries();
std::vector<std::string>& libdirs = m_Makefile->GetLinkDirectories();
std::vector<std::string>::iterator dir, lib;
diff --git a/Source/cmUnixMakefileGenerator.h b/Source/cmUnixMakefileGenerator.h
index b672e72..3826e73 100644
--- a/Source/cmUnixMakefileGenerator.h
+++ b/Source/cmUnixMakefileGenerator.h
@@ -45,7 +45,7 @@ protected:
void OutputMakeFlags(std::ostream&);
void OutputVerbatim(std::ostream&);
void OutputTargetRules(std::ostream& fout);
- void OutputLinkLibs(std::ostream& fout);
+ void OutputLinkLibraries(std::ostream&, const char*);
void OutputTargets(std::ostream&);
void OutputSubDirectoryRules(std::ostream&);
void OutputDependInformation(std::ostream&);