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
|
#ifdef CMAKE_HAS_AUTOCONF
|
||||||
return;
|
return;
|
||||||
#else
|
#else
|
||||||
m_Makefile->ExpandVariblesInString(m_InputFile);
|
m_Makefile->ExpandVariablesInString(m_InputFile);
|
||||||
m_Makefile->ExpandVariblesInString(m_OuputFile);
|
m_Makefile->ExpandVariablesInString(m_OuputFile);
|
||||||
std::ifstream fin(m_InputFile.c_str());
|
std::ifstream fin(m_InputFile.c_str());
|
||||||
if(!fin)
|
if(!fin)
|
||||||
{
|
{
|
||||||
|
@ -65,7 +65,7 @@ void cmConfigureFileNoAutoconf::FinalPass()
|
||||||
{
|
{
|
||||||
fin.getline(buffer, bufSize);
|
fin.getline(buffer, bufSize);
|
||||||
inLine = buffer;
|
inLine = buffer;
|
||||||
m_Makefile->ExpandVariblesInString(inLine);
|
m_Makefile->ExpandVariablesInString(inLine);
|
||||||
fout << inLine << "\n";
|
fout << inLine << "\n";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -157,7 +157,7 @@ void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
|
||||||
// to be removed as this may be built in a different directory
|
// to be removed as this may be built in a different directory
|
||||||
// than the source
|
// than the source
|
||||||
std::string dir = (*k)->GetDSPMakefile()->
|
std::string dir = (*k)->GetDSPMakefile()->
|
||||||
GetMakefile()->GetCurrentDirectory();
|
GetMakefile()->GetStartDirectory();
|
||||||
// Get the home directory with the trailing slash
|
// Get the home directory with the trailing slash
|
||||||
std::string homedir = m_Makefile->GetHomeDirectory();
|
std::string homedir = m_Makefile->GetHomeDirectory();
|
||||||
homedir += "/";
|
homedir += "/";
|
||||||
|
@ -187,6 +187,7 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
|
||||||
const char* dir,
|
const char* dir,
|
||||||
cmDSPMakefile* project)
|
cmDSPMakefile* project)
|
||||||
{
|
{
|
||||||
|
project->GetMakefile()->ExpandVariables();
|
||||||
fout << "###############################################################################\n\n";
|
fout << "###############################################################################\n\n";
|
||||||
fout << "Project: \"" << dspname << "\"="
|
fout << "Project: \"" << dspname << "\"="
|
||||||
<< dir << "\\" << dspname << ".dsp - Package Owner=<4>\n\n";
|
<< dir << "\\" << dspname << ".dsp - Package Owner=<4>\n\n";
|
||||||
|
@ -201,9 +202,12 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
|
||||||
end = project->GetMakefile()->GetLinkLibraries().end();
|
end = project->GetMakefile()->GetLinkLibraries().end();
|
||||||
for(;i!= end; ++i)
|
for(;i!= end; ++i)
|
||||||
{
|
{
|
||||||
fout << "Begin Project Dependency\n";
|
if (strcmp(i->c_str(),dspname))
|
||||||
fout << "Project_Dep_Name " << *i << "\n";
|
{
|
||||||
fout << "End Project Dependency\n";
|
fout << "Begin Project Dependency\n";
|
||||||
|
fout << "Project_Dep_Name " << *i << "\n";
|
||||||
|
fout << "End Project Dependency\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fout << "}}}\n\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
|
// to be removed as this may be built in a different directory
|
||||||
// than the source
|
// than the source
|
||||||
std::string dir = (*k)->GetDSPMakefile()->
|
std::string dir = (*k)->GetDSPMakefile()->
|
||||||
GetMakefile()->GetCurrentDirectory();
|
GetMakefile()->GetStartDirectory();
|
||||||
// Get the home directory with the trailing slash
|
// Get the home directory with the trailing slash
|
||||||
std::string homedir = m_Makefile->GetHomeDirectory();
|
std::string homedir = m_Makefile->GetHomeDirectory();
|
||||||
homedir += "/";
|
homedir += "/";
|
||||||
|
@ -187,6 +187,7 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
|
||||||
const char* dir,
|
const char* dir,
|
||||||
cmDSPMakefile* project)
|
cmDSPMakefile* project)
|
||||||
{
|
{
|
||||||
|
project->GetMakefile()->ExpandVariables();
|
||||||
fout << "###############################################################################\n\n";
|
fout << "###############################################################################\n\n";
|
||||||
fout << "Project: \"" << dspname << "\"="
|
fout << "Project: \"" << dspname << "\"="
|
||||||
<< dir << "\\" << dspname << ".dsp - Package Owner=<4>\n\n";
|
<< dir << "\\" << dspname << ".dsp - Package Owner=<4>\n\n";
|
||||||
|
@ -201,9 +202,12 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
|
||||||
end = project->GetMakefile()->GetLinkLibraries().end();
|
end = project->GetMakefile()->GetLinkLibraries().end();
|
||||||
for(;i!= end; ++i)
|
for(;i!= end; ++i)
|
||||||
{
|
{
|
||||||
fout << "Begin Project Dependency\n";
|
if (strcmp(i->c_str(),dspname))
|
||||||
fout << "Project_Dep_Name " << *i << "\n";
|
{
|
||||||
fout << "End Project Dependency\n";
|
fout << "Begin Project Dependency\n";
|
||||||
|
fout << "Project_Dep_Name " << *i << "\n";
|
||||||
|
fout << "End Project Dependency\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fout << "}}}\n\n";
|
fout << "}}}\n\n";
|
||||||
|
|
|
@ -18,16 +18,35 @@
|
||||||
// cmFindIncludeCommand
|
// cmFindIncludeCommand
|
||||||
bool cmFindIncludeCommand::Invoke(std::vector<std::string>& args)
|
bool cmFindIncludeCommand::Invoke(std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
return false;
|
if(args.size() < 2 )
|
||||||
if(args.size() < 1 )
|
|
||||||
{
|
{
|
||||||
this->SetError("called with incorrect number of arguments");
|
this->SetError("called with incorrect number of arguments");
|
||||||
return false;
|
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
|
// cmFindLibraryCommand
|
||||||
bool cmFindLibraryCommand::Invoke(std::vector<std::string>& args)
|
bool cmFindLibraryCommand::Invoke(std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
return false;
|
if(args.size() < 2 )
|
||||||
if(args.size() < 1 )
|
|
||||||
{
|
{
|
||||||
this->SetError("called with incorrect number of arguments");
|
this->SetError("called with incorrect number of arguments");
|
||||||
return false;
|
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()
|
virtual const char* GetFullDocumentation()
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
"FIND_LIBRARY(DEFINE try1 try2)";
|
"FIND_LIBRARY(DEFINE libraryName path1 path2 path3...)";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,32 +16,6 @@
|
||||||
#include "cmFindProgramCommand.h"
|
#include "cmFindProgramCommand.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.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
|
// cmFindProgramCommand
|
||||||
|
@ -54,7 +28,8 @@ bool cmFindProgramCommand::Invoke(std::vector<std::string>& args)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> path;
|
std::vector<std::string> path;
|
||||||
GetPath(path);
|
cmSystemTools::GetPath(path);
|
||||||
|
|
||||||
std::vector<std::string>::iterator i = args.begin();
|
std::vector<std::string>::iterator i = args.begin();
|
||||||
const char* define = (*i).c_str();
|
const char* define = (*i).c_str();
|
||||||
i++;
|
i++;
|
||||||
|
|
|
@ -226,7 +226,7 @@ void cmMakefile::SetMakefileGenerator(cmMakefileGenerator* mf)
|
||||||
void cmMakefile::GenerateMakefile()
|
void cmMakefile::GenerateMakefile()
|
||||||
{
|
{
|
||||||
// do all the variable expansions here
|
// do all the variable expansions here
|
||||||
this->ExpandVaribles();
|
this->ExpandVariables();
|
||||||
// set the makefile on the generator
|
// set the makefile on the generator
|
||||||
m_MakefileGenerator->SetMakefile(this);
|
m_MakefileGenerator->SetMakefile(this);
|
||||||
// give all the commands a chance to do something
|
// 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
|
// expance CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR in the
|
||||||
// include and library directories.
|
// include and library directories.
|
||||||
|
|
||||||
void cmMakefile::ExpandVaribles()
|
void cmMakefile::ExpandVariables()
|
||||||
{
|
{
|
||||||
// make sure binary and source dir are defined
|
// make sure binary and source dir are defined
|
||||||
this->AddDefinition("CMAKE_BINARY_DIR", this->GetHomeOutputDirectory());
|
this->AddDefinition("CMAKE_BINARY_DIR", this->GetHomeOutputDirectory());
|
||||||
|
@ -385,13 +385,19 @@ void cmMakefile::ExpandVaribles()
|
||||||
end = m_IncludeDirectories.end();
|
end = m_IncludeDirectories.end();
|
||||||
for(j = begin; j != end; ++j)
|
for(j = begin; j != end; ++j)
|
||||||
{
|
{
|
||||||
this->ExpandVariblesInString(*j);
|
this->ExpandVariablesInString(*j);
|
||||||
}
|
}
|
||||||
begin = m_LinkDirectories.begin();
|
begin = m_LinkDirectories.begin();
|
||||||
end = m_LinkDirectories.end();
|
end = m_LinkDirectories.end();
|
||||||
for(j = begin; j != end; ++j)
|
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();
|
for(DefinitionMap::iterator i = m_Definitions.begin();
|
||||||
i != m_Definitions.end(); ++i)
|
i != m_Definitions.end(); ++i)
|
||||||
|
|
|
@ -339,7 +339,13 @@ public:
|
||||||
* entry in the m_Definitions map. Also @var@ is
|
* entry in the m_Definitions map. Also @var@ is
|
||||||
* expanded to match autoconf style expansions.
|
* 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:
|
protected:
|
||||||
std::string m_Prefix;
|
std::string m_Prefix;
|
||||||
std::vector<std::string> m_AuxSourceDirectories; //
|
std::vector<std::string> m_AuxSourceDirectories; //
|
||||||
|
@ -384,11 +390,6 @@ private:
|
||||||
*/
|
*/
|
||||||
std::string GetParentListFileName(const char *listFileName);
|
std::string GetParentListFileName(const char *listFileName);
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse a file for includes links and libs
|
|
||||||
*/
|
|
||||||
void ExpandVaribles();
|
|
||||||
|
|
||||||
void ReadClasses(std::ifstream& fin, bool t);
|
void ReadClasses(std::ifstream& fin, bool t);
|
||||||
friend class cmMakeDepend; // make depend needs direct access
|
friend class cmMakeDepend; // make depend needs direct access
|
||||||
// to the m_Classes array
|
// to the m_Classes array
|
||||||
|
|
|
@ -35,6 +35,31 @@ inline int Mkdir(const char* dir)
|
||||||
}
|
}
|
||||||
#endif
|
#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)
|
bool cmSystemTools::MakeDirectory(const char* path)
|
||||||
{
|
{
|
||||||
|
|
|
@ -81,6 +81,12 @@ public:
|
||||||
static void GetArguments(std::string& line,
|
static void GetArguments(std::string& line,
|
||||||
std::vector<std::string>& arguments);
|
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.
|
* Display an error message.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue