From f7d56df39eb4567c187e429a7162a1204f8d2d1b Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 31 Oct 2010 14:46:09 +0100 Subject: [PATCH 1/9] Remove trailing whitespace and minor formatting changes for the dot-code Alex --- Source/cmake.cxx | 204 +++++++++++++++++++++++++---------------------- 1 file changed, 107 insertions(+), 97 deletions(-) diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 2ebd16592..de8db7927 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -169,7 +169,7 @@ cmake::cmake() this->ProgressCallback = 0; this->ProgressCallbackClientData = 0; this->ScriptMode = false; - + #ifdef CMAKE_BUILD_WITH_CMAKE this->VariableWatch = new cmVariableWatch; this->VariableWatch->AddWatch("CMAKE_WORDS_BIGENDIAN", @@ -382,7 +382,7 @@ bool cmake::SetCacheArgs(const std::vector& args) this->DoSuppressDevWarnings = true; } else if(arg.find("-Wdev",0) == 0) - { + { this->SuppressDevWarnings = false; this->DoSuppressDevWarnings = true; } @@ -406,7 +406,7 @@ bool cmake::SetCacheArgs(const std::vector& args) cmsys::Glob::PatternToRegex(entryPattern.c_str(), true, true).c_str()); //go through all cache entries and collect the vars which will be removed std::vector entriesToDelete; - cmCacheManager::CacheIterator it = + cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(); for ( it.Begin(); !it.IsAtEnd(); it.Next() ) { @@ -422,8 +422,8 @@ bool cmake::SetCacheArgs(const std::vector& args) } // now remove them from the cache - for(std::vector::const_iterator currentEntry = - entriesToDelete.begin(); + for(std::vector::const_iterator currentEntry = + entriesToDelete.begin(); currentEntry != entriesToDelete.end(); ++currentEntry) { @@ -791,7 +791,7 @@ int cmake::AddCMakePaths() cMakeSelf += "/cmake"; std::cerr << cMakeSelf.c_str() << "\n"; } -#endif +#endif if(!cmSystemTools::FileExists(cMakeSelf.c_str())) { cmSystemTools::Error("CMake executable cannot be found at ", @@ -802,12 +802,12 @@ int cmake::AddCMakePaths() this->CacheManager->AddCacheEntry ("CMAKE_COMMAND",cMakeSelf.c_str(), "Path to CMake executable.", cmCacheManager::INTERNAL); - // if the edit command is not yet in the cache, + // if the edit command is not yet in the cache, // or if CMakeEditCommand has been set on this object, // then set the CMAKE_EDIT_COMMAND in the cache // This will mean that the last gui to edit the cache // will be the one that make edit_cache uses. - if(!this->GetCacheDefinition("CMAKE_EDIT_COMMAND") + if(!this->GetCacheDefinition("CMAKE_EDIT_COMMAND") || !this->CMakeEditCommand.empty()) { // Find and save the command to edit the cache @@ -815,8 +815,8 @@ int cmake::AddCMakePaths() if(!this->CMakeEditCommand.empty()) { editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) - + std::string("/") - + this->CMakeEditCommand + + std::string("/") + + this->CMakeEditCommand + cmSystemTools::GetFilenameExtension(cMakeSelf); } if( !cmSystemTools::FileExists(editCacheCommand.c_str())) @@ -936,7 +936,7 @@ void CMakeCommandUsage(const char* program) errorStream << "cmake bootstrap\n"; #endif - // If you add new commands, change here, + // If you add new commands, change here, // and in cmakemain.cxx in the options table errorStream << "Usage: " << program << " -E [command] [arguments ...]\n" @@ -1091,7 +1091,7 @@ int cmake::ExecuteCMakeCommand(std::vector& args) return 0; } #endif - + else if (args[1] == "make_directory" && args.size() == 3) { if(!cmSystemTools::MakeDirectory(args[2].c_str())) @@ -1342,7 +1342,7 @@ int cmake::ExecuteCMakeCommand(std::vector& args) } return 0; } - + // Command to create a symbolic link. Fails on platforms not // supporting them. else if (args[1] == "create_symlink" && args.size() == 4) @@ -1410,7 +1410,7 @@ int cmake::ExecuteCMakeCommand(std::vector& args) // Use the make system's VERBOSE environment variable to enable // verbose output. This can be skipped by also setting CMAKE_NO_VERBOSE // (which is set by the Eclipse and KDevelop generators). - bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0) + bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0) && (cmSystemTools::GetEnv("CMAKE_NO_VERBOSE") == 0)); // Create a cmake object instance to process dependencies. @@ -1635,14 +1635,14 @@ int cmake::ExecuteCMakeCommand(std::vector& args) return 1; } -void cmake::AddExtraGenerator(const char* name, +void cmake::AddExtraGenerator(const char* name, CreateExtraGeneratorFunctionType newFunction) { cmExternalMakefileProjectGenerator* extraGenerator = newFunction(); const std::vector& supportedGlobalGenerators = extraGenerator->GetSupportedGlobalGenerators(); - for(std::vector::const_iterator + for(std::vector::const_iterator it = supportedGlobalGenerators.begin(); it != supportedGlobalGenerators.end(); ++it ) @@ -1670,11 +1670,11 @@ void cmake::AddDefaultExtraGenerators() #endif #ifdef CMAKE_USE_KDEVELOP - this->AddExtraGenerator(cmGlobalKdevelopGenerator::GetActualName(), + this->AddExtraGenerator(cmGlobalKdevelopGenerator::GetActualName(), &cmGlobalKdevelopGenerator::New); - // for kdevelop also add the generator with just the name of the + // for kdevelop also add the generator with just the name of the // extra generator, since it was this way since cmake 2.2 - this->ExtraGenerators[cmGlobalKdevelopGenerator::GetActualName()] + this->ExtraGenerators[cmGlobalKdevelopGenerator::GetActualName()] = &cmGlobalKdevelopGenerator::New; #endif @@ -1690,7 +1690,7 @@ void cmake::GetRegisteredGenerators(std::vector& names) { names.push_back(i->first); } - for(RegisteredExtraGeneratorsMap::const_iterator + for(RegisteredExtraGeneratorsMap::const_iterator i = this->ExtraGenerators.begin(); i != this->ExtraGenerators.end(); ++i) { @@ -1828,7 +1828,7 @@ int cmake::DoPreConfigureChecks() // do a sanity check on some values if(this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY")) { - std::string cacheStart = + std::string cacheStart = this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY"); cacheStart += "/CMakeLists.txt"; std::string currentStart = this->GetHomeDirectory(); @@ -1872,13 +1872,13 @@ int cmake::HandleDeleteCacheVariables(const char* var) cmCacheManager::CacheIterator ci = this->CacheManager->NewIterator(); std::vector saved; cmOStringStream warning; - warning + warning << "You have changed variables that require your cache to be deleted.\n" << "Configure will be re-run and you may have to reset some variables.\n" << "The following variables have changed:\n"; for(std::vector::iterator i = argsSplit.begin(); i != argsSplit.end(); ++i) - { + { SaveCacheEntry save; save.key = *i; warning << *i << "= "; @@ -1892,7 +1892,7 @@ int cmake::HandleDeleteCacheVariables(const char* var) } saved.push_back(save); } - + // remove the cache this->CacheManager->DeleteCache(this->GetStartOutputDirectory()); // load the empty cache @@ -1964,7 +1964,7 @@ int cmake::ActualConfigure() if ( !res ) { this->CacheManager->AddCacheEntry - ("CMAKE_HOME_DIRECTORY", + ("CMAKE_HOME_DIRECTORY", this->GetHomeDirectory(), "Start directory with the top level CMakeLists.txt file for this " "project", @@ -1974,9 +1974,9 @@ int cmake::ActualConfigure() // no generator specified on the command line if(!this->GlobalGenerator) { - const char* genName = + const char* genName = this->CacheManager->GetCacheValue("CMAKE_GENERATOR"); - const char* extraGenName = + const char* extraGenName = this->CacheManager->GetCacheValue("CMAKE_EXTRA_GENERATOR"); if(genName) { @@ -1998,7 +1998,7 @@ int cmake::ActualConfigure() this->SetGlobalGenerator(new cmGlobalBorlandMakefileGenerator); #elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW) std::string installedCompiler; - // Try to find the newest VS installed on the computer and + // Try to find the newest VS installed on the computer and // use that as a default if -G is not specified std::string vsregBase = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\"; @@ -2062,11 +2062,11 @@ int cmake::ActualConfigure() } if(!this->CacheManager->GetCacheValue("CMAKE_GENERATOR")) { - this->CacheManager->AddCacheEntry("CMAKE_GENERATOR", + this->CacheManager->AddCacheEntry("CMAKE_GENERATOR", this->GlobalGenerator->GetName(), "Name of generator.", cmCacheManager::INTERNAL); - this->CacheManager->AddCacheEntry("CMAKE_EXTRA_GENERATOR", + this->CacheManager->AddCacheEntry("CMAKE_EXTRA_GENERATOR", this->GlobalGenerator->GetExtraGeneratorName(), "Name of external makefile project generator.", cmCacheManager::INTERNAL); @@ -2205,7 +2205,7 @@ int cmake::Run(const std::vector& args, bool noconfigure) // set the cmake command this->CMakeCommand = args[0]; - + if ( !this->ScriptMode ) { // load the cache @@ -2330,7 +2330,7 @@ void cmake::AddCacheEntry(const char* key, const char* value, const char* helpString, int type) { - this->CacheManager->AddCacheEntry(key, value, + this->CacheManager->AddCacheEntry(key, value, helpString, cmCacheManager::CacheEntryType(type)); } @@ -2445,8 +2445,8 @@ void cmake::UpdateProgress(const char *msg, float prog) } } -void cmake::GetCommandDocumentation(std::vector& v, - bool withCurrentCommands, +void cmake::GetCommandDocumentation(std::vector& v, + bool withCurrentCommands, bool withCompatCommands) const { for(RegisteredCommandsMap::const_iterator j = this->Commands.begin(); @@ -2457,7 +2457,7 @@ void cmake::GetCommandDocumentation(std::vector& v, { continue; } - + cmDocumentationEntry e((*j).second->GetName(), (*j).second->GetTerseDocumentation(), (*j).second->GetFullDocumentation()); @@ -2493,7 +2493,7 @@ void cmake::GetGeneratorDocumentation(std::vector& v) delete generator; v.push_back(e); } - for(RegisteredExtraGeneratorsMap::const_iterator + for(RegisteredExtraGeneratorsMap::const_iterator i = this->ExtraGenerators.begin(); i != this->ExtraGenerators.end(); ++i) { cmDocumentationEntry e; @@ -2508,7 +2508,7 @@ void cmake::GetGeneratorDocumentation(std::vector& v) void cmake::UpdateConversionPathTable() { // Update the path conversion table with any specified file: - const char* tablepath = + const char* tablepath = this->CacheManager->GetCacheValue("CMAKE_PATH_TRANSLATION_FILE"); if(tablepath) @@ -2540,7 +2540,7 @@ int cmake::CheckBuildSystem() // the make system's VERBOSE environment variable to enable verbose // output. This can be skipped by setting CMAKE_NO_VERBOSE (which is set // by the Eclipse and KDevelop generators). - bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0) + bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0) && (cmSystemTools::GetEnv("CMAKE_NO_VERBOSE") == 0)); // This method will check the integrity of the build system if the @@ -2549,7 +2549,7 @@ int cmake::CheckBuildSystem() // If no file is provided for the check, we have to rerun. if(this->CheckBuildSystemArgument.size() == 0) - { + { if(verbose) { cmOStringStream msg; @@ -2565,7 +2565,7 @@ int cmake::CheckBuildSystem() if(verbose) { cmOStringStream msg; - msg << "Re-run cmake missing file: " + msg << "Re-run cmake missing file: " << this->CheckBuildSystemArgument.c_str() << "\n"; cmSystemTools::Stdout(msg.str().c_str()); } @@ -2585,7 +2585,7 @@ int cmake::CheckBuildSystem() if(verbose) { cmOStringStream msg; - msg << "Re-run cmake error reading : " + msg << "Re-run cmake error reading : " << this->CheckBuildSystemArgument.c_str() << "\n"; cmSystemTools::Stdout(msg.str().c_str()); } @@ -2902,7 +2902,7 @@ void cmake::GenerateGraphViz(const char* fileName) const str << graphHeader << std::endl; const cmGlobalGenerator* gg = this->GetGlobalGenerator(); - const std::vector& localGenerators = + const std::vector& localGenerators = gg->GetLocalGenerators(); std::vector::const_iterator lit; // for target deps @@ -2917,8 +2917,9 @@ void cmake::GenerateGraphViz(const char* fileName) const for ( lit = localGenerators.begin(); lit != localGenerators.end(); ++ lit ) { const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); - cmTargets::const_iterator tit; - for ( tit = targets->begin(); tit != targets->end(); ++ tit ) + for ( cmTargets::const_iterator tit = targets->begin(); + tit != targets->end(); + ++ tit ) { const char* realTargetName = tit->first.c_str(); if ( ignoreTargetsSet.find(realTargetName) != ignoreTargetsSet.end() ) @@ -2933,16 +2934,17 @@ void cmake::GenerateGraphViz(const char* fileName) const targetPtrs[realTargetName] = &tit->second; } } + // Ok, now find all the stuff we link to that is not in cmake for ( lit = localGenerators.begin(); lit != localGenerators.end(); ++ lit ) { const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); - cmTargets::const_iterator tit; - for ( tit = targets->begin(); tit != targets->end(); ++ tit ) + for ( cmTargets::const_iterator tit = targets->begin(); + tit != targets->end(); + ++ tit ) { - const cmTarget::LinkLibraryVectorType* ll - = &(tit->second.GetOriginalLinkLibraries()); - cmTarget::LinkLibraryVectorType::const_iterator llit; + const cmTarget::LinkLibraryVectorType* ll = + &(tit->second.GetOriginalLinkLibraries()); const char* realTargetName = tit->first.c_str(); if ( ignoreTargetsSet.find(realTargetName) != ignoreTargetsSet.end() ) { @@ -2953,11 +2955,13 @@ void cmake::GenerateGraphViz(const char* fileName) const { targetDeps[realTargetName] = 1; } - for ( llit = ll->begin(); llit != ll->end(); ++ llit ) + for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin(); + llit != ll->end(); + ++ llit ) { const char* libName = llit->first.c_str(); - std::map::const_iterator tarIt - = targetNamesNodes.find(libName); + std::map::const_iterator tarIt = + targetNamesNodes.find(libName); if ( ignoreTargetsSet.find(libName) != ignoreTargetsSet.end() ) { // Skip ignored targets @@ -2986,31 +2990,34 @@ void cmake::GenerateGraphViz(const char* fileName) const } // Write out nodes - std::map::const_iterator depIt; - for ( depIt = targetDeps.begin(); depIt != targetDeps.end(); ++ depIt ) + for(std::map::const_iterator depIt = targetDeps.begin(); + depIt != targetDeps.end(); + ++ depIt ) { const char* newTargetName = depIt->first.c_str(); - std::map::const_iterator tarIt - = targetNamesNodes.find(newTargetName); + std::map::const_iterator tarIt = + 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; + << " even though it was added in the previous pass" + << std::endl; abort(); } str << " \"" << tarIt->second.c_str() << "\" [ label=\"" - << newTargetName << "\" shape=\""; + << newTargetName << "\" shape=\""; if ( depIt->second == 1 ) { - std::map::const_iterator tarTypeIt = + 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; + << " even though it was added in the previous pass" + << std::endl; abort(); } const cmTarget* tg = tarTypeIt->second; @@ -3043,25 +3050,28 @@ void cmake::GenerateGraphViz(const char* fileName) const for ( lit = localGenerators.begin(); lit != localGenerators.end(); ++ lit ) { const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); - cmTargets::const_iterator tit; - for ( tit = targets->begin(); tit != targets->end(); ++ tit ) + for (cmTargets::const_iterator tit = targets->begin(); + tit != targets->end(); + ++ tit ) { std::map::iterator dependIt - = targetDeps.find(tit->first.c_str()); + = targetDeps.find(tit->first.c_str()); if ( dependIt == targetDeps.end() ) { continue; } - std::map::iterator cmakeTarIt - = targetNamesNodes.find(tit->first.c_str()); - const cmTarget::LinkLibraryVectorType* ll - = &(tit->second.GetOriginalLinkLibraries()); - cmTarget::LinkLibraryVectorType::const_iterator llit; - for ( llit = ll->begin(); llit != ll->end(); ++ llit ) + std::map::iterator cmakeTarIt = + targetNamesNodes.find(tit->first.c_str()); + const cmTarget::LinkLibraryVectorType* ll = + &(tit->second.GetOriginalLinkLibraries()); + + for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin(); + llit != ll->end(); + ++ llit ) { const char* libName = llit->first.c_str(); - std::map::const_iterator tarIt - = targetNamesNodes.find(libName); + std::map::const_iterator tarIt = + targetNamesNodes.find(libName); if ( tarIt == targetNamesNodes.end() ) { // We should not be here. @@ -3070,7 +3080,7 @@ void cmake::GenerateGraphViz(const char* fileName) const abort(); } str << " \"" << cmakeTarIt->second.c_str() << "\" -> \"" - << tarIt->second.c_str() << "\"" << std::endl; + << tarIt->second.c_str() << "\"" << std::endl; } } } @@ -3336,7 +3346,7 @@ int cmake::ExecuteLinkScript(std::vector& args) void cmake::DefineProperties(cmake *cm) { cm->DefineProperty - ("REPORT_UNDEFINED_PROPERTIES", cmProperty::GLOBAL, + ("REPORT_UNDEFINED_PROPERTIES", cmProperty::GLOBAL, "If set, report any undefined properties to this file.", "If this property is set to a filename then when CMake runs " "it will report any properties or variables that were accessed " @@ -3344,7 +3354,7 @@ void cmake::DefineProperties(cmake *cm) ); cm->DefineProperty - ("TARGET_SUPPORTS_SHARED_LIBS", cmProperty::GLOBAL, + ("TARGET_SUPPORTS_SHARED_LIBS", cmProperty::GLOBAL, "Does the target platform support shared libraries.", "TARGET_SUPPORTS_SHARED_LIBS is a boolean specifying whether the target " "platform supports shared libraries. Basically all current general " @@ -3381,7 +3391,7 @@ void cmake::DefineProperties(cmake *cm) "this list.This property is used by the macros in FeatureSummary.cmake."); cm->DefineProperty ("DISABLED_FEATURES", cmProperty::GLOBAL, - "List of features which are disabled during the CMake run.", + "List of features which are disabled during the CMake run.", "List of features which are disabled during the CMake run. Be default " "it contains the names of all packages which were not found. This is " "determined using the _FOUND variables. Packages which are " @@ -3531,13 +3541,13 @@ void cmake::DefineProperty(const char *name, cmProperty::ScopeType scope, bool chained, const char *docSection) { this->PropertyDefinitions[scope].DefineProperty(name,scope,ShortDescription, - FullDescription, + FullDescription, docSection, chained); } cmPropertyDefinition *cmake -::GetPropertyDefinition(const char *name, +::GetPropertyDefinition(const char *name, cmProperty::ScopeType scope) { if (this->IsPropertyDefined(name,scope)) @@ -3547,7 +3557,7 @@ cmPropertyDefinition *cmake return 0; } -void cmake::RecordPropertyAccess(const char *name, +void cmake::RecordPropertyAccess(const char *name, cmProperty::ScopeType scope) { this->AccessedProperties.insert @@ -3619,13 +3629,13 @@ void cmake::ReportUndefinedPropertyAccesses(const char *filename) { if (!this->IsPropertyDefined(ap->first.c_str(),ap->second) && aliasedProperties.find(std::pair - (ap->first,ap->second)) == + (ap->first,ap->second)) == aliasedProperties.end()) { const char *scopeStr = ""; switch (ap->second) { - case cmProperty::TARGET: + case cmProperty::TARGET: scopeStr = "TARGET"; break; case cmProperty::SOURCE_FILE: @@ -3727,7 +3737,7 @@ const char *cmake::GetProperty(const char* prop, cmProperty::ScopeType scope) } else if ( propname == "COMMANDS" ) { - cmake::RegisteredCommandsMap::iterator cmds + cmake::RegisteredCommandsMap::iterator cmds = this->GetCommands()->begin(); for (unsigned int cc=0 ; cmds != this->GetCommands()->end(); ++ cmds ) { @@ -3835,14 +3845,14 @@ int cmake::GetSystemInformation(std::vector& args) // we have to find the module directory, so we can copy the files this->AddCMakePaths(); - std::string modulesPath = + std::string modulesPath = this->CacheManager->GetCacheValue("CMAKE_ROOT"); modulesPath += "/Modules"; std::string inFile = modulesPath; inFile += "/SystemInformation.cmake"; std::string outFile = destPath; outFile += "/CMakeLists.txt"; - + // Copy file if(!cmSystemTools::cmCopyFile(inFile.c_str(), outFile.c_str())) { @@ -3850,7 +3860,7 @@ int cmake::GetSystemInformation(std::vector& args) << "\" to \"" << outFile.c_str() << "\".\n"; return 1; } - + // do we write to a file or to stdout? if (resultFile.size() == 0) { @@ -3876,7 +3886,7 @@ int cmake::GetSystemInformation(std::vector& args) // change back to the original directory cmSystemTools::ChangeDirectory(cwd.c_str()); - + // echo results to stdout if needed if (writeToStdout) { @@ -3897,7 +3907,7 @@ int cmake::GetSystemInformation(std::vector& args) fclose(fin); } } - + // clean up the directory cmSystemTools::RemoveADirectory(destPath.c_str()); return 0; @@ -4016,7 +4026,7 @@ int cmake::VisualStudioLink(std::vector& args, int type) for(std::vector::iterator i = args.begin(); i != args.end(); ++i) { - // check for nmake temporary files + // check for nmake temporary files if((*i)[0] == '@' && i->find("@CMakeFiles") != 0 ) { std::ifstream fin(i->substr(1).c_str()); @@ -4069,7 +4079,7 @@ int cmake::VisualStudioLink(std::vector& args, int type) type, hasManifest, verbose); } -int cmake::ParseVisualStudioLinkCommand(std::vector& args, +int cmake::ParseVisualStudioLinkCommand(std::vector& args, std::vector& command, std::string& targetName) { @@ -4120,7 +4130,7 @@ bool cmake::RunCommand(const char* comment, &retCode, 0, false); // always print the output of the command, unless // it is the dumb rc command banner, but if the command - // returned an error code then print the output anyway as + // returned an error code then print the output anyway as // the banner may be mixed with some other important information. if(output.find("Resource Compiler Version") == output.npos || retCode !=0) @@ -4141,12 +4151,12 @@ bool cmake::RunCommand(const char* comment, return retCode == 0; } -int cmake::VisualStudioLinkIncremental(std::vector& args, +int cmake::VisualStudioLinkIncremental(std::vector& args, int type, bool verbose) { // This follows the steps listed here: // http://blogs.msdn.com/zakramer/archive/2006/05/22/603558.aspx - + // 1. Compiler compiles the application and generates the *.obj files. // 2. An empty manifest file is generated if this is a clean build and if // not the previous one is reused. @@ -4158,10 +4168,10 @@ int cmake::VisualStudioLinkIncremental(std::vector& args, // on. // 5. The manifest tool (mt.exe) is then used to generate the final // manifest. - + // If the final manifest is changed, then 6 and 7 are run, if not // they are skipped, and it is done. - + // 6. The resource compiler is invoked one more time. // 7. Finally, the Linker does another incremental link, but since the // only thing that has changed is the *.res file that contains the @@ -4220,7 +4230,7 @@ int cmake::VisualStudioLinkIncremental(std::vector& args, outputOpt += resourceFile; rcCommand.push_back(outputOpt); rcCommand.push_back(resourceInputFile); - // Run rc command to create resource + // Run rc command to create resource if(!cmake::RunCommand("RC Pass 1", rcCommand, verbose)) { return -1; @@ -4230,7 +4240,7 @@ int cmake::VisualStudioLinkIncremental(std::vector& args, { return -1; } - // create mt command + // create mt command std::string outArg("/out:"); outArg+= manifestFile; mtCommand.push_back("/nologo"); @@ -4281,7 +4291,7 @@ int cmake::VisualStudioLinkNonIncremental(std::vector& args, { return -1; } - // Run the link command as given + // Run the link command as given linkCommand.push_back("/MANIFEST"); if(!cmake::RunCommand("LINK", linkCommand, verbose)) { @@ -4472,7 +4482,7 @@ int cmake::Build(const std::string& dir, makeProgram = it.GetValue(); return gen->Build(0, dir.c_str(), projName.c_str(), target.c_str(), - &output, + &output, makeProgram.c_str(), config.c_str(), clean, false, 0, true, 0, nativeOptions); From de2b2bf9efe88bbde1b66857d00538084cc6c591 Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 31 Oct 2010 15:58:18 +0100 Subject: [PATCH 2/9] Move the code for collecting targets and libraries into separate functions Found bug: targets which don't link to anything don't get inserted in the dot file. Alex --- Source/cmake.cxx | 208 ++++++++++++++++++++++++++++------------------- Source/cmake.h | 86 +++++++++++--------- 2 files changed, 175 insertions(+), 119 deletions(-) diff --git a/Source/cmake.cxx b/Source/cmake.cxx index de8db7927..6ccb2d2dc 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2835,6 +2835,11 @@ 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 + void cmake::GenerateGraphViz(const char* fileName) const { cmGeneratedFileStream str(fileName); @@ -2904,90 +2909,17 @@ void cmake::GenerateGraphViz(const char* fileName) const const cmGlobalGenerator* gg = this->GetGlobalGenerator(); const std::vector& localGenerators = gg->GetLocalGenerators(); - std::vector::const_iterator lit; - // for target deps - // 1 - cmake target - // 2 - external target - // 0 - no deps + std::map targetDeps; std::map targetPtrs; - std::map targetNamesNodes; + std::map targetNamesNodes; // maps from the actual strings to node names in dot int cnt = 0; - // First pass get the list of all cmake targets - for ( lit = localGenerators.begin(); lit != localGenerators.end(); ++ lit ) - { - const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); - for ( cmTargets::const_iterator tit = targets->begin(); - tit != targets->end(); - ++ tit ) - { - const char* realTargetName = tit->first.c_str(); - if ( ignoreTargetsSet.find(realTargetName) != ignoreTargetsSet.end() ) - { - // Skip ignored targets - continue; - } - //std::cout << "Found target: " << tit->first.c_str() << std::endl; - cmOStringStream ostr; - ostr << graphNodePrefix << cnt++; - targetNamesNodes[realTargetName] = ostr.str(); - targetPtrs[realTargetName] = &tit->second; - } - } + cnt += getAllTargets(ignoreTargetsSet, targetNamesNodes, targetPtrs, + graphNodePrefix); + + cnt += getAllExternalLibs(ignoreTargetsSet, targetNamesNodes, targetPtrs, + targetDeps, graphNodePrefix); - // Ok, now find all the stuff we link to that is not in cmake - for ( lit = localGenerators.begin(); lit != localGenerators.end(); ++ lit ) - { - const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); - for ( cmTargets::const_iterator tit = targets->begin(); - tit != targets->end(); - ++ tit ) - { - const cmTarget::LinkLibraryVectorType* ll = - &(tit->second.GetOriginalLinkLibraries()); - const char* realTargetName = tit->first.c_str(); - if ( ignoreTargetsSet.find(realTargetName) != ignoreTargetsSet.end() ) - { - // Skip ignored targets - continue; - } - if ( ll->size() > 0 ) - { - targetDeps[realTargetName] = 1; - } - for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin(); - llit != ll->end(); - ++ llit ) - { - const char* libName = llit->first.c_str(); - std::map::const_iterator tarIt = - targetNamesNodes.find(libName); - if ( ignoreTargetsSet.find(libName) != ignoreTargetsSet.end() ) - { - // Skip ignored targets - continue; - } - if ( tarIt == targetNamesNodes.end() ) - { - cmOStringStream ostr; - ostr << graphNodePrefix << cnt++; - targetDeps[libName] = 2; - targetNamesNodes[libName] = ostr.str(); - //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] = 1; - } - } - } - } - } // Write out nodes for(std::map::const_iterator depIt = targetDeps.begin(); @@ -3008,7 +2940,7 @@ void cmake::GenerateGraphViz(const char* fileName) const str << " \"" << tarIt->second.c_str() << "\" [ label=\"" << newTargetName << "\" shape=\""; - if ( depIt->second == 1 ) + if ( depIt->second == DOT_DEP_TARGET ) { std::map::const_iterator tarTypeIt = targetPtrs.find(newTargetName); @@ -3047,7 +2979,10 @@ void cmake::GenerateGraphViz(const char* fileName) const } // Now generate the connectivity - for ( lit = localGenerators.begin(); lit != localGenerators.end(); ++ lit ) + for ( std::vector::const_iterator lit = + localGenerators.begin(); + lit != localGenerators.end(); + ++ lit ) { const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); for (cmTargets::const_iterator tit = targets->begin(); @@ -3092,6 +3027,115 @@ void cmake::GenerateGraphViz(const char* fileName) const str << "}" << std::endl; } + +int cmake::getAllTargets(const std::set& ignoreTargetsSet, + std::map& targetNamesNodes, + std::map& targetPtrs, + const char* graphNodePrefix) const +{ + int cnt = 0; + const std::vector& localGenerators = + this->GetGlobalGenerator()->GetLocalGenerators(); + // First pass get the list of all cmake targets + for (std::vector::const_iterator lit = + localGenerators.begin(); + lit != localGenerators.end(); + ++ lit ) + { + const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); + for ( cmTargets::const_iterator tit = targets->begin(); + tit != targets->end(); + ++ tit ) + { + const char* realTargetName = tit->first.c_str(); + if ( ignoreTargetsSet.find(realTargetName) != ignoreTargetsSet.end() ) + { + // Skip ignored targets + continue; + } + //std::cout << "Found target: " << tit->first.c_str() << std::endl; + cmOStringStream ostr; + ostr << graphNodePrefix << cnt++; + targetNamesNodes[realTargetName] = ostr.str(); + targetPtrs[realTargetName] = &tit->second; + } + } + + return cnt; +} + + +int cmake::getAllExternalLibs(const std::set& ignoreTargetsSet, + std::map& targetNamesNodes, + std::map& targetPtrs, + std::map& targetDeps, + const char* graphNodePrefix) const +{ + int cnt = 0; + + const std::vector& localGenerators = + this->GetGlobalGenerator()->GetLocalGenerators(); + // Ok, now find all the stuff we link to that is not in cmake + for (std::vector::const_iterator lit = + localGenerators.begin(); + lit != localGenerators.end(); + ++ lit ) + { + const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); + for ( cmTargets::const_iterator tit = targets->begin(); + tit != targets->end(); + ++ tit ) + { + const char* realTargetName = tit->first.c_str(); + if ( ignoreTargetsSet.find(realTargetName) != ignoreTargetsSet.end() ) + { + // Skip ignored targets + continue; + } + 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 ) + { + const char* libName = llit->first.c_str(); + if ( ignoreTargetsSet.find(libName) != ignoreTargetsSet.end() ) + { + // Skip ignored targets + continue; + } + + std::map::const_iterator tarIt = + targetNamesNodes.find(libName); + if ( tarIt == targetNamesNodes.end() ) + { + cmOStringStream ostr; + ostr << graphNodePrefix << cnt++; + targetDeps[libName] = DOT_DEP_EXTERNAL; + targetNamesNodes[libName] = ostr.str(); + //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; + } + } + } + } + } + return cnt; +} + //---------------------------------------------------------------------------- int cmake::SymlinkLibrary(std::vector& args) { diff --git a/Source/cmake.h b/Source/cmake.h index 8312795eb..6d6fd94ae 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -21,14 +21,14 @@ // command line arguments. // 3) Load the cache by calling LoadCache (duh) // 4) if you are using command line arguments with -D or -C flags then -// call SetCacheArgs (or if for some other reason you want to modify the +// call SetCacheArgs (or if for some other reason you want to modify the // cache, do it now. // 5) Finally call Configure // 6) Let the user change values and go back to step 5 // 7) call Generate // // If your GUI allows the user to change the start & home directories then -// you must at a minimum redo steps 2 through 7. +// you must at a minimum redo steps 2 through 7. // @@ -50,6 +50,7 @@ class cmExternalMakefileProjectGenerator; class cmDocumentationSection; class cmPolicies; class cmListFileBacktrace; +class cmTarget; class cmake { @@ -73,14 +74,14 @@ class cmake static const char *GetCMakeFilesDirectory() {return "/CMakeFiles";}; static const char *GetCMakeFilesDirectoryPostSlash() { return "CMakeFiles/";}; - + //@{ /** * Set/Get the home directory (or output directory) in the project. The * home directory is the top directory of the project. It is where * cmake was run. Remember that CMake processes * CMakeLists files by recursing up the tree starting at the StartDirectory - * and going up until it reaches the HomeDirectory. + * and going up until it reaches the HomeDirectory. */ void SetHomeDirectory(const char* dir); const char* GetHomeDirectory() const @@ -100,9 +101,9 @@ class cmake * is the directory of the CMakeLists.txt file that started the current * round of processing. Remember that CMake processes CMakeLists files by * recursing up the tree starting at the StartDirectory and going up until - * it reaches the HomeDirectory. + * it reaches the HomeDirectory. */ - void SetStartDirectory(const char* dir) + void SetStartDirectory(const char* dir) { this->cmStartDirectory = dir; cmSystemTools::ConvertToUnixSlashes(this->cmStartDirectory); @@ -158,7 +159,7 @@ class cmake ///! Return the global generator assigned to this instance of cmake cmGlobalGenerator* GetGlobalGenerator() { return this->GlobalGenerator; } ///! Return the global generator assigned to this instance of cmake, const - const cmGlobalGenerator* GetGlobalGenerator() const + const cmGlobalGenerator* GetGlobalGenerator() const { return this->GlobalGenerator; } ///! Return the global generator assigned to this instance of cmake @@ -169,25 +170,25 @@ class cmake ///! get the cmCachemManager used by this invocation of cmake cmCacheManager *GetCacheManager() { return this->CacheManager; } - + ///! set the cmake command this instance of cmake should use void SetCMakeCommand(const char* cmd) { this->CMakeCommand = cmd; } - + /** * Given a variable name, return its value (as a string). */ const char* GetCacheDefinition(const char*) const; ///! Add an entry into the cache - void AddCacheEntry(const char* key, const char* value, - const char* helpString, + void AddCacheEntry(const char* key, const char* value, + const char* helpString, int type); - /** + /** * Execute commands during the build process. Supports options such * as echo, remove file etc. */ static int ExecuteCMakeCommand(std::vector&); - /** + /** * Get the system information and write it to the file specified */ int GetSystemInformation(std::vector&); @@ -210,16 +211,16 @@ class cmake /** Check if a command exists. */ bool CommandExists(const char* name) const; - + ///! Parse command line arguments void SetArgs(const std::vector&); ///! Is this cmake running as a result of a TRY_COMPILE command bool GetIsInTryCompile() { return this->InTryCompile; } - + ///! Is this cmake running as a result of a TRY_COMPILE command void SetIsInTryCompile(bool i) { this->InTryCompile = i; } - + ///! Parse command line arguments that might set cache values bool SetCacheArgs(const std::vector&); @@ -227,9 +228,9 @@ class cmake (const char*msg, float progress, void *); /** * Set the function used by GUI's to receive progress updates - * Function gets passed: message as a const char*, a progress + * Function gets passed: message as a const char*, a progress * amount ranging from 0 to 1.0 and client data. The progress - * number provided may be negative in cases where a message is + * number provided may be negative in cases where a message is * to be displayed without any progress percentage. */ void SetProgressCallback(ProgressCallbackType f, void* clientData=0); @@ -244,14 +245,14 @@ class cmake cmVariableWatch* GetVariableWatch() { return this->VariableWatch; } /** Get the documentation entries for the supported commands. - * If withCurrentCommands is true, the documentation for the + * If withCurrentCommands is true, the documentation for the * recommended set of commands is included. * If withCompatCommands is true, the documentation for discouraged * (compatibility) commands is included. * You probably don't want to set both to false. */ - void GetCommandDocumentation(std::vector& entries, - bool withCurrentCommands = true, + void GetCommandDocumentation(std::vector& entries, + bool withCurrentCommands = true, bool withCompatCommands = true) const; void GetPropertiesDocumentation(std::map&); @@ -278,7 +279,7 @@ class cmake */ void SetScriptMode(bool mode) { this->ScriptMode = mode; } bool GetScriptMode() { return this->ScriptMode; } - + ///! Debug the try compile stuff by not delelting the files bool GetDebugTryCompile(){return this->DebugTryCompile;} void DebugTryCompileOn(){this->DebugTryCompile = true;} @@ -310,7 +311,7 @@ class cmake void DefineProperty(const char *name, cmProperty::ScopeType scope, const char *ShortDescription, const char *FullDescription, - bool chain = false, + bool chain = false, const char *variableGroup = 0); // get property definition @@ -338,7 +339,7 @@ class cmake } void SetSuppressDevWarnings(bool v) { - this->SuppressDevWarnings = v; + this->SuppressDevWarnings = v; this->DoSuppressDevWarnings = true; } @@ -357,10 +358,10 @@ protected: cmPropertyMap Properties; std::set > AccessedProperties; - std::map + std::map PropertyDefinitions; - typedef + typedef cmExternalMakefileProjectGenerator* (*CreateExtraGeneratorFunctionType)(); typedef std::map RegisteredExtraGeneratorsMap; @@ -374,15 +375,15 @@ protected: void AddDefaultCommands(); void AddDefaultGenerators(); void AddDefaultExtraGenerators(); - void AddExtraGenerator(const char* name, + void AddExtraGenerator(const char* name, CreateExtraGeneratorFunctionType newFunction); - cmPolicies *Policies; + cmPolicies *Policies; cmGlobalGenerator *GlobalGenerator; cmCacheManager *CacheManager; - std::string cmHomeDirectory; + std::string cmHomeDirectory; std::string HomeOutputDirectory; - std::string cmStartDirectory; + std::string cmStartDirectory; std::string StartOutputDirectory; bool SuppressDevWarnings; bool DoSuppressDevWarnings; @@ -393,7 +394,7 @@ protected: ///! Check if CMAKE_CACHEFILE_DIR is set. If it is not, delete the log file. /// If it is set, truncate it to 50kb void TruncateOutputLog(const char* fname); - + /** * Method called to check build system integrity at build time. * Returns 1 if CMake should rerun and 0 otherwise. @@ -416,24 +417,35 @@ protected: static int ExecuteLinkScript(std::vector& args); static int VisualStudioLink(std::vector& args, int type); static int VisualStudioLinkIncremental(std::vector& args, - int type, + int type, bool verbose); static int VisualStudioLinkNonIncremental(std::vector& args, int type, bool hasManifest, bool verbose); - static int ParseVisualStudioLinkCommand(std::vector& args, - std::vector& command, + static int ParseVisualStudioLinkCommand(std::vector& args, + std::vector& command, std::string& targetName); static bool RunCommand(const char* comment, std::vector& command, bool verbose, int* retCodeOut = 0); cmVariableWatch* VariableWatch; - + + int getAllTargets(const std::set& ignoreTargetsSet, + std::map& targetNamesNodes, + std::map& targetPtrs, + const char* graphNodePrefix) const; + + 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. std::string FindCMakeProgram(const char* name) const; -private: +private: cmake(const cmake&); // Not implemented. void operator=(const cmake&); // Not implemented. ProgressCallbackType ProgressCallback; @@ -458,7 +470,7 @@ private: cmFileTimeComparison* FileComparison; std::string GraphVizFile; std::vector DebugConfigs; - + void UpdateConversionPathTable(); }; From 487bd571d56134b15b1060e1921a7e16711f12e6 Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 31 Oct 2010 16:23:40 +0100 Subject: [PATCH 3/9] 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 6ccb2d2dc..af01d0d18 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 6d6fd94ae..b2cc7e7ad 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. From a60b09927d4c29756c428d4c38f5ee2810a8f66e Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 31 Oct 2010 17:40:46 +0100 Subject: [PATCH 4/9] Generate separate dot files for each target, and a big one with everything. The big all-in-one file is basically unusable for e.g. kdelibs, it contains around 1000 nodes and the created image is huuuuge ! Too big actually to be displayable or viewable or comprehensable. Alex --- Source/cmake.cxx | 216 +++++++++++++++++++++++++++++++---------------- Source/cmake.h | 10 ++- 2 files changed, 153 insertions(+), 73 deletions(-) diff --git a/Source/cmake.cxx b/Source/cmake.cxx index af01d0d18..5386fb4f1 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2861,13 +2861,26 @@ static const char* getShapeForTarget(const cmTarget* target) } +static void writeNode(const char* targetName, const cmTarget* target, + const std::map& targetNamesNodes, + std::set& insertedNodes, + cmGeneratedFileStream& str) +{ + if (insertedNodes.find(targetName) == insertedNodes.end()) + { + insertedNodes.insert(targetName); + std::map::const_iterator nameIt = + targetNamesNodes.find(targetName); + + str << " \"" << nameIt->second.c_str() << "\" [ label=\"" + << targetName << "\" shape=\"" << getShapeForTarget(target) + << "\"];" << std::endl; + } +} + + void cmake::GenerateGraphViz(const char* fileName) const { - cmGeneratedFileStream str(fileName); - if ( !str ) - { - return; - } cmake cm; cmGlobalGenerator ggi; ggi.SetCMakeInstance(&cm); @@ -2924,83 +2937,144 @@ void cmake::GenerateGraphViz(const char* fileName) const } } + std::map targetPtrs; + std::map targetNamesNodes; // maps from the actual strings to node names in dot + int cnt = getAllTargets(ignoreTargetsSet, targetNamesNodes, targetPtrs, + graphNodePrefix); + + cnt = getAllExternalLibs(ignoreTargetsSet, targetNamesNodes, targetPtrs, + graphNodePrefix, cnt); + + for(std::map::const_iterator ptrIt = + targetPtrs.begin(); + ptrIt != targetPtrs.end(); + ++ptrIt) + { + if (ptrIt->second == NULL) + { + continue; + } + + if ((ptrIt->second->GetType() != cmTarget::EXECUTABLE) + && (ptrIt->second->GetType() != cmTarget::STATIC_LIBRARY) + && (ptrIt->second->GetType() != cmTarget::SHARED_LIBRARY) + && (ptrIt->second->GetType() != cmTarget::MODULE_LIBRARY)) + { + continue; + } + + std::set insertedConnections; + std::set insertedNodes; + + std::string currentFilename = fileName; + currentFilename += "."; + currentFilename += ptrIt->first; + cmGeneratedFileStream str(currentFilename.c_str()); + if ( !str ) + { + return; + } + + fprintf(stderr, "Writing %s...\n", currentFilename.c_str()); + str << graphType << " " << graphName << " {" << std::endl; + str << graphHeader << std::endl; + + writeDotConnections(ptrIt->first.c_str(), targetNamesNodes, targetPtrs, + insertedNodes, insertedConnections, str); + str << "}" << std::endl; + } + + cmGeneratedFileStream str(fileName); + if ( !str ) + { + return; + } str << graphType << " " << graphName << " {" << std::endl; str << graphHeader << std::endl; - const cmGlobalGenerator* gg = this->GetGlobalGenerator(); - const std::vector& localGenerators = - gg->GetLocalGenerators(); + fprintf(stderr, "Writing %s...\n", fileName); + std::set insertedConnections; + std::set insertedNodes; - std::map targetPtrs; - std::map targetNamesNodes; // maps from the actual strings to node names in dot - int cnt = 0; - cnt += getAllTargets(ignoreTargetsSet, targetNamesNodes, targetPtrs, - graphNodePrefix); - - cnt += getAllExternalLibs(ignoreTargetsSet, targetNamesNodes, targetPtrs, - graphNodePrefix); - - - // Write out nodes - for(std::map::const_iterator tarIt = - targetPtrs.begin(); tarIt != targetPtrs.end(); ++ tarIt ) + for(std::map::const_iterator ptrIt = + targetPtrs.begin(); + ptrIt != targetPtrs.end(); + ++ptrIt) { - const char* newTargetName = tarIt->first.c_str(); - std::map::const_iterator nameIt = - targetNamesNodes.find(newTargetName); + if (ptrIt->second == NULL) + { + continue; + } - str << " \"" << nameIt->second.c_str() << "\" [ label=\"" - << newTargetName << "\" shape=\"" << getShapeForTarget(tarIt->second) - << "\"];" << std::endl; + if ((ptrIt->second->GetType() != cmTarget::EXECUTABLE) + && (ptrIt->second->GetType() != cmTarget::STATIC_LIBRARY) + && (ptrIt->second->GetType() != cmTarget::SHARED_LIBRARY) + && (ptrIt->second->GetType() != cmTarget::MODULE_LIBRARY)) + { + continue; + } + + writeDotConnections(ptrIt->first.c_str(), targetNamesNodes, targetPtrs, + insertedNodes, insertedConnections, str); + } + str << "}" << std::endl; +} + + +void cmake::writeDotConnections(const char* targetName, + const std::map& targetNamesNodes, + const std::map& targetPtrs, + std::set& insertedNodes, + std::set& insertedConnections, + cmGeneratedFileStream& str) const +{ + std::map::const_iterator targetPtrIt = + targetPtrs.find(targetName); + + if (targetPtrIt == targetPtrs.end()) // not found at all + { + return; } - // Now generate the connectivity - for ( std::vector::const_iterator lit = - localGenerators.begin(); - lit != localGenerators.end(); - ++ lit ) - { - const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); - for (cmTargets::const_iterator tit = targets->begin(); - tit != targets->end(); - ++ tit ) - { - std::map::iterator cmakeTarIt - = targetPtrs.find(tit->first.c_str()); - if ( cmakeTarIt == targetPtrs.end() ) // skip ignored targets - { - continue; - } - std::map::iterator targetNameIt = - targetNamesNodes.find(tit->first.c_str()); - const cmTarget::LinkLibraryVectorType* ll = - &(tit->second.GetOriginalLinkLibraries()); + writeNode(targetName, targetPtrIt->second, targetNamesNodes, insertedNodes, + str); - for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin(); - llit != ll->end(); - ++ llit ) - { - const char* libName = llit->first.c_str(); - std::map::const_iterator libNameIt = + if (targetPtrIt->second == NULL) // it's an external library + { + return; + } + + + std::string myNodeName = targetNamesNodes.find(targetName)->second; + + const cmTarget::LinkLibraryVectorType* ll = + &(targetPtrIt->second->GetOriginalLinkLibraries()); + + for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin(); + llit != ll->end(); + ++ llit ) + { + const char* libName = llit->first.c_str(); + std::map::const_iterator libNameIt = targetNamesNodes.find(libName); - 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 << " \"" << targetNameIt->second.c_str() << "\" -> \"" - << libNameIt->second.c_str() << "\"" << std::endl; - } + + std::string connectionName = myNodeName; + connectionName += "-"; + connectionName += libNameIt->second; + if (insertedConnections.find(connectionName) == insertedConnections.end()) + { + insertedConnections.insert(connectionName); + writeNode(libName, targetPtrs.find(libName)->second, targetNamesNodes, + insertedNodes, str); + + str << " \"" << myNodeName.c_str() << "\" -> \"" + << libNameIt->second.c_str() << "\""; + str << " // " << targetName << " -> " << libName << std::endl; + writeDotConnections(libName, targetNamesNodes, targetPtrs, insertedNodes, + insertedConnections, str); } } - // TODO: Use dotted or something for external libraries - //str << " \"node0\":f4 -> \"node12\"[color=\"#0000ff\" style=dotted]" - //<< std::endl; - // - str << "}" << std::endl; } @@ -3044,10 +3118,8 @@ int cmake::getAllTargets(const std::set& ignoreTargetsSet, int cmake::getAllExternalLibs(const std::set& ignoreTargetsSet, std::map& targetNamesNodes, std::map& targetPtrs, - const char* graphNodePrefix) const + const char* graphNodePrefix, int cnt) const { - int cnt = 0; - const std::vector& localGenerators = this->GetGlobalGenerator()->GetLocalGenerators(); // Ok, now find all the stuff we link to that is not in cmake diff --git a/Source/cmake.h b/Source/cmake.h index b2cc7e7ad..0de72d9d6 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -51,6 +51,7 @@ class cmDocumentationSection; class cmPolicies; class cmListFileBacktrace; class cmTarget; +class cmGeneratedFileStream; class cmake { @@ -440,7 +441,14 @@ protected: int getAllExternalLibs(const std::set& ignoreTargetsSet, std::map& targetNamesNodes, std::map& targetPtrs, - const char* graphNodePrefix) const; + const char* graphNodePrefix, int cnt) const; + + void writeDotConnections(const char* targetName, + const std::map& targetNamesNodes, + const std::map& targetPtrs, + std::set& insertedNodes, + std::set& insertedConnections, + cmGeneratedFileStream& str) const; ///! Find the full path to one of the cmake programs like ctest, cpack, etc. std::string FindCMakeProgram(const char* name) const; From 84ce612c65520c273aa3b1d2efd2f8f4de7d3867 Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Tue, 9 Nov 2010 21:37:51 +0100 Subject: [PATCH 5/9] Move the code for generating dot-files into separate class cmGraphVizWriter Alex --- Source/CMakeLists.txt | 6 +- Source/cmGraphVizWriter.cxx | 370 ++++++++++++++++++++++++++++++++++++ Source/cmGraphVizWriter.h | 70 +++++++ Source/cmake.cxx | 336 ++------------------------------ Source/cmake.h | 17 -- 5 files changed, 456 insertions(+), 343 deletions(-) create mode 100644 Source/cmGraphVizWriter.cxx create mode 100644 Source/cmGraphVizWriter.h diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 71284b2dc..718e52e8e 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -183,6 +183,8 @@ SET(SRCS cmGlobalUnixMakefileGenerator3.cxx cmGlobalUnixMakefileGenerator3.h cmGraphAdjacencyList.h + cmGraphVizWriter.cxx + cmGraphVizWriter.h cmInstallGenerator.h cmInstallGenerator.cxx cmInstallExportGenerator.cxx @@ -332,7 +334,7 @@ ENDIF (WIN32) # create a library used by the command line and the GUI ADD_LIBRARY(CMakeLib ${SRCS}) -TARGET_LINK_LIBRARIES(CMakeLib cmsys +TARGET_LINK_LIBRARIES(CMakeLib cmsys ${CMAKE_EXPAT_LIBRARIES} ${CMAKE_ZLIB_LIBRARIES} ${CMAKE_TAR_LIBRARIES} ${CMAKE_COMPRESS_LIBRARIES} ${CMAKE_CURL_LIBRARIES} ) @@ -432,7 +434,7 @@ IF(CYGWIN) CPack/cmCPackCygwinSourceGenerator.cxx ) ENDIF(CYGWIN) - + IF(UNIX) SET(CPACK_SRCS ${CPACK_SRCS} CPack/cmCPackDebGenerator.cxx diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx new file mode 100644 index 000000000..749202b9a --- /dev/null +++ b/Source/cmGraphVizWriter.cxx @@ -0,0 +1,370 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2009 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmGraphVizWriter.h" +#include "cmMakefile.h" +#include "cmLocalGenerator.h" +#include "cmGlobalGenerator.h" +#include "cmGeneratedFileStream.h" + +#include + + + +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"; +} + + +cmGraphVizWriter::cmGraphVizWriter(const std::vector& + localGenerators) +:GraphType("digraph") +,GraphName("GG") +,GraphHeader("node [\n fontsize = \"12\"\n];") +,GraphNodePrefix("node") +,LocalGenerators(localGenerators) +{ + int cnt = collectAllTargets(); + collectAllExternalLibs(cnt); +} + + +void cmGraphVizWriter::ReadSettings(const char* settingsFileName, + const char* fallbackSettingsFileName) +{ + cmake cm; + cmGlobalGenerator ggi; + ggi.SetCMakeInstance(&cm); + std::auto_ptr lg(ggi.CreateLocalGenerator()); + cmMakefile *mf = lg->GetMakefile(); + + const char* inFileName = settingsFileName; + + if ( !cmSystemTools::FileExists(inFileName) ) + { + inFileName = fallbackSettingsFileName; + if ( !cmSystemTools::FileExists(inFileName) ) + { + return; + } + } + + if ( !mf->ReadListFile(0, inFileName) ) + { + cmSystemTools::Error("Problem opening GraphViz options file: ", + inFileName); + return; + } + + std::cout << "Reading GraphViz options file: " << inFileName << std::endl; + +#define __set_if_set(var, cmakeDefinition) \ + { \ + const char* value = mf->GetDefinition(cmakeDefinition); \ + if ( value ) \ + { \ + var = value; \ + } \ + } + + __set_if_set(this->GraphType, "GRAPHVIZ_GRAPH_TYPE"); + __set_if_set(this->GraphName, "GRAPHVIZ_GRAPH_NAME"); + __set_if_set(this->GraphHeader, "GRAPHVIZ_GRAPH_HEADER"); + __set_if_set(this->GraphNodePrefix, "GRAPHVIZ_NODE_PREFIX"); + + this->TargetsToIgnore.clear(); + const char* ignoreTargets = mf->GetDefinition("GRAPHVIZ_IGNORE_TARGETS"); + if ( ignoreTargets ) + { + std::vector ignoreTargetsVector; + cmSystemTools::ExpandListArgument(ignoreTargets,ignoreTargetsVector); + for(std::vector::iterator itvIt = ignoreTargetsVector.begin(); + itvIt != ignoreTargetsVector.end(); + ++ itvIt ) + { + this->TargetsToIgnore.insert(itvIt->c_str()); + } + } + +} + + +void cmGraphVizWriter::WritePerTargetFiles(const char* fileName) +{ + for(std::map::const_iterator ptrIt = + this->TargetPtrs.begin(); + ptrIt != this->TargetPtrs.end(); + ++ptrIt) + { + if (ptrIt->second == NULL) + { + continue; + } + + if ((ptrIt->second->GetType() != cmTarget::EXECUTABLE) + && (ptrIt->second->GetType() != cmTarget::STATIC_LIBRARY) + && (ptrIt->second->GetType() != cmTarget::SHARED_LIBRARY) + && (ptrIt->second->GetType() != cmTarget::MODULE_LIBRARY)) + { + continue; + } + + std::set insertedConnections; + std::set insertedNodes; + + std::string currentFilename = fileName; + currentFilename += "."; + currentFilename += ptrIt->first; + cmGeneratedFileStream str(currentFilename.c_str()); + if ( !str ) + { + return; + } + + fprintf(stderr, "Writing %s...\n", currentFilename.c_str()); + this->WriteHeader(str); + + this->WriteConnections(ptrIt->first.c_str(), + insertedNodes, insertedConnections, str); + this->WriteFooter(str); + } + +} + + +void cmGraphVizWriter::WriteGlobalFile(const char* fileName) +{ + cmGeneratedFileStream str(fileName); + if ( !str ) + { + return; + } + this->WriteHeader(str); + + fprintf(stderr, "Writing %s...\n", fileName); + std::set insertedConnections; + std::set insertedNodes; + + for(std::map::const_iterator ptrIt = + this->TargetPtrs.begin(); + ptrIt != this->TargetPtrs.end(); + ++ptrIt) + { + if (ptrIt->second == NULL) + { + continue; + } + + if ((ptrIt->second->GetType() != cmTarget::EXECUTABLE) + && (ptrIt->second->GetType() != cmTarget::STATIC_LIBRARY) + && (ptrIt->second->GetType() != cmTarget::SHARED_LIBRARY) + && (ptrIt->second->GetType() != cmTarget::MODULE_LIBRARY)) + { + continue; + } + + this->WriteConnections(ptrIt->first.c_str(), + insertedNodes, insertedConnections, str); + } + this->WriteFooter(str); +} + + +void cmGraphVizWriter::WriteHeader(cmGeneratedFileStream& str) const +{ + str << this->GraphType << " " << this->GraphName << " {" << std::endl; + str << this->GraphHeader << std::endl; +} + + +void cmGraphVizWriter::WriteFooter(cmGeneratedFileStream& str) const +{ + str << "}" << std::endl; +} + + +void cmGraphVizWriter::WriteConnections(const char* targetName, + std::set& insertedNodes, + std::set& insertedConnections, + cmGeneratedFileStream& str) const +{ + std::map::const_iterator targetPtrIt = + this->TargetPtrs.find(targetName); + + if (targetPtrIt == this->TargetPtrs.end()) // not found at all + { + return; + } + + this->WriteNode(targetName, targetPtrIt->second, insertedNodes, str); + + if (targetPtrIt->second == NULL) // it's an external library + { + return; + } + + + std::string myNodeName = this->TargetNamesNodes.find(targetName)->second; + + const cmTarget::LinkLibraryVectorType* ll = + &(targetPtrIt->second->GetOriginalLinkLibraries()); + + for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin(); + llit != ll->end(); + ++ llit ) + { + const char* libName = llit->first.c_str(); + std::map::const_iterator libNameIt = + this->TargetNamesNodes.find(libName); + + std::string connectionName = myNodeName; + connectionName += "-"; + connectionName += libNameIt->second; + if (insertedConnections.find(connectionName) == insertedConnections.end()) + { + insertedConnections.insert(connectionName); + this->WriteNode(libName, this->TargetPtrs.find(libName)->second, + insertedNodes, str); + + str << " \"" << myNodeName.c_str() << "\" -> \"" + << libNameIt->second.c_str() << "\""; + str << " // " << targetName << " -> " << libName << std::endl; + this->WriteConnections(libName, insertedNodes, insertedConnections, str); + } + } + +} + + +void cmGraphVizWriter::WriteNode(const char* targetName, + const cmTarget* target, + std::set& insertedNodes, + cmGeneratedFileStream& str) const +{ + if (insertedNodes.find(targetName) == insertedNodes.end()) + { + insertedNodes.insert(targetName); + std::map::const_iterator nameIt = + this->TargetNamesNodes.find(targetName); + + str << " \"" << nameIt->second.c_str() << "\" [ label=\"" + << targetName << "\" shape=\"" << getShapeForTarget(target) + << "\"];" << std::endl; + } +} + + +int cmGraphVizWriter::collectAllTargets() +{ + int cnt = 0; + // First pass get the list of all cmake targets + for (std::vector::const_iterator lit = + this->LocalGenerators.begin(); + lit != this->LocalGenerators.end(); + ++ lit ) + { + const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); + for ( cmTargets::const_iterator tit = targets->begin(); + tit != targets->end(); + ++ tit ) + { + const char* realTargetName = tit->first.c_str(); + if(this->IgnoreThisTarget(realTargetName)) + { + // Skip ignored targets + continue; + } + //std::cout << "Found target: " << tit->first.c_str() << std::endl; + cmOStringStream ostr; + ostr << this->GraphNodePrefix << cnt++; + this->TargetNamesNodes[realTargetName] = ostr.str(); + this->TargetPtrs[realTargetName] = &tit->second; + } + } + + return cnt; +} + + +int cmGraphVizWriter::collectAllExternalLibs(int cnt) +{ + // Ok, now find all the stuff we link to that is not in cmake + for (std::vector::const_iterator lit = + this->LocalGenerators.begin(); + lit != this->LocalGenerators.end(); + ++ lit ) + { + const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); + for ( cmTargets::const_iterator tit = targets->begin(); + tit != targets->end(); + ++ tit ) + { + const char* realTargetName = tit->first.c_str(); + if (this->IgnoreThisTarget(realTargetName)) + { + // Skip ignored targets + continue; + } + const cmTarget::LinkLibraryVectorType* ll = + &(tit->second.GetOriginalLinkLibraries()); + for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin(); + llit != ll->end(); + ++ llit ) + { + const char* libName = llit->first.c_str(); + if (this->IgnoreThisTarget(libName)) + { + // Skip ignored targets + continue; + } + + std::map::const_iterator tarIt = + this->TargetPtrs.find(libName); + if ( tarIt == this->TargetPtrs.end() ) + { + cmOStringStream ostr; + ostr << this->GraphNodePrefix << cnt++; + this->TargetNamesNodes[libName] = ostr.str(); + this->TargetPtrs[libName] = NULL; + //str << " \"" << ostr.c_str() << "\" [ label=\"" << libName + //<< "\" shape=\"ellipse\"];" << std::endl; + } + } + } + } + return cnt; +} + + +bool cmGraphVizWriter::IgnoreThisTarget(const char* name) const +{ + return (this->TargetsToIgnore.find(name) != this->TargetsToIgnore.end()); +} diff --git a/Source/cmGraphVizWriter.h b/Source/cmGraphVizWriter.h new file mode 100644 index 000000000..fd3d3e20c --- /dev/null +++ b/Source/cmGraphVizWriter.h @@ -0,0 +1,70 @@ +#ifndef CMGRAPHVIZWRITER_H +#define CMGRAPHVIZWRITER_H +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2009 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmStandardIncludes.h" +#include "cmLocalGenerator.h" +#include "cmGeneratedFileStream.h" + + +/** This class implements writing files for graphviz (dot) for graphs + * representing the dependencies between the targets in the project. */ +class cmGraphVizWriter +{ +public: + + cmGraphVizWriter(const std::vector& localGenerators); + + void ReadSettings(const char* settingsFileName, + const char* fallbackSettingsFileName); + + void WritePerTargetFiles(const char* fileName); + + void WriteGlobalFile(const char* fileName); + +protected: + + int collectAllTargets(); + + int collectAllExternalLibs(int cnt); + + void WriteHeader(cmGeneratedFileStream& str) const; + + void WriteConnections(const char* targetName, + std::set& insertedNodes, + std::set& insertedConnections, + cmGeneratedFileStream& str) const; + + void WriteNode(const char* targetName, const cmTarget* target, + std::set& insertedNodes, + cmGeneratedFileStream& str) const; + + void WriteFooter(cmGeneratedFileStream& str) const; + + bool IgnoreThisTarget(const char* name) const; + + cmStdString GraphType; + cmStdString GraphName; + cmStdString GraphHeader; + cmStdString GraphNodePrefix; + + const std::vector& LocalGenerators; + + std::map TargetPtrs; + // maps from the actual target names to node names in dot: + std::map TargetNamesNodes; + + std::set TargetsToIgnore; + +}; + +#endif diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 5386fb4f1..aec8e0619 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -26,6 +26,7 @@ #include "cmDocumentationFormatterText.h" #if defined(CMAKE_BUILD_WITH_CMAKE) +# include "cmGraphVizWriter.h" # include "cmDependsFortran.h" // For -E cmake_copy_f90_mod callback. # include "cmVariableWatch.h" # include @@ -2836,339 +2837,26 @@ const char* cmake::GetCPackCommand() } -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"; -} - - -static void writeNode(const char* targetName, const cmTarget* target, - const std::map& targetNamesNodes, - std::set& insertedNodes, - cmGeneratedFileStream& str) -{ - if (insertedNodes.find(targetName) == insertedNodes.end()) - { - insertedNodes.insert(targetName); - std::map::const_iterator nameIt = - targetNamesNodes.find(targetName); - - str << " \"" << nameIt->second.c_str() << "\" [ label=\"" - << targetName << "\" shape=\"" << getShapeForTarget(target) - << "\"];" << std::endl; - } -} - - void cmake::GenerateGraphViz(const char* fileName) const { - cmake cm; - cmGlobalGenerator ggi; - ggi.SetCMakeInstance(&cm); - std::auto_ptr lg(ggi.CreateLocalGenerator()); - cmMakefile *mf = lg->GetMakefile(); +#ifdef CMAKE_BUILD_WITH_CMAKE + std::auto_ptr gvWriter( + new cmGraphVizWriter(this->GetGlobalGenerator()->GetLocalGenerators())); - std::string infile = this->GetHomeOutputDirectory(); - infile += "/CMakeGraphVizOptions.cmake"; - if ( !cmSystemTools::FileExists(infile.c_str()) ) - { - infile = this->GetHomeDirectory(); - infile += "/CMakeGraphVizOptions.cmake"; - if ( !cmSystemTools::FileExists(infile.c_str()) ) - { - infile = ""; - } - } + std::string settingsFile = this->GetHomeOutputDirectory(); + settingsFile += "/CMakeGraphVizOptions.cmake"; + std::string fallbackSettingsFile = this->GetHomeDirectory(); + fallbackSettingsFile += "/CMakeGraphVizOptions.cmake"; - if ( !infile.empty() ) - { - if ( !mf->ReadListFile(0, infile.c_str()) ) - { - cmSystemTools::Error("Problem opening GraphViz options file: ", - infile.c_str()); - return; - } - std::cout << "Read GraphViz options file: " << infile.c_str() - << std::endl; - } + gvWriter->ReadSettings(settingsFile.c_str(), fallbackSettingsFile.c_str()); -#define __set_if_not_set(var, value, cmakeDefinition) \ - const char* var = mf->GetDefinition(cmakeDefinition); \ - if ( !var ) \ - { \ - var = value; \ - } - __set_if_not_set(graphType, "digraph", "GRAPHVIZ_GRAPH_TYPE"); - __set_if_not_set(graphName, "GG", "GRAPHVIZ_GRAPH_NAME"); - __set_if_not_set(graphHeader, "node [\n fontsize = \"12\"\n];", - "GRAPHVIZ_GRAPH_HEADER"); - __set_if_not_set(graphNodePrefix, "node", "GRAPHVIZ_NODE_PREFIX"); - const char* ignoreTargets = mf->GetDefinition("GRAPHVIZ_IGNORE_TARGETS"); - std::set ignoreTargetsSet; - if ( ignoreTargets ) - { - std::vector ignoreTargetsVector; - cmSystemTools::ExpandListArgument(ignoreTargets,ignoreTargetsVector); - std::vector::iterator itvIt; - for ( itvIt = ignoreTargetsVector.begin(); - itvIt != ignoreTargetsVector.end(); - ++ itvIt ) - { - ignoreTargetsSet.insert(itvIt->c_str()); - } - } + gvWriter->WritePerTargetFiles(fileName); + gvWriter->WriteGlobalFile(fileName); - std::map targetPtrs; - std::map targetNamesNodes; // maps from the actual strings to node names in dot - int cnt = getAllTargets(ignoreTargetsSet, targetNamesNodes, targetPtrs, - graphNodePrefix); - - cnt = getAllExternalLibs(ignoreTargetsSet, targetNamesNodes, targetPtrs, - graphNodePrefix, cnt); - - for(std::map::const_iterator ptrIt = - targetPtrs.begin(); - ptrIt != targetPtrs.end(); - ++ptrIt) - { - if (ptrIt->second == NULL) - { - continue; - } - - if ((ptrIt->second->GetType() != cmTarget::EXECUTABLE) - && (ptrIt->second->GetType() != cmTarget::STATIC_LIBRARY) - && (ptrIt->second->GetType() != cmTarget::SHARED_LIBRARY) - && (ptrIt->second->GetType() != cmTarget::MODULE_LIBRARY)) - { - continue; - } - - std::set insertedConnections; - std::set insertedNodes; - - std::string currentFilename = fileName; - currentFilename += "."; - currentFilename += ptrIt->first; - cmGeneratedFileStream str(currentFilename.c_str()); - if ( !str ) - { - return; - } - - fprintf(stderr, "Writing %s...\n", currentFilename.c_str()); - str << graphType << " " << graphName << " {" << std::endl; - str << graphHeader << std::endl; - - writeDotConnections(ptrIt->first.c_str(), targetNamesNodes, targetPtrs, - insertedNodes, insertedConnections, str); - str << "}" << std::endl; - } - - cmGeneratedFileStream str(fileName); - if ( !str ) - { - return; - } - str << graphType << " " << graphName << " {" << std::endl; - str << graphHeader << std::endl; - - fprintf(stderr, "Writing %s...\n", fileName); - std::set insertedConnections; - std::set insertedNodes; - - for(std::map::const_iterator ptrIt = - targetPtrs.begin(); - ptrIt != targetPtrs.end(); - ++ptrIt) - { - if (ptrIt->second == NULL) - { - continue; - } - - if ((ptrIt->second->GetType() != cmTarget::EXECUTABLE) - && (ptrIt->second->GetType() != cmTarget::STATIC_LIBRARY) - && (ptrIt->second->GetType() != cmTarget::SHARED_LIBRARY) - && (ptrIt->second->GetType() != cmTarget::MODULE_LIBRARY)) - { - continue; - } - - writeDotConnections(ptrIt->first.c_str(), targetNamesNodes, targetPtrs, - insertedNodes, insertedConnections, str); - } - str << "}" << std::endl; +#endif } -void cmake::writeDotConnections(const char* targetName, - const std::map& targetNamesNodes, - const std::map& targetPtrs, - std::set& insertedNodes, - std::set& insertedConnections, - cmGeneratedFileStream& str) const -{ - std::map::const_iterator targetPtrIt = - targetPtrs.find(targetName); - - if (targetPtrIt == targetPtrs.end()) // not found at all - { - return; - } - - writeNode(targetName, targetPtrIt->second, targetNamesNodes, insertedNodes, - str); - - if (targetPtrIt->second == NULL) // it's an external library - { - return; - } - - - std::string myNodeName = targetNamesNodes.find(targetName)->second; - - const cmTarget::LinkLibraryVectorType* ll = - &(targetPtrIt->second->GetOriginalLinkLibraries()); - - for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin(); - llit != ll->end(); - ++ llit ) - { - const char* libName = llit->first.c_str(); - std::map::const_iterator libNameIt = - targetNamesNodes.find(libName); - - std::string connectionName = myNodeName; - connectionName += "-"; - connectionName += libNameIt->second; - if (insertedConnections.find(connectionName) == insertedConnections.end()) - { - insertedConnections.insert(connectionName); - writeNode(libName, targetPtrs.find(libName)->second, targetNamesNodes, - insertedNodes, str); - - str << " \"" << myNodeName.c_str() << "\" -> \"" - << libNameIt->second.c_str() << "\""; - str << " // " << targetName << " -> " << libName << std::endl; - writeDotConnections(libName, targetNamesNodes, targetPtrs, insertedNodes, - insertedConnections, str); - } - } - -} - - -int cmake::getAllTargets(const std::set& ignoreTargetsSet, - std::map& targetNamesNodes, - std::map& targetPtrs, - const char* graphNodePrefix) const -{ - int cnt = 0; - const std::vector& localGenerators = - this->GetGlobalGenerator()->GetLocalGenerators(); - // First pass get the list of all cmake targets - for (std::vector::const_iterator lit = - localGenerators.begin(); - lit != localGenerators.end(); - ++ lit ) - { - const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); - for ( cmTargets::const_iterator tit = targets->begin(); - tit != targets->end(); - ++ tit ) - { - const char* realTargetName = tit->first.c_str(); - if ( ignoreTargetsSet.find(realTargetName) != ignoreTargetsSet.end() ) - { - // Skip ignored targets - continue; - } - //std::cout << "Found target: " << tit->first.c_str() << std::endl; - cmOStringStream ostr; - ostr << graphNodePrefix << cnt++; - targetNamesNodes[realTargetName] = ostr.str(); - targetPtrs[realTargetName] = &tit->second; - } - } - - return cnt; -} - - -int cmake::getAllExternalLibs(const std::set& ignoreTargetsSet, - std::map& targetNamesNodes, - std::map& targetPtrs, - const char* graphNodePrefix, int cnt) const -{ - const std::vector& localGenerators = - this->GetGlobalGenerator()->GetLocalGenerators(); - // Ok, now find all the stuff we link to that is not in cmake - for (std::vector::const_iterator lit = - localGenerators.begin(); - lit != localGenerators.end(); - ++ lit ) - { - const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); - for ( cmTargets::const_iterator tit = targets->begin(); - tit != targets->end(); - ++ tit ) - { - const char* realTargetName = tit->first.c_str(); - if ( ignoreTargetsSet.find(realTargetName) != ignoreTargetsSet.end() ) - { - // Skip ignored targets - continue; - } - const cmTarget::LinkLibraryVectorType* ll = - &(tit->second.GetOriginalLinkLibraries()); - for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin(); - llit != ll->end(); - ++ llit ) - { - const char* libName = llit->first.c_str(); - if ( ignoreTargetsSet.find(libName) != ignoreTargetsSet.end() ) - { - // Skip ignored targets - continue; - } - - std::map::const_iterator tarIt = - targetPtrs.find(libName); - if ( tarIt == targetPtrs.end() ) - { - cmOStringStream ostr; - ostr << graphNodePrefix << cnt++; - targetNamesNodes[libName] = ostr.str(); - targetPtrs[libName] = NULL; - //str << " \"" << ostr.c_str() << "\" [ label=\"" << libName - //<< "\" shape=\"ellipse\"];" << std::endl; - } - } - } - } - return cnt; -} - //---------------------------------------------------------------------------- int cmake::SymlinkLibrary(std::vector& args) { diff --git a/Source/cmake.h b/Source/cmake.h index 0de72d9d6..435d38bfa 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -433,23 +433,6 @@ protected: int* retCodeOut = 0); cmVariableWatch* VariableWatch; - int getAllTargets(const std::set& ignoreTargetsSet, - std::map& targetNamesNodes, - std::map& targetPtrs, - const char* graphNodePrefix) const; - - int getAllExternalLibs(const std::set& ignoreTargetsSet, - std::map& targetNamesNodes, - std::map& targetPtrs, - const char* graphNodePrefix, int cnt) const; - - void writeDotConnections(const char* targetName, - const std::map& targetNamesNodes, - const std::map& targetPtrs, - std::set& insertedNodes, - std::set& insertedConnections, - cmGeneratedFileStream& str) const; - ///! Find the full path to one of the cmake programs like ctest, cpack, etc. std::string FindCMakeProgram(const char* name) const; private: From 7ba2d365858d259572b22ab35ea6c709ba1514ea Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 14 Nov 2010 19:30:58 +0100 Subject: [PATCH 6/9] Enable/disable generating graphs depending on the target type In CMakeGraphVizOptions.cmake you can now set GRAPHVIZ_EXECUTABLES, GRAPHVIZ_STATIC_LIBS, GRAPHVIZ_SHARED_LIBS and GRAPHVIZ_MODULE_LIBS to TRUE or FALSE depending on whether you want graphs for the targets of the respective types. Alex --- Source/cmGraphVizWriter.cxx | 48 ++++++++++++++++++++++++++++++------- Source/cmGraphVizWriter.h | 8 +++++++ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx index 749202b9a..b62badfbe 100644 --- a/Source/cmGraphVizWriter.cxx +++ b/Source/cmGraphVizWriter.cxx @@ -50,6 +50,10 @@ cmGraphVizWriter::cmGraphVizWriter(const std::vector& ,GraphName("GG") ,GraphHeader("node [\n fontsize = \"12\"\n];") ,GraphNodePrefix("node") +,GenerateForExecutables(true) +,GenerateForStaticLibs(true) +,GenerateForSharedLibs(true) +,GenerateForModuleLibs(true) ,LocalGenerators(localGenerators) { int cnt = collectAllTargets(); @@ -100,6 +104,20 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName, __set_if_set(this->GraphHeader, "GRAPHVIZ_GRAPH_HEADER"); __set_if_set(this->GraphNodePrefix, "GRAPHVIZ_NODE_PREFIX"); +#define __set_bool_if_set(var, cmakeDefinition) \ + { \ + const char* value = mf->GetDefinition(cmakeDefinition); \ + if ( value ) \ + { \ + var = mf->IsOn(cmakeDefinition); \ + } \ + } + + __set_bool_if_set(this->GenerateForExecutables, "GRAPHVIZ_EXECUTABLES"); + __set_bool_if_set(this->GenerateForStaticLibs, "GRAPHVIZ_STATIC_LIBS"); + __set_bool_if_set(this->GenerateForSharedLibs, "GRAPHVIZ_SHARED_LIBS"); + __set_bool_if_set(this->GenerateForModuleLibs , "GRAPHVIZ_MODULE_LIBS"); + this->TargetsToIgnore.clear(); const char* ignoreTargets = mf->GetDefinition("GRAPHVIZ_IGNORE_TARGETS"); if ( ignoreTargets ) @@ -129,10 +147,7 @@ void cmGraphVizWriter::WritePerTargetFiles(const char* fileName) continue; } - if ((ptrIt->second->GetType() != cmTarget::EXECUTABLE) - && (ptrIt->second->GetType() != cmTarget::STATIC_LIBRARY) - && (ptrIt->second->GetType() != cmTarget::SHARED_LIBRARY) - && (ptrIt->second->GetType() != cmTarget::MODULE_LIBRARY)) + if (this->GenerateForTargetType(ptrIt->second->GetType()) == false) { continue; } @@ -183,10 +198,7 @@ void cmGraphVizWriter::WriteGlobalFile(const char* fileName) continue; } - if ((ptrIt->second->GetType() != cmTarget::EXECUTABLE) - && (ptrIt->second->GetType() != cmTarget::STATIC_LIBRARY) - && (ptrIt->second->GetType() != cmTarget::SHARED_LIBRARY) - && (ptrIt->second->GetType() != cmTarget::MODULE_LIBRARY)) + if (this->GenerateForTargetType(ptrIt->second->GetType()) == false) { continue; } @@ -368,3 +380,23 @@ bool cmGraphVizWriter::IgnoreThisTarget(const char* name) const { return (this->TargetsToIgnore.find(name) != this->TargetsToIgnore.end()); } + + +bool cmGraphVizWriter::GenerateForTargetType(cmTarget::TargetType targetType) + const +{ + switch (targetType) + { + case cmTarget::EXECUTABLE: + return this->GenerateForExecutables; + case cmTarget::STATIC_LIBRARY: + return this->GenerateForStaticLibs; + case cmTarget::SHARED_LIBRARY: + return this->GenerateForSharedLibs; + case cmTarget::MODULE_LIBRARY: + return this->GenerateForModuleLibs; + default: + break; + } + return false; +} diff --git a/Source/cmGraphVizWriter.h b/Source/cmGraphVizWriter.h index fd3d3e20c..af8b71638 100644 --- a/Source/cmGraphVizWriter.h +++ b/Source/cmGraphVizWriter.h @@ -14,6 +14,7 @@ #include "cmStandardIncludes.h" #include "cmLocalGenerator.h" #include "cmGeneratedFileStream.h" +#include "cmTarget.h" /** This class implements writing files for graphviz (dot) for graphs @@ -52,11 +53,18 @@ protected: bool IgnoreThisTarget(const char* name) const; + bool GenerateForTargetType(cmTarget::TargetType targetType) const; + cmStdString GraphType; cmStdString GraphName; cmStdString GraphHeader; cmStdString GraphNodePrefix; + bool GenerateForExecutables; + bool GenerateForStaticLibs; + bool GenerateForSharedLibs; + bool GenerateForModuleLibs; + const std::vector& LocalGenerators; std::map TargetPtrs; From 2a5790a080d86c63daf3d2c17d533c919cbef582 Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 14 Nov 2010 19:33:12 +0100 Subject: [PATCH 7/9] Use std::cout instead of fprintf Alex --- Source/cmGraphVizWriter.cxx | 5 +++-- Source/cmGraphVizWriter.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx index b62badfbe..94918a5e6 100644 --- a/Source/cmGraphVizWriter.cxx +++ b/Source/cmGraphVizWriter.cxx @@ -164,7 +164,7 @@ void cmGraphVizWriter::WritePerTargetFiles(const char* fileName) return; } - fprintf(stderr, "Writing %s...\n", currentFilename.c_str()); + std::cout << "Writing " << currentFilename << "..." << std::endl; this->WriteHeader(str); this->WriteConnections(ptrIt->first.c_str(), @@ -184,7 +184,8 @@ void cmGraphVizWriter::WriteGlobalFile(const char* fileName) } this->WriteHeader(str); - fprintf(stderr, "Writing %s...\n", fileName); + std::cout << "Writing " << fileName << "..." << std::endl; + std::set insertedConnections; std::set insertedNodes; diff --git a/Source/cmGraphVizWriter.h b/Source/cmGraphVizWriter.h index af8b71638..c9e5fbdc4 100644 --- a/Source/cmGraphVizWriter.h +++ b/Source/cmGraphVizWriter.h @@ -65,14 +65,14 @@ protected: bool GenerateForSharedLibs; bool GenerateForModuleLibs; + std::set TargetsToIgnore; + const std::vector& LocalGenerators; std::map TargetPtrs; // maps from the actual target names to node names in dot: std::map TargetNamesNodes; - std::set TargetsToIgnore; - }; #endif From 5ea1e4cb36d813bcb1377637779a54f18411763b Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 14 Nov 2010 19:37:03 +0100 Subject: [PATCH 8/9] Collect targets and libs on demand instead of in the ctor This is necessary for the next commit which requires that the targets are collected after the settings have been read. Alex --- Source/cmGraphVizWriter.cxx | 22 ++++++++++++++++++---- Source/cmGraphVizWriter.h | 10 ++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx index 94918a5e6..00befec3f 100644 --- a/Source/cmGraphVizWriter.cxx +++ b/Source/cmGraphVizWriter.cxx @@ -55,9 +55,8 @@ cmGraphVizWriter::cmGraphVizWriter(const std::vector& ,GenerateForSharedLibs(true) ,GenerateForModuleLibs(true) ,LocalGenerators(localGenerators) +,HaveTargetsAndLibs(false) { - int cnt = collectAllTargets(); - collectAllExternalLibs(cnt); } @@ -137,6 +136,8 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName, void cmGraphVizWriter::WritePerTargetFiles(const char* fileName) { + this->CollectTargetsAndLibs(); + for(std::map::const_iterator ptrIt = this->TargetPtrs.begin(); ptrIt != this->TargetPtrs.end(); @@ -177,6 +178,8 @@ void cmGraphVizWriter::WritePerTargetFiles(const char* fileName) void cmGraphVizWriter::WriteGlobalFile(const char* fileName) { + this->CollectTargetsAndLibs(); + cmGeneratedFileStream str(fileName); if ( !str ) { @@ -295,7 +298,18 @@ void cmGraphVizWriter::WriteNode(const char* targetName, } -int cmGraphVizWriter::collectAllTargets() +void cmGraphVizWriter::CollectTargetsAndLibs() +{ + if (this->HaveTargetsAndLibs == false) + { + this->HaveTargetsAndLibs = true; + int cnt = this->CollectAllTargets(); + this->CollectAllExternalLibs(cnt); + } +} + + +int cmGraphVizWriter::CollectAllTargets() { int cnt = 0; // First pass get the list of all cmake targets @@ -327,7 +341,7 @@ int cmGraphVizWriter::collectAllTargets() } -int cmGraphVizWriter::collectAllExternalLibs(int cnt) +int cmGraphVizWriter::CollectAllExternalLibs(int cnt) { // Ok, now find all the stuff we link to that is not in cmake for (std::vector::const_iterator lit = diff --git a/Source/cmGraphVizWriter.h b/Source/cmGraphVizWriter.h index c9e5fbdc4..88842a6f0 100644 --- a/Source/cmGraphVizWriter.h +++ b/Source/cmGraphVizWriter.h @@ -15,6 +15,7 @@ #include "cmLocalGenerator.h" #include "cmGeneratedFileStream.h" #include "cmTarget.h" +#include /** This class implements writing files for graphviz (dot) for graphs @@ -34,9 +35,11 @@ public: protected: - int collectAllTargets(); + void CollectTargetsAndLibs(); - int collectAllExternalLibs(int cnt); + int CollectAllTargets(); + + int CollectAllExternalLibs(int cnt); void WriteHeader(cmGeneratedFileStream& str) const; @@ -65,6 +68,8 @@ protected: bool GenerateForSharedLibs; bool GenerateForModuleLibs; + cmsys::RegularExpression TargetIgnoreRegex; + std::set TargetsToIgnore; const std::vector& LocalGenerators; @@ -73,6 +78,7 @@ protected: // maps from the actual target names to node names in dot: std::map TargetNamesNodes; + bool HaveTargetsAndLibs; }; #endif From 78c86f454272a2ac417ad6a89e4c7ed7e4975adb Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 14 Nov 2010 19:47:28 +0100 Subject: [PATCH 9/9] Exclude targets from the graphviz file based on a regex This commit adds support for a GRAPHVIZ_TARGET_IGNORE_REGEX variable which can be set() in CMakeGraphVizOptions.cmake. Targets matching this regex will be skipped when generating the graphviz graphs. Alex --- Source/cmGraphVizWriter.cxx | 20 +++++++++++++++++++- Source/cmGraphVizWriter.h | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx index 00befec3f..bdb33bcdf 100644 --- a/Source/cmGraphVizWriter.cxx +++ b/Source/cmGraphVizWriter.cxx @@ -117,6 +117,17 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName, __set_bool_if_set(this->GenerateForSharedLibs, "GRAPHVIZ_SHARED_LIBS"); __set_bool_if_set(this->GenerateForModuleLibs , "GRAPHVIZ_MODULE_LIBS"); + cmStdString tmpRegexString; + __set_if_set(tmpRegexString, "GRAPHVIZ_TARGET_IGNORE_REGEX"); + if (tmpRegexString.size() > 0) + { + if (!this->TargetIgnoreRegex.compile(tmpRegexString.c_str())) + { + std::cerr << "Could not compile bad regex \"" << tmpRegexString << "\"" + << std::endl; + } + } + this->TargetsToIgnore.clear(); const char* ignoreTargets = mf->GetDefinition("GRAPHVIZ_IGNORE_TARGETS"); if ( ignoreTargets ) @@ -391,8 +402,15 @@ int cmGraphVizWriter::CollectAllExternalLibs(int cnt) } -bool cmGraphVizWriter::IgnoreThisTarget(const char* name) const +bool cmGraphVizWriter::IgnoreThisTarget(const char* name) { + if (this->TargetIgnoreRegex.is_valid()) + { + if (this->TargetIgnoreRegex.find(name)) + { + return true; + } + } return (this->TargetsToIgnore.find(name) != this->TargetsToIgnore.end()); } diff --git a/Source/cmGraphVizWriter.h b/Source/cmGraphVizWriter.h index 88842a6f0..105eb9635 100644 --- a/Source/cmGraphVizWriter.h +++ b/Source/cmGraphVizWriter.h @@ -54,7 +54,7 @@ protected: void WriteFooter(cmGeneratedFileStream& str) const; - bool IgnoreThisTarget(const char* name) const; + bool IgnoreThisTarget(const char* name); bool GenerateForTargetType(cmTarget::TargetType targetType) const;