[cmake-commits] king committed cmLocalGenerator.cxx 1.246 1.247 cmLocalGenerator.h 1.91 1.92 cmLocalUnixMakefileGenerator3.cxx 1.229 1.230 cmLocalUnixMakefileGenerator3.h 1.80 1.81 cmMakefileTargetGenerator.cxx 1.81 1.82

cmake-commits at cmake.org cmake-commits at cmake.org
Mon Jan 7 16:12:39 EST 2008


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

Modified Files:
	cmLocalGenerator.cxx cmLocalGenerator.h 
	cmLocalUnixMakefileGenerator3.cxx 
	cmLocalUnixMakefileGenerator3.h cmMakefileTargetGenerator.cxx 
Log Message:
BUG: Restore old interface of "make foo.o" and "make foo.i" even though object file names now include source extensions.  For Java we also need to always remove the source extension (.java -> .class).  This fixes the re-opening of bug #6169.


Index: cmLocalUnixMakefileGenerator3.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalUnixMakefileGenerator3.h,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- cmLocalUnixMakefileGenerator3.h	23 Dec 2007 20:03:42 -0000	1.80
+++ cmLocalUnixMakefileGenerator3.h	7 Jan 2008 21:12:37 -0000	1.81
@@ -238,7 +238,10 @@
     LocalObjectEntry(cmTarget* t, const char* lang):
       Target(t), Language(lang) {}
   };
-  class LocalObjectInfo: public std::vector<LocalObjectEntry> {};
+  struct LocalObjectInfo: public std::vector<LocalObjectEntry>
+  {
+    bool HasSourceExtension;
+  };
   std::map<cmStdString, LocalObjectInfo> const& GetLocalObjectFiles()
     { return this->LocalObjectFiles;}
 
@@ -299,11 +302,12 @@
                                const std::vector<std::string>& objects);
   void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
                                   const char* comment, const char* output,
-                                  LocalObjectInfo const& targets);
+                                  LocalObjectInfo const& info);
   
   std::string GetObjectFileName(cmTarget& target,
                                 const cmSourceFile& source,
-                                std::string* nameWithoutTargetDir = 0);
+                                std::string* nameWithoutTargetDir = 0,
+                                bool* hasSourceExtension = 0);
 
   void AppendRuleDepend(std::vector<std::string>& depends,
                         const char* ruleFileName);

Index: cmLocalGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalGenerator.cxx,v
retrieving revision 1.246
retrieving revision 1.247
diff -u -d -r1.246 -r1.247
--- cmLocalGenerator.cxx	29 Dec 2007 04:07:26 -0000	1.246
+++ cmLocalGenerator.cxx	7 Jan 2008 21:12:37 -0000	1.247
@@ -2700,7 +2700,8 @@
 std::string
 cmLocalGenerator
 ::GetObjectFileNameWithoutTarget(const cmSourceFile& source,
-                                 std::string::size_type dir_len)
+                                 std::string::size_type dir_len,
+                                 bool* hasSourceExtension)
 {
   // Construct the object file name using the full path to the source
   // file which is its only unique identification.
@@ -2751,11 +2752,25 @@
 
   // Replace the original source file extension with the object file
   // extension.
+  bool keptSourceExtension = true;
   if(!source.GetPropertyAsBool("KEEP_EXTENSION"))
     {
-    // Remove the original extension for CMake 2.4 compatibility.
-    if(this->NeedBackwardsCompatibility(2, 4))
+    // Decide whether this language wants to replace the source
+    // extension with the object extension.  For CMake 2.4
+    // compatibility do this by default.
+    bool replaceExt = this->NeedBackwardsCompatibility(2, 4);
+    if(!replaceExt)
       {
+      std::string repVar = "CMAKE_";
+      repVar += source.GetLanguage();
+      repVar += "_OUTPUT_EXTENSION_REPLACE";
+      replaceExt = this->Makefile->IsOn(repVar.c_str());
+      }
+
+    // Remove the source extension if it is to be replaced.
+    if(replaceExt)
+      {
+      keptSourceExtension = false;
       std::string::size_type dot_pos = objectName.rfind(".");
       if(dot_pos != std::string::npos)
         {
@@ -2767,6 +2782,10 @@
     objectName +=
       this->GlobalGenerator->GetLanguageOutputExtension(source);
     }
+  if(hasSourceExtension)
+    {
+    *hasSourceExtension = keptSourceExtension;
+    }
 
   // Convert to a safe name.
   return this->CreateSafeUniqueObjectFileName(objectName.c_str(), dir_len);

Index: cmLocalGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalGenerator.h,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -d -r1.91 -r1.92
--- cmLocalGenerator.h	29 Dec 2007 04:07:14 -0000	1.91
+++ cmLocalGenerator.h	7 Jan 2008 21:12:37 -0000	1.92
@@ -314,7 +314,8 @@
 
   // Compute object file names.
   std::string GetObjectFileNameWithoutTarget(const cmSourceFile& source,
-                                             std::string::size_type dir_len);
+                                             std::string::size_type dir_len,
+                                             bool* hasSourceExtension = 0);
   std::string& CreateSafeUniqueObjectFileName(const char* sin,
                                               std::string::size_type dir_len);
 

Index: cmLocalUnixMakefileGenerator3.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalUnixMakefileGenerator3.cxx,v
retrieving revision 1.229
retrieving revision 1.230
diff -u -d -r1.229 -r1.230
--- cmLocalUnixMakefileGenerator3.cxx	2 Jan 2008 16:04:52 -0000	1.229
+++ cmLocalUnixMakefileGenerator3.cxx	7 Jan 2008 21:12:37 -0000	1.230
@@ -38,6 +38,25 @@
 #include <queue>
 
 //----------------------------------------------------------------------------
+// Helper function used below.
+static std::string cmSplitExtension(std::string const& in, std::string& base)
+{
+  std::string ext;
+  std::string::size_type dot_pos = in.rfind(".");
+  if(dot_pos != std::string::npos)
+    {
+    // Remove the extension first in case &base == &in.
+    ext = in.substr(dot_pos, std::string::npos);
+    base = in.substr(0, dot_pos);
+    }
+  else
+    {
+    base = in;
+    }
+  return ext;
+}
+
+//----------------------------------------------------------------------------
 cmLocalUnixMakefileGenerator3::cmLocalUnixMakefileGenerator3()
 {
   this->SilentNoColon = false;
@@ -298,12 +317,45 @@
 cmLocalUnixMakefileGenerator3
 ::WriteObjectConvenienceRule(std::ostream& ruleFileStream,
                              const char* comment, const char* output,
-                             LocalObjectInfo const& targets)
+                             LocalObjectInfo const& info)
 {
+  // If the rule includes the source file extension then create a
+  // version that has the extension removed.  The help should include
+  // only the version without source extension.
+  bool inHelp = true;
+  if(info.HasSourceExtension)
+    {
+    // Remove the last extension.  This should be kept.
+    std::string outBase1 = output;
+    std::string outExt1 = cmSplitExtension(outBase1, outBase1);
+
+    // Now remove the source extension and put back the last
+    // extension.
+    std::string outNoExt;
+    cmSplitExtension(outBase1, outNoExt);
+    outNoExt += outExt1;
+
+    // Add a rule to drive the rule below.
+    std::vector<std::string> depends;
+    depends.push_back(output);
+    std::vector<std::string> commands;
+    cmGlobalUnixMakefileGenerator3* gg =
+      static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
+    std::string emptyCommand = gg->GetEmptyRuleHackCommand();
+    if(!emptyCommand.empty())
+      {
+      commands.push_back(emptyCommand);
+      }
+
+    this->WriteMakeRule(ruleFileStream, 0,
+                        outNoExt.c_str(), depends, commands, true, true);
+    inHelp = false;
+    }
+
   // Recursively make the rule for each target using the object file.
   std::vector<std::string> commands;
-  for(std::vector<LocalObjectEntry>::const_iterator t = targets.begin();
-      t != targets.end(); ++t)
+  for(std::vector<LocalObjectEntry>::const_iterator t = info.begin();
+      t != info.end(); ++t)
     {
     std::string tgtMakefileName =
       this->GetRelativeTargetDirectory(*(t->Target));
@@ -322,7 +374,7 @@
   // Write the rule to the makefile.
   std::vector<std::string> no_depends;
   this->WriteMakeRule(ruleFileStream, comment,
-                      output, no_depends, commands, true, true);
+                      output, no_depends, commands, true, inHelp);
 }
 
 //----------------------------------------------------------------------------
@@ -1800,13 +1852,16 @@
 cmLocalUnixMakefileGenerator3
 ::GetObjectFileName(cmTarget& target,
                     const cmSourceFile& source,
-                    std::string* nameWithoutTargetDir)
+                    std::string* nameWithoutTargetDir,
+                    bool* hasSourceExtension)
 {
   if(const char* fileTargetDirectory =
      source.GetProperty("MACOSX_PACKAGE_LOCATION"))
     {
     // Special handling for OSX package files.
-    std::string objectName = this->GetObjectFileNameWithoutTarget(source, 0);
+    std::string objectName =
+      this->GetObjectFileNameWithoutTarget(source, 0,
+                                           hasSourceExtension);
     if(nameWithoutTargetDir)
       {
       *nameWithoutTargetDir = objectName;
@@ -1857,7 +1912,8 @@
     dir_len += 1;
     dir_len += obj.size();
     std::string objectName =
-      this->GetObjectFileNameWithoutTarget(source, dir_len);
+      this->GetObjectFileNameWithoutTarget(source, dir_len,
+                                           hasSourceExtension);
     if(nameWithoutTargetDir)
       {
       *nameWithoutTargetDir = objectName;

Index: cmMakefileTargetGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefileTargetGenerator.cxx,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- cmMakefileTargetGenerator.cxx	30 Dec 2007 21:11:38 -0000	1.81
+++ cmMakefileTargetGenerator.cxx	7 Jan 2008 21:12:37 -0000	1.82
@@ -310,10 +310,12 @@
     }
 
   // Get the full path name of the object file.
+  bool hasSourceExtension;
   std::string objNoTargetDir;
   std::string obj =
     this->LocalGenerator->GetObjectFileName(*this->Target, source,
-                                            &objNoTargetDir);
+                                            &objNoTargetDir,
+                                            &hasSourceExtension);
 
   // Avoid generating duplicate rules.
   if(this->ObjectFiles.find(obj) == this->ObjectFiles.end())
@@ -377,10 +379,12 @@
     {
     objNoTargetDir = cmSystemTools::GetFilenameName(objNoTargetDir);
     }
-  this->LocalGenerator->LocalObjectFiles[objNoTargetDir].
-    push_back(
-      cmLocalUnixMakefileGenerator3::LocalObjectEntry(this->Target, lang)
-      );
+  cmLocalUnixMakefileGenerator3::LocalObjectInfo& info =
+    this->LocalGenerator->LocalObjectFiles[objNoTargetDir];
+  info.HasSourceExtension = hasSourceExtension;
+  info.push_back(
+    cmLocalUnixMakefileGenerator3::LocalObjectEntry(this->Target, lang)
+    );
 }
 
 //----------------------------------------------------------------------------



More information about the Cmake-commits mailing list