BUG: Fix export_library_dependencies command to produce a file that is compatible with CMake 2.4.
This commit is contained in:
parent
7b048433c1
commit
968c53ff6f
@ -77,42 +77,118 @@ void cmExportLibraryDependenciesCommand::ConstFinalPass() const
|
|||||||
cmSystemTools::ReportLastSystemError("");
|
cmSystemTools::ReportLastSystemError("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Collect dependency information about all library targets built in
|
||||||
|
// the project.
|
||||||
const cmake* cm = this->Makefile->GetCMakeInstance();
|
const cmake* cm = this->Makefile->GetCMakeInstance();
|
||||||
const cmGlobalGenerator* global = cm->GetGlobalGenerator();
|
const cmGlobalGenerator* global = cm->GetGlobalGenerator();
|
||||||
const std::vector<cmLocalGenerator *>& locals = global->GetLocalGenerators();
|
const std::vector<cmLocalGenerator *>& locals = global->GetLocalGenerators();
|
||||||
std::string libDepName;
|
std::map<cmStdString, cmStdString> libDepsOld;
|
||||||
|
std::map<cmStdString, cmStdString> libDepsNew;
|
||||||
|
std::map<cmStdString, cmStdString> libTypes;
|
||||||
for(std::vector<cmLocalGenerator *>::const_iterator i = locals.begin();
|
for(std::vector<cmLocalGenerator *>::const_iterator i = locals.begin();
|
||||||
i != locals.end(); ++i)
|
i != locals.end(); ++i)
|
||||||
{
|
{
|
||||||
const cmLocalGenerator* gen = *i;
|
const cmLocalGenerator* gen = *i;
|
||||||
const cmTargets &tgts = gen->GetMakefile()->GetTargets();
|
const cmTargets &tgts = gen->GetMakefile()->GetTargets();
|
||||||
std::vector<std::string> depends;
|
|
||||||
const char *defType;
|
|
||||||
for(cmTargets::const_iterator l = tgts.begin();
|
for(cmTargets::const_iterator l = tgts.begin();
|
||||||
l != tgts.end(); ++l)
|
l != tgts.end(); ++l)
|
||||||
{
|
{
|
||||||
libDepName = l->first;
|
// Get the current target.
|
||||||
libDepName += "_LIB_DEPENDS";
|
cmTarget const& target = l->second;
|
||||||
const char* def = this->Makefile->GetDefinition(libDepName.c_str());
|
|
||||||
if(def)
|
// Skip non-library targets.
|
||||||
|
if(target.GetType() < cmTarget::STATIC_LIBRARY
|
||||||
|
|| target.GetType() > cmTarget::MODULE_LIBRARY)
|
||||||
{
|
{
|
||||||
fout << "SET(" << libDepName << " \"" << def << "\")\n";
|
continue;
|
||||||
// now for each dependency, check for link type
|
}
|
||||||
cmSystemTools::ExpandListArgument(def, depends);
|
|
||||||
for(std::vector<std::string>::const_iterator d = depends.begin();
|
// Construct the dependency variable name.
|
||||||
d != depends.end(); ++d)
|
std::string targetEntry = target.GetName();
|
||||||
|
targetEntry += "_LIB_DEPENDS";
|
||||||
|
|
||||||
|
// Construct the dependency variable value. It is safe to use
|
||||||
|
// the target GetLinkLibraries method here because this code is
|
||||||
|
// called at the end of configure but before generate so library
|
||||||
|
// dependencies have yet to be analyzed. Therefore the value
|
||||||
|
// will be the direct link dependencies.
|
||||||
|
std::string valueOld;
|
||||||
|
std::string valueNew;
|
||||||
|
cmTarget::LinkLibraryVectorType const& libs = target.GetLinkLibraries();
|
||||||
|
for(cmTarget::LinkLibraryVectorType::const_iterator li = libs.begin();
|
||||||
|
li != libs.end(); ++li)
|
||||||
|
{
|
||||||
|
std::string ltVar = li->first;
|
||||||
|
ltVar += "_LINK_TYPE";
|
||||||
|
std::string ltValue;
|
||||||
|
switch(li->second)
|
||||||
{
|
{
|
||||||
libDepName = *d;
|
case cmTarget::GENERAL:
|
||||||
libDepName += "_LINK_TYPE";
|
valueNew += "general;";
|
||||||
defType = this->Makefile->GetDefinition(libDepName.c_str());
|
ltValue = "general";
|
||||||
libDepName = cmSystemTools::EscapeSpaces(libDepName.c_str());
|
break;
|
||||||
if(defType)
|
case cmTarget::DEBUG:
|
||||||
{
|
valueNew += "debug;";
|
||||||
fout << "SET(" << libDepName << " \"" << defType << "\")\n";
|
ltValue = "debug";
|
||||||
}
|
break;
|
||||||
|
case cmTarget::OPTIMIZED:
|
||||||
|
valueNew += "optimized;";
|
||||||
|
ltValue = "optimized";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
valueOld += li->first;
|
||||||
|
valueOld += ";";
|
||||||
|
valueNew += li->first;
|
||||||
|
valueNew += ";";
|
||||||
|
|
||||||
|
std::string& ltEntry = libTypes[ltVar];
|
||||||
|
if(ltEntry.empty())
|
||||||
|
{
|
||||||
|
ltEntry = ltValue;
|
||||||
|
}
|
||||||
|
else if(ltEntry != ltValue)
|
||||||
|
{
|
||||||
|
ltEntry = "general";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
libDepsNew[targetEntry] = valueNew;
|
||||||
|
libDepsOld[targetEntry] = valueOld;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate dependency information for both old and new style CMake
|
||||||
|
// versions.
|
||||||
|
const char* vertest =
|
||||||
|
"\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" GREATER 2.4";
|
||||||
|
fout << "IF(" << vertest << ")\n";
|
||||||
|
fout << " # Information for CMake 2.6 and above.\n";
|
||||||
|
for(std::map<cmStdString, cmStdString>::const_iterator i = libDepsNew.begin();
|
||||||
|
i != libDepsNew.end(); ++i)
|
||||||
|
{
|
||||||
|
if(!i->second.empty())
|
||||||
|
{
|
||||||
|
fout << " SET(\"" << i->first << "\" \"" << i->second << "\")\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fout << "ELSE(" << vertest << ")\n";
|
||||||
|
fout << " # Information for CMake 2.4 and lower.\n";
|
||||||
|
for(std::map<cmStdString, cmStdString>::const_iterator i = libDepsOld.begin();
|
||||||
|
i != libDepsOld.end(); ++i)
|
||||||
|
{
|
||||||
|
if(!i->second.empty())
|
||||||
|
{
|
||||||
|
fout << " SET(\"" << i->first << "\" \"" << i->second << "\")\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(std::map<cmStdString, cmStdString>::const_iterator i = libTypes.begin();
|
||||||
|
i != libTypes.end(); ++i)
|
||||||
|
{
|
||||||
|
if(i->second != "general")
|
||||||
|
{
|
||||||
|
fout << " SET(\"" << i->first << "\" \"" << i->second << "\")\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fout << "ENDIF(" << vertest << ")\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user