mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-28 03:38:43 -06:00
ENH: Add globbing to FILE command
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
=========================================================================*/
|
||||
#include "cmFileCommand.h"
|
||||
|
||||
#include "cmGlob.h"
|
||||
|
||||
// cmLibraryCommand
|
||||
bool cmFileCommand::InitialPass(std::vector<std::string> const& args)
|
||||
{
|
||||
@@ -37,6 +39,10 @@ bool cmFileCommand::InitialPass(std::vector<std::string> const& args)
|
||||
{
|
||||
return this->HandleReadCommand(args);
|
||||
}
|
||||
else if ( subCommand == "GLOB" )
|
||||
{
|
||||
return this->HandleGlobCommand(args);
|
||||
}
|
||||
|
||||
std::string e = "does not recognize sub-command "+subCommand;
|
||||
this->SetError(e.c_str());
|
||||
@@ -53,6 +59,12 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
|
||||
i++; // Get rid of subcommand
|
||||
|
||||
std::string fileName = *i;
|
||||
if ( !cmsys::SystemTools::FileIsFullPath(i->c_str()) )
|
||||
{
|
||||
fileName = m_Makefile->GetCurrentDirectory();
|
||||
fileName += "/" + *i;
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
for(;i != args.end(); ++i)
|
||||
@@ -82,9 +94,16 @@ bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args)
|
||||
if ( args.size() != 3 )
|
||||
{
|
||||
this->SetError("READ must be called with two additional arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string fileName = args[1];
|
||||
if ( !cmsys::SystemTools::FileIsFullPath(args[1].c_str()) )
|
||||
{
|
||||
fileName = m_Makefile->GetCurrentDirectory();
|
||||
fileName += "/" + args[1];
|
||||
}
|
||||
|
||||
std::string variable = args[2];
|
||||
std::ifstream file(fileName.c_str(), std::ios::in);
|
||||
if ( !file )
|
||||
@@ -111,3 +130,48 @@ bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args)
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args)
|
||||
{
|
||||
if ( args.size() < 2 )
|
||||
{
|
||||
this->SetError("GLOB requires at least a variable name");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string>::const_iterator i = args.begin();
|
||||
|
||||
i++; // Get rid of subcommand
|
||||
|
||||
std::string variable = *i;
|
||||
i++;
|
||||
cmGlob g;
|
||||
std::string output = "";
|
||||
bool first = true;
|
||||
for ( ; i != args.end(); ++i )
|
||||
{
|
||||
if ( !cmsys::SystemTools::FileIsFullPath(i->c_str()) )
|
||||
{
|
||||
std::string expr = m_Makefile->GetCurrentDirectory();
|
||||
expr += "/" + *i;
|
||||
g.FindFiles(expr);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.FindFiles(*i);
|
||||
}
|
||||
std::vector<std::string>::size_type cc;
|
||||
std::vector<std::string>& files = g.GetFiles();
|
||||
for ( cc = 0; cc < files.size(); cc ++ )
|
||||
{
|
||||
if ( !first )
|
||||
{
|
||||
output += ";";
|
||||
}
|
||||
output += files[cc];
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
m_Makefile->AddDefinition(variable.c_str(), output.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user