ENH: Make the LinkLibraries command contribute dependencies towards AddLibraries.

This commit is contained in:
Amitha Perera 2002-05-01 16:33:27 -04:00
parent 36f80fe6c8
commit 099436db26
6 changed files with 62 additions and 29 deletions

View File

@ -33,7 +33,7 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& argsIn)
std::vector<std::string>::const_iterator s = args.begin();
std::string libname = *s;
m_LibName = *s;
++s;
@ -67,8 +67,18 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& argsIn)
++s;
}
m_Makefile->AddLibrary(libname.c_str(), shared, srclists);
m_Makefile->AddLibrary(m_LibName.c_str(), shared, srclists);
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 );
}
}

View File

@ -43,6 +43,13 @@ 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.
*/
@ -72,6 +79,9 @@ public:
}
cmTypeMacro(cmAddLibraryCommand, cmCommand);
private:
std::string m_LibName;
};

View File

@ -1362,3 +1362,26 @@ void cmMakefile::EnableLanguage(const char* lang)
{
m_MakefileGenerator->EnableLanguage(lang);
}
void cmMakefile::AddDependencyToCache( std::string target, const std::string& lib )
{
// Add the explicit dependency information for this target. This is
// simply a set of libraries separated by ";". There should always
// be a trailing ";". These library names are not canonical, in that
// they may be "-framework x", "-ly", "/path/libz.a", etc.
target += "_LIB_DEPENDS";
std::string dependencies;
const char* old_val = GetDefinition( target.c_str() );
if( old_val )
{
dependencies += old_val;
}
if( dependencies.find( lib ) == std::string::npos )
{
dependencies += lib;
dependencies += ";";
}
AddCacheDefinition( target.c_str(), dependencies.c_str(),
"Dependencies for the target", cmCacheManager::INTERNAL );
}

View File

@ -155,13 +155,13 @@ 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.
// */
// cmTarget::LinkLibraries& GetLinkLibraries()
// {
// return m_LinkLibraries;
// }
/**
* Get a list of link libraries in the build.
@ -519,6 +519,11 @@ public:
///! Enable support for the named language, if null then all languages are enabled.
void EnableLanguage(const char* );
/**
* Adds the specified library to the explicit dependency list of target.
*/
void AddDependencyToCache( std::string target, const std::string& lib );
protected:
std::string m_Prefix;

View File

@ -90,25 +90,7 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf,
{
m_LinkLibraries.push_back( std::pair<std::string, cmTarget::LinkLibraryType>(lib,llt) );
// Add the explicit dependency information for this target. This is
// simply a set of libraries separated by ";". There should always
// be a trailing ";". These library names are not canonical, in that
// they may be "-framework x", "-ly", "/path/libz.a", etc.
std::string cache_name( target );
cache_name += "_LIB_DEPENDS";
std::string dependencies;
const char* old_val = mf.GetDefinition( cache_name.c_str() );
if( old_val )
{
dependencies += old_val;
}
if( dependencies.find( lib ) == std::string::npos )
{
dependencies += lib;
dependencies += ";";
}
mf.AddCacheDefinition( cache_name.c_str(), dependencies.c_str(),
"Dependencies for the target", cmCacheManager::INTERNAL );
mf.AddDependencyToCache( target, lib );
}
bool cmTarget::HasCxx() const
@ -125,6 +107,9 @@ bool cmTarget::HasCxx() const
}
void
cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
{

View File

@ -28,7 +28,7 @@ SET( CMAKE_ANALYZE_LIB_DEPENDS "ON" )
# One:
# Two: Three
# Three: One Four
# Four: One Two A
# Four: One Two NoDepA
# Five: Two
# SixA: Two Five
# SixB: Four Five