Browse Source

BUG: Fix/cleanup custom commands and custom targets. Make empty comment strings work. Fix ZERO_CHECK target always out of date for debugging. Fix Makefile driving of custom commands in a custom target. Fix dependencies on custom targets not in ALL in VS generators.

Brad King 19 years ago
parent
commit
9a1d4e92eb

+ 8 - 6
Source/cmAddCustomCommandCommand.cxx

@@ -32,8 +32,9 @@ bool cmAddCustomCommandCommand::InitialPass(
       return false;
     }
 
-  std::string source, target, comment, main_dependency,
-    working;
+  std::string source, target, main_dependency, working;
+  std::string comment_buffer;
+  const char* comment = 0;
   std::vector<std::string> depends, outputs, output;
   bool verbatim = false;
 
@@ -178,7 +179,8 @@ bool cmAddCustomCommandCommand::InitialPass(
            outputs.push_back(filename);
            break;
          case doing_comment:
-           comment = copy;
+           comment_buffer = copy;
+           comment = comment_buffer.c_str();
            break;
          default:
            this->SetError("Wrong syntax. Unknown type of argument.");
@@ -223,7 +225,7 @@ bool cmAddCustomCommandCommand::InitialPass(
     std::vector<std::string> no_depends;
     this->Makefile->AddCustomCommandToTarget(target.c_str(), no_depends,
                                              commandLines, cctype,
-                                             comment.c_str(), working.c_str(),
+                                             comment, working.c_str(),
                                              escapeOldStyle);
     }
   else if(target.empty())
@@ -231,7 +233,7 @@ bool cmAddCustomCommandCommand::InitialPass(
     // Target is empty, use the output.
     this->Makefile->AddCustomCommandToOutput(output, depends,
                                              main_dependency.c_str(),
-                                             commandLines, comment.c_str(),
+                                             commandLines, comment,
                                              working.c_str(), false,
                                              escapeOldStyle);
     }
@@ -240,7 +242,7 @@ bool cmAddCustomCommandCommand::InitialPass(
     // Use the old-style mode for backward compatibility.
     this->Makefile->AddCustomCommandOldStyle(target.c_str(), outputs, depends,
                                              source.c_str(), commandLines,
-                                             comment.c_str());
+                                             comment);
     }
   return true;
 }

+ 9 - 3
Source/cmCustomCommand.cxx

@@ -19,6 +19,7 @@
 //----------------------------------------------------------------------------
 cmCustomCommand::cmCustomCommand()
 {
+  this->HaveComment = false;
   this->EscapeOldStyle = true;
   this->EscapeAllowMakeVars = false;
   this->Used = false;
@@ -29,6 +30,7 @@ cmCustomCommand::cmCustomCommand(const cmCustomCommand& r):
   Outputs(r.Outputs),
   Depends(r.Depends),
   CommandLines(r.CommandLines),
+  HaveComment(r.HaveComment),
   Comment(r.Comment),
   WorkingDirectory(r.WorkingDirectory),
   EscapeAllowMakeVars(r.EscapeAllowMakeVars),
@@ -41,13 +43,16 @@ cmCustomCommand::cmCustomCommand(const cmCustomCommand& r):
 cmCustomCommand::cmCustomCommand(const std::vector<std::string>& outputs,
                                  const std::vector<std::string>& depends,
                                  const cmCustomCommandLines& commandLines,
-                                 const char* comment, 
+                                 const char* comment,
                                  const char* workingDirectory):
   Outputs(outputs),
   Depends(depends),
   CommandLines(commandLines),
+  HaveComment(comment?true:false),
   Comment(comment?comment:""),
-  WorkingDirectory(workingDirectory?workingDirectory:"")
+  WorkingDirectory(workingDirectory?workingDirectory:""),
+  EscapeAllowMakeVars(false),
+  EscapeOldStyle(true)
 {
   this->EscapeOldStyle = true;
   this->EscapeAllowMakeVars = false;
@@ -85,7 +90,8 @@ const cmCustomCommandLines& cmCustomCommand::GetCommandLines() const
 //----------------------------------------------------------------------------
 const char* cmCustomCommand::GetComment() const
 {
-  return this->Comment.c_str();
+  const char* no_comment = 0;
+  return this->HaveComment? this->Comment.c_str() : no_comment;
 }
 
 //----------------------------------------------------------------------------

+ 1 - 0
Source/cmCustomCommand.h

@@ -70,6 +70,7 @@ private:
   std::vector<std::string> Outputs;
   std::vector<std::string> Depends;
   cmCustomCommandLines CommandLines;
+  bool HaveComment;
   std::string Comment;
   std::string WorkingDirectory;
   bool EscapeAllowMakeVars;

+ 9 - 10
Source/cmGlobalVisualStudio71Generator.cxx

@@ -253,14 +253,14 @@ void cmGlobalVisualStudio71Generator
         cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
         const cmCustomCommandLines& cmds = cc.GetCommandLines();
         std::string project = cmds[0][0];
-        this->WriteProjectConfigurations(fout, project.c_str(), 
-                                         l->second.IsInAll());
+        this->WriteProjectConfigurations(fout, project.c_str(),
+                                         l->second.GetType());
         }
       else if ((l->second.GetType() != cmTarget::INSTALL_FILES)
                && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
         {
-        this->WriteProjectConfigurations(fout, si->c_str(), 
-                                         l->second.IsInAll());
+        this->WriteProjectConfigurations(fout, si->c_str(),
+                                         l->second.GetType());
         ++si;
         }
       }
@@ -415,19 +415,18 @@ void cmGlobalVisualStudio71Generator
 // Write a dsp file into the SLN file, Note, that dependencies from
 // executables to the libraries it uses are also done here
 void cmGlobalVisualStudio71Generator
-::WriteProjectConfigurations(std::ostream& fout, 
-                             const char* name, 
-                             bool in_all_build)
+::WriteProjectConfigurations(std::ostream& fout, const char* name,
+                             int targetType)
 {
   std::string guid = this->GetGUID(name);
   for(std::vector<std::string>::iterator i = this->Configurations.begin();
       i != this->Configurations.end(); ++i)
     {
-    fout << "\t\t{" << guid << "}." << *i 
+    fout << "\t\t{" << guid << "}." << *i
          << ".ActiveCfg = " << *i << "|Win32\n";
-    if (in_all_build)
+    if(targetType != cmTarget::GLOBAL_TARGET)
       {
-      fout << "\t\t{" << guid << "}." << *i 
+      fout << "\t\t{" << guid << "}." << *i
            << ".Build.0 = " << *i << "|Win32\n";
       }
     }

+ 2 - 2
Source/cmGlobalVisualStudio71Generator.h

@@ -53,9 +53,9 @@ protected:
                             const char* name, const char* path, cmTarget &t);
   virtual void WriteProjectDepends(std::ostream& fout, 
                            const char* name, const char* path, cmTarget &t);
-  virtual void WriteProjectConfigurations(std::ostream& fout, 
+  virtual void WriteProjectConfigurations(std::ostream& fout,
                                           const char* name,
-                                          bool in_all);
+                                          int targetType);
   virtual void WriteExternalProject(std::ostream& fout, const char* name,
                                     const char* path,
                                     const std::vector<std::string>& depends);

+ 9 - 10
Source/cmGlobalVisualStudio7Generator.cxx

@@ -536,14 +536,14 @@ void cmGlobalVisualStudio7Generator
         cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
         const cmCustomCommandLines& cmds = cc.GetCommandLines();
         std::string name = cmds[0][0];
-        this->WriteProjectConfigurations(fout, name.c_str(), 
-                                         l->second.IsInAll());
+        this->WriteProjectConfigurations(fout, name.c_str(),
+                                         l->second.GetType());
         }
       else if ((l->second.GetType() != cmTarget::INSTALL_FILES)
           && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
         {
-        this->WriteProjectConfigurations(fout, si->c_str(), 
-                                         l->second.IsInAll());
+        this->WriteProjectConfigurations(fout, si->c_str(),
+                                         l->second.GetType());
         ++si;
         }
       }
@@ -651,19 +651,18 @@ cmGlobalVisualStudio7Generator
 // Write a dsp file into the SLN file, Note, that dependencies from
 // executables to the libraries it uses are also done here
 void cmGlobalVisualStudio7Generator
-::WriteProjectConfigurations(std::ostream& fout, 
-                             const char* name, 
-                             bool in_all_build)
+::WriteProjectConfigurations(std::ostream& fout, const char* name,
+                             int targetType)
 {
   std::string guid = this->GetGUID(name);
   for(std::vector<std::string>::iterator i = this->Configurations.begin();
       i != this->Configurations.end(); ++i)
     {
-    fout << "\t\t{" << guid << "}." << *i 
+    fout << "\t\t{" << guid << "}." << *i
          << ".ActiveCfg = " << *i << "|Win32\n";
-    if (in_all_build)
+    if(targetType != cmTarget::GLOBAL_TARGET)
       {
-      fout << "\t\t{" << guid << "}." << *i 
+      fout << "\t\t{" << guid << "}." << *i
            << ".Build.0 = " << *i << "|Win32\n";
       }
     }

+ 2 - 2
Source/cmGlobalVisualStudio7Generator.h

@@ -105,9 +105,9 @@ protected:
                             const char* name, const char* path, cmTarget &t);
   virtual void WriteProjectDepends(std::ostream& fout, 
                            const char* name, const char* path, cmTarget &t);
-  virtual void WriteProjectConfigurations(std::ostream& fout, 
+  virtual void WriteProjectConfigurations(std::ostream& fout,
                                           const char* name,
-                                          bool in_all);
+                                          int targetType);
   virtual void WriteSLNFooter(std::ostream& fout);
   virtual void WriteSLNHeader(std::ostream& fout);
   virtual void AddPlatformDefinitions(cmMakefile* mf);

+ 7 - 7
Source/cmGlobalVisualStudio8Generator.cxx

@@ -227,20 +227,20 @@ cmGlobalVisualStudio8Generator
 //----------------------------------------------------------------------------
 void
 cmGlobalVisualStudio8Generator
-::WriteProjectConfigurations(std::ostream& fout,
-                             const char* name, bool in_all_build)
+::WriteProjectConfigurations(std::ostream& fout, const char* name,
+                             int targetType)
 {
   std::string guid = this->GetGUID(name);
   for(std::vector<std::string>::iterator i = this->Configurations.begin();
       i != this->Configurations.end(); ++i)
     {
-    fout << "\t\t{" << guid << "}." << *i 
-         << "|" << this->PlatformName << ".ActiveCfg = " 
+    fout << "\t\t{" << guid << "}." << *i
+         << "|" << this->PlatformName << ".ActiveCfg = "
          << *i << "|" << this->PlatformName << "\n";
-    if (in_all_build)
+    if(targetType != cmTarget::GLOBAL_TARGET)
       {
-      fout << "\t\t{" << guid << "}." << *i 
-           << "|" << this->PlatformName << ".Build.0 = " 
+      fout << "\t\t{" << guid << "}." << *i
+           << "|" << this->PlatformName << ".Build.0 = "
            << *i << "|" << this->PlatformName << "\n";
       }
     }

+ 2 - 1
Source/cmGlobalVisualStudio8Generator.h

@@ -56,7 +56,8 @@ protected:
   virtual void WriteSLNHeader(std::ostream& fout);
   virtual void WriteSolutionConfigurations(std::ostream& fout);
   virtual void WriteProjectConfigurations(std::ostream& fout,
-                                          const char* name, bool in_all);
+                                          const char* name,
+                                          int targetType);
   std::string PlatformName; // Win32 or x64 
 };
 #endif

+ 1 - 1
Source/cmLocalGenerator.cxx

@@ -1910,7 +1910,7 @@ cmLocalGenerator::ConstructComment(const cmCustomCommand& cc,
                                    const char* default_comment)
 {
   // Check for a comment provided with the command.
-  if(cc.GetComment() && *cc.GetComment())
+  if(cc.GetComment())
     {
     return cc.GetComment();
     }

+ 3 - 4
Source/cmLocalVisualStudio7Generator.cxx

@@ -44,11 +44,11 @@ void cmLocalVisualStudio7Generator::Generate()
   lang.insert("IDL");
   lang.insert("DEF");
   this->CreateCustomTargetsAndCommands(lang);
-  this->FixTargets();
+  this->FixGlobalTargets();
   this->OutputVCProjFile();
 }
 
-void cmLocalVisualStudio7Generator::FixTargets()
+void cmLocalVisualStudio7Generator::FixGlobalTargets()
 {
   // Visual Studio .NET 2003 Service Pack 1 will not run post-build
   // commands for targets in which no sources are built.  Add dummy
@@ -58,8 +58,7 @@ void cmLocalVisualStudio7Generator::FixTargets()
       l != tgts.end(); l++)
     {
     cmTarget& tgt = l->second;
-    if(tgt.GetType() == cmTarget::GLOBAL_TARGET ||
-       tgt.GetType() == cmTarget::UTILITY)
+    if(tgt.GetType() == cmTarget::GLOBAL_TARGET)
       {
       std::vector<std::string> no_depends;
       cmCustomCommandLine force_command;

+ 1 - 1
Source/cmLocalVisualStudio7Generator.h

@@ -71,7 +71,7 @@ private:
                                    std::string& flags);
   std::string GetBuildTypeLinkerFlags(std::string rootLinkerFlags,
                                       const char* configName);
-  void FixTargets();
+  void FixGlobalTargets();
   void OutputVCProjFile();
   void WriteVCProjHeader(std::ostream& fout, const char *libName,
                          cmTarget &tgt, std::vector<cmSourceGroup> &sgs);

+ 14 - 4
Source/cmMakefile.cxx

@@ -830,11 +830,21 @@ void cmMakefile::AddUtilityCommand(const char* utilityName, bool all,
   target.SetType(cmTarget::UTILITY, utilityName);
   target.SetInAll(all);
   target.SetMakefile(this);
+
   // Store the custom command in the target.
-  std::vector<std::string> outputs;
-  cmCustomCommand cc(outputs, depends, commandLines, 0, workingDirectory);
-  cc.SetEscapeOldStyle(escapeOldStyle);
-  target.GetPostBuildCommands().push_back(cc);
+  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,
+                                 workingDirectory, no_replace,
+                                 escapeOldStyle);
+  target.GetSourceLists().push_back(force);
 
   // Add the target to the set of targets.
   cmTargets::iterator it = 

+ 6 - 0
Source/cmMakefileExecutableTargetGenerator.cxx

@@ -24,6 +24,12 @@
 #include "cmTarget.h"
 #include "cmake.h"
 
+//----------------------------------------------------------------------------
+cmMakefileExecutableTargetGenerator::cmMakefileExecutableTargetGenerator()
+{
+  this->DriveCustomCommandsOnDepends = true;
+}
+
 //----------------------------------------------------------------------------
 void cmMakefileExecutableTargetGenerator::WriteRuleFiles()
 {

+ 2 - 0
Source/cmMakefileExecutableTargetGenerator.h

@@ -22,6 +22,8 @@
 class cmMakefileExecutableTargetGenerator: public cmMakefileTargetGenerator
 {
 public:
+  cmMakefileExecutableTargetGenerator();
+
   /* the main entry point for this class. Writes the Makefiles associated
      with this target */
   virtual void WriteRuleFiles();

+ 6 - 0
Source/cmMakefileLibraryTargetGenerator.cxx

@@ -26,6 +26,12 @@
 
 #include <memory> // auto_ptr
 
+//----------------------------------------------------------------------------
+cmMakefileLibraryTargetGenerator::cmMakefileLibraryTargetGenerator()
+{
+  this->DriveCustomCommandsOnDepends = true;
+}
+
 //----------------------------------------------------------------------------
 void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
 {

+ 2 - 0
Source/cmMakefileLibraryTargetGenerator.h

@@ -23,6 +23,8 @@ class cmMakefileLibraryTargetGenerator:
   public cmMakefileTargetGenerator
 {
 public:
+  cmMakefileLibraryTargetGenerator();
+
   /* the main entry point for this class. Writes the Makefiles associated
      with this target */
   virtual void WriteRuleFiles();  

+ 24 - 5
Source/cmMakefileTargetGenerator.cxx

@@ -35,6 +35,7 @@ cmMakefileTargetGenerator::cmMakefileTargetGenerator()
   this->BuildFileStream = 0;
   this->InfoFileStream = 0;
   this->FlagFileStream = 0;
+  this->DriveCustomCommandsOnDepends = false;
 }
 
 cmMakefileTargetGenerator *
@@ -775,6 +776,23 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
   commands.push_back(depCmd.str());
 
   // Make sure all custom command outputs in this target are built.
+  if(this->DriveCustomCommandsOnDepends)
+    {
+    this->DriveCustomCommands(depends);
+    }
+
+  // Write the rule.
+  this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+                                      depMark.c_str(),
+                                      depends, commands, false);
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefileTargetGenerator
+::DriveCustomCommands(std::vector<std::string>& depends)
+{
+  // Depend on all custom command outputs.
   const std::vector<cmSourceFile*>& sources =
     this->Target->GetSourceFiles();
   for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
@@ -790,11 +808,6 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
         }
       }
     }
-
-  // Write the rule.
-  this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
-                                      depMark.c_str(),
-                                      depends, commands, false);
 }
 
 //----------------------------------------------------------------------------
@@ -1040,6 +1053,12 @@ void cmMakefileTargetGenerator::WriteTargetDriverRule(const char* main_output,
     {
     // Setup the comment for the main build driver.
     comment = "Rule to build all files generated by this target.";
+
+    // Make sure all custom command outputs in this target are built.
+    if(!this->DriveCustomCommandsOnDepends)
+      {
+      this->DriveCustomCommands(depends);
+      }
     }
 
   // Write the driver rule.

+ 4 - 0
Source/cmMakefileTargetGenerator.h

@@ -107,6 +107,8 @@ protected:
   // write the driver rule to build target outputs
   void WriteTargetDriverRule(const char* main_output, bool relink);
 
+  void DriveCustomCommands(std::vector<std::string>& depends);
+
   // Return the a string with -F flags on apple
   std::string GetFrameworkFlags();
 
@@ -122,6 +124,8 @@ protected:
   cmGlobalGenerator *GlobalGenerator;
   cmMakefile *Makefile;
 
+  bool DriveCustomCommandsOnDepends;
+
   // the full path to the build file
   std::string BuildFileName;
   std::string BuildFileNameFull;