summaryrefslogtreecommitdiffstats
path: root/Source/cmTransformDepfile.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-06-10 12:23:39 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-06-10 12:23:45 (GMT)
commit5fd68d3ef75d590da383b5189ee7f952bd560a30 (patch)
tree7ece5b57c9c6177c18b4c4cca235312d39ccb3e0 /Source/cmTransformDepfile.cxx
parentcf85c6bf85398213d965a41f81b604142456bd23 (diff)
parent526e2ef71c5b797818bbf232e21d0152a3938197 (diff)
downloadCMake-5fd68d3ef75d590da383b5189ee7f952bd560a30.zip
CMake-5fd68d3ef75d590da383b5189ee7f952bd560a30.tar.gz
CMake-5fd68d3ef75d590da383b5189ee7f952bd560a30.tar.bz2
Merge topic 'vs-custom-depfile'
526e2ef71c VS: Add support for add_custom_command DEPFILE 794ad78abb Help: Generalize release note filename for add_custom_command DEPFILE 7291f31254 cmTransformDepfile: Add support for MSBuild AdditionalInputs format a6de8ec51b cmTransformDepfile: Make directory for transformed depfile automatically Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6206
Diffstat (limited to 'Source/cmTransformDepfile.cxx')
-rw-r--r--Source/cmTransformDepfile.cxx32
1 files changed, 32 insertions, 0 deletions
diff --git a/Source/cmTransformDepfile.cxx b/Source/cmTransformDepfile.cxx
index 0df9550..4032596 100644
--- a/Source/cmTransformDepfile.cxx
+++ b/Source/cmTransformDepfile.cxx
@@ -2,7 +2,9 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmTransformDepfile.h"
+#include <algorithm>
#include <functional>
+#include <memory>
#include <string>
#include <type_traits>
#include <utility>
@@ -78,6 +80,32 @@ void WriteDepfile(cmDepfileFormat format, cmsys::ofstream& fout,
}
}
}
+
+void WriteMSBuildAdditionalInputs(cmsys::ofstream& fout,
+ cmLocalGenerator const& lg,
+ cmGccDepfileContent const& content)
+{
+ if (content.empty()) {
+ return;
+ }
+
+ // Write a UTF-8 BOM so MSBuild knows the encoding when reading the file.
+ static const char utf8bom[] = { char(0xEF), char(0xBB), char(0xBF) };
+ fout.write(utf8bom, sizeof(utf8bom));
+
+ // Write the format expected by MSBuild CustomBuild AdditionalInputs.
+ const char* sep = "";
+ for (std::string path : content.front().paths) {
+ if (!cmSystemTools::FileIsFullPath(path)) {
+ path =
+ cmSystemTools::CollapseFullPath(path, lg.GetCurrentBinaryDirectory());
+ }
+ std::replace(path.begin(), path.end(), '/', '\\');
+ fout << sep << path;
+ sep = ";";
+ }
+ fout << "\n";
+}
}
bool cmTransformDepfile(cmDepfileFormat format, const cmLocalGenerator& lg,
@@ -93,6 +121,7 @@ bool cmTransformDepfile(cmDepfileFormat format, const cmLocalGenerator& lg,
content = *std::move(result);
}
+ cmSystemTools::MakeDirectory(cmSystemTools::GetFilenamePath(outfile));
cmsys::ofstream fout(outfile.c_str());
if (!fout) {
return false;
@@ -102,6 +131,9 @@ bool cmTransformDepfile(cmDepfileFormat format, const cmLocalGenerator& lg,
case cmDepfileFormat::MakeDepfile:
WriteDepfile(format, fout, lg, content);
break;
+ case cmDepfileFormat::MSBuildAdditionalInputs:
+ WriteMSBuildAdditionalInputs(fout, lg, content);
+ break;
}
return true;
}