summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-05-30 14:11:19 -0400
committerBrad King <brad.king@kitware.com>2019-05-30 14:11:19 -0400
commitdd7ba6ff19ae34aa748240fad02ce006e4425cab (patch)
treefb7e12141faf09f3a0b6a291379b5ba2937521b5
parent540a175d2059e59fc0c5c8b8d5812c89639b27e3 (diff)
parent42bc67bd43ca67c98dc33f8cb8e2f4ee3884697f (diff)
downloadcmake-dd7ba6ff19ae34aa748240fad02ce006e4425cab.tar.gz
Merge branch 'vs-depends-dedup' into release-3.14
Merge-request: !3388
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx62
-rw-r--r--Source/cmVisualStudio10TargetGenerator.h3
2 files changed, 45 insertions, 20 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 7736e593b7..f2f5e3f63d 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -18,6 +18,7 @@
#include <iterator>
#include <memory> // IWYU pragma: keep
+#include <set>
static void ConvertToWindowsSlash(std::string& s);
@@ -1353,46 +1354,69 @@ void cmVisualStudio10TargetGenerator::WriteCustomRule(
comment = cmVS10EscapeComment(comment);
std::string script = lg->ConstructScript(ccg);
// input files for custom command
- std::stringstream inputs;
- inputs << source->GetFullPath();
- for (std::string const& d : ccg.GetDepends()) {
- std::string dep;
- if (lg->GetRealDependency(d, c, dep)) {
- ConvertToWindowsSlash(dep);
- inputs << ";" << dep;
+ std::stringstream additional_inputs;
+ {
+ const char* sep = "";
+ if (this->ProjectType == csproj) {
+ // csproj files do not attach the command to a specific file
+ // so the primary input must be listed explicitly.
+ additional_inputs << source->GetFullPath();
+ sep = ";";
+ }
+
+ // Avoid listing an input more than once.
+ std::set<std::string> unique_inputs;
+ // The source is either implicit an input or has been added above.
+ unique_inputs.insert(source->GetFullPath());
+
+ for (std::string const& d : ccg.GetDepends()) {
+ std::string dep;
+ if (lg->GetRealDependency(d, c, dep)) {
+ if (!unique_inputs.insert(dep).second) {
+ // already listed
+ continue;
+ }
+ ConvertToWindowsSlash(dep);
+ additional_inputs << sep << dep;
+ sep = ";";
+ }
+ }
+ if (this->ProjectType != csproj) {
+ additional_inputs << sep << "%(AdditionalInputs)";
}
}
// output files for custom command
std::stringstream outputs;
- const char* sep = "";
- for (std::string const& o : ccg.GetOutputs()) {
- std::string out = o;
- ConvertToWindowsSlash(out);
- outputs << sep << out;
- sep = ";";
+ {
+ const char* sep = "";
+ for (std::string const& o : ccg.GetOutputs()) {
+ std::string out = o;
+ ConvertToWindowsSlash(out);
+ outputs << sep << out;
+ sep = ";";
+ }
}
if (this->ProjectType == csproj) {
std::string name = "CustomCommand_" + c + "_" +
cmSystemTools::ComputeStringMD5(sourcePath);
- this->WriteCustomRuleCSharp(e0, c, name, script, inputs.str(),
+ this->WriteCustomRuleCSharp(e0, c, name, script, additional_inputs.str(),
outputs.str(), comment);
} else {
- this->WriteCustomRuleCpp(*spe2, c, script, inputs.str(), outputs.str(),
- comment);
+ this->WriteCustomRuleCpp(*spe2, c, script, additional_inputs.str(),
+ outputs.str(), comment);
}
}
}
void cmVisualStudio10TargetGenerator::WriteCustomRuleCpp(
Elem& e2, std::string const& config, std::string const& script,
- std::string const& inputs, std::string const& outputs,
+ std::string const& additional_inputs, std::string const& outputs,
std::string const& comment)
{
const std::string cond = this->CalcCondition(config);
e2.WritePlatformConfigTag("Message", cond, comment);
e2.WritePlatformConfigTag("Command", cond, script);
- e2.WritePlatformConfigTag("AdditionalInputs", cond,
- inputs + ";%(AdditionalInputs)");
+ e2.WritePlatformConfigTag("AdditionalInputs", cond, additional_inputs);
e2.WritePlatformConfigTag("Outputs", cond, outputs);
if (this->LocalGenerator->GetVersion() >
cmGlobalVisualStudioGenerator::VS10) {
diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h
index 590100496d..68db332e15 100644
--- a/Source/cmVisualStudio10TargetGenerator.h
+++ b/Source/cmVisualStudio10TargetGenerator.h
@@ -135,7 +135,8 @@ private:
void WriteCustomRule(Elem& e0, cmSourceFile const* source,
cmCustomCommand const& command);
void WriteCustomRuleCpp(Elem& e2, std::string const& config,
- std::string const& script, std::string const& inputs,
+ std::string const& script,
+ std::string const& additional_inputs,
std::string const& outputs,
std::string const& comment);
void WriteCustomRuleCSharp(Elem& e0, std::string const& config,