diff options
author | Brad King <brad.king@kitware.com> | 2015-02-06 16:01:48 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-02-06 16:44:41 (GMT) |
commit | 9924486f8a979bf937c8fd7749aaf37c1bd762e1 (patch) | |
tree | 3eaaadedd17d3694e689978b04f78959ae7e8fc6 /Source/cmGlobalXCodeGenerator.cxx | |
parent | 098160d5f2a1aa35d2f14c585dd87cefd8f56f41 (diff) | |
download | CMake-9924486f8a979bf937c8fd7749aaf37c1bd762e1.zip CMake-9924486f8a979bf937c8fd7749aaf37c1bd762e1.tar.gz CMake-9924486f8a979bf937c8fd7749aaf37c1bd762e1.tar.bz2 |
Xcode: Refactor generation of per-language compiler flags
Diffstat (limited to 'Source/cmGlobalXCodeGenerator.cxx')
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 140 |
1 files changed, 69 insertions, 71 deletions
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index cd0dcc6..7b2ac8e 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1743,7 +1743,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, return; } - std::string flags; std::string defFlags; bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) || (target.GetType() == cmTarget::MODULE_LIBRARY)); @@ -1752,19 +1751,15 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, (target.GetType() == cmTarget::EXECUTABLE) || shared); - std::string lang = target.GetLinkerLanguage(configName); - std::string cflags; - if(!lang.empty()) + // Compute the compilation flags for each language. + std::set<std::string> languages; + target.GetLanguages(languages, configName); + std::map<std::string, std::string> cflags; + for (std::set<std::string>::iterator li = languages.begin(); + li != languages.end(); ++li) { - // for c++ projects get the c flags as well - if(lang == "CXX") - { - this->CurrentLocalGenerator->AddLanguageFlags(cflags, "C", configName); - this->CurrentLocalGenerator->AddCMP0018Flags(cflags, &target, - "C", configName); - this->CurrentLocalGenerator-> - AddCompileOptions(cflags, &target, "C", configName); - } + std::string const& lang = *li; + std::string& flags = cflags[lang]; // Add language-specific flags. this->CurrentLocalGenerator->AddLanguageFlags(flags, lang, configName); @@ -1779,13 +1774,15 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, this->CurrentLocalGenerator-> AddCompileOptions(flags, &target, lang, configName); } - else if(binary) - { + + std::string lang = target.GetLinkerLanguage(configName); + if(binary && lang.empty()) + { cmSystemTools::Error ("CMake can not determine linker language for target: ", target.GetName().c_str()); return; - } + } // Add define flags this->CurrentLocalGenerator-> @@ -2178,53 +2175,58 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, buildSettings->AddAttribute("HEADER_SEARCH_PATHS", dirs.CreateList()); } - std::string oflagc = this->ExtractFlag("-O", cflags); + + 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; - if(oflagc.size() == 3) - { - optLevel[0] = oflagc[2]; - } - if(oflagc.size() == 2) - { - optLevel[0] = '1'; - } - std::string oflag = this->ExtractFlag("-O", flags); - if(oflag.size() == 3) - { - optLevel[0] = oflag[2]; - } - if(oflag.size() == 2) - { - optLevel[0] = '1'; - } - std::string gflagc = this->ExtractFlag("-g", cflags); - // put back gdwarf-2 if used since there is no way - // to represent it in the gui, but we still want debug yes - if(gflagc == "-gdwarf-2") - { - cflags += " "; - cflags += gflagc; - } - std::string gflag = this->ExtractFlag("-g", flags); - if(gflag == "-gdwarf-2") + + // Minimal map of flags to build settings. + for (std::set<std::string>::iterator li = languages.begin(); + li != languages.end(); ++li) { - flags += " "; - flags += gflag; + std::string& flags = cflags[*li]; + std::string& gflag = gflags[*li]; + std::string oflag = this->ExtractFlag("-O", flags); + if(oflag.size() == 3) + { + optLevel[0] = oflag[2]; + } + if(oflag.size() == 2) + { + optLevel[0] = '1'; + } + gflag = this->ExtractFlag("-g", flags); + // put back gdwarf-2 if used since there is no way + // to represent it in the gui, but we still want debug yes + if(gflag == "-gdwarf-2") + { + flags += " "; + flags += gflag; + } + if (last_gflag && *last_gflag != gflag) + { + same_gflags = false; + } + last_gflag = &gflag; } + const char* debugStr = "YES"; - // We can't set the Xcode flag differently depending on the language, - // so put them back in this case. - if( (lang == "CXX") && gflag != gflagc ) + if (!same_gflags) { - cflags += " "; - cflags += gflagc; - flags += " "; - flags += gflag; + // We can't set the Xcode flag differently depending on the language, + // so put them back in this case. + for (std::set<std::string>::iterator li = languages.begin(); + li != languages.end(); ++li) + { + cflags[*li] += " "; + cflags[*li] += gflags[*li]; + } debugStr = "NO"; } - if( gflag == "-g0" || gflag.size() == 0 ) + else if (last_gflag && (last_gflag->empty() || *last_gflag == "-g0")) { debugStr = "NO"; } @@ -2239,24 +2241,20 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, this->CreateString("NO")); buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN", this->CreateString("NO")); - if(lang == "CXX") - { - flags += " "; - flags += defFlags; - buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS", - this->CreateString(flags.c_str())); - cflags += " "; - cflags += defFlags; - buildSettings->AddAttribute("OTHER_CFLAGS", - this->CreateString(cflags.c_str())); - - } - else + for (std::set<std::string>::iterator li = languages.begin(); + li != languages.end(); ++li) { - flags += " "; - flags += defFlags; - buildSettings->AddAttribute("OTHER_CFLAGS", - this->CreateString(flags.c_str())); + std::string flags = cflags[*li] + " " + defFlags; + if (*li == "CXX") + { + buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS", + this->CreateString(flags.c_str())); + } + else if (*li == "C") + { + buildSettings->AddAttribute("OTHER_CFLAGS", + this->CreateString(flags.c_str())); + } } // Add Fortran source format attribute if property is set. |