From 872553de7e729788242da37124f41e40228c6f13 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 18 Dec 2007 09:50:08 -0500 Subject: [PATCH] ENH: Implemented generation of display for pre-build, pre-link, and post-build custom command comments during the build. This addresses issue #5353. --- Source/cmGlobalXCodeGenerator.cxx | 13 ++++++++----- Source/cmLocalUnixMakefileGenerator3.cxx | 18 ++++++++++++++++-- Source/cmLocalUnixMakefileGenerator3.h | 3 ++- Source/cmLocalVisualStudio7Generator.cxx | 18 ++++++++++++++++++ Tests/CustomCommand/CMakeLists.txt | 2 ++ 5 files changed, 46 insertions(+), 8 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 0ecd9aa13..f08c36eb4 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1144,11 +1144,6 @@ void cmGlobalXCodeGenerator { bool escapeOldStyle = cc.GetEscapeOldStyle(); bool escapeAllowMakeVars = cc.GetEscapeAllowMakeVars(); - makefileStream << "\n#" << "Custom command rule: "; - if(cc.GetComment()) - { - makefileStream << cc.GetComment(); - } makefileStream << "\n"; const std::vector& outputs = cc.GetOutputs(); if(!outputs.empty()) @@ -1175,6 +1170,14 @@ void cmGlobalXCodeGenerator } makefileStream << "\n"; + if(const char* comment = cc.GetComment()) + { + std::string echo_cmd = "echo "; + echo_cmd += (this->CurrentLocalGenerator-> + EscapeForShell(comment, escapeAllowMakeVars)); + makefileStream << "\t" << echo_cmd.c_str() << "\n"; + } + // Add each command line to the set of commands. for(cmCustomCommandLines::const_iterator cl = cc.GetCommandLines().begin(); diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 6fa4dd96c..f6c091abb 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -902,7 +902,7 @@ cmLocalUnixMakefileGenerator3 for(std::vector::const_iterator i = ccs.begin(); i != ccs.end(); ++i) { - this->AppendCustomCommand(commands, *i); + this->AppendCustomCommand(commands, *i, true); } } @@ -910,8 +910,22 @@ cmLocalUnixMakefileGenerator3 void cmLocalUnixMakefileGenerator3 ::AppendCustomCommand(std::vector& commands, - const cmCustomCommand& cc) + const cmCustomCommand& cc, bool echo_comment) { + // Optionally create a command to display the custom command's + // comment text. This is used for pre-build, pre-link, and + // post-build command comments. Custom build step commands have + // their comments generated elsewhere. + if(echo_comment) + { + const char* comment = cc.GetComment(); + if(comment && *comment) + { + this->AppendEcho(commands, comment, + cmLocalUnixMakefileGenerator3::EchoGenerate); + } + } + // if the command specified a working directory use it. const char* dir = this->Makefile->GetStartOutputDirectory(); const char* workingDir = cc.GetWorkingDirectory(); diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index dfb3641b0..671d768da 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -313,7 +313,8 @@ protected: void AppendCustomCommands(std::vector& commands, const std::vector& ccs); void AppendCustomCommand(std::vector& commands, - const cmCustomCommand& cc); + const cmCustomCommand& cc, + bool echo_comment=false); void AppendCleanCommand(std::vector& commands, const std::vector& files, cmTarget& target, const char* filename =0); diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index a912931a4..1c144e279 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1355,6 +1355,12 @@ void cmLocalVisualStudio7Generator { if(!init) { + const char* comment = cr->GetComment(); + if(comment && *comment) + { + fout << "\nDescription=\"" + << this->EscapeForXML(comment) << "\""; + } fout << "\nCommandLine=\""; init = true; } @@ -1385,6 +1391,12 @@ void cmLocalVisualStudio7Generator { if(!init) { + const char* comment = cr->GetComment(); + if(comment && *comment) + { + fout << "\nDescription=\"" + << this->EscapeForXML(comment) << "\""; + } fout << "\nCommandLine=\""; init = true; } @@ -1415,6 +1427,12 @@ void cmLocalVisualStudio7Generator { if(!init) { + const char* comment = cr->GetComment(); + if(comment && *comment) + { + fout << "\nDescription=\"" + << this->EscapeForXML(comment) << "\""; + } fout << "\nCommandLine=\""; init = true; } diff --git a/Tests/CustomCommand/CMakeLists.txt b/Tests/CustomCommand/CMakeLists.txt index 669fbb8c4..71ded6d44 100644 --- a/Tests/CustomCommand/CMakeLists.txt +++ b/Tests/CustomCommand/CMakeLists.txt @@ -95,12 +95,14 @@ ADD_CUSTOM_COMMAND( TARGET TDocument PRE_BUILD COMMAND ${CMAKE_COMMAND} -E echo " Writing doc1pre.txt." COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/doc1.tex ${PROJECT_BINARY_DIR}/doc1pre.txt + COMMENT "Running TDocument pre-build commands" ) ADD_CUSTOM_COMMAND( TARGET TDocument POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1pre.txt to doc2post.txt." COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1pre.txt ${PROJECT_BINARY_DIR}/doc2post.txt + COMMENT "Running TDocument post-build commands" ) ################################################################