diff options
author | Alexander Neundorf <neundorf@kde.org> | 2007-06-15 14:10:24 (GMT) |
---|---|---|
committer | Alexander Neundorf <neundorf@kde.org> | 2007-06-15 14:10:24 (GMT) |
commit | 9d4f3a06864b3b5fe96073ddc256ef39ab24ddad (patch) | |
tree | e55df81497545d678b13be3c5ccdcd34ae62af5a | |
parent | c2f7a3c02730759d6bde6b6b50daa1f23cc5fe24 (diff) | |
download | CMake-9d4f3a06864b3b5fe96073ddc256ef39ab24ddad.zip CMake-9d4f3a06864b3b5fe96073ddc256ef39ab24ddad.tar.gz CMake-9d4f3a06864b3b5fe96073ddc256ef39ab24ddad.tar.bz2 |
STYLE: remove duplicate non-const accessors GetLocalGenerator(int) and
GetLocaGenerators(cmLocalGenerators) from cmGlobalGenerator(). Now there is
one const accessor which is even faster since it returns a reference
(instead of copying a vector)
-more const to ensure that this the returned local generators don't actually
get modified
-removed duplicated code in GetCTestCommand() and GetCPackCommand()
-added some const accessors
Alex
-rw-r--r-- | Source/cmExportLibraryDependencies.cxx | 51 | ||||
-rw-r--r-- | Source/cmExportLibraryDependencies.h | 4 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 6 | ||||
-rw-r--r-- | Source/cmLocalGenerator.h | 4 | ||||
-rw-r--r-- | Source/cmMakefile.h | 4 | ||||
-rw-r--r-- | Source/cmTarget.h | 4 | ||||
-rw-r--r-- | Source/cmake.cxx | 159 | ||||
-rw-r--r-- | Source/cmake.h | 11 |
8 files changed, 113 insertions, 130 deletions
diff --git a/Source/cmExportLibraryDependencies.cxx b/Source/cmExportLibraryDependencies.cxx index 51d9498..6720c3e 100644 --- a/Source/cmExportLibraryDependencies.cxx +++ b/Source/cmExportLibraryDependencies.cxx @@ -32,38 +32,40 @@ bool cmExportLibraryDependenciesCommand } // store the arguments for the final pass - // also expand any CMake variables - - this->Args = args; + this->Filename = args[0]; + this->Append = false; + if(args.size() > 1) + { + if(args[1] == "APPEND") + { + this->Append = true; + } + } return true; } void cmExportLibraryDependenciesCommand::FinalPass() { - // Create a full path filename for output - std::string fname = this->Args[0]; - bool append = false; - if(this->Args.size() > 1) - { - if(this->Args[1] == "APPEND") - { - append = true; - } - } + // export_library_dependencies() shouldn't modify anything + // ensure this by calling a const method + this->ConstFinalPass(); +} +void cmExportLibraryDependenciesCommand::ConstFinalPass() const +{ // Use copy-if-different if not appending. cmsys::auto_ptr<std::ofstream> foutPtr; - if(append) + if(this->Append) { cmsys::auto_ptr<std::ofstream> ap( - new std::ofstream(fname.c_str(), std::ios::app)); + new std::ofstream(this->Filename.c_str(), std::ios::app)); foutPtr = ap; } else { cmsys::auto_ptr<cmGeneratedFileStream> ap( - new cmGeneratedFileStream(fname.c_str(), true)); + new cmGeneratedFileStream(this->Filename.c_str(), true)); ap->SetCopyIfDifferent(true); foutPtr = ap; } @@ -71,23 +73,22 @@ void cmExportLibraryDependenciesCommand::FinalPass() if (!fout) { - cmSystemTools::Error("Error Writing ", fname.c_str()); + cmSystemTools::Error("Error Writing ", this->Filename.c_str()); cmSystemTools::ReportLastSystemError(""); return; } - cmake* cm = this->Makefile->GetCMakeInstance(); - cmGlobalGenerator* global = cm->GetGlobalGenerator(); - std::vector<cmLocalGenerator *> locals; - global->GetLocalGenerators(locals); + const cmake* cm = this->Makefile->GetCMakeInstance(); + const cmGlobalGenerator* global = cm->GetGlobalGenerator(); + const std::vector<cmLocalGenerator *>& locals = global->GetLocalGenerators(); std::string libDepName; - for(std::vector<cmLocalGenerator *>::iterator i = locals.begin(); + for(std::vector<cmLocalGenerator *>::const_iterator i = locals.begin(); i != locals.end(); ++i) { - cmLocalGenerator* gen = *i; - cmTargets &tgts = gen->GetMakefile()->GetTargets(); + const cmLocalGenerator* gen = *i; + const cmTargets &tgts = gen->GetMakefile()->GetTargets(); std::vector<std::string> depends; const char *defType; - for(cmTargets::iterator l = tgts.begin(); + for(cmTargets::const_iterator l = tgts.begin(); l != tgts.end(); ++l) { libDepName = l->first; diff --git a/Source/cmExportLibraryDependencies.h b/Source/cmExportLibraryDependencies.h index e8af97e..73a068f 100644 --- a/Source/cmExportLibraryDependencies.h +++ b/Source/cmExportLibraryDependencies.h @@ -81,7 +81,9 @@ public: cmTypeMacro(cmExportLibraryDependenciesCommand, cmCommand); private: - std::vector<std::string> Args; + std::string Filename; + bool Append; + void ConstFinalPass() const; }; diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index eb49883..3ab18bc 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -117,10 +117,8 @@ public: cmake *GetCMakeInstance() { return this->CMakeInstance; }; void SetConfiguredFilesPath(const char* s){this->ConfiguredFilesPath = s;} - cmLocalGenerator* GetLocalGenerator(int p) { - return this->LocalGenerators[p];} - void GetLocalGenerators(std::vector<cmLocalGenerator *>&g) { - g = this->LocalGenerators;} + const std::vector<cmLocalGenerator *>& GetLocalGenerators() const { + return this->LocalGenerators;} void AddLocalGenerator(cmLocalGenerator *lg); diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index f767a69..cc5a39d 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -81,6 +81,10 @@ public: cmMakefile *GetMakefile() { return this->Makefile; }; + ///! Get the makefile for this generator, const version + const cmMakefile *GetMakefile() const { + return this->Makefile; }; + ///! Get the GlobalGenerator this is associated with cmGlobalGenerator *GetGlobalGenerator() { return this->GlobalGenerator; }; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index dfd3ff8..39ca4f8 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -418,6 +418,10 @@ public: * Get the list of targets */ cmTargets &GetTargets() { return this->Targets; } + /** + * Get the list of targets, const version + */ + const cmTargets &GetTargets() const { return this->Targets; } const cmTargets &GetImportedTargets() const { return this->ImportedTargets; } cmTarget* FindTarget(const char* name, bool useImportedTargets); diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 97f574d..e8b17ee 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -102,9 +102,9 @@ public: typedef std::pair<cmStdString, LinkLibraryType> LibraryID; typedef std::vector<LibraryID > LinkLibraryVectorType; - const LinkLibraryVectorType &GetLinkLibraries() { + const LinkLibraryVectorType &GetLinkLibraries() const { return this->LinkLibraries;} - const LinkLibraryVectorType &GetOriginalLinkLibraries() + const LinkLibraryVectorType &GetOriginalLinkLibraries() const {return this->OriginalLinkLibraries;} /** diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 664108e..b340917 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2402,47 +2402,52 @@ inline std::string removeQuotes(const std::string& s) return s; } -const char* cmake::GetCTestCommand() +std::string cmake::FindCMakeProgram(const char* name) const { - if ( !this->CTestCommand.empty() ) + std::string path; + if ((name) && (*name)) { - return this->CTestCommand.c_str(); - } - - cmMakefile* mf - = this->GetGlobalGenerator()->GetLocalGenerator(0)->GetMakefile(); + const cmMakefile* mf + = this->GetGlobalGenerator()->GetLocalGenerators()[0]->GetMakefile(); #ifdef CMAKE_BUILD_WITH_CMAKE - this->CTestCommand = mf->GetRequiredDefinition("CMAKE_COMMAND"); - this->CTestCommand = removeQuotes(this->CTestCommand); - this->CTestCommand = - cmSystemTools::GetFilenamePath(this->CTestCommand.c_str()); - this->CTestCommand += "/"; - this->CTestCommand += "ctest"; - this->CTestCommand += cmSystemTools::GetExecutableExtension(); - if(!cmSystemTools::FileExists(this->CTestCommand.c_str())) - { - this->CTestCommand = mf->GetRequiredDefinition("CMAKE_COMMAND"); - this->CTestCommand = - cmSystemTools::GetFilenamePath(this->CTestCommand.c_str()); - this->CTestCommand += "/Debug/"; - this->CTestCommand += "ctest"; - this->CTestCommand += cmSystemTools::GetExecutableExtension(); - } - if(!cmSystemTools::FileExists(this->CTestCommand.c_str())) - { - this->CTestCommand = mf->GetRequiredDefinition("CMAKE_COMMAND"); - this->CTestCommand = - cmSystemTools::GetFilenamePath(this->CTestCommand.c_str()); - this->CTestCommand += "/Release/"; - this->CTestCommand += "ctest"; - this->CTestCommand += cmSystemTools::GetExecutableExtension(); + path = mf->GetRequiredDefinition("CMAKE_COMMAND"); + path = removeQuotes(path); + path = cmSystemTools::GetFilenamePath(path.c_str()); + path += "/"; + path += name; + path += cmSystemTools::GetExecutableExtension(); + if(!cmSystemTools::FileExists(path.c_str())) + { + path = mf->GetRequiredDefinition("CMAKE_COMMAND"); + path = cmSystemTools::GetFilenamePath(path.c_str()); + path += "/Debug/"; + path += name; + path += cmSystemTools::GetExecutableExtension(); + } + if(!cmSystemTools::FileExists(path.c_str())) + { + path = mf->GetRequiredDefinition("CMAKE_COMMAND"); + path = cmSystemTools::GetFilenamePath(path.c_str()); + path += "/Release/"; + path += name; + path += cmSystemTools::GetExecutableExtension(); } #else - // Only for bootstrap - this->CTestCommand += mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH"); - this->CTestCommand += "/ctest"; - this->CTestCommand += cmSystemTools::GetExecutableExtension(); + // Only for bootstrap + path += mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH"); + path += name; + path += cmSystemTools::GetExecutableExtension(); #endif + } + return path; +} + +const char* cmake::GetCTestCommand() +{ + if ( this->CTestCommand.empty() ) + { + this->CTestCommand = this->FindCMakeProgram("ctest"); + } if ( this->CTestCommand.empty() ) { cmSystemTools::Error("Cannot find the CTest executable"); @@ -2453,55 +2458,19 @@ const char* cmake::GetCTestCommand() const char* cmake::GetCPackCommand() { - if ( !this->CPackCommand.empty() ) + if ( this->CPackCommand.empty() ) { - return this->CPackCommand.c_str(); + this->CPackCommand = this->FindCMakeProgram("cpack"); } - - cmMakefile* mf - = this->GetGlobalGenerator()->GetLocalGenerator(0)->GetMakefile(); - -#ifdef CMAKE_BUILD_WITH_CMAKE - this->CPackCommand = mf->GetRequiredDefinition("CMAKE_COMMAND"); - this->CPackCommand = removeQuotes(this->CPackCommand); - this->CPackCommand = - cmSystemTools::GetFilenamePath(this->CPackCommand.c_str()); - this->CPackCommand += "/"; - this->CPackCommand += "cpack"; - this->CPackCommand += cmSystemTools::GetExecutableExtension(); - if(!cmSystemTools::FileExists(this->CPackCommand.c_str())) - { - this->CPackCommand = mf->GetRequiredDefinition("CMAKE_COMMAND"); - this->CPackCommand = - cmSystemTools::GetFilenamePath(this->CPackCommand.c_str()); - this->CPackCommand += "/Debug/"; - this->CPackCommand += "cpack"; - this->CPackCommand += cmSystemTools::GetExecutableExtension(); - } - if(!cmSystemTools::FileExists(this->CPackCommand.c_str())) - { - this->CPackCommand = mf->GetRequiredDefinition("CMAKE_COMMAND"); - this->CPackCommand = - cmSystemTools::GetFilenamePath(this->CPackCommand.c_str()); - this->CPackCommand += "/Release/"; - this->CPackCommand += "cpack"; - this->CPackCommand += cmSystemTools::GetExecutableExtension(); - } - if (!cmSystemTools::FileExists(this->CPackCommand.c_str())) + if ( this->CPackCommand.empty() ) { cmSystemTools::Error("Cannot find the CPack executable"); this->CPackCommand = "CPACK-COMMAND-NOT-FOUND"; } -#else - // Only for bootstrap - this->CPackCommand += mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH"); - this->CPackCommand += "/cpack"; - this->CPackCommand += cmSystemTools::GetExecutableExtension(); -#endif - return this->CPackCommand.c_str(); + return this->CPackCommand.c_str(); } -void cmake::GenerateGraphViz(const char* fileName) +void cmake::GenerateGraphViz(const char* fileName) const { cmGeneratedFileStream str(fileName); if ( !str ) @@ -2568,23 +2537,23 @@ void cmake::GenerateGraphViz(const char* fileName) str << graphType << " " << graphName << " {" << std::endl; str << graphHeader << std::endl; - cmGlobalGenerator* gg = this->GetGlobalGenerator(); - std::vector<cmLocalGenerator*> localGenerators; - gg->GetLocalGenerators(localGenerators); - std::vector<cmLocalGenerator*>::iterator lit; + const cmGlobalGenerator* gg = this->GetGlobalGenerator(); + const std::vector<cmLocalGenerator*>& localGenerators = + gg->GetLocalGenerators(); + std::vector<cmLocalGenerator*>::const_iterator lit; // for target deps // 1 - cmake target // 2 - external target // 0 - no deps std::map<cmStdString, int> targetDeps; - std::map<cmStdString, cmTarget*> targetPtrs; + std::map<cmStdString, const cmTarget*> targetPtrs; std::map<cmStdString, cmStdString> targetNamesNodes; int cnt = 0; // First pass get the list of all cmake targets for ( lit = localGenerators.begin(); lit != localGenerators.end(); ++ lit ) { - cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); - cmTargets::iterator tit; + const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); + cmTargets::const_iterator tit; for ( tit = targets->begin(); tit != targets->end(); ++ tit ) { const char* realTargetName = tit->first.c_str(); @@ -2603,8 +2572,8 @@ void cmake::GenerateGraphViz(const char* fileName) // Ok, now find all the stuff we link to that is not in cmake for ( lit = localGenerators.begin(); lit != localGenerators.end(); ++ lit ) { - cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); - cmTargets::iterator tit; + const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); + cmTargets::const_iterator tit; for ( tit = targets->begin(); tit != targets->end(); ++ tit ) { const cmTarget::LinkLibraryVectorType* ll @@ -2623,7 +2592,7 @@ void cmake::GenerateGraphViz(const char* fileName) for ( llit = ll->begin(); llit != ll->end(); ++ llit ) { const char* libName = llit->first.c_str(); - std::map<cmStdString, cmStdString>::iterator tarIt + std::map<cmStdString, cmStdString>::const_iterator tarIt = targetNamesNodes.find(libName); if ( ignoreTargetsSet.find(libName) != ignoreTargetsSet.end() ) { @@ -2641,7 +2610,7 @@ void cmake::GenerateGraphViz(const char* fileName) } else { - std::map<cmStdString, int>::iterator depIt + std::map<cmStdString, int>::const_iterator depIt = targetDeps.find(libName); if ( depIt == targetDeps.end() ) { @@ -2653,11 +2622,11 @@ void cmake::GenerateGraphViz(const char* fileName) } // Write out nodes - std::map<cmStdString, int>::iterator depIt; + std::map<cmStdString, int>::const_iterator depIt; for ( depIt = targetDeps.begin(); depIt != targetDeps.end(); ++ depIt ) { const char* newTargetName = depIt->first.c_str(); - std::map<cmStdString, cmStdString>::iterator tarIt + std::map<cmStdString, cmStdString>::const_iterator tarIt = targetNamesNodes.find(newTargetName); if ( tarIt == targetNamesNodes.end() ) { @@ -2671,8 +2640,8 @@ void cmake::GenerateGraphViz(const char* fileName) << newTargetName << "\" shape=\""; if ( depIt->second == 1 ) { - std::map<cmStdString, cmTarget*>::iterator tarTypeIt= targetPtrs.find( - newTargetName); + std::map<cmStdString, const cmTarget*>::const_iterator tarTypeIt = + targetPtrs.find(newTargetName); if ( tarTypeIt == targetPtrs.end() ) { // We should not be here. @@ -2680,7 +2649,7 @@ void cmake::GenerateGraphViz(const char* fileName) << " even though it was added in the previous pass" << std::endl; abort(); } - cmTarget* tg = tarTypeIt->second; + const cmTarget* tg = tarTypeIt->second; switch ( tg->GetType() ) { case cmTarget::EXECUTABLE: @@ -2709,8 +2678,8 @@ void cmake::GenerateGraphViz(const char* fileName) // Now generate the connectivity for ( lit = localGenerators.begin(); lit != localGenerators.end(); ++ lit ) { - cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); - cmTargets::iterator tit; + const cmTargets* targets = &((*lit)->GetMakefile()->GetTargets()); + cmTargets::const_iterator tit; for ( tit = targets->begin(); tit != targets->end(); ++ tit ) { std::map<cmStdString, int>::iterator dependIt @@ -2727,7 +2696,7 @@ void cmake::GenerateGraphViz(const char* fileName) for ( llit = ll->begin(); llit != ll->end(); ++ llit ) { const char* libName = llit->first.c_str(); - std::map<cmStdString, cmStdString>::iterator tarIt + std::map<cmStdString, cmStdString>::const_iterator tarIt = targetNamesNodes.find(libName); if ( tarIt == targetNamesNodes.end() ) { diff --git a/Source/cmake.h b/Source/cmake.h index 9edbd67..6b1f756 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -155,7 +155,10 @@ class cmake cmGlobalGenerator* CreateGlobalGenerator(const char* name); ///! Return the global generator assigned to this instance of cmake - cmGlobalGenerator* GetGlobalGenerator() { return this->GlobalGenerator; }; + cmGlobalGenerator* GetGlobalGenerator() { return this->GlobalGenerator; } + ///! Return the global generator assigned to this instance of cmake, const + const cmGlobalGenerator* GetGlobalGenerator() const + { return this->GlobalGenerator; } ///! Return the global generator assigned to this instance of cmake void SetGlobalGenerator(cmGlobalGenerator *); @@ -284,7 +287,7 @@ class cmake */ const char* GetCTestCommand(); const char* GetCPackCommand(); - const char* GetCMakeCommand() { return this->CMakeCommand.c_str(); } + const char* GetCMakeCommand() const { return this->CMakeCommand.c_str(); } // Do we want debug output during the cmake run. bool GetDebugOutput() { return this->DebugOutput; } @@ -354,13 +357,15 @@ protected: //macros. void CleanupCommandsAndMacros(); - void GenerateGraphViz(const char* fileName); + void GenerateGraphViz(const char* fileName) const; static int ExecuteEchoColor(std::vector<std::string>& args); static int ExecuteLinkScript(std::vector<std::string>& args); cmVariableWatch* VariableWatch; + ///! Find the full path to one of the cmake programs like ctest, cpack, etc. + std::string FindCMakeProgram(const char* name) const; private: ProgressCallbackType ProgressCallback; void* ProgressCallbackClientData; |