Commit 099436db authored by Amitha Perera's avatar Amitha Perera
Browse files

ENH: Make the LinkLibraries command contribute dependencies towards AddLibraries.

parent 36f80fe6
......@@ -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 );
}
}
......@@ -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;
};
......
......@@ -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 );
}
......@@ -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.
......@@ -520,6 +520,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;
std::vector<std::string> m_AuxSourceDirectories; //
......
......@@ -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 )
{
......
......@@ -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
......
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