diff options
author | Brad King <brad.king@kitware.com> | 2017-09-11 11:53:00 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2017-09-11 11:53:18 (GMT) |
commit | 28adf3833c23411dfce12b5be754ad53bc2b9b05 (patch) | |
tree | 00cd2f817a879541d0b290f322c56c5be06dc3b9 /Source | |
parent | bf19bb5609b409c9c4043b22a7bbdb38354af73a (diff) | |
parent | 9ed242807893becd4cd8245248fade93f7054c71 (diff) | |
download | CMake-28adf3833c23411dfce12b5be754ad53bc2b9b05.zip CMake-28adf3833c23411dfce12b5be754ad53bc2b9b05.tar.gz CMake-28adf3833c23411dfce12b5be754ad53bc2b9b05.tar.bz2 |
Merge topic 'vs_improve_custom_command'
9ed24280 VS: only add custom command line if it is not empty
34c4108b add HasOnlyEmptyCommandLines() method to cmCustomCommandGenerator
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1050
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCustomCommandGenerator.cxx | 12 | ||||
-rw-r--r-- | Source/cmCustomCommandGenerator.h | 1 | ||||
-rw-r--r-- | Source/cmLocalVisualStudioGenerator.cxx | 10 | ||||
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 12 |
4 files changed, 27 insertions, 8 deletions
diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index fdc0a97..c6a2800 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -97,6 +97,18 @@ const char* cmCustomCommandGenerator::GetArgv0Location(unsigned int c) const return nullptr; } +bool cmCustomCommandGenerator::HasOnlyEmptyCommandLines() const +{ + for (size_t i = 0; i < this->CommandLines.size(); ++i) { + for (size_t j = 0; j < this->CommandLines[i].size(); ++j) { + if (!this->CommandLines[i][j].empty()) { + return false; + } + } + } + return true; +} + std::string cmCustomCommandGenerator::GetCommand(unsigned int c) const { if (const char* emulator = this->GetCrossCompilingEmulator(c)) { diff --git a/Source/cmCustomCommandGenerator.h b/Source/cmCustomCommandGenerator.h index ea33b51..34fd653 100644 --- a/Source/cmCustomCommandGenerator.h +++ b/Source/cmCustomCommandGenerator.h @@ -40,6 +40,7 @@ public: std::vector<std::string> const& GetOutputs() const; std::vector<std::string> const& GetByproducts() const; std::vector<std::string> const& GetDepends() const; + bool HasOnlyEmptyCommandLines() const; }; #endif diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx index 41025af..d772d95 100644 --- a/Source/cmLocalVisualStudioGenerator.cxx +++ b/Source/cmLocalVisualStudioGenerator.cxx @@ -191,13 +191,17 @@ std::string cmLocalVisualStudioGenerator::ConstructScript( // Write each command on a single line. for (unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c) { + // Add this command line. + std::string cmd = ccg.GetCommand(c); + + if (cmd.empty()) { + continue; + } + // Start a new line. script += newline; newline = newline_text; - // Add this command line. - std::string cmd = ccg.GetCommand(c); - // Use "call " before any invocations of .bat or .cmd files // invoked as custom commands. // diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 7fe2f2a..bd3e82d 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -3536,11 +3536,13 @@ void cmVisualStudio10TargetGenerator::WriteEvent( for (std::vector<cmCustomCommand>::const_iterator i = commands.begin(); i != commands.end(); ++i) { cmCustomCommandGenerator ccg(*i, configName, this->LocalGenerator); - comment += pre; - comment += lg->ConstructComment(ccg); - script += pre; - pre = "\n"; - script += cmVS10EscapeXML(lg->ConstructScript(ccg)); + if (!ccg.HasOnlyEmptyCommandLines()) { + comment += pre; + comment += lg->ConstructComment(ccg); + script += pre; + pre = "\n"; + script += cmVS10EscapeXML(lg->ConstructScript(ccg)); + } } comment = cmVS10EscapeComment(comment); if (this->ProjectType != csproj) { |