ENH: add path conversion stuff and rm SYSTEM_PATH

This commit is contained in:
Bill Hoffman 2006-04-05 07:46:32 -04:00
parent 13bc9efe2e
commit 24f08322be
2 changed files with 46 additions and 12 deletions

View File

@ -70,9 +70,13 @@ bool cmFileCommand::InitialPass(std::vector<std::string> const& args)
{ {
return this->HandleRelativePathCommand(args); return this->HandleRelativePathCommand(args);
} }
else if ( subCommand == "SYSTEM_PATH" ) else if ( subCommand == "TO_CMAKE_PATH" )
{ {
return this->HandleSystemPathCommand(args); return this->HandleCMakePathCommand(args, false);
}
else if ( subCommand == "TO_NATIVE_PATH" )
{
return this->HandleCMakePathCommand(args, true);
} }
std::string e = "does not recognize sub-command "+subCommand; std::string e = "does not recognize sub-command "+subCommand;
@ -971,8 +975,9 @@ bool cmFileCommand::HandleRemove(std::vector<std::string> const& args,
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmFileCommand::HandleSystemPathCommand(std::vector<std::string> bool cmFileCommand::HandleCMakePathCommand(std::vector<std::string>
const& args) const& args,
bool nativePath)
{ {
std::vector<std::string>::const_iterator i = args.begin(); std::vector<std::string>::const_iterator i = args.begin();
if(args.size() != 3) if(args.size() != 3)
@ -982,17 +987,39 @@ bool cmFileCommand::HandleSystemPathCommand(std::vector<std::string>
return false; return false;
} }
i++; // Get rid of subcommand i++; // Get rid of subcommand
std::vector<std::string> path; #if defined(_WIN32) && !defined(__CYGWIN__)
cmSystemTools::GetPath(path, i->c_str()); char pathSep = ';';
#else
char pathSep = ':';
#endif
std::vector<cmsys::String> path = cmSystemTools::SplitString(i->c_str(),
pathSep);
i++; i++;
const char* var = i->c_str(); const char* var = i->c_str();
std::string value; std::string value;
for(std::vector<std::string>::iterator j = path.begin(); for(std::vector<cmsys::String>::iterator j = path.begin();
j != path.end(); ++j) j != path.end(); ++j)
{ {
if(!nativePath)
{
cmSystemTools::ConvertToUnixSlashes(*j);
}
else
{
*j = cmSystemTools::ConvertToOutputPath(j->c_str());
// remove double quotes in the path
cmsys::String& s = *j;
if(s.size() > 1 && s[0] == '\"' && s[s.size()-1] == '\"')
{
s = s.substr(1,s.size()-2);
}
}
value += *j; value += *j;
value += ";"; value += ";";
} }
this->Makefile->AddDefinition(var, value.c_str()); this->Makefile->AddDefinition(var, value.c_str());
return true; return true;
} }

View File

@ -73,7 +73,8 @@ public:
" FILE(REMOVE_RECURSE [directory]...)\n" " FILE(REMOVE_RECURSE [directory]...)\n"
" FILE(MAKE_DIRECTORY [directory]...)\n" " FILE(MAKE_DIRECTORY [directory]...)\n"
" FILE(RELATIVE_PATH variable directory file)\n" " FILE(RELATIVE_PATH variable directory file)\n"
" FILE(SYSTEM_PATH ENVIRONMENT_VARIABLE result)\n" " FILE(TO_CMAKE_PATH path result)\n"
" FILE(TO_NATIVE_PATH path result)\n"
"WRITE will write a message into a file called 'filename'. It " "WRITE will write a message into a file called 'filename'. It "
"overwrites the file if it already exists, and creates the file " "overwrites the file if it already exists, and creates the file "
"if it does not exist.\n" "if it does not exist.\n"
@ -101,9 +102,14 @@ public:
" /dir/*.py - match all python files in /dir and subdirectories\n" " /dir/*.py - match all python files in /dir and subdirectories\n"
"MAKE_DIRECTORY will create a directory at the specified location\n" "MAKE_DIRECTORY will create a directory at the specified location\n"
"RELATIVE_PATH will determine relative path from directory to the given" "RELATIVE_PATH will determine relative path from directory to the given"
" file." " file.\n"
" SYSTEM_PATH will look up the environment variable named and " "TO_CMAKE_PATH will convert path into a cmake sytle path with unix /. "
"convert its contents into a cmake list of unix style paths. "; " The input can be a single path or a system path like \"$ENV{PATH}\". "
" Note the double quotes around the ENV call TO_CMAKE_PATH only takes "
" one argument.\n"
"TO_NATIVE_PATH works just like TO_CMAKE_PATH, but will convert from "
" a cmake style path into the native path style \\ for windows and / "
"for UNIX.";
} }
cmTypeMacro(cmFileCommand, cmCommand); cmTypeMacro(cmFileCommand, cmCommand);
@ -116,7 +122,8 @@ protected:
bool HandleMakeDirectoryCommand(std::vector<std::string> const& args); bool HandleMakeDirectoryCommand(std::vector<std::string> const& args);
bool HandleInstallCommand(std::vector<std::string> const& args); bool HandleInstallCommand(std::vector<std::string> const& args);
bool HandleRelativePathCommand(std::vector<std::string> const& args); bool HandleRelativePathCommand(std::vector<std::string> const& args);
bool HandleSystemPathCommand(std::vector<std::string> const& args); bool HandleCMakePathCommand(std::vector<std::string> const& args,
bool nativePath);
}; };