summaryrefslogtreecommitdiffstats
path: root/Source/cmGlobalXCodeGenerator.cxx
diff options
context:
space:
mode:
authorGregor Jasny <gjasny@googlemail.com>2015-10-18 19:53:12 (GMT)
committerGregor Jasny <gjasny@googlemail.com>2015-10-23 17:29:09 (GMT)
commit601e6e1ad10b83dcb5ad09d061b04e6974cda283 (patch)
treeb6658bdbf3e84d2c3e6d5aac30dcec0860e56010 /Source/cmGlobalXCodeGenerator.cxx
parent2f269fdf0c293e80325c748c985279bc4067af3e (diff)
downloadCMake-601e6e1ad10b83dcb5ad09d061b04e6974cda283.zip
CMake-601e6e1ad10b83dcb5ad09d061b04e6974cda283.tar.gz
CMake-601e6e1ad10b83dcb5ad09d061b04e6974cda283.tar.bz2
Xcode: Use regular expression to extract all optimisation flags (#15794)
Diffstat (limited to 'Source/cmGlobalXCodeGenerator.cxx')
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx48
1 files changed, 40 insertions, 8 deletions
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index bc05aea..0e3af88 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -1612,6 +1612,39 @@ std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag,
}
//----------------------------------------------------------------------------
+// This function removes each matching occurrence of the expression and
+// returns the last one (i.e., the dominant flag in GCC)
+std::string cmGlobalXCodeGenerator::ExtractFlagRegex(const char* exp,
+ int matchIndex,
+ std::string& flags)
+{
+ std::string retFlag;
+
+ cmsys::RegularExpression regex(exp);
+ assert(regex.is_valid());
+ if(!regex.is_valid())
+ {
+ return retFlag;
+ }
+
+ std::string::size_type offset = 0;
+
+ while(regex.find(flags.c_str() + offset))
+ {
+ const std::string::size_type startPos = offset + regex.start(matchIndex);
+ const std::string::size_type endPos = offset + regex.end(matchIndex);
+ const std::string::size_type size = endPos - startPos;
+
+ offset = startPos + 1;
+
+ retFlag.assign(flags, startPos, size);
+ flags.replace(startPos, size, size, ' ');
+ }
+
+ return retFlag;
+}
+
+//----------------------------------------------------------------------------
void
cmGlobalXCodeGenerator::AddCommandsToBuildPhase(cmXCodeObject* buildphase,
cmTarget& target,
@@ -2227,9 +2260,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
bool same_gflags = true;
std::map<std::string, std::string> gflags;
std::string const* last_gflag = 0;
- char optLevel[2];
- optLevel[0] = '0';
- optLevel[1] = 0;
+ std::string optLevel = "0";
// Minimal map of flags to build settings.
for (std::set<std::string>::iterator li = languages.begin();
@@ -2237,14 +2268,15 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
{
std::string& flags = cflags[*li];
std::string& gflag = gflags[*li];
- std::string oflag = this->ExtractFlag("-O", flags);
- if(oflag.size() == 3)
+ std::string oflag =
+ this->ExtractFlagRegex("(^| )(-Ofast|-Os|-O[0-9]*)( |$)", 2, flags);
+ if(oflag.size() == 2)
{
- optLevel[0] = oflag[2];
+ optLevel = "1";
}
- if(oflag.size() == 2)
+ else if(oflag.size() > 2)
{
- optLevel[0] = '1';
+ optLevel = oflag.substr(2);
}
gflag = this->ExtractFlag("-g", flags);
// put back gdwarf-2 if used since there is no way