Commit 27fe57b7 authored by Bill Hoffman's avatar Bill Hoffman
Browse files

ENH: change LINK_LIBRARY to add to targets

parent b5b46599
......@@ -72,13 +72,4 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& argsIn)
return true;
}
void cmAddLibraryCommand::FinalPass()
{
const cmTarget::LinkLibraries& libs = m_Makefile->GetLinkLibraries();
for( cmTarget::LinkLibraries::const_iterator i = libs.begin();
i != libs.end(); ++i )
{
m_Makefile->AddDependencyToCache( m_LibName.c_str(), i->first );
}
}
......@@ -43,13 +43,6 @@ public:
*/
virtual bool InitialPass(std::vector<std::string> const& args);
/**
* This is called at the end after all the information specified by
* the command is accumulated. This is where we add in the
* dependencies that were globally specified.
*/
virtual void FinalPass();
/**
* The name of the command as specified in CMakeList.txt.
*/
......
......@@ -428,8 +428,6 @@ void cmMakefile::GenerateMakefile()
l != m_Targets.end(); l++)
{
l->second.GenerateSourceFilesFromSourceLists(*this);
l->second.MergeLibraries(m_LinkLibraries);
l->second.MergeDirectories(m_LinkDirectories);
l->second.AnalyzeLibDependencies(*this);
}
// now do the generation
......@@ -520,10 +518,11 @@ void cmMakefile::AddLinkLibrary(const char* lib, cmTarget::LinkLibraryType llt)
void cmMakefile::AddLinkLibraryForTarget(const char *target,
const char* lib,
cmTarget::LinkLibraryType llt)
{
if (m_Targets.find(target) != m_Targets.end())
{
cmTargets::iterator i = m_Targets.find(target);
if ( i != m_Targets.end())
{
m_Targets[target].AddLinkLibrary( *this, target, lib, llt );
i->second.AddLinkLibrary( *this, target, lib, llt );
}
else
{
......@@ -531,6 +530,21 @@ void cmMakefile::AddLinkLibraryForTarget(const char *target,
}
}
void cmMakefile::AddLinkDirectoryForTarget(const char *target,
const char* d)
{
cmTargets::iterator i = m_Targets.find(target);
if ( i != m_Targets.end())
{
i->second.AddLinkDirectory( d );
}
else
{
cmSystemTools::Error("Attempt to add link directories to non-existant target: ",
target, " for directory ", d);
}
}
void cmMakefile::AddLinkLibrary(const char* lib)
{
this->AddLinkLibrary(lib,cmTarget::GENERAL);
......@@ -654,7 +668,20 @@ void cmMakefile::AddLibrary(const char* lname, int shared,
target.SetInAll(true);
target.GetSourceLists() = srcs;
std::vector<std::string>::iterator j;
for(j = m_LinkDirectories.begin();
j != m_LinkDirectories.end(); ++j)
{
target.AddLinkDirectory(j->c_str());
}
m_Targets.insert(cmTargets::value_type(lname,target));
cmTarget::LinkLibraries::iterator i;
for(i = m_LinkLibraries.begin(); i != m_LinkLibraries.end(); ++i)
{
this->AddLinkLibraryForTarget(lname, i->first.c_str(), i->second);
}
// Add an entry into the cache
cmCacheManager::GetInstance()->
......@@ -727,7 +754,18 @@ void cmMakefile::AddExecutable(const char *exeName,
}
target.SetInAll(true);
target.GetSourceLists() = srcs;
std::vector<std::string>::iterator j;
for(j = m_LinkDirectories.begin();
j != m_LinkDirectories.end(); ++j)
{
target.AddLinkDirectory(j->c_str());
}
m_Targets.insert(cmTargets::value_type(exeName,target));
cmTarget::LinkLibraries::iterator i;
for(i = m_LinkLibraries.begin(); i != m_LinkLibraries.end(); ++i)
{
this->AddLinkLibraryForTarget(exeName, i->first.c_str(), i->second);
}
// Add an entry into the cache
cmCacheManager::GetInstance()->
......
......@@ -155,22 +155,6 @@ public:
const std::vector<std::string> &depends,
const std::vector<std::string> &outputs);
// /**
// * Get a list of link libraries in the build.
// */
// cmTarget::LinkLibraries& GetLinkLibraries()
// {
// return m_LinkLibraries;
// }
/**
* Get a list of link libraries in the build.
*/
const cmTarget::LinkLibraries& GetLinkLibraries() const
{
return m_LinkLibraries;
}
/**
* Add a link library to the build.
*/
......@@ -178,6 +162,7 @@ public:
void AddLinkLibrary(const char*, cmTarget::LinkLibraryType type);
void AddLinkLibraryForTarget(const char *tgt, const char*,
cmTarget::LinkLibraryType type);
void AddLinkDirectoryForTarget(const char *tgt, const char* d);
/**
* Add a link directory to the build.
......
......@@ -67,16 +67,6 @@ void cmTarget::GenerateSourceFilesFromSourceLists( cmMakefile &mf)
}
}
void cmTarget::MergeLibraries(const LinkLibraries &ll)
{
m_LinkLibraries.insert( m_LinkLibraries.end(), ll.begin(), ll.end() );
}
void cmTarget::MergeDirectories(const std::vector<std::string> &ld)
{
m_LinkDirectories.insert( m_LinkDirectories.end(), ld.begin(), ld.end() );
}
void cmTarget::AddLinkLibrary(const std::string& lib,
LinkLibraryType llt)
......@@ -276,7 +266,9 @@ void cmTarget::Emit( const std::string& lib,
{
// It's already been emitted
if( emitted.find(lib) != emitted.end() )
{
return;
}
// If this library hasn't been visited before, then emit all its
// dependencies before emitting the library itself. If it has been
......
......@@ -81,6 +81,7 @@ public:
const LinkLibraries &GetLinkLibraries() const {return m_LinkLibraries;}
const std::vector<std::string>& GetLinkDirectories() const {return m_LinkDirectories;}
void AddLinkDirectory(const char* d) { m_LinkDirectories.push_back(d);}
/**
* Set the path where this target should be installed. This is relative to
......@@ -96,16 +97,6 @@ public:
void AddLinkLibrary(const std::string& lib,
LinkLibraryType llt);
/**
* Merge Link Libraries into this targets current list
*/
void MergeLibraries(const LinkLibraries &ll);
/**
* Merge Link Directories into this targets current list
*/
void MergeDirectories(const std::vector<std::string> &ld);
/**
* Generate the SourceFilesList from the SourceLists. This should only be
* done once to be safe.
......
......@@ -57,12 +57,12 @@ bool cmTargetLinkLibrariesCommand::InitialPass(std::vector<std::string> const& a
const char* dir = m_Makefile->GetDefinition(i->c_str());
if( dir )
{
m_Makefile->AddLinkDirectory( dir );
m_Makefile->AddLinkDirectoryForTarget(args[0].c_str(), dir );
}
}
else
{
m_Makefile->AddLinkDirectory( ldir );
m_Makefile->AddLinkDirectoryForTarget(args[0].c_str(), ldir );
}
}
return true;
......
......@@ -890,22 +890,6 @@ void cmUnixMakefileGenerator::OutputDependLibs(std::ostream& fout)
// A library should not depend on itself!
emitted.insert(l->first);
// First look at all makefile level link libraries.
const cmTarget::LinkLibraries& libs = m_Makefile->GetLinkLibraries();
for(cmTarget::LinkLibraries::const_iterator lib = libs.begin();
lib != libs.end(); ++lib)
{
// Record that this library was used.
used.insert(lib->first);
// Don't emit the same library twice for this target.
if(emitted.insert(lib->first).second)
{
// Output this dependency.
this->OutputLibDepend(fout, lib->first.c_str());
}
}
// Now, look at all link libraries specific to this target.
const cmTarget::LinkLibraries& tlibs = l->second.GetLinkLibraries();
for(cmTarget::LinkLibraries::const_iterator lib = tlibs.begin();
......
......@@ -5,22 +5,16 @@ CMAKE_MINIMUM_REQUIRED(VERSION 1.3)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS")
SET_SOURCE_FILES_PROPERTIES(complex COMPILE_FLAGS
"-DFILE_HAS_EXTRA_COMPILE_FLAGS")
ADD_EXECUTABLE(complex complex)
SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
# Link to CMake lib
LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source)
# Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to
SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
LINK_LIBRARIES(${COMPLEX_LIBS})
#
# Link to CMake lib
# Specify the same one for debug/optimized to increase coverage
#
LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source)
ADD_EXECUTABLE(complex complex)
TARGET_LINK_LIBRARIES(complex
CMakeLib
debug CMakeLib
optimized CMakeLib)
CMakeLib)
#
# Output the files required by 'complex' to a file.
......
......@@ -5,22 +5,16 @@ CMAKE_MINIMUM_REQUIRED(VERSION 1.3)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS")
SET_SOURCE_FILES_PROPERTIES(complex COMPILE_FLAGS
"-DFILE_HAS_EXTRA_COMPILE_FLAGS")
ADD_EXECUTABLE(complex complex)
SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
# Link to CMake lib
LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source)
# Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to
SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
LINK_LIBRARIES(${COMPLEX_LIBS})
#
# Link to CMake lib
# Specify the same one for debug/optimized to increase coverage
#
LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source)
ADD_EXECUTABLE(complex complex)
TARGET_LINK_LIBRARIES(complex
CMakeLib
debug CMakeLib
optimized CMakeLib)
CMakeLib)
#
# Output the files required by 'complex' to a file.
......
......@@ -5,22 +5,16 @@ CMAKE_MINIMUM_REQUIRED(VERSION 1.3)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS")
SET_SOURCE_FILES_PROPERTIES(complex COMPILE_FLAGS
"-DFILE_HAS_EXTRA_COMPILE_FLAGS")
ADD_EXECUTABLE(complex complex)
SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
# Link to CMake lib
LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source)
# Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to
SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
LINK_LIBRARIES(${COMPLEX_LIBS})
#
# Link to CMake lib
# Specify the same one for debug/optimized to increase coverage
#
LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source)
ADD_EXECUTABLE(complex complex)
TARGET_LINK_LIBRARIES(complex
CMakeLib
debug CMakeLib
optimized CMakeLib)
CMakeLib)
#
# Output the files required by 'complex' to a file.
......
ADD_EXECUTABLE( exec ExecMain.c )
# This executable directly depends on NoDepB, NoDepC, SixA and SixB. However,
# since NoDepB and NoDepC do not have explicit dependency information,
# and they depend on NoDepA, we have to manually specify that dependency.
LINK_LIBRARIES( NoDepB NoDepC NoDepA SixB SixA )
ADD_EXECUTABLE( exec ExecMain.c )
......@@ -3,10 +3,10 @@
# specify them in the correct order.
LINK_LIBRARIES( Two )
LINK_LIBRARIES( Five )
ADD_LIBRARY( SixA SixASrc.c )
ADD_LIBRARY( SixB SixBSrc.c )
TARGET_LINK_LIBRARIES( SixB Four )
LINK_LIBRARIES( Five )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment