Merge topic 'xcode-duplicate-flags-13354'

f447db7 XCode generator won't infinitely parse compiler flags (bug #13354).
This commit is contained in:
Brad King 2013-01-23 15:11:09 -05:00 committed by CMake Topic Stage
commit e7be8be8c0
1 changed files with 10 additions and 5 deletions

View File

@ -1367,16 +1367,18 @@ void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// This function removes each occurence of the flag and returns the last one // This function removes each occurrence of the flag and returns the last one
// (i.e., the dominant flag in GCC) // (i.e., the dominant flag in GCC)
std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag, std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag,
std::string& flags) std::string& flags)
{ {
std::string retFlag; std::string retFlag;
std::string::size_type pos = flags.rfind(flag); std::string::size_type lastOccurancePos = flags.rfind(flag);
bool saved = false; bool saved = false;
while(pos != flags.npos) while(lastOccurancePos != flags.npos)
{ {
//increment pos, we use lastOccurancePos to reduce search space on next inc
std::string::size_type pos = lastOccurancePos;
if(pos == 0 || flags[pos-1]==' ') if(pos == 0 || flags[pos-1]==' ')
{ {
while(pos < flags.size() && flags[pos] != ' ') while(pos < flags.size() && flags[pos] != ' ')
@ -1388,9 +1390,12 @@ std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag,
flags[pos] = ' '; flags[pos] = ' ';
pos++; pos++;
} }
}
saved = true; saved = true;
pos = flags.rfind(flag); }
//decrement lastOccurancePos while making sure we don't loop around
//and become a very large positive number since size_type is unsigned
lastOccurancePos = lastOccurancePos == 0 ? 0 : lastOccurancePos-1;
lastOccurancePos = flags.rfind(flag,lastOccurancePos);
} }
return retFlag; return retFlag;
} }