Introduce "build feature" lookup framework

This creates cmTarget::GetFeature and cmMakefile::GetFeature methods to
query "build feature" properties.  These methods handle local-to-global
scope and per-configuration property lookup.  Specific build features
will be defined later.
This commit is contained in:
Brad King 2009-10-02 13:52:01 -04:00
parent 57df2abca8
commit 1e48243591
8 changed files with 89 additions and 0 deletions

View File

@ -2082,6 +2082,26 @@ void cmLocalGenerator::AppendDefines(std::string& defines,
}
}
//----------------------------------------------------------------------------
void cmLocalGenerator::AppendFeatureOptions(
std::string& flags, const char* lang, const char* feature)
{
std::string optVar = "CMAKE_";
optVar += lang;
optVar += "_COMPILE_OPTIONS_";
optVar += feature;
if(const char* optionList = this->Makefile->GetDefinition(optVar.c_str()))
{
std::vector<std::string> options;
cmSystemTools::ExpandListArgument(optionList, options);
for(std::vector<std::string>::const_iterator oi = options.begin();
oi != options.end(); ++oi)
{
this->AppendFlags(flags, this->EscapeForShell(oi->c_str()).c_str());
}
}
}
//----------------------------------------------------------------------------
std::string
cmLocalGenerator::ConstructComment(const cmCustomCommand& cc,

View File

@ -149,6 +149,10 @@ public:
void AppendDefines(std::string& defines, const char* defines_list,
const char* lang);
/** Lookup and append options associated with a particular feature. */
void AppendFeatureOptions(std::string& flags, const char* lang,
const char* feature);
/** Translate a dependency as given in CMake code to the name to
appear in a generated build file. If the given name is that of
a CMake target it will be transformed to the real output

View File

@ -3311,6 +3311,31 @@ bool cmMakefile::GetPropertyAsBool(const char* prop)
return cmSystemTools::IsOn(this->GetProperty(prop));
}
//----------------------------------------------------------------------------
const char* cmMakefile::GetFeature(const char* feature, const char* config)
{
// TODO: Define accumulation policy for features (prepend, append, replace).
// Currently we always replace.
if(config && *config)
{
std::string featureConfig = feature;
featureConfig += "_";
featureConfig += cmSystemTools::UpperCase(config);
if(const char* value = this->GetProperty(featureConfig.c_str()))
{
return value;
}
}
if(const char* value = this->GetProperty(feature))
{
return value;
}
if(cmLocalGenerator* parent = this->LocalGenerator->GetParent())
{
return parent->GetMakefile()->GetFeature(feature, config);
}
return 0;
}
cmTarget* cmMakefile::FindTarget(const char* name)
{

View File

@ -793,6 +793,8 @@ public:
const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
bool GetPropertyAsBool(const char *prop);
const char* GetFeature(const char* feature, const char* config);
// Get the properties
cmPropertyMap &GetProperties() { return this->Properties; };

View File

@ -1761,6 +1761,18 @@ void cmMakefileTargetGenerator::AddModuleDefinitionFlag(std::string& flags)
this->LocalGenerator->AppendFlags(flags, flag.c_str());
}
//----------------------------------------------------------------------------
const char* cmMakefileTargetGenerator::GetFeature(const char* feature)
{
return this->Target->GetFeature(feature, this->ConfigName);
}
//----------------------------------------------------------------------------
bool cmMakefileTargetGenerator::GetFeatureAsBool(const char* feature)
{
return cmSystemTools::IsOn(this->GetFeature(feature));
}
//----------------------------------------------------------------------------
void cmMakefileTargetGenerator::AddFeatureFlags(
std::string& flags, const char* lang

View File

@ -223,6 +223,10 @@ protected:
// Add language feature flags.
void AddFeatureFlags(std::string& flags, const char* lang);
// Feature query methods.
const char* GetFeature(const char* feature);
bool GetFeatureAsBool(const char* feature);
//==================================================================
// Convenience routines that do nothing more than forward to
// implementaitons

View File

@ -2244,6 +2244,26 @@ void cmTarget::GetTargetVersion(bool soversion,
}
}
//----------------------------------------------------------------------------
const char* cmTarget::GetFeature(const char* feature, const char* config)
{
if(config && *config)
{
std::string featureConfig = feature;
featureConfig += "_";
featureConfig += cmSystemTools::UpperCase(config);
if(const char* value = this->GetProperty(featureConfig.c_str()))
{
return value;
}
}
if(const char* value = this->GetProperty(feature))
{
return value;
}
return this->Makefile->GetFeature(feature, config);
}
//----------------------------------------------------------------------------
const char *cmTarget::GetProperty(const char* prop)
{

View File

@ -232,6 +232,8 @@ public:
bool GetPropertyAsBool(const char *prop);
void CheckProperty(const char* prop, cmMakefile* context);
const char* GetFeature(const char* feature, const char* config);
bool IsImported() const {return this->IsImportedTarget;}
/** The link interface specifies transitive library dependencies and