فهرست منبع

ENH: Added ConvertToQuotedOutputPath method and used it to properly generate external object references with spaces in the path.

Brad King 20 سال پیش
والد
کامیت
03e2878db8
2فایلهای تغییر یافته به همراه51 افزوده شده و 3 حذف شده
  1. 50 3
      Source/cmLocalUnixMakefileGenerator2.cxx
  2. 1 0
      Source/cmLocalUnixMakefileGenerator2.h

+ 50 - 3
Source/cmLocalUnixMakefileGenerator2.cxx

@@ -1995,10 +1995,10 @@ cmLocalUnixMakefileGenerator2
   for(std::vector<std::string>::const_iterator i = objects.begin();
       i != objects.end(); ++i)
     {
-    // TODO: Make sure we don't escape spaces and quote.
+    std::string object = this->ConvertToRelativePath(i->c_str());
     ruleFileStream
       << " \\\n"
-      << "\"" << this->ConvertToRelativeOutputPath(i->c_str()) << "\"";
+      << this->ConvertToQuotedOutputPath(object.c_str());
     }
   ruleFileStream
     << "\n";
@@ -2008,14 +2008,16 @@ cmLocalUnixMakefileGenerator2
   variableNameExternal = this->CreateMakeVariable(target.GetName(),
                                                   "_EXTERNAL_OBJECTS");
   ruleFileStream
+    << "\n"
     << "# External object files for target " << target.GetName() << "\n"
     << variableNameExternal.c_str() << " =";
   for(std::vector<std::string>::const_iterator i = external_objects.begin();
       i != external_objects.end(); ++i)
     {
+    std::string object = this->ConvertToRelativePath(i->c_str());
     ruleFileStream
       << " \\\n"
-      << "\"" << this->ConvertToRelativeOutputPath(i->c_str()) << "\"";
+      << this->ConvertToQuotedOutputPath(object.c_str());
     }
   ruleFileStream
     << "\n"
@@ -2317,6 +2319,51 @@ cmLocalUnixMakefileGenerator2::ConvertToRelativeOutputPath(const char* p)
   return cmSystemTools::ConvertToOutputPath(relative.c_str());
 }
 
+//----------------------------------------------------------------------------
+std::string
+cmLocalUnixMakefileGenerator2::ConvertToQuotedOutputPath(const char* p)
+{
+  // Split the path into its components.
+  std::vector<std::string> components;
+  cmSystemTools::SplitPath(p, components);
+
+  // Return an empty path if there are no components.
+  if(components.empty())
+    {
+    return "\"\"";
+    }
+
+  // Begin the quoted result with the root component.
+  std::string result = "\"";
+  result += components[0];
+
+  // Now add the rest of the components separated by the proper slash
+  // direction for this platform.
+  bool first = true;
+  for(unsigned int i=1; i < components.size(); ++i)
+    {
+    // Only the last component can be empty to avoid double slashes.
+    if(components[i].length() > 0 || (i == (components.size()-1)))
+      {
+      if(!first)
+        {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+        result += "\\";
+#else
+        result += "/";
+#endif
+        }
+      result += components[i];
+      first = false;
+      }
+    }
+
+  // Close the quoted result.
+  result += "\"";
+
+  return result;
+}
+
 //----------------------------------------------------------------------------
 void cmLocalUnixMakefileGenerator2::ConfigureOutputPaths()
 {

+ 1 - 0
Source/cmLocalUnixMakefileGenerator2.h

@@ -199,6 +199,7 @@ protected:
   const char* GetSourceFileLanguage(const cmSourceFile& source);
   std::string ConvertToFullPath(const std::string& localPath);
   std::string ConvertToRelativeOutputPath(const char* p);
+  std::string ConvertToQuotedOutputPath(const char* p);
   void ConfigureOutputPaths();
   void FormatOutputPath(std::string& path, const char* name);