diff options
author | Stefan Kislinskiy <s.kislinskiy@dkfz-heidelberg.de> | 2015-09-24 10:33:01 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-09-28 14:37:33 (GMT) |
commit | ca6ba3fee544997b72579e97f9c64eb1a24a7fc9 (patch) | |
tree | 25bf04ef772fdbaeb1eb13f14454384873e3e968 /Source | |
parent | 7de868c4d7c8bfe35d201ed480328f3177a1325b (diff) | |
download | CMake-ca6ba3fee544997b72579e97f9c64eb1a24a7fc9.zip CMake-ca6ba3fee544997b72579e97f9c64eb1a24a7fc9.tar.gz CMake-ca6ba3fee544997b72579e97f9c64eb1a24a7fc9.tar.bz2 |
Genex: Add a SHELL_PATH expression
Some commands on Windows do not understand forward slash paths and
require backslashes. In order to help projects generate shell
invocations of such commands, provide a generator expression to convert
paths to the shell-preferred path format for the current generator.
This will allow custom commands to generate paths the same way CMake
does for compiler command invocations.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGeneratorExpressionNode.cxx | 23 | ||||
-rw-r--r-- | Source/cmOutputConverter.cxx | 39 | ||||
-rw-r--r-- | Source/cmOutputConverter.h | 2 |
3 files changed, 49 insertions, 15 deletions
diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 31b6766..1c350ab 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -13,6 +13,7 @@ #include "cmGeneratorExpressionNode.h" #include "cmGlobalGenerator.h" #include "cmAlgorithms.h" +#include "cmOutputConverter.h" //---------------------------------------------------------------------------- std::string cmGeneratorExpressionNode::EvaluateDependentExpression( @@ -1792,6 +1793,27 @@ static const TargetFilesystemArtifactNodeGroup<ArtifactPdbTag> targetPdbNodeGroup; //---------------------------------------------------------------------------- +static const struct ShellPathNode : public cmGeneratorExpressionNode +{ + ShellPathNode() {} + + std::string Evaluate(const std::vector<std::string> ¶meters, + cmGeneratorExpressionContext *context, + const GeneratorExpressionContent *content, + cmGeneratorExpressionDAGChecker *) const + { + if (!cmSystemTools::FileIsFullPath(parameters.front())) + { + reportError(context, content->GetOriginalExpression(), + "\"" + parameters.front() + "\" is not an absolute path."); + return std::string(); + } + cmOutputConverter converter(context->Makefile->GetStateSnapshot()); + return converter.ConvertDirectorySeparatorsForShell(parameters.front()); + } +} shellPathNode; + +//---------------------------------------------------------------------------- const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode(const std::string &identifier) { @@ -1846,6 +1868,7 @@ cmGeneratorExpressionNode::GetNode(const std::string &identifier) nodeMap["JOIN"] = &joinNode; nodeMap["LINK_ONLY"] = &linkOnlyNode; nodeMap["COMPILE_LANGUAGE"] = &languageNode; + nodeMap["SHELL_PATH"] = &shellPathNode; } NodeMap::const_iterator i = nodeMap.find(identifier); if (i == nodeMap.end()) diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx index 7be5b3f..5acae2f 100644 --- a/Source/cmOutputConverter.cxx +++ b/Source/cmOutputConverter.cxx @@ -142,21 +142,7 @@ std::string cmOutputConverter::ConvertToOutputFormat(const std::string& source, } else if(output == SHELL || output == WATCOMQUOTE) { - // For the MSYS shell convert drive letters to posix paths, so - // that c:/some/path becomes /c/some/path. This is needed to - // avoid problems with the shell path translation. - if(this->GetState()->UseMSYSShell() && !this->LinkScriptShell) - { - if(result.size() > 2 && result[1] == ':') - { - result[1] = result[0]; - result[0] = '/'; - } - } - if(this->GetState()->UseWindowsShell()) - { - std::replace(result.begin(), result.end(), '/', '\\'); - } + result = this->ConvertDirectorySeparatorsForShell(source); result = this->EscapeForShell(result, true, false, output == WATCOMQUOTE); } else if(output == RESPONSE) @@ -167,6 +153,29 @@ std::string cmOutputConverter::ConvertToOutputFormat(const std::string& source, } //---------------------------------------------------------------------------- +std::string cmOutputConverter::ConvertDirectorySeparatorsForShell( + const std::string& source) const +{ + std::string result = source; + // For the MSYS shell convert drive letters to posix paths, so + // that c:/some/path becomes /c/some/path. This is needed to + // avoid problems with the shell path translation. + if(this->GetState()->UseMSYSShell() && !this->LinkScriptShell) + { + if(result.size() > 2 && result[1] == ':') + { + result[1] = result[0]; + result[0] = '/'; + } + } + if(this->GetState()->UseWindowsShell()) + { + std::replace(result.begin(), result.end(), '/', '\\'); + } + return result; +} + +//---------------------------------------------------------------------------- std::string cmOutputConverter::Convert(RelativeRoot remote, const std::string& local, OutputFormat output, diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h index ed7739e..852df5d 100644 --- a/Source/cmOutputConverter.h +++ b/Source/cmOutputConverter.h @@ -45,6 +45,8 @@ public: std::string Convert(RelativeRoot remote, const std::string& local, OutputFormat output = UNCHANGED, bool optional = false) const; + std::string ConvertDirectorySeparatorsForShell( + const std::string& source) const; /** * Get path for the specified relative root. |