diff options
author | Ken Martin <ken.martin@kitware.com> | 2001-02-16 16:34:23 (GMT) |
---|---|---|
committer | Ken Martin <ken.martin@kitware.com> | 2001-02-16 16:34:23 (GMT) |
commit | 43859e36cfa3dede4f935ada5ad08ee6e7eb1d76 (patch) | |
tree | 622fb609e84cbefa6e34bd2a60bc084ab15b5ab7 /Source | |
parent | fce56c57c497ede3a7afcbc7965846cc8bad9db2 (diff) | |
download | CMake-43859e36cfa3dede4f935ada5ad08ee6e7eb1d76.zip CMake-43859e36cfa3dede4f935ada5ad08ee6e7eb1d76.tar.gz CMake-43859e36cfa3dede4f935ada5ad08ee6e7eb1d76.tar.bz2 |
ENH: add new commands fro find library and find program
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmConfigureFileNoAutoconf.cxx | 6 | ||||
-rw-r--r-- | Source/cmDSWMakefile.cxx | 12 | ||||
-rw-r--r-- | Source/cmDSWWriter.cxx | 12 | ||||
-rw-r--r-- | Source/cmFindIncludeCommand.cxx | 29 | ||||
-rw-r--r-- | Source/cmFindLibraryCommand.cxx | 29 | ||||
-rw-r--r-- | Source/cmFindLibraryCommand.h | 2 | ||||
-rw-r--r-- | Source/cmFindProgramCommand.cxx | 29 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 16 | ||||
-rw-r--r-- | Source/cmMakefile.h | 13 | ||||
-rw-r--r-- | Source/cmSystemTools.cxx | 25 | ||||
-rw-r--r-- | Source/cmSystemTools.h | 6 |
11 files changed, 119 insertions, 60 deletions
diff --git a/Source/cmConfigureFileNoAutoconf.cxx b/Source/cmConfigureFileNoAutoconf.cxx index e4815a1..4d60e81 100644 --- a/Source/cmConfigureFileNoAutoconf.cxx +++ b/Source/cmConfigureFileNoAutoconf.cxx @@ -33,8 +33,8 @@ void cmConfigureFileNoAutoconf::FinalPass() #ifdef CMAKE_HAS_AUTOCONF return; #else - m_Makefile->ExpandVariblesInString(m_InputFile); - m_Makefile->ExpandVariblesInString(m_OuputFile); + m_Makefile->ExpandVariablesInString(m_InputFile); + m_Makefile->ExpandVariablesInString(m_OuputFile); std::ifstream fin(m_InputFile.c_str()); if(!fin) { @@ -65,7 +65,7 @@ void cmConfigureFileNoAutoconf::FinalPass() { fin.getline(buffer, bufSize); inLine = buffer; - m_Makefile->ExpandVariblesInString(inLine); + m_Makefile->ExpandVariablesInString(inLine); fout << inLine << "\n"; } #endif diff --git a/Source/cmDSWMakefile.cxx b/Source/cmDSWMakefile.cxx index 28bc09d..2bb46ee 100644 --- a/Source/cmDSWMakefile.cxx +++ b/Source/cmDSWMakefile.cxx @@ -157,7 +157,7 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout) // to be removed as this may be built in a different directory // than the source std::string dir = (*k)->GetDSPMakefile()-> - GetMakefile()->GetCurrentDirectory(); + GetMakefile()->GetStartDirectory(); // Get the home directory with the trailing slash std::string homedir = m_Makefile->GetHomeDirectory(); homedir += "/"; @@ -187,6 +187,7 @@ void cmDSWMakefile::WriteProject(std::ostream& fout, const char* dir, cmDSPMakefile* project) { + project->GetMakefile()->ExpandVariables(); fout << "###############################################################################\n\n"; fout << "Project: \"" << dspname << "\"=" << dir << "\\" << dspname << ".dsp - Package Owner=<4>\n\n"; @@ -201,9 +202,12 @@ void cmDSWMakefile::WriteProject(std::ostream& fout, end = project->GetMakefile()->GetLinkLibraries().end(); for(;i!= end; ++i) { - fout << "Begin Project Dependency\n"; - fout << "Project_Dep_Name " << *i << "\n"; - fout << "End Project Dependency\n"; + if (strcmp(i->c_str(),dspname)) + { + fout << "Begin Project Dependency\n"; + fout << "Project_Dep_Name " << *i << "\n"; + fout << "End Project Dependency\n"; + } } } fout << "}}}\n\n"; diff --git a/Source/cmDSWWriter.cxx b/Source/cmDSWWriter.cxx index 28bc09d..2bb46ee 100644 --- a/Source/cmDSWWriter.cxx +++ b/Source/cmDSWWriter.cxx @@ -157,7 +157,7 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout) // to be removed as this may be built in a different directory // than the source std::string dir = (*k)->GetDSPMakefile()-> - GetMakefile()->GetCurrentDirectory(); + GetMakefile()->GetStartDirectory(); // Get the home directory with the trailing slash std::string homedir = m_Makefile->GetHomeDirectory(); homedir += "/"; @@ -187,6 +187,7 @@ void cmDSWMakefile::WriteProject(std::ostream& fout, const char* dir, cmDSPMakefile* project) { + project->GetMakefile()->ExpandVariables(); fout << "###############################################################################\n\n"; fout << "Project: \"" << dspname << "\"=" << dir << "\\" << dspname << ".dsp - Package Owner=<4>\n\n"; @@ -201,9 +202,12 @@ void cmDSWMakefile::WriteProject(std::ostream& fout, end = project->GetMakefile()->GetLinkLibraries().end(); for(;i!= end; ++i) { - fout << "Begin Project Dependency\n"; - fout << "Project_Dep_Name " << *i << "\n"; - fout << "End Project Dependency\n"; + if (strcmp(i->c_str(),dspname)) + { + fout << "Begin Project Dependency\n"; + fout << "Project_Dep_Name " << *i << "\n"; + fout << "End Project Dependency\n"; + } } } fout << "}}}\n\n"; diff --git a/Source/cmFindIncludeCommand.cxx b/Source/cmFindIncludeCommand.cxx index 2b4160d..706a617 100644 --- a/Source/cmFindIncludeCommand.cxx +++ b/Source/cmFindIncludeCommand.cxx @@ -18,16 +18,35 @@ // cmFindIncludeCommand bool cmFindIncludeCommand::Invoke(std::vector<std::string>& args) { - return false; - if(args.size() < 1 ) + if(args.size() < 2 ) { this->SetError("called with incorrect number of arguments"); return false; } - for(std::vector<std::string>::iterator i = args.begin(); - i != args.end(); ++i) + + std::vector<std::string> path; + // add any user specified paths + for (int j = 2; j < args.size(); j++) { - m_Makefile->AddDefineFlag((*i).c_str()); + // expand variables + std::string exp = args[j]; + m_Makefile->ExpandVariablesInString(exp); + path.push_back(exp); + } + + // add the standard path + cmSystemTools::GetPath(path); + + for(int k=0; k < path.size(); k++) + { + std::string tryPath = path[k]; + tryPath += "/"; + tryPath += args[1]; + if(cmSystemTools::FileExists(tryPath.c_str())) + { + m_Makefile->AddDefinition(args[0].c_str(), path[k].c_str()); + return true; + } } } diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 1eb2a5d..883a5ea 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -18,16 +18,35 @@ // cmFindLibraryCommand bool cmFindLibraryCommand::Invoke(std::vector<std::string>& args) { - return false; - if(args.size() < 1 ) + if(args.size() < 2 ) { this->SetError("called with incorrect number of arguments"); return false; } - for(std::vector<std::string>::iterator i = args.begin(); - i != args.end(); ++i) + + std::vector<std::string> path; + // add any user specified paths + for (int j = 2; j < args.size(); j++) { - m_Makefile->AddDefineFlag((*i).c_str()); + // expand variables + std::string exp = args[j]; + m_Makefile->ExpandVariablesInString(exp); + path.push_back(exp); + } + + // add the standard path + cmSystemTools::GetPath(path); + + for(int k=0; k < path.size(); k++) + { + std::string tryPath = path[k]; + tryPath += "/"; + tryPath += args[1]; + if(cmSystemTools::FileExists(tryPath.c_str())) + { + m_Makefile->AddDefinition(args[0].c_str(), path[k].c_str()); + return true; + } } } diff --git a/Source/cmFindLibraryCommand.h b/Source/cmFindLibraryCommand.h index a106409..eca2e60 100644 --- a/Source/cmFindLibraryCommand.h +++ b/Source/cmFindLibraryCommand.h @@ -69,7 +69,7 @@ public: virtual const char* GetFullDocumentation() { return - "FIND_LIBRARY(DEFINE try1 try2)"; + "FIND_LIBRARY(DEFINE libraryName path1 path2 path3...)"; } }; diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx index 1c0d6e1..c3d3275 100644 --- a/Source/cmFindProgramCommand.cxx +++ b/Source/cmFindProgramCommand.cxx @@ -16,32 +16,6 @@ #include "cmFindProgramCommand.h" #include <stdlib.h> #include <stdio.h> - -static void GetPath(std::vector<std::string>& path) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - char* pathSep = ";"; -#else - char* pathSep = ":"; -#endif - std::string pathEnv = getenv("PATH"); - std::string::size_type start =0; - bool done = false; - while(!done) - { - std::string::size_type endpos = pathEnv.find(pathSep, start); - if(endpos != std::string::npos) - { - path.push_back(pathEnv.substr(start, endpos-start)); - start = endpos+1; - } - else - { - done = true; - } - } -} - // cmFindProgramCommand @@ -54,7 +28,8 @@ bool cmFindProgramCommand::Invoke(std::vector<std::string>& args) } std::vector<std::string> path; - GetPath(path); + cmSystemTools::GetPath(path); + std::vector<std::string>::iterator i = args.begin(); const char* define = (*i).c_str(); i++; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index e16ea75..ee29a6d 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -226,7 +226,7 @@ void cmMakefile::SetMakefileGenerator(cmMakefileGenerator* mf) void cmMakefile::GenerateMakefile() { // do all the variable expansions here - this->ExpandVaribles(); + this->ExpandVariables(); // set the makefile on the generator m_MakefileGenerator->SetMakefile(this); // give all the commands a chance to do something @@ -373,7 +373,7 @@ std::string cmMakefile::GetParentListFileName(const char *currentFileName) // expance CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR in the // include and library directories. -void cmMakefile::ExpandVaribles() +void cmMakefile::ExpandVariables() { // make sure binary and source dir are defined this->AddDefinition("CMAKE_BINARY_DIR", this->GetHomeOutputDirectory()); @@ -385,13 +385,19 @@ void cmMakefile::ExpandVaribles() end = m_IncludeDirectories.end(); for(j = begin; j != end; ++j) { - this->ExpandVariblesInString(*j); + this->ExpandVariablesInString(*j); } begin = m_LinkDirectories.begin(); end = m_LinkDirectories.end(); for(j = begin; j != end; ++j) { - this->ExpandVariblesInString(*j); + this->ExpandVariablesInString(*j); + } + begin = m_LinkLibraries.begin(); + end = m_LinkLibraries.end(); + for(j = begin; j != end; ++j) + { + this->ExpandVariablesInString(*j); } } @@ -436,7 +442,7 @@ int cmMakefile::DumpDocumentationToFile(const char *fileName) } -void cmMakefile::ExpandVariblesInString(std::string& source) +void cmMakefile::ExpandVariablesInString(std::string& source) { for(DefinitionMap::iterator i = m_Definitions.begin(); i != m_Definitions.end(); ++i) diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index a23fa11..2556601 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -339,7 +339,13 @@ public: * entry in the m_Definitions map. Also @var@ is * expanded to match autoconf style expansions. */ - void ExpandVariblesInString(std::string& source); + void ExpandVariablesInString(std::string& source); + + /** + * Expand variables in the makefiles ivars such as link directories etc + */ + void ExpandVariables(); + protected: std::string m_Prefix; std::vector<std::string> m_AuxSourceDirectories; // @@ -384,11 +390,6 @@ private: */ std::string GetParentListFileName(const char *listFileName); - /** - * Parse a file for includes links and libs - */ - void ExpandVaribles(); - void ReadClasses(std::ifstream& fin, bool t); friend class cmMakeDepend; // make depend needs direct access // to the m_Classes array diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 1f10cb2..da953ba 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -35,6 +35,31 @@ inline int Mkdir(const char* dir) } #endif +// adds the elements of the env variable path to the arg passed in +void cmSystemTools::GetPath(std::vector<std::string>& path) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + char* pathSep = ";"; +#else + char* pathSep = ":"; +#endif + std::string pathEnv = getenv("PATH"); + std::string::size_type start =0; + bool done = false; + while(!done) + { + std::string::size_type endpos = pathEnv.find(pathSep, start); + if(endpos != std::string::npos) + { + path.push_back(pathEnv.substr(start, endpos-start)); + start = endpos+1; + } + else + { + done = true; + } + } +} bool cmSystemTools::MakeDirectory(const char* path) { diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index cabdac0..bdcac7a 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -82,6 +82,12 @@ public: std::vector<std::string>& arguments); /** + * Add the paths from the environment variable PATH to the + * string vector passed in. + */ + static void GetPath(std::vector<std::string>& path); + + /** * Display an error message. */ static void Error(const char* m, const char* m2=0 ); |