ENH: add new commands fro find library and find program
This commit is contained in:
parent
fce56c57c4
commit
43859e36cf
|
@ -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
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public:
|
|||
virtual const char* GetFullDocumentation()
|
||||
{
|
||||
return
|
||||
"FIND_LIBRARY(DEFINE try1 try2)";
|
||||
"FIND_LIBRARY(DEFINE libraryName path1 path2 path3...)";
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -17,32 +17,6 @@
|
|||
#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
|
||||
bool cmFindProgramCommand::Invoke(std::vector<std::string>& args)
|
||||
|
@ -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++;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -81,6 +81,12 @@ public:
|
|||
static void GetArguments(std::string& line,
|
||||
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.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue