summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-02-28 16:43:30 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-02-28 16:43:39 (GMT)
commitd0a328c9f67bb8e267bdeeb1cfa95da41bf7d6b6 (patch)
tree124b4bf4fccfada8e8e8124471b63b50e704ab93 /Source
parent6066aa471e28eb3d95b251d4d2a3bf83a31bba4f (diff)
parent9636b03cca8b812fa2e33adf9b30ab5268b6eefb (diff)
downloadCMake-d0a328c9f67bb8e267bdeeb1cfa95da41bf7d6b6.zip
CMake-d0a328c9f67bb8e267bdeeb1cfa95da41bf7d6b6.tar.gz
CMake-d0a328c9f67bb8e267bdeeb1cfa95da41bf7d6b6.tar.bz2
Merge topic 'refactor-handle-path-command'
9636b03cca cmFileCommand: Refactor HandleCMakePathCommand Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !2960
Diffstat (limited to 'Source')
-rw-r--r--Source/cmFileCommand.cxx47
1 files changed, 23 insertions, 24 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 59ef48d..a2018c3 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -2500,44 +2500,43 @@ bool cmFileCommand::HandleRemove(std::vector<std::string> const& args,
return true;
}
+namespace {
+std::string ToNativePath(const std::string& path)
+{
+ const auto& outPath = cmSystemTools::ConvertToOutputPath(path);
+ if (outPath.size() > 1 && outPath.front() == '\"' &&
+ outPath.back() == '\"') {
+ return outPath.substr(1, outPath.size() - 2);
+ }
+ return outPath;
+}
+
+std::string ToCMakePath(const std::string& path)
+{
+ auto temp = path;
+ cmSystemTools::ConvertToUnixSlashes(temp);
+ return temp;
+}
+}
+
bool cmFileCommand::HandleCMakePathCommand(
std::vector<std::string> const& args, bool nativePath)
{
- std::vector<std::string>::const_iterator i = args.begin();
if (args.size() != 3) {
this->SetError("FILE([TO_CMAKE_PATH|TO_NATIVE_PATH] path result) must be "
"called with exactly three arguments.");
return false;
}
- i++; // Get rid of subcommand
#if defined(_WIN32) && !defined(__CYGWIN__)
char pathSep = ';';
#else
char pathSep = ':';
#endif
- std::vector<std::string> path = cmSystemTools::SplitString(*i, pathSep);
- i++;
- const char* var = i->c_str();
- std::string value;
- for (std::vector<std::string>::iterator j = path.begin(); j != path.end();
- ++j) {
- if (j != path.begin()) {
- value += ";";
- }
- if (!nativePath) {
- cmSystemTools::ConvertToUnixSlashes(*j);
- } else {
- *j = cmSystemTools::ConvertToOutputPath(*j);
- // remove double quotes in the path
- std::string& s = *j;
+ std::vector<std::string> path = cmSystemTools::SplitString(args[1], pathSep);
- if (s.size() > 1 && s.front() == '\"' && s.back() == '\"') {
- s = s.substr(1, s.size() - 2);
- }
- }
- value += *j;
- }
- this->Makefile->AddDefinition(var, value.c_str());
+ std::string value = cmJoin(
+ cmMakeRange(path).transform(nativePath ? ToNativePath : ToCMakePath), ";");
+ this->Makefile->AddDefinition(args[2], value.c_str());
return true;
}