diff options
author | Brad King <brad.king@kitware.com> | 2021-06-08 21:58:33 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-06-09 14:09:58 (GMT) |
commit | 7291f312545d4a22339a4f9763ea61e16507c8a3 (patch) | |
tree | c9ec37b15c1ef0304e7af23a600d58eb8b163471 | |
parent | a6de8ec51b5afdef747e0dfd8f5d67e2b92429c0 (diff) | |
download | CMake-7291f312545d4a22339a4f9763ea61e16507c8a3.zip CMake-7291f312545d4a22339a4f9763ea61e16507c8a3.tar.gz CMake-7291f312545d4a22339a4f9763ea61e16507c8a3.tar.bz2 |
cmTransformDepfile: Add support for MSBuild AdditionalInputs format
-rw-r--r-- | Source/cmCustomCommandGenerator.cxx | 6 | ||||
-rw-r--r-- | Source/cmTransformDepfile.cxx | 31 | ||||
-rw-r--r-- | Source/cmTransformDepfile.h | 3 | ||||
-rw-r--r-- | Source/cmcmd.cxx | 2 |
4 files changed, 41 insertions, 1 deletions
diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index 10a6491..5a2683b 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -230,6 +230,9 @@ cmCustomCommandGenerator::cmCustomCommandGenerator( case cmDepfileFormat::MakeDepfile: argv.emplace_back("makedepfile"); break; + case cmDepfileFormat::MSBuildAdditionalInputs: + argv.emplace_back("MSBuildAdditionalInputs"); + break; } argv.push_back(this->LG->GetSourceDirectory()); argv.push_back(this->LG->GetCurrentSourceDirectory()); @@ -437,6 +440,9 @@ std::string cmCustomCommandGenerator::GetInternalDepfileName( case cmDepfileFormat::MakeDepfile: extension = ".d"; break; + case cmDepfileFormat::MSBuildAdditionalInputs: + extension = ".AdditionalInputs"; + break; } return cmStrCat(this->LG->GetBinaryDirectory(), "/CMakeFiles/d/", hash.HashString(depfile), extension); diff --git a/Source/cmTransformDepfile.cxx b/Source/cmTransformDepfile.cxx index 039b19d..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, @@ -103,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; } diff --git a/Source/cmTransformDepfile.h b/Source/cmTransformDepfile.h index ce7cd66..379e8bc 100644 --- a/Source/cmTransformDepfile.h +++ b/Source/cmTransformDepfile.h @@ -7,7 +7,8 @@ enum class cmDepfileFormat { GccDepfile, - MakeDepfile + MakeDepfile, + MSBuildAdditionalInputs, }; class cmLocalGenerator; diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 84ac189..1f4c0b8 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1531,6 +1531,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args, format = cmDepfileFormat::GccDepfile; } else if (args[3] == "makedepfile") { format = cmDepfileFormat::MakeDepfile; + } else if (args[3] == "MSBuildAdditionalInputs") { + format = cmDepfileFormat::MSBuildAdditionalInputs; } else { return 1; } |