Merge topic 'xcode-flags-per-language'

d2fe4c42 cmGlobalXCodeGenerator: Rename variable 'lang' => 'llang'
de63ff48 Xcode: Generate Intel Fortran compiler flags in project files
9924486f Xcode: Refactor generation of per-language compiler flags
This commit is contained in:
Brad King 2015-02-10 09:37:46 -05:00 committed by CMake Topic Stage
commit 06e527b36c

View File

@ -1743,7 +1743,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
return; return;
} }
std::string flags;
std::string defFlags; std::string defFlags;
bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) || bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
(target.GetType() == cmTarget::MODULE_LIBRARY)); (target.GetType() == cmTarget::MODULE_LIBRARY));
@ -1752,19 +1751,15 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
(target.GetType() == cmTarget::EXECUTABLE) || (target.GetType() == cmTarget::EXECUTABLE) ||
shared); shared);
std::string lang = target.GetLinkerLanguage(configName); // Compute the compilation flags for each language.
std::string cflags; std::set<std::string> languages;
if(!lang.empty()) 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 std::string const& lang = *li;
if(lang == "CXX") std::string& flags = cflags[lang];
{
this->CurrentLocalGenerator->AddLanguageFlags(cflags, "C", configName);
this->CurrentLocalGenerator->AddCMP0018Flags(cflags, &target,
"C", configName);
this->CurrentLocalGenerator->
AddCompileOptions(cflags, &target, "C", configName);
}
// Add language-specific flags. // Add language-specific flags.
this->CurrentLocalGenerator->AddLanguageFlags(flags, lang, configName); this->CurrentLocalGenerator->AddLanguageFlags(flags, lang, configName);
@ -1779,13 +1774,15 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
this->CurrentLocalGenerator-> this->CurrentLocalGenerator->
AddCompileOptions(flags, &target, lang, configName); AddCompileOptions(flags, &target, lang, configName);
} }
else if(binary)
{ std::string llang = target.GetLinkerLanguage(configName);
if(binary && llang.empty())
{
cmSystemTools::Error cmSystemTools::Error
("CMake can not determine linker language for target: ", ("CMake can not determine linker language for target: ",
target.GetName().c_str()); target.GetName().c_str());
return; return;
} }
// Add define flags // Add define flags
this->CurrentLocalGenerator-> this->CurrentLocalGenerator->
@ -2004,7 +2001,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
// in many ways as an application bundle, as far as // in many ways as an application bundle, as far as
// link flags go // link flags go
std::string createFlags = std::string createFlags =
this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", lang, "_FLAGS", this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", llang, "_FLAGS",
"-bundle"); "-bundle");
if(!createFlags.empty()) if(!createFlags.empty())
{ {
@ -2032,7 +2029,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
this->CreateString("NO")); this->CreateString("NO"));
// Add the flags to create an executable. // Add the flags to create an executable.
std::string createFlags = std::string createFlags =
this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", ""); this->LookupFlags("CMAKE_", llang, "_LINK_FLAGS", "");
if(!createFlags.empty()) if(!createFlags.empty())
{ {
extraLinkOptions += " "; extraLinkOptions += " ";
@ -2043,7 +2040,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
{ {
// Add the flags to create a module. // Add the flags to create a module.
std::string createFlags = std::string createFlags =
this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", lang, "_FLAGS", this->LookupFlags("CMAKE_SHARED_MODULE_CREATE_", llang, "_FLAGS",
"-bundle"); "-bundle");
if(!createFlags.empty()) if(!createFlags.empty())
{ {
@ -2077,7 +2074,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
{ {
// Add the flags to create a shared library. // Add the flags to create a shared library.
std::string createFlags = std::string createFlags =
this->LookupFlags("CMAKE_SHARED_LIBRARY_CREATE_", lang, "_FLAGS", this->LookupFlags("CMAKE_SHARED_LIBRARY_CREATE_", llang, "_FLAGS",
"-dynamiclib"); "-dynamiclib");
if(!createFlags.empty()) if(!createFlags.empty())
{ {
@ -2094,7 +2091,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
{ {
// Add the flags to create an executable. // Add the flags to create an executable.
std::string createFlags = std::string createFlags =
this->LookupFlags("CMAKE_", lang, "_LINK_FLAGS", ""); this->LookupFlags("CMAKE_", llang, "_LINK_FLAGS", "");
if(!createFlags.empty()) if(!createFlags.empty())
{ {
extraLinkOptions += " "; extraLinkOptions += " ";
@ -2178,53 +2175,58 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
buildSettings->AddAttribute("HEADER_SEARCH_PATHS", buildSettings->AddAttribute("HEADER_SEARCH_PATHS",
dirs.CreateList()); 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]; char optLevel[2];
optLevel[0] = '0'; optLevel[0] = '0';
optLevel[1] = 0; optLevel[1] = 0;
if(oflagc.size() == 3)
// Minimal map of flags to build settings.
for (std::set<std::string>::iterator li = languages.begin();
li != languages.end(); ++li)
{ {
optLevel[0] = oflagc[2]; std::string& flags = cflags[*li];
} std::string& gflag = gflags[*li];
if(oflagc.size() == 2) std::string oflag = this->ExtractFlag("-O", flags);
{ if(oflag.size() == 3)
optLevel[0] = '1'; {
} optLevel[0] = oflag[2];
std::string oflag = this->ExtractFlag("-O", flags); }
if(oflag.size() == 3) if(oflag.size() == 2)
{ {
optLevel[0] = oflag[2]; optLevel[0] = '1';
} }
if(oflag.size() == 2) gflag = this->ExtractFlag("-g", flags);
{ // put back gdwarf-2 if used since there is no way
optLevel[0] = '1'; // to represent it in the gui, but we still want debug yes
} if(gflag == "-gdwarf-2")
std::string gflagc = this->ExtractFlag("-g", cflags); {
// put back gdwarf-2 if used since there is no way flags += " ";
// to represent it in the gui, but we still want debug yes flags += gflag;
if(gflagc == "-gdwarf-2") }
{ if (last_gflag && *last_gflag != gflag)
cflags += " "; {
cflags += gflagc; same_gflags = false;
} }
std::string gflag = this->ExtractFlag("-g", flags); last_gflag = &gflag;
if(gflag == "-gdwarf-2")
{
flags += " ";
flags += gflag;
} }
const char* debugStr = "YES"; const char* debugStr = "YES";
// We can't set the Xcode flag differently depending on the language, if (!same_gflags)
// so put them back in this case.
if( (lang == "CXX") && gflag != gflagc )
{ {
cflags += " "; // We can't set the Xcode flag differently depending on the language,
cflags += gflagc; // so put them back in this case.
flags += " "; for (std::set<std::string>::iterator li = languages.begin();
flags += gflag; li != languages.end(); ++li)
{
cflags[*li] += " ";
cflags[*li] += gflags[*li];
}
debugStr = "NO"; debugStr = "NO";
} }
if( gflag == "-g0" || gflag.size() == 0 ) else if (last_gflag && (last_gflag->empty() || *last_gflag == "-g0"))
{ {
debugStr = "NO"; debugStr = "NO";
} }
@ -2239,24 +2241,25 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
this->CreateString("NO")); this->CreateString("NO"));
buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN", buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN",
this->CreateString("NO")); this->CreateString("NO"));
if(lang == "CXX") for (std::set<std::string>::iterator li = languages.begin();
li != languages.end(); ++li)
{ {
flags += " "; std::string flags = cflags[*li] + " " + defFlags;
flags += defFlags; if (*li == "CXX")
buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS", {
this->CreateString(flags.c_str())); buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS",
cflags += " "; this->CreateString(flags.c_str()));
cflags += defFlags; }
buildSettings->AddAttribute("OTHER_CFLAGS", else if (*li == "Fortran")
this->CreateString(cflags.c_str())); {
buildSettings->AddAttribute("IFORT_OTHER_FLAGS",
} this->CreateString(flags.c_str()));
else }
{ else if (*li == "C")
flags += " "; {
flags += defFlags; buildSettings->AddAttribute("OTHER_CFLAGS",
buildSettings->AddAttribute("OTHER_CFLAGS", this->CreateString(flags.c_str()));
this->CreateString(flags.c_str())); }
} }
// Add Fortran source format attribute if property is set. // Add Fortran source format attribute if property is set.