cmCommonTargetGenerator: Adopt GetFlags method

De-duplicate per-target flag computation in Makefile and Ninja target
generators.
This commit is contained in:
Brad King 2015-07-09 10:05:12 -04:00
parent f4875bbdd6
commit 0837538e46
6 changed files with 56 additions and 103 deletions

View File

@ -284,3 +284,51 @@ std::string cmCommonTargetGenerator::GetFrameworkFlags(std::string const& l)
}
return flags;
}
//----------------------------------------------------------------------------
std::string cmCommonTargetGenerator::GetFlags(const std::string &l)
{
ByLanguageMap::iterator i = this->FlagsByLanguage.find(l);
if (i == this->FlagsByLanguage.end())
{
std::string flags;
const char *lang = l.c_str();
// Add language feature flags.
this->AddFeatureFlags(flags, lang);
this->LocalGenerator->AddArchitectureFlags(flags, this->GeneratorTarget,
lang, this->ConfigName);
// Fortran-specific flags computed for this target.
if(l == "Fortran")
{
this->AddFortranFlags(flags);
}
this->LocalGenerator->AddCMP0018Flags(flags, this->Target,
lang, this->ConfigName);
this->LocalGenerator->AddVisibilityPresetFlags(flags, this->Target,
lang);
// Add include directory flags.
this->AddIncludeFlags(flags, lang);
// Append old-style preprocessor definition flags.
this->LocalGenerator->
AppendFlags(flags, this->Makefile->GetDefineFlags());
// Add framework directory flags.
this->LocalGenerator->
AppendFlags(flags,this->GetFrameworkFlags(l));
// Add target-specific flags.
this->LocalGenerator->AddCompileOptions(flags, this->Target,
lang, this->ConfigName);
ByLanguageMap::value_type entry(l, flags);
i = this->FlagsByLanguage.insert(entry).first;
}
return i->second;
}

View File

@ -74,6 +74,13 @@ protected:
// Return the a string with -F flags on apple
std::string GetFrameworkFlags(std::string const& l);
virtual void AddIncludeFlags(std::string& flags,
std::string const& lang) = 0;
typedef std::map<std::string, std::string> ByLanguageMap;
std::string GetFlags(const std::string &l);
ByLanguageMap FlagsByLanguage;
};
#endif

View File

@ -272,54 +272,6 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules()
<< "\n\n";
}
//----------------------------------------------------------------------------
std::string cmMakefileTargetGenerator::GetFlags(const std::string &l)
{
ByLanguageMap::iterator i = this->FlagsByLanguage.find(l);
if (i == this->FlagsByLanguage.end())
{
std::string flags;
const char *lang = l.c_str();
// Add language feature flags.
this->AddFeatureFlags(flags, lang);
this->LocalGenerator->AddArchitectureFlags(flags, this->GeneratorTarget,
lang, this->ConfigName);
// Fortran-specific flags computed for this target.
if(l == "Fortran")
{
this->AddFortranFlags(flags);
}
this->LocalGenerator->AddCMP0018Flags(flags, this->Target,
lang, this->ConfigName);
this->LocalGenerator->AddVisibilityPresetFlags(flags, this->Target,
lang);
// Add include directory flags.
this->AddIncludeFlags(flags, lang);
// Append old-style preprocessor definition flags.
this->LocalGenerator->
AppendFlags(flags, this->Makefile->GetDefineFlags());
// Add framework directory flags.
this->LocalGenerator->
AppendFlags(flags,this->GetFrameworkFlags(l));
// Add target-specific flags.
this->LocalGenerator->AddCompileOptions(flags, this->Target,
lang, this->ConfigName);
ByLanguageMap::value_type entry(l, flags);
i = this->FlagsByLanguage.insert(entry).first;
}
return i->second;
}
std::string cmMakefileTargetGenerator::GetDefines(const std::string &l)
{
ByLanguageMap::iterator i = this->DefinesByLanguage.find(l);

View File

@ -235,9 +235,6 @@ protected:
cmOSXBundleGenerator* OSXBundleGenerator;
MacOSXContentGeneratorType* MacOSXContentGenerator;
typedef std::map<std::string, std::string> ByLanguageMap;
std::string GetFlags(const std::string &l);
ByLanguageMap FlagsByLanguage;
std::string GetDefines(const std::string &l);
ByLanguageMap DefinesByLanguage;
};

View File

@ -110,55 +110,7 @@ std::string
cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile const* source,
const std::string& language)
{
bool hasLangCached = this->LanguageFlags.count(language) != 0;
std::string& languageFlags = this->LanguageFlags[language];
if(!hasLangCached)
{
this->AddFeatureFlags(languageFlags, language);
this->GetLocalGenerator()->AddArchitectureFlags(languageFlags,
this->GeneratorTarget,
language,
this->GetConfigName());
// Fortran-specific flags computed for this target.
if(language == "Fortran")
{
this->AddFortranFlags(languageFlags);
}
// Add shared-library flags if needed.
this->LocalGenerator->AddCMP0018Flags(languageFlags, this->Target,
language,
this->GetConfigName());
this->LocalGenerator->AddVisibilityPresetFlags(languageFlags, this->Target,
language);
// Add include directory flags.
this->AddIncludeFlags(languageFlags, language);
// Append old-style preprocessor definition flags.
this->LocalGenerator->AppendFlags(languageFlags,
this->Makefile->GetDefineFlags());
// Add framework directory flags.
this->LocalGenerator->
AppendFlags(languageFlags, this->GetFrameworkFlags(language));
// Add target-specific flags.
this->LocalGenerator->AddCompileOptions(languageFlags, this->Target,
language,
this->GetConfigName());
}
std::string flags = languageFlags;
// Add Fortran format flags.
if(language == "Fortran")
{
this->AppendFortranFormatFlags(flags, *source);
}
std::string flags = this->GetFlags(language);
// Add source file specific flags.
this->LocalGenerator->AppendFlags(flags,

View File

@ -149,9 +149,6 @@ private:
/// List of object files for this target.
cmNinjaDeps Objects;
std::vector<cmCustomCommand const*> CustomCommands;
typedef std::map<std::string, std::string> LanguageFlagMap;
LanguageFlagMap LanguageFlags;
};
#endif // ! cmNinjaTargetGenerator_h