From 968c53ff6f42eb3e60a10009c308017aea5e0506 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 11 Feb 2008 10:31:44 -0500 Subject: BUG: Fix export_library_dependencies command to produce a file that is compatible with CMake 2.4. --- Source/cmExportLibraryDependencies.cxx | 118 +++++++++++++++++++++++++++------ 1 file changed, 97 insertions(+), 21 deletions(-) diff --git a/Source/cmExportLibraryDependencies.cxx b/Source/cmExportLibraryDependencies.cxx index 4a49696..c7ae3e9 100644 --- a/Source/cmExportLibraryDependencies.cxx +++ b/Source/cmExportLibraryDependencies.cxx @@ -77,42 +77,118 @@ void cmExportLibraryDependenciesCommand::ConstFinalPass() const cmSystemTools::ReportLastSystemError(""); return; } + + // Collect dependency information about all library targets built in + // the project. const cmake* cm = this->Makefile->GetCMakeInstance(); const cmGlobalGenerator* global = cm->GetGlobalGenerator(); const std::vector& locals = global->GetLocalGenerators(); - std::string libDepName; + std::map libDepsOld; + std::map libDepsNew; + std::map libTypes; for(std::vector::const_iterator i = locals.begin(); i != locals.end(); ++i) { const cmLocalGenerator* gen = *i; - const cmTargets &tgts = gen->GetMakefile()->GetTargets(); - std::vector depends; - const char *defType; + const cmTargets &tgts = gen->GetMakefile()->GetTargets(); for(cmTargets::const_iterator l = tgts.begin(); l != tgts.end(); ++l) { - libDepName = l->first; - libDepName += "_LIB_DEPENDS"; - const char* def = this->Makefile->GetDefinition(libDepName.c_str()); - if(def) + // Get the current target. + cmTarget const& target = l->second; + + // Skip non-library targets. + if(target.GetType() < cmTarget::STATIC_LIBRARY + || target.GetType() > cmTarget::MODULE_LIBRARY) + { + continue; + } + + // Construct the dependency variable name. + 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) { - fout << "SET(" << libDepName << " \"" << def << "\")\n"; - // now for each dependency, check for link type - cmSystemTools::ExpandListArgument(def, depends); - for(std::vector::const_iterator d = depends.begin(); - d != depends.end(); ++d) + std::string ltVar = li->first; + ltVar += "_LINK_TYPE"; + std::string ltValue; + switch(li->second) { - libDepName = *d; - libDepName += "_LINK_TYPE"; - defType = this->Makefile->GetDefinition(libDepName.c_str()); - libDepName = cmSystemTools::EscapeSpaces(libDepName.c_str()); - if(defType) - { - fout << "SET(" << libDepName << " \"" << defType << "\")\n"; - } + case cmTarget::GENERAL: + valueNew += "general;"; + ltValue = "general"; + break; + case cmTarget::DEBUG: + valueNew += "debug;"; + 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::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::const_iterator i = libDepsOld.begin(); + i != libDepsOld.end(); ++i) + { + if(!i->second.empty()) + { + fout << " SET(\"" << i->first << "\" \"" << i->second << "\")\n"; + } + } + for(std::map::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; } -- cgit v0.12