cmCommonTargetGenerator: Adopt GetFlags method
De-duplicate per-target flag computation in Makefile and Ninja target generators.
This commit is contained in:
parent
f4875bbdd6
commit
0837538e46
|
@ -284,3 +284,51 @@ std::string cmCommonTargetGenerator::GetFrameworkFlags(std::string const& l)
|
||||||
}
|
}
|
||||||
return flags;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -74,6 +74,13 @@ protected:
|
||||||
|
|
||||||
// Return the a string with -F flags on apple
|
// Return the a string with -F flags on apple
|
||||||
std::string GetFrameworkFlags(std::string const& l);
|
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
|
#endif
|
||||||
|
|
|
@ -272,54 +272,6 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules()
|
||||||
<< "\n\n";
|
<< "\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)
|
std::string cmMakefileTargetGenerator::GetDefines(const std::string &l)
|
||||||
{
|
{
|
||||||
ByLanguageMap::iterator i = this->DefinesByLanguage.find(l);
|
ByLanguageMap::iterator i = this->DefinesByLanguage.find(l);
|
||||||
|
|
|
@ -235,9 +235,6 @@ protected:
|
||||||
cmOSXBundleGenerator* OSXBundleGenerator;
|
cmOSXBundleGenerator* OSXBundleGenerator;
|
||||||
MacOSXContentGeneratorType* MacOSXContentGenerator;
|
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);
|
std::string GetDefines(const std::string &l);
|
||||||
ByLanguageMap DefinesByLanguage;
|
ByLanguageMap DefinesByLanguage;
|
||||||
};
|
};
|
||||||
|
|
|
@ -110,55 +110,7 @@ std::string
|
||||||
cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile const* source,
|
cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile const* source,
|
||||||
const std::string& language)
|
const std::string& language)
|
||||||
{
|
{
|
||||||
bool hasLangCached = this->LanguageFlags.count(language) != 0;
|
std::string flags = this->GetFlags(language);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add source file specific flags.
|
// Add source file specific flags.
|
||||||
this->LocalGenerator->AppendFlags(flags,
|
this->LocalGenerator->AppendFlags(flags,
|
||||||
|
|
|
@ -149,9 +149,6 @@ private:
|
||||||
/// List of object files for this target.
|
/// List of object files for this target.
|
||||||
cmNinjaDeps Objects;
|
cmNinjaDeps Objects;
|
||||||
std::vector<cmCustomCommand const*> CustomCommands;
|
std::vector<cmCustomCommand const*> CustomCommands;
|
||||||
|
|
||||||
typedef std::map<std::string, std::string> LanguageFlagMap;
|
|
||||||
LanguageFlagMap LanguageFlags;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ! cmNinjaTargetGenerator_h
|
#endif // ! cmNinjaTargetGenerator_h
|
||||||
|
|
Loading…
Reference in New Issue