[cmake-commits] alex committed cmGlobalUnixMakefileGenerator3.cxx 1.105 1.105.4.1 cmGlobalXCodeGenerator.cxx 1.142 1.142.4.1 cmGlobalXCodeGenerator.h 1.45 1.45.4.1 cmLocalGenerator.cxx 1.212 1.212.4.1 cmLocalGenerator.h 1.78 1.78.4.1 cmLocalUnixMakefileGenerator3.cxx 1.204 1.204.4.1 cmLocalVisualStudio6Generator.cxx 1.120 1.120.4.1 cmLocalVisualStudio6Generator.h 1.16 1.16.4.1 cmLocalVisualStudio7Generator.cxx 1.187 1.187.2.1 cmLocalVisualStudio7Generator.h 1.37 1.37.4.1 cmLocalVisualStudioGenerator.cxx 1.10 1.10.4.1 cmLocalVisualStudioGenerator.h 1.5 1.5.4.1 cmTarget.cxx 1.134 1.134.4.1

cmake-commits at cmake.org cmake-commits at cmake.org
Fri May 4 16:43:31 EDT 2007


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv17125/Source

Modified Files:
      Tag: CMake-ACC-TargetUsedAsCommand
	cmGlobalUnixMakefileGenerator3.cxx cmGlobalXCodeGenerator.cxx 
	cmGlobalXCodeGenerator.h cmLocalGenerator.cxx 
	cmLocalGenerator.h cmLocalUnixMakefileGenerator3.cxx 
	cmLocalVisualStudio6Generator.cxx 
	cmLocalVisualStudio6Generator.h 
	cmLocalVisualStudio7Generator.cxx 
	cmLocalVisualStudio7Generator.h 
	cmLocalVisualStudioGenerator.cxx 
	cmLocalVisualStudioGenerator.h cmTarget.cxx 
Log Message:

ENH: you can now use the target name of a executable target in cmake as
command in add_custom_command, it should also honor the buildtypes. A
testcase in Tests/CustomCommand/ is also coming soon. Tested on Linux with
Makefiles, OSX with XCode and MSVC 7. MSVC 6 and 8 are not tested. Next will
be to also automatically add the dependencies to this target automatically.

Alex


Index: cmLocalVisualStudio7Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudio7Generator.cxx,v
retrieving revision 1.187
retrieving revision 1.187.2.1
diff -u -d -r1.187 -r1.187.2.1
--- cmLocalVisualStudio7Generator.cxx	4 May 2007 18:08:50 -0000	1.187
+++ cmLocalVisualStudio7Generator.cxx	4 May 2007 20:43:29 -0000	1.187.2.1
@@ -623,7 +623,7 @@
          << "\t\t\t/>\n";
     }
 
-  this->OutputTargetRules(fout, target, libName);
+  this->OutputTargetRules(fout, configName, target, libName);
   this->OutputBuildTool(fout, configName, target);
   fout << "\t\t</Configuration>\n";
 }
@@ -1142,16 +1142,18 @@
       if (command)
         {
         // Construct the entire set of commands in one string.
-        std::string script = 
+/*        std::string script = 
           this->ConstructScript(command->GetCommandLines(),
                                 command->GetWorkingDirectory(),
                                 command->GetEscapeOldStyle(),
-                                command->GetEscapeAllowMakeVars());
-        std::string comment = this->ConstructComment(*command);
+                                command->GetEscapeAllowMakeVars());*/
+//        std::string comment = this->ConstructComment(*command);
         const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
-        this->WriteCustomRule(fout, source.c_str(), script.c_str(),
+        
+/*        this->WriteCustomRule(fout, source.c_str(), script.c_str(),
                               comment.c_str(), command->GetDepends(),
-                              command->GetOutputs(), flags);
+                              command->GetOutputs(), flags);*/
+        this->WriteCustomRule(fout, source.c_str(), *command, flags);
         }
       else if(compileFlags.size() || additionalDeps.length() 
               || objectName.size() || excludedFromBuild)
@@ -1228,12 +1230,11 @@
 void cmLocalVisualStudio7Generator::
 WriteCustomRule(std::ostream& fout,
                 const char* source,
-                const char* command,
-                const char* comment,
-                const std::vector<std::string>& depends,
-                const std::vector<std::string>& outputs,
+                const cmCustomCommand& command,
                 const char* compileFlags)
 {
+  std::string comment = this->ConstructComment(command);
+  
   // Write the rule for each configuration.
   std::vector<std::string>::iterator i;
   std::vector<std::string> *configs =
@@ -1251,14 +1252,21 @@
            << "\t\t\t\t\tAdditionalOptions=\""
            << this->EscapeForXML(compileFlags) << "\"/>\n";
       }
+
+    std::string script = 
+      this->ConstructScript(command.GetCommandLines(),
+                            command.GetWorkingDirectory(),
+                            i->c_str(),
+                            command.GetEscapeOldStyle(),
+                            command.GetEscapeAllowMakeVars());
     fout << "\t\t\t\t\t<Tool\n"
          << "\t\t\t\t\tName=\"VCCustomBuildTool\"\n"
          << "\t\t\t\t\tDescription=\"" 
-         << this->EscapeForXML(comment) << "\"\n"
+         << this->EscapeForXML(comment.c_str()) << "\"\n"
          << "\t\t\t\t\tCommandLine=\"" 
-         << this->EscapeForXML(command) << "\"\n"
+         << this->EscapeForXML(script.c_str()) << "\"\n"
          << "\t\t\t\t\tAdditionalDependencies=\"";
-    if(depends.empty())
+    if(command.GetDepends().empty())
       {
       // There are no real dependencies.  Produce an artificial one to
       // make sure the rule runs reliably.
@@ -1272,8 +1280,10 @@
     else
       {
       // Write out the dependencies for the rule.
-      for(std::vector<std::string>::const_iterator d = depends.begin();
-          d != depends.end(); ++d)
+      for(std::vector<std::string>::const_iterator d = 
+          command.GetDepends().begin();
+          d != command.GetDepends().end(); 
+          ++d)
         {
         // Get the real name of the dependency in case it is a CMake target.
         std::string dep = this->GetRealDependency(d->c_str(), i->c_str());
@@ -1283,7 +1293,7 @@
       }
     fout << "\"\n";
     fout << "\t\t\t\t\tOutputs=\"";
-    if(outputs.empty())
+    if(command.GetOutputs().empty())
       {
       fout << source << "_force";
       }
@@ -1291,8 +1301,9 @@
       {
       // Write a rule for the output generated by this command.
       const char* sep = "";
-      for(std::vector<std::string>::const_iterator o = outputs.begin();
-          o != outputs.end(); ++o)
+      for(std::vector<std::string>::const_iterator o = command.GetOutputs().begin();
+          o != command.GetOutputs().end(); 
+          ++o)
         {
         fout << sep << this->ConvertToXMLOutputPathSingle(o->c_str());
         sep = ";";
@@ -1323,6 +1334,7 @@
 // look for custom rules on a target and collect them together
 void cmLocalVisualStudio7Generator
 ::OutputTargetRules(std::ostream& fout,
+                    const char* configName,
                     cmTarget &target,
                     const char * /*libName*/)
 {
@@ -1350,6 +1362,7 @@
     std::string script =
       this->ConstructScript(cr->GetCommandLines(),
                             cr->GetWorkingDirectory(),
+                            configName,
                             cr->GetEscapeOldStyle(),
                             cr->GetEscapeAllowMakeVars());
     fout << this->EscapeForXML(script.c_str()).c_str();
@@ -1379,6 +1392,7 @@
     std::string script =
       this->ConstructScript(cr->GetCommandLines(),
                             cr->GetWorkingDirectory(),
+                            configName,
                             cr->GetEscapeOldStyle(),
                             cr->GetEscapeAllowMakeVars());
     fout << this->EscapeForXML(script.c_str()).c_str();
@@ -1408,6 +1422,7 @@
     std::string script =
       this->ConstructScript(cr->GetCommandLines(),
                             cr->GetWorkingDirectory(),
+                            configName,
                             cr->GetEscapeOldStyle(),
                             cr->GetEscapeAllowMakeVars());
     fout << this->EscapeForXML(script.c_str()).c_str();

Index: cmLocalVisualStudioGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudioGenerator.cxx,v
retrieving revision 1.10
retrieving revision 1.10.4.1
diff -u -d -r1.10 -r1.10.4.1
--- cmLocalVisualStudioGenerator.cxx	16 Feb 2007 21:12:16 -0000	1.10
+++ cmLocalVisualStudioGenerator.cxx	4 May 2007 20:43:29 -0000	1.10.4.1
@@ -111,6 +111,7 @@
 cmLocalVisualStudioGenerator
 ::ConstructScript(const cmCustomCommandLines& commandLines,
                   const char* workingDirectory,
+                  const char* configName,
                   bool escapeOldStyle,
                   bool escapeAllowMakeVars,
                   const char* newline_text)
@@ -152,13 +153,15 @@
 
     // Start with the command name.
     const cmCustomCommandLine& commandLine = *cl;
+    std::string commandName = this->GetRealLocation(commandLine[0].c_str(), 
+                                                    configName);
     if(!workingDirectory)
       {
-      script += this->Convert(commandLine[0].c_str(),START_OUTPUT,SHELL);
+      script += this->Convert(commandName.c_str(),START_OUTPUT,SHELL);
       }
     else
       {
-      script += this->Convert(commandLine[0].c_str(),NONE,SHELL);
+      script += this->Convert(commandName.c_str(),NONE,SHELL);
       }
 
     // Add the arguments.

Index: cmLocalVisualStudio7Generator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudio7Generator.h,v
retrieving revision 1.37
retrieving revision 1.37.4.1
diff -u -d -r1.37 -r1.37.4.1
--- cmLocalVisualStudio7Generator.h	10 Apr 2007 13:54:01 -0000	1.37
+++ cmLocalVisualStudio7Generator.h	4 May 2007 20:43:29 -0000	1.37.4.1
@@ -89,8 +89,8 @@
   std::string EscapeForXML(const char* s);
   std::string ConvertToXMLOutputPath(const char* path);
   std::string ConvertToXMLOutputPathSingle(const char* path);
-  void OutputTargetRules(std::ostream& fout, cmTarget &target, 
-                         const char *libName);
+  void OutputTargetRules(std::ostream& fout, const char* configName, 
+                         cmTarget &target, const char *libName);
   void OutputBuildTool(std::ostream& fout, const char* configName,
                        cmTarget& t);
   void OutputLibraries(std::ostream& fout,
@@ -104,12 +104,10 @@
                           const char* group,
                           const char* filter);
   void WriteVCProjEndGroup(std::ostream& fout);
+  
   void WriteCustomRule(std::ostream& fout,
                        const char* source,
-                       const char* command,
-                       const char* comment,
-                       const std::vector<std::string>& depends,
-                       const std::vector<std::string>& outputs,
+                       const cmCustomCommand& command,
                        const char* extraFlags);
   void WriteTargetVersionAttribute(std::ostream& fout, cmTarget& target);
 

Index: cmLocalGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalGenerator.cxx,v
retrieving revision 1.212
retrieving revision 1.212.4.1
diff -u -d -r1.212 -r1.212.4.1
--- cmLocalGenerator.cxx	18 Apr 2007 13:56:06 -0000	1.212
+++ cmLocalGenerator.cxx	4 May 2007 20:43:29 -0000	1.212.4.1
@@ -1979,6 +1979,20 @@
 }
 
 //----------------------------------------------------------------------------
+std::string cmLocalGenerator::GetRealLocation(const char* inName,
+                                              const char* config)
+{
+  std::string outName=inName;
+  // Look for a CMake target with the given name.
+  cmTarget* target = this->GlobalGenerator->FindTarget(0, inName);
+  if ((target!=0) && (target->GetType()==cmTarget::EXECUTABLE))
+    {
+    outName = target->GetLocation( config );
+    }
+  return outName;
+}
+
+//----------------------------------------------------------------------------
 void cmLocalGenerator::AddSharedFlags(std::string& flags,
                                       const char* lang,
                                       bool shared)

Index: cmGlobalXCodeGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalXCodeGenerator.cxx,v
retrieving revision 1.142
retrieving revision 1.142.4.1
diff -u -d -r1.142 -r1.142.4.1
--- cmGlobalXCodeGenerator.cxx	30 Mar 2007 14:53:02 -0000	1.142
+++ cmGlobalXCodeGenerator.cxx	4 May 2007 20:43:29 -0000	1.142.4.1
@@ -849,6 +849,7 @@
     }
   return retFlag;
 }
+
 //----------------------------------------------------------------------------
 void 
 cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase,
@@ -872,8 +873,31 @@
     return;
     }
 
+  // collect multiple outputs of custom commands into a set
+  // which will be used for every configuration
   std::map<cmStdString, cmStdString> multipleOutputPairs;
-  
+  for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
+      i != commands.end(); ++i)
+    {
+    cmCustomCommand const& cc = *i; 
+    if(!cc.GetCommandLines().empty())
+      {
+      const std::vector<std::string>& outputs = cc.GetOutputs();
+      if(!outputs.empty())
+        {
+        // If there are more than one outputs treat the
+        // first as the primary output and make the rest depend on it.
+        std::vector<std::string>::const_iterator o = outputs.begin();
+        std::string primaryOutput = this->ConvertToRelativeForMake(o->c_str());
+        for(++o; o != outputs.end(); ++o)
+          {
+          std::string currentOutput =this->ConvertToRelativeForMake(o->c_str());
+          multipleOutputPairs[currentOutput] = primaryOutput;
+          }
+        }
+      }
+    }
+    
   std::string dir = this->CurrentMakefile->GetCurrentOutputDirectory();
   dir += "/CMakeScripts";
   cmSystemTools::MakeDirectory(dir.c_str());
@@ -883,7 +907,48 @@
   makefile += "_";
   makefile += name;
   makefile += ".make";
-  cmGeneratedFileStream makefileStream(makefile.c_str());
+  
+  for (std::vector<std::string>::const_iterator currentConfig= 
+            this->CurrentConfigurationTypes.begin();
+       currentConfig!=this->CurrentConfigurationTypes.end();
+       currentConfig++ )
+    {
+    this->CreateCustomRulesMakefile(makefile.c_str(), 
+                                    target, 
+                                    commands, 
+                                    currentConfig->c_str(),
+                                    multipleOutputPairs);
+    }
+  
+  std::string cdir = this->CurrentMakefile->GetCurrentOutputDirectory();
+  cdir = this->ConvertToRelativeForXCode(cdir.c_str());
+  std::string makecmd = "make -C ";
+  makecmd += cdir;
+  makecmd += " -f ";
+  makecmd += this->ConvertToRelativeForMake((makefile+"$CONFIGURATION").c_str());
+  if(!multipleOutputPairs.empty())
+    {
+    makecmd += " cmake_check_multiple_outputs";
+    }
+  makecmd += " all";
+  cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
+  buildphase->AddAttribute("shellScript", 
+                           this->CreateString(makecmd.c_str()));
+}
+
+//----------------------------------------------------------------------------
+void  cmGlobalXCodeGenerator
+::CreateCustomRulesMakefile(const char* makefileBasename, 
+                            cmTarget& target, 
+                            std::vector<cmCustomCommand> 
+                            const & commands,
+                            const char* configName,
+                            const std::map<cmStdString, cmStdString>& multipleOutputPairs
+                           )
+{
+  std::string makefileName=makefileBasename;
+  makefileName+=configName;
+  cmGeneratedFileStream makefileStream(makefileName.c_str());
   if(!makefileStream)
     {
     return;
@@ -909,7 +974,7 @@
             o != outputs.end(); ++o)
           {
           makefileStream
-            << "\\\n\t" << this->ConvertToRelativeForMake(o->c_str());
+              << "\\\n\t" << this->ConvertToRelativeForMake(o->c_str());
           }
         }
       else
@@ -939,21 +1004,9 @@
       const std::vector<std::string>& outputs = cc.GetOutputs();
       if(!outputs.empty())
         {
-        // There is at least one output.  If there is more than one treat the
-        // first as the primary output and make the rest depend on it.
-        std::vector<std::string>::const_iterator o = outputs.begin();
+        // There is at least one output, start the rule for it
         std::string primary_output =
-          this->ConvertToRelativeForMake(o->c_str());
-        for(++o; o != outputs.end(); ++o)
-          {
-          std::string current_output =
-            this->ConvertToRelativeForMake(o->c_str());
-          makefileStream << current_output << ": "
-                         << primary_output << "\n";
-          multipleOutputPairs[current_output] = primary_output;
-          }
-
-        // Start the rule for the primary output.
+            this->ConvertToRelativeForMake(outputs.begin()->c_str());
         makefileStream << primary_output << ": ";
         }
       else
@@ -962,11 +1015,11 @@
         makefileStream << tname[&cc] << ": ";
         }
       for(std::vector<std::string>::const_iterator d = 
-            cc.GetDepends().begin();
+          cc.GetDepends().begin();
           d != cc.GetDepends().end(); ++d)
         {
         if(!this->FindTarget(this->CurrentProject.c_str(),
-                             d->c_str()))
+            d->c_str()))
           {
           // if the depend is not a target but
           // is a full path then use it, if not then
@@ -974,7 +1027,7 @@
           if(cmSystemTools::FileIsFullPath(d->c_str()))
             {
             makefileStream << "\\\n" << this
-              ->ConvertToRelativeForMake(d->c_str());
+                ->ConvertToRelativeForMake(d->c_str());
             }
           }
         else
@@ -989,12 +1042,14 @@
 
       // Add each command line to the set of commands.
       for(cmCustomCommandLines::const_iterator cl = 
-            cc.GetCommandLines().begin();
+          cc.GetCommandLines().begin();
           cl != cc.GetCommandLines().end(); ++cl)
         {
         // Build the command line in a single string.
         const cmCustomCommandLine& commandLine = *cl;
-        std::string cmd2 = commandLine[0];
+        std::string cmd2 = this->CurrentLocalGenerator
+                         ->GetRealLocation(commandLine[0].c_str(), configName);
+        
         cmSystemTools::ReplaceString(cmd2, "/./", "/");
         cmd2 = this->ConvertToRelativeForMake(cmd2.c_str());
         std::string cmd;
@@ -1011,13 +1066,13 @@
           if(escapeOldStyle)
             {
             cmd += (this->CurrentLocalGenerator
-                    ->EscapeForShellOldStyle(commandLine[j].c_str()));
+                ->EscapeForShellOldStyle(commandLine[j].c_str()));
             }
           else
             {
             cmd += (this->CurrentLocalGenerator->
-                    EscapeForShell(commandLine[j].c_str(),
-                                   escapeAllowMakeVars));
+                EscapeForShell(commandLine[j].c_str(),
+                               escapeAllowMakeVars));
             }
           }
         makefileStream << "\t" << cmd.c_str() << "\n";
@@ -1025,38 +1080,31 @@
       }
     }
 
-  // Add a rule to deal with multiple outputs of custom commands.
+  // Add rules to deal with multiple outputs of custom commands.
   if(!multipleOutputPairs.empty())
     {
+    makefileStream << 
+        "\n# Dependencies of multiple outputs to their primary outputs \n";
+
+    for(std::map<cmStdString, cmStdString>::const_iterator o =
+        multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
+      {
+      makefileStream << o->first << ": " << o->second << "\n";
+      }
+
     makefileStream <<
-      "\n"
-      "cmake_check_multiple_outputs:\n";
+        "\n"
+        "cmake_check_multiple_outputs:\n";
     for(std::map<cmStdString, cmStdString>::const_iterator o =
-          multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
+        multipleOutputPairs.begin(); o != multipleOutputPairs.end(); ++o)
       {
       makefileStream << "\t at if [ ! -f "
-                     << o->first << " ]; then rm -f "
-                     << o->second << "; fi\n";
+          << o->first << " ]; then rm -f "
+          << o->second << "; fi\n";
       }
     }
-
-  std::string cdir = this->CurrentMakefile->GetCurrentOutputDirectory();
-  cdir = this->ConvertToRelativeForXCode(cdir.c_str());
-  std::string makecmd = "make -C ";
-  makecmd += cdir;
-  makecmd += " -f ";
-  makecmd += this->ConvertToRelativeForMake(makefile.c_str());
-  if(!multipleOutputPairs.empty())
-    {
-    makecmd += " cmake_check_multiple_outputs";
-    }
-  makecmd += " all";
-  cmSystemTools::ReplaceString(makecmd, "\\ ", "\\\\ ");
-  buildphase->AddAttribute("shellScript", 
-                           this->CreateString(makecmd.c_str()));
 }
 
-
 //----------------------------------------------------------------------------
 void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
                                                  cmXCodeObject* buildSettings,

Index: cmGlobalUnixMakefileGenerator3.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalUnixMakefileGenerator3.cxx,v
retrieving revision 1.105
retrieving revision 1.105.4.1
diff -u -d -r1.105 -r1.105.4.1
--- cmGlobalUnixMakefileGenerator3.cxx	13 Apr 2007 14:22:33 -0000	1.105
+++ cmGlobalUnixMakefileGenerator3.cxx	4 May 2007 20:43:29 -0000	1.105.4.1
@@ -1056,7 +1056,7 @@
 {
   cmTarget *result;
   cmLocalUnixMakefileGenerator3 *lg3;
- 
+
   // first check the same dir as the current target
   lg3 = static_cast<cmLocalUnixMakefileGenerator3 *>
     (target.GetMakefile()->GetLocalGenerator());

Index: cmLocalVisualStudioGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudioGenerator.h,v
retrieving revision 1.5
retrieving revision 1.5.4.1
diff -u -d -r1.5 -r1.5.4.1
--- cmLocalVisualStudioGenerator.h	16 Feb 2007 21:12:16 -0000	1.5
+++ cmLocalVisualStudioGenerator.h	4 May 2007 20:43:29 -0000	1.5.4.1
@@ -41,6 +41,7 @@
   /** Construct a script from the given list of command lines.  */
   std::string ConstructScript(const cmCustomCommandLines& commandLines,
                               const char* workingDirectory,
+                              const char* configName,
                               bool escapeOldStyle,
                               bool escapeAllowMakeVars,
                               const char* newline = "\n");

Index: cmLocalVisualStudio6Generator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudio6Generator.h,v
retrieving revision 1.16
retrieving revision 1.16.4.1
diff -u -d -r1.16 -r1.16.4.1
--- cmLocalVisualStudio6Generator.h	16 Feb 2007 21:12:16 -0000	1.16
+++ cmLocalVisualStudio6Generator.h	4 May 2007 20:43:29 -0000	1.16.4.1
@@ -84,10 +84,7 @@
   void AddDSPBuildRule(cmTarget& tgt);
   void WriteCustomRule(std::ostream& fout,
                        const char* source,
-                       const char* command,
-                       const char* comment,
-                       const std::vector<std::string>& depends,
-                       const std::vector<std::string>& outputs,
+                       const cmCustomCommand& command,
                        const char* flags);
   void AddUtilityCommandHack(cmTarget& target, int count,
                              std::vector<std::string>& depends,

Index: cmLocalVisualStudio6Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudio6Generator.cxx,v
retrieving revision 1.120
retrieving revision 1.120.4.1
diff -u -d -r1.120 -r1.120.4.1
--- cmLocalVisualStudio6Generator.cxx	28 Mar 2007 03:13:25 -0000	1.120
+++ cmLocalVisualStudio6Generator.cxx	4 May 2007 20:43:29 -0000	1.120.4.1
@@ -490,23 +490,8 @@
         }
       if (command)
         {
-        std::string script =
-          this->ConstructScript(command->GetCommandLines(), 
-                                command->GetWorkingDirectory(),
-                                command->GetEscapeOldStyle(),
-                                command->GetEscapeAllowMakeVars(),
-                                "\\\n\t");
-        std::string comment =
-          this->ConstructComment(*command,
-                                 "Building Custom Rule $(InputPath)");
-        if(comment == "<hack>")
-          {
-          comment = "";
-          }
         const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
-        this->WriteCustomRule(fout, source.c_str(), script.c_str(),
-                              comment.c_str(), command->GetDepends(),
-                              command->GetOutputs(), flags);
+        this->WriteCustomRule(fout, source.c_str(), *command, flags);
         }
       else if(!compileFlags.empty() || !objectNameDir.empty())
         {
@@ -603,16 +588,29 @@
 cmLocalVisualStudio6Generator
 ::WriteCustomRule(std::ostream& fout,
                   const char* source,
-                  const char* command,
-                  const char* comment,
-                  const std::vector<std::string>& depends,
-                  const std::vector<std::string>& outputs,
+                  const cmCustomCommand& command,
                   const char* flags)
 {
+  std::string comment =
+    this->ConstructComment(command, "Building Custom Rule $(InputPath)");
+  if(comment == "<hack>")
+    {
+    comment = "";
+    }
+  
   // Write the rule for each configuration.
   std::vector<std::string>::iterator i;
   for(i = this->Configurations.begin(); i != this->Configurations.end(); ++i)
     {
+      
+    std::string script =
+      this->ConstructScript(command.GetCommandLines(), 
+                            command.GetWorkingDirectory(),
+                            i->c_str(),
+                            command.GetEscapeOldStyle(),
+                            command.GetEscapeAllowMakeVars(),
+                            "\\\n\t");
+      
     if (i == this->Configurations.begin())
       {
       fout << "!IF  \"$(CFG)\" == " << i->c_str() << std::endl;
@@ -627,8 +625,9 @@
       }
     // Write out the dependencies for the rule.
     fout << "USERDEP__HACK=";
-    for(std::vector<std::string>::const_iterator d = depends.begin();
-        d != depends.end(); ++d)
+    for(std::vector<std::string>::const_iterator d=command.GetDepends().begin();
+        d != command.GetDepends().end(); 
+        ++d)
       {
       // Lookup the real name of the dependency in case it is a CMake target.
       std::string dep = this->GetRealDependency(d->c_str(), i->c_str());
@@ -639,26 +638,28 @@
 
     fout << "# PROP Ignore_Default_Tool 1\n";
     fout << "# Begin Custom Build -";
-    if(comment && *comment)
+    if(!comment.empty())
       {
-      fout << " " << comment;
+      fout << " " << comment.c_str();
       }
     fout << "\n\n";
-    if(outputs.empty())
+    if(command.GetOutputs().empty())
       {
       fout << source 
            << "_force :  \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"\n\t";
-      fout << command << "\n\n";
+      fout << script.c_str() << "\n\n";
       }
     else
       {
-      for(std::vector<std::string>::const_iterator o = outputs.begin();
-          o != outputs.end(); ++o)
+      for(std::vector<std::string>::const_iterator o = 
+          command.GetOutputs().begin();
+          o != command.GetOutputs().end(); 
+          ++o)
         {
         // Write a rule for every output generated by this command.
         fout << this->ConvertToOptionallyRelativeOutputPath(o->c_str())
              << " :  \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"\n\t";
-        fout << command << "\n\n";
+        fout << script.c_str() << "\n\n";
         }
       }
     fout << "# End Custom Build\n\n";
@@ -808,6 +809,7 @@
       }
     customRuleCode += this->ConstructScript(cr->GetCommandLines(),
                                             cr->GetWorkingDirectory(),
+                                            0, 
                                             cr->GetEscapeOldStyle(),
                                             cr->GetEscapeAllowMakeVars(),
                                             "\\\n\t");
@@ -822,6 +824,7 @@
       }
     customRuleCode += this->ConstructScript(cr->GetCommandLines(),
                                             cr->GetWorkingDirectory(),
+                                            0,
                                             cr->GetEscapeOldStyle(),
                                             cr->GetEscapeAllowMakeVars(),
                                             "\\\n\t");
@@ -850,6 +853,7 @@
       }
     customRuleCode += this->ConstructScript(cr->GetCommandLines(),
                                             cr->GetWorkingDirectory(),
+                                            0,
                                             cr->GetEscapeOldStyle(),
                                             cr->GetEscapeAllowMakeVars(),
                                             "\\\n\t");

Index: cmLocalGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalGenerator.h,v
retrieving revision 1.78
retrieving revision 1.78.4.1
diff -u -d -r1.78 -r1.78.4.1
--- cmLocalGenerator.h	16 Mar 2007 14:34:25 -0000	1.78
+++ cmLocalGenerator.h	4 May 2007 20:43:29 -0000	1.78.4.1
@@ -137,6 +137,11 @@
       the source directory of this generator.  This should only be
       used for dependencies of custom commands.  */
   std::string GetRealDependency(const char* name, const char* config);
+  
+  /** Translate a command as given in CMake code to the location of the 
+      executable if the command is the name of a CMake executable target.
+      If that's not the case, just return the original name. */
+  std::string GetRealLocation(const char* inName, const char* config);
 
   ///! for existing files convert to output path and short path if spaces
   std::string ConvertToOutputForExisting(const char* p);

Index: cmGlobalXCodeGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalXCodeGenerator.h,v
retrieving revision 1.45
retrieving revision 1.45.4.1
diff -u -d -r1.45 -r1.45.4.1
--- cmGlobalXCodeGenerator.h	8 Mar 2007 20:24:01 -0000	1.45
+++ cmGlobalXCodeGenerator.h	4 May 2007 20:43:29 -0000	1.45.4.1
@@ -106,6 +106,15 @@
                                std::vector<cmCustomCommand> 
                                const & commands,
                                const char* commandFileName);
+  
+  void CreateCustomRulesMakefile(const char* makefileBasename, 
+                                 cmTarget& target,
+                                 std::vector<cmCustomCommand> const & commands, 
+                                 const char* configName,
+                                 const std::map<cmStdString, cmStdString>& 
+                                     multipleOutputPairs
+                                );
+  
   cmXCodeObject* FindXCodeTarget(cmTarget*);
   // create cmXCodeObject from these functions so that memory can be managed
   // correctly.  All objects created are stored in this->XCodeObjects.

Index: cmTarget.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTarget.cxx,v
retrieving revision 1.134
retrieving revision 1.134.4.1
diff -u -d -r1.134 -r1.134.4.1
--- cmTarget.cxx	10 Apr 2007 13:54:01 -0000	1.134
+++ cmTarget.cxx	4 May 2007 20:43:29 -0000	1.134.4.1
@@ -534,8 +534,7 @@
           }
         }
       // add its dependencies to the list to check
-      unsigned int i;
-      for (i = 0; i < outsf->GetCustomCommand()->GetDepends().size(); ++i)
+      for (unsigned int i = 0; i < outsf->GetCustomCommand()->GetDepends().size(); ++i)
         {
         const std::string& fullName 
           = outsf->GetCustomCommand()->GetDepends()[i];
@@ -590,6 +589,19 @@
             }
           }
         }
+        
+      // add its dependencies to the list to check
+/*      for (unsigned int i = 0; i < outsf->GetCustomCommand()->GetCommandLines().size(); ++i)
+        {
+        // see if we can find a target with this name
+        cmTarget* t =  this->Makefile->GetLocalGenerator()->
+            GetGlobalGenerator()->FindTarget(0, outsf->GetCustomCommand()->GetCommandLines()[i][0].c_str());
+        if (( t) && (t->GetType()==cmTarget::EXECUTABLE))
+          {
+            this->AddUtility(t->GetName());
+            fprintf(stderr, "adding dep: %s\n", t->GetName());
+          }
+        }*/
       }
     // finished with this SF move to the next
     srcFilesToProcess.pop();

Index: cmLocalUnixMakefileGenerator3.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalUnixMakefileGenerator3.cxx,v
retrieving revision 1.204
retrieving revision 1.204.4.1
diff -u -d -r1.204 -r1.204.4.1
--- cmLocalUnixMakefileGenerator3.cxx	19 Mar 2007 14:00:35 -0000	1.204
+++ cmLocalUnixMakefileGenerator3.cxx	4 May 2007 20:43:29 -0000	1.204.4.1
@@ -847,6 +847,21 @@
       (d->c_str(), this->ConfigurationName.c_str());
     depends.push_back(dep);
     }
+
+  // if the any of the commands for this custom command are a target
+  // within cmake, add the dependency to the generated executable
+/*  for(cmCustomCommandLines::const_iterator cl = cc.GetCommandLines().begin();
+      cl != cc.GetCommandLines().end(); ++cl)
+    {
+    const cmCustomCommandLine& commandLine = *cl;
+    cmTarget *target = 
+      this->GetGlobalGenerator()->FindTarget(0, commandLine[0].c_str());
+    if ((target!=0) && (target->GetType()==cmTarget::EXECUTABLE))
+      {
+      depends.push_back( target->GetLocation( this->ConfigurationName.c_str()));
+      fprintf(stderr, "adding file dep %s\n", target->GetLocation( this->ConfigurationName.c_str()));
+      }
+    }*/
 }
 
 //----------------------------------------------------------------------------
@@ -885,7 +900,8 @@
     {
     // Build the command line in a single string.
     const cmCustomCommandLine& commandLine = *cl;
-    std::string cmd = commandLine[0];
+    std::string cmd = GetRealLocation(commandLine[0].c_str(), 
+                                      this->ConfigurationName.c_str());
     if (cmd.size())
       {
       cmSystemTools::ReplaceString(cmd, "/./", "/");



More information about the Cmake-commits mailing list