cmTarget: Add enumeration for consistency to expect from properties.

The type of consistency to be expected will be extended to cover
numeric minimum and maximum.
This commit is contained in:
Stephen Kelly 2013-10-22 19:23:06 +02:00
parent 98777694b9
commit e4e20c1d19

View File

@ -4450,20 +4450,34 @@ const char *getTypedProperty<const char *>(cmTarget *tgt, const char *prop,
return tgt->GetProperty(prop); return tgt->GetProperty(prop);
} }
enum CompatibleType
{
BoolType,
StringType
};
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
template<typename PropertyType> template<typename PropertyType>
PropertyType consistentProperty(PropertyType lhs, PropertyType rhs); PropertyType consistentProperty(PropertyType lhs, PropertyType rhs,
CompatibleType t);
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
template<> template<>
bool consistentProperty(bool lhs, bool rhs) bool consistentProperty(bool lhs, bool rhs, CompatibleType)
{ {
return lhs == rhs; return lhs == rhs;
} }
//----------------------------------------------------------------------------
const char * consistentStringProperty(const char *lhs, const char *rhs)
{
return strcmp(lhs, rhs) == 0 ? lhs : 0;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
template<> template<>
const char* consistentProperty(const char *lhs, const char *rhs) const char* consistentProperty(const char *lhs, const char *rhs,
CompatibleType t)
{ {
if (!lhs && !rhs) if (!lhs && !rhs)
{ {
@ -4477,7 +4491,16 @@ const char* consistentProperty(const char *lhs, const char *rhs)
{ {
return lhs ? lhs : ""; return lhs ? lhs : "";
} }
return strcmp(lhs, rhs) == 0 ? lhs : 0; switch(t)
{
case BoolType:
assert(!"consistentProperty for strings called with BoolType");
return 0;
case StringType:
return consistentStringProperty(lhs, rhs);
}
assert(!"Unreachable!");
return 0;
} }
template<typename PropertyType> template<typename PropertyType>
@ -4499,6 +4522,7 @@ PropertyType checkInterfacePropertyCompatibility(cmTarget *tgt,
const std::string &p, const std::string &p,
const char *config, const char *config,
const char *defaultValue, const char *defaultValue,
CompatibleType t,
PropertyType *) PropertyType *)
{ {
PropertyType propContent = getTypedProperty<PropertyType>(tgt, p.c_str(), PropertyType propContent = getTypedProperty<PropertyType>(tgt, p.c_str(),
@ -4545,7 +4569,7 @@ PropertyType checkInterfacePropertyCompatibility(cmTarget *tgt,
if (ifaceIsSet) if (ifaceIsSet)
{ {
PropertyType consistent = consistentProperty(propContent, PropertyType consistent = consistentProperty(propContent,
ifacePropContent); ifacePropContent, t);
if (!consistent) if (!consistent)
{ {
cmOStringStream e; cmOStringStream e;
@ -4575,7 +4599,7 @@ PropertyType checkInterfacePropertyCompatibility(cmTarget *tgt,
if (ifaceIsSet) if (ifaceIsSet)
{ {
PropertyType consistent = consistentProperty(propContent, PropertyType consistent = consistentProperty(propContent,
ifacePropContent); ifacePropContent, t);
if (!consistent) if (!consistent)
{ {
cmOStringStream e; cmOStringStream e;
@ -4607,7 +4631,7 @@ PropertyType checkInterfacePropertyCompatibility(cmTarget *tgt,
if (propInitialized) if (propInitialized)
{ {
PropertyType consistent = consistentProperty(propContent, PropertyType consistent = consistentProperty(propContent,
ifacePropContent); ifacePropContent, t);
if (!consistent) if (!consistent)
{ {
cmOStringStream e; cmOStringStream e;
@ -4646,7 +4670,7 @@ bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p,
const char *config) const char *config)
{ {
return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE", return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
0); BoolType, 0);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -4657,7 +4681,8 @@ const char * cmTarget::GetLinkInterfaceDependentStringProperty(
return checkInterfacePropertyCompatibility<const char *>(this, return checkInterfacePropertyCompatibility<const char *>(this,
p, p,
config, config,
"empty", 0); "empty",
StringType, 0);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -5708,23 +5733,35 @@ template<typename PropertyType>
PropertyType getLinkInterfaceDependentProperty(cmTarget *tgt, PropertyType getLinkInterfaceDependentProperty(cmTarget *tgt,
const std::string prop, const std::string prop,
const char *config, const char *config,
CompatibleType,
PropertyType *); PropertyType *);
template<> template<>
bool getLinkInterfaceDependentProperty(cmTarget *tgt, bool getLinkInterfaceDependentProperty(cmTarget *tgt,
const std::string prop, const std::string prop,
const char *config, bool *) const char *config,
CompatibleType, bool *)
{ {
return tgt->GetLinkInterfaceDependentBoolProperty(prop, config); return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
} }
template<> template<>
const char * getLinkInterfaceDependentProperty(cmTarget *tgt, const char * getLinkInterfaceDependentProperty(cmTarget *tgt,
const std::string prop, const std::string prop,
const char *config, const char *config,
const char **) CompatibleType t,
const char **)
{ {
return tgt->GetLinkInterfaceDependentStringProperty(prop, config); switch(t)
{
case BoolType:
assert(!"String compatibility check function called for boolean");
return 0;
case StringType:
return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
}
assert(!"Unreachable!");
return 0;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -5733,6 +5770,7 @@ void checkPropertyConsistency(cmTarget *depender, cmTarget *dependee,
const char *propName, const char *propName,
std::set<cmStdString> &emitted, std::set<cmStdString> &emitted,
const char *config, const char *config,
CompatibleType t,
PropertyType *) PropertyType *)
{ {
const char *prop = dependee->GetProperty(propName); const char *prop = dependee->GetProperty(propName);
@ -5765,7 +5803,7 @@ void checkPropertyConsistency(cmTarget *depender, cmTarget *dependee,
if(emitted.insert(*pi).second) if(emitted.insert(*pi).second)
{ {
getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config, getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
0); t, 0);
if (cmSystemTools::GetErrorOccuredFlag()) if (cmSystemTools::GetErrorOccuredFlag())
{ {
return; return;
@ -5794,14 +5832,15 @@ void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info,
checkPropertyConsistency<bool>(this, li->Target, checkPropertyConsistency<bool>(this, li->Target,
"COMPATIBLE_INTERFACE_BOOL", "COMPATIBLE_INTERFACE_BOOL",
emittedBools, config, 0); emittedBools, config, BoolType, 0);
if (cmSystemTools::GetErrorOccuredFlag()) if (cmSystemTools::GetErrorOccuredFlag())
{ {
return; return;
} }
checkPropertyConsistency<const char *>(this, li->Target, checkPropertyConsistency<const char *>(this, li->Target,
"COMPATIBLE_INTERFACE_STRING", "COMPATIBLE_INTERFACE_STRING",
emittedStrings, config, 0); emittedStrings, config,
StringType, 0);
if (cmSystemTools::GetErrorOccuredFlag()) if (cmSystemTools::GetErrorOccuredFlag())
{ {
return; return;