From 487bd571d56134b15b1060e1921a7e16711f12e6 Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 31 Oct 2010 16:23:40 +0100 Subject: Properly insert all targets, also those which don't link to anything. Alex --- Source/cmake.cxx | 129 +++++++++++++++++++------------------------------------ Source/cmake.h | 1 - 2 files changed, 45 insertions(+), 85 deletions(-) diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 6ccb2d2..af01d0d 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2835,10 +2835,31 @@ const char* cmake::GetCPackCommand() return this->CPackCommand.c_str(); } -// for target deps -#define DOT_DEP_TARGET 1 -#define DOT_DEP_EXTERNAL 2 -#define DOT_DEP_NONE 0 + +static const char* getShapeForTarget(const cmTarget* target) +{ + if (!target) + { + return "ellipse"; + } + + switch ( target->GetType() ) + { + case cmTarget::EXECUTABLE: + return "house"; + case cmTarget::STATIC_LIBRARY: + return "diamond"; + case cmTarget::SHARED_LIBRARY: + return "polygon"; + case cmTarget::MODULE_LIBRARY: + return "octagon"; + default: + break; + } + + return "box"; +} + void cmake::GenerateGraphViz(const char* fileName) const { @@ -2910,7 +2931,6 @@ void cmake::GenerateGraphViz(const char* fileName) const const std::vector& localGenerators = gg->GetLocalGenerators(); - std::map targetDeps; std::map targetPtrs; std::map targetNamesNodes; // maps from the actual strings to node names in dot int cnt = 0; @@ -2918,64 +2938,20 @@ void cmake::GenerateGraphViz(const char* fileName) const graphNodePrefix); cnt += getAllExternalLibs(ignoreTargetsSet, targetNamesNodes, targetPtrs, - targetDeps, graphNodePrefix); + graphNodePrefix); // Write out nodes - for(std::map::const_iterator depIt = targetDeps.begin(); - depIt != targetDeps.end(); - ++ depIt ) + for(std::map::const_iterator tarIt = + targetPtrs.begin(); tarIt != targetPtrs.end(); ++ tarIt ) { - const char* newTargetName = depIt->first.c_str(); - std::map::const_iterator tarIt = + const char* newTargetName = tarIt->first.c_str(); + std::map::const_iterator nameIt = targetNamesNodes.find(newTargetName); - if ( tarIt == targetNamesNodes.end() ) - { - // We should not be here. - std::cout << __LINE__ << " Cannot find library: " << newTargetName - << " even though it was added in the previous pass" - << std::endl; - abort(); - } - str << " \"" << tarIt->second.c_str() << "\" [ label=\"" - << newTargetName << "\" shape=\""; - if ( depIt->second == DOT_DEP_TARGET ) - { - std::map::const_iterator tarTypeIt = - targetPtrs.find(newTargetName); - if ( tarTypeIt == targetPtrs.end() ) - { - // We should not be here. - std::cout << __LINE__ << " Cannot find library: " << newTargetName - << " even though it was added in the previous pass" - << std::endl; - abort(); - } - const cmTarget* tg = tarTypeIt->second; - switch ( tg->GetType() ) - { - case cmTarget::EXECUTABLE: - str << "house"; - break; - case cmTarget::STATIC_LIBRARY: - str << "diamond"; - break; - case cmTarget::SHARED_LIBRARY: - str << "polygon"; - break; - case cmTarget::MODULE_LIBRARY: - str << "octagon"; - break; - default: - str << "box"; - } - } - else - { - str << "ellipse"; - } - str << "\"];" << std::endl; + str << " \"" << nameIt->second.c_str() << "\" [ label=\"" + << newTargetName << "\" shape=\"" << getShapeForTarget(tarIt->second) + << "\"];" << std::endl; } // Now generate the connectivity @@ -2989,13 +2965,13 @@ void cmake::GenerateGraphViz(const char* fileName) const tit != targets->end(); ++ tit ) { - std::map::iterator dependIt - = targetDeps.find(tit->first.c_str()); - if ( dependIt == targetDeps.end() ) + std::map::iterator cmakeTarIt + = targetPtrs.find(tit->first.c_str()); + if ( cmakeTarIt == targetPtrs.end() ) // skip ignored targets { continue; } - std::map::iterator cmakeTarIt = + std::map::iterator targetNameIt = targetNamesNodes.find(tit->first.c_str()); const cmTarget::LinkLibraryVectorType* ll = &(tit->second.GetOriginalLinkLibraries()); @@ -3005,17 +2981,17 @@ void cmake::GenerateGraphViz(const char* fileName) const ++ llit ) { const char* libName = llit->first.c_str(); - std::map::const_iterator tarIt = + std::map::const_iterator libNameIt = targetNamesNodes.find(libName); - if ( tarIt == targetNamesNodes.end() ) + if ( libNameIt == targetNamesNodes.end() ) { // We should not be here. std::cout << __LINE__ << " Cannot find library: " << libName << " even though it was added in the previous pass" << std::endl; abort(); } - str << " \"" << cmakeTarIt->second.c_str() << "\" -> \"" - << tarIt->second.c_str() << "\"" << std::endl; + str << " \"" << targetNameIt->second.c_str() << "\" -> \"" + << libNameIt->second.c_str() << "\"" << std::endl; } } } @@ -3068,7 +3044,6 @@ int cmake::getAllTargets(const std::set& ignoreTargetsSet, int cmake::getAllExternalLibs(const std::set& ignoreTargetsSet, std::map& targetNamesNodes, std::map& targetPtrs, - std::map& targetDeps, const char* graphNodePrefix) const { int cnt = 0; @@ -3094,11 +3069,6 @@ int cmake::getAllExternalLibs(const std::set& ignoreTargetsSet, } const cmTarget::LinkLibraryVectorType* ll = &(tit->second.GetOriginalLinkLibraries()); - if ( ll->size() > 0 ) - { - targetDeps[realTargetName] = DOT_DEP_TARGET; - fprintf(stderr, " + %s\n", realTargetName); - } for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin(); llit != ll->end(); ++ llit ) @@ -3110,26 +3080,17 @@ int cmake::getAllExternalLibs(const std::set& ignoreTargetsSet, continue; } - std::map::const_iterator tarIt = - targetNamesNodes.find(libName); - if ( tarIt == targetNamesNodes.end() ) + std::map::const_iterator tarIt = + targetPtrs.find(libName); + if ( tarIt == targetPtrs.end() ) { cmOStringStream ostr; ostr << graphNodePrefix << cnt++; - targetDeps[libName] = DOT_DEP_EXTERNAL; targetNamesNodes[libName] = ostr.str(); + targetPtrs[libName] = NULL; //str << " \"" << ostr.c_str() << "\" [ label=\"" << libName //<< "\" shape=\"ellipse\"];" << std::endl; } - else - { - std::map::const_iterator depIt = - targetDeps.find(libName); - if ( depIt == targetDeps.end() ) - { - targetDeps[libName] = DOT_DEP_TARGET; - } - } } } } diff --git a/Source/cmake.h b/Source/cmake.h index 6d6fd94..b2cc7e7 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -440,7 +440,6 @@ protected: int getAllExternalLibs(const std::set& ignoreTargetsSet, std::map& targetNamesNodes, std::map& targetPtrs, - std::map& targetDeps, const char* graphNodePrefix) const; ///! Find the full path to one of the cmake programs like ctest, cpack, etc. -- cgit v0.12