summaryrefslogtreecommitdiffstats
path: root/Source/cmGlobalXCodeGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-10-26 17:12:59 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2015-10-26 17:12:59 (GMT)
commit4c4da56b2eb22fd902a100b294ff2acb6d77fac3 (patch)
treea7986e6fc8491b28932504bc43a75013f69cf530 /Source/cmGlobalXCodeGenerator.cxx
parent06ee07b854d4a77c4147dadb97f9769b17da832d (diff)
parent601e6e1ad10b83dcb5ad09d061b04e6974cda283 (diff)
downloadCMake-4c4da56b2eb22fd902a100b294ff2acb6d77fac3.zip
CMake-4c4da56b2eb22fd902a100b294ff2acb6d77fac3.tar.gz
CMake-4c4da56b2eb22fd902a100b294ff2acb6d77fac3.tar.bz2
Merge topic 'xcode-optimization-flags'
601e6e1a 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 df208f6..576827c 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -1617,6 +1617,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,
@@ -2232,9 +2265,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();
@@ -2242,14 +2273,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