Bug filed here: https://cmake.org/Bug/view.php?id=15794
Patch file against git master HEAD attached to this email.

Acceptable?

Thanks
>From 99ca3254e4886155c20de54761dc9c2ca64fdf89 Mon Sep 17 00:00:00 2001
From: Davy Durham <[email protected]>
Date: Thu, 15 Oct 2015 12:04:43 -0500
Subject: [PATCH] Fixed an issue where the Xcode generated was clobbering
 "-O..." flags that aren't optimization flags

---
 Source/cmGlobalXCodeGenerator.cxx | 28 ++++++++++++++++++++--------
 Source/cmGlobalXCodeGenerator.h   |  3 ++-
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 6291796..8d361ec 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -1580,8 +1580,11 @@ void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
 //----------------------------------------------------------------------------
 // This function removes each occurrence of the flag and returns the last one
 // (i.e., the dominant flag in GCC)
+// If an argument is longer than ignore_longer_than, then it will be ignored
+// and not removed.
 std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag,
-                                                std::string& flags)
+                                                std::string& flags,
+                                                unsigned int ignore_longer_than)
 {
   std::string retFlag;
   std::string::size_type lastOccurancePos = flags.rfind(flag);
@@ -1592,16 +1595,25 @@ std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag,
     std::string::size_type pos = lastOccurancePos;
     if(pos == 0 || flags[pos-1]==' ')
       {
-      while(pos < flags.size() && flags[pos] != ' ')
+      // determine the argument's length and ignore if the argument is to long
+      std::string::size_type tpos = pos;
+      while(tpos < flags.size() && flags[tpos] != ' ')
         {
-        if(!saved)
+        tpos++;
+        }
+      if ((tpos - pos) <= ignore_longer_than)
+        {
+        while(pos < flags.size() && flags[pos] != ' ')
           {
-          retFlag += flags[pos];
+          if(!saved)
+            {
+            retFlag += flags[pos];
+            }
+          flags[pos] = ' ';
+          pos++;
           }
-        flags[pos] = ' ';
-        pos++;
+        saved = true;
         }
-      saved = true;
       }
     //decrement lastOccurancePos while making sure we don't loop around
     //and become a very large positive number since size_type is unsigned
@@ -2237,7 +2249,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
     {
     std::string& flags = cflags[*li];
     std::string& gflag = gflags[*li];
-    std::string oflag = this->ExtractFlag("-O", flags);
+    std::string oflagc = this->ExtractFlag("-O", cflags, 3);
     if(oflag.size() == 3)
       {
       optLevel[0] = oflag[2];
diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h
index 9daf0ab..aa6260f 100644
--- a/Source/cmGlobalXCodeGenerator.h
+++ b/Source/cmGlobalXCodeGenerator.h
@@ -150,7 +150,8 @@ private:
   void CreateBuildSettings(cmTarget& target,
                            cmXCodeObject* buildSettings,
                            const std::string& buildType);
-  std::string ExtractFlag(const char* flag, std::string& flags);
+  std::string ExtractFlag(const char* flag, std::string& flags,
+                          unsigned int ignore_longer_than = 256);
   void SortXCodeObjects();
   // delete all objects in the this->XCodeObjects vector.
   void ClearXCodeObjects();
-- 
1.8.5.2 (Apple Git-48)

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to