浏览代码

ENH: Added COMMENT option to ADD_CUSTOM_TARGET. This addresses bug#3461.

Brad King 19 年之前
父节点
当前提交
5a6b0792cd

+ 12 - 1
Source/cmAddCustomTargetCommand.cxx

@@ -59,12 +59,15 @@ bool cmAddCustomTargetCommand::InitialPass(
   std::vector<std::string> depends;
   std::string working_directory;
   bool verbatim = false;
+  std::string comment_buffer;
+  const char* comment = 0;
 
   // Keep track of parser state.
   enum tdoing {
     doing_command,
     doing_depends,
     doing_working_directory,
+    doing_comment,
     doing_verbatim
   };
   tdoing doing = doing_command;
@@ -99,6 +102,10 @@ bool cmAddCustomTargetCommand::InitialPass(
       doing = doing_verbatim;
       verbatim = true;
       }
+    else if (copy == "COMMENT")
+      {
+      doing = doing_comment;
+      }
     else if(copy == "COMMAND")
       {
       doing = doing_command;
@@ -123,6 +130,10 @@ bool cmAddCustomTargetCommand::InitialPass(
         case doing_depends:
           depends.push_back(copy);
           break;
+         case doing_comment:
+           comment_buffer = copy;
+           comment = comment_buffer.c_str();
+           break;
         default:
           this->SetError("Wrong syntax. Unknown type of argument.");
           return false;
@@ -151,7 +162,7 @@ bool cmAddCustomTargetCommand::InitialPass(
   bool escapeOldStyle = !verbatim;
   this->Makefile->AddUtilityCommand(args[0].c_str(), all,
                                     working_directory.c_str(), depends,
-                                    commandLines, escapeOldStyle);
+                                    commandLines, escapeOldStyle, comment);
 
   return true;
 }

+ 4 - 1
Source/cmAddCustomTargetCommand.h

@@ -66,7 +66,8 @@ public:
       "  ADD_CUSTOM_TARGET(Name [ALL] [command1 [args1...]]\n"
       "                    [COMMAND command2 [args2...] ...]\n"
       "                    [DEPENDS depend depend depend ... ]\n"
-      "                    [WORKING_DIRECTORY dir] [VERBATIM])\n"
+      "                    [WORKING_DIRECTORY dir]\n"
+      "                    [COMMENT comment] [VERBATIM])\n"
       "Adds a target with the given name that executes the given commands. "
       "The target has no output file and is ALWAYS CONSIDERED OUT OF DATE "
       "even if the commands try to create a file with the name of the "
@@ -81,6 +82,8 @@ public:
       "empty target will be created. "
       "If WORKING_DIRECTORY is set, then the command will be run in that "
       "directory. "
+      "If COMMENT is set, the value will be displayed as a "
+      "message before the commands are executed at build time. "
       "Dependencies listed with the DEPENDS argument may reference files "
       "and outputs of custom commands created with ADD_CUSTOM_COMMAND.\n"
       "If VERBATIM is given then all the arguments to the commands will be "

+ 8 - 3
Source/cmMakefile.cxx

@@ -823,7 +823,7 @@ void cmMakefile::AddUtilityCommand(const char* utilityName, bool all,
                                    const char* workingDirectory,
                                    const std::vector<std::string>& depends,
                                    const cmCustomCommandLines& commandLines,
-                                   bool escapeOldStyle)
+                                   bool escapeOldStyle, const char* comment)
 {
   // Create a target instance for this utility.
   cmTarget target;
@@ -831,17 +831,22 @@ void cmMakefile::AddUtilityCommand(const char* utilityName, bool all,
   target.SetInAll(all);
   target.SetMakefile(this);
 
+  if(!comment)
+    {
+    // Use an empty comment to avoid generation of default comment.
+    comment = "";
+    }
+
   // Store the custom command in the target.
   std::string force = this->GetStartOutputDirectory();
   force += cmake::GetCMakeFilesDirectory();
   force += "/";
   force += utilityName;
   const char* no_main_dependency = 0;
-  const char* empty_comment = "";
   bool no_replace = false;
   this->AddCustomCommandToOutput(force.c_str(), depends,
                                  no_main_dependency,
-                                 commandLines, empty_comment,
+                                 commandLines, comment,
                                  workingDirectory, no_replace,
                                  escapeOldStyle);
   target.GetSourceLists().push_back(force);

+ 2 - 1
Source/cmMakefile.h

@@ -195,7 +195,8 @@ public:
                          const char* workingDirectory,
                          const std::vector<std::string>& depends,
                          const cmCustomCommandLines& commandLines,
-                         bool escapeOldStyle = true);
+                         bool escapeOldStyle = true,
+                         const char* comment = 0);
 
   /**
    * Add a link library to the build.

+ 1 - 0
Tests/CustomCommand/CMakeLists.txt

@@ -98,6 +98,7 @@ ADD_CUSTOM_TARGET(TDocument ALL
   COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1.h
                                    ${PROJECT_BINARY_DIR}/doc2.h
   DEPENDS ${PROJECT_BINARY_DIR}/doc1.h
+  COMMENT "Running top-level TDocument commands"
   )
 
 # Setup a pre- and post-build pair that will fail if not run in the