diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2003-07-08 18:18:17 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2003-07-08 18:18:17 (GMT) |
commit | db77d2e0192893ad9dda95bec0ebd9d6287fea14 (patch) | |
tree | 5aedd49117119e12af9b50647fdb696042d5ab29 /Source/cmFileCommand.cxx | |
parent | 1a4ec91593b8133897c2741d6dd43b2216ebb590 (diff) | |
download | CMake-db77d2e0192893ad9dda95bec0ebd9d6287fea14.zip CMake-db77d2e0192893ad9dda95bec0ebd9d6287fea14.tar.gz CMake-db77d2e0192893ad9dda95bec0ebd9d6287fea14.tar.bz2 |
ENH: Add globbing to FILE command
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r-- | Source/cmFileCommand.cxx | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index a24769f..6b7f036 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -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; +} |