cmTarget: Allow populating COMPILE_FEATURES using generator expressions.

Delay validation of the content as a feature if it contains a
generator expression. It will be checked again at generate-time
after evaluation.
This commit is contained in:
Stephen Kelly 2013-10-22 15:05:49 +02:00
parent f97bf4370c
commit baff44345c
10 changed files with 44 additions and 9 deletions

View File

@ -5,3 +5,7 @@ Compiler features enabled for this target.
The list of features in this property are a subset of the features listed
in the :variable:`CMAKE_CXX_COMPILE_FEATURES` variable.
Contents of ``COMPILE_FEATURES`` may use "generator expressions" with the
syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)` manual for
available expressions.

View File

@ -1459,10 +1459,8 @@ void cmLocalGenerator::AddCompileOptions(
this->AppendFlagEscape(flags, *i);
}
}
if (const char* featureProp = target->GetProperty("COMPILE_FEATURES"))
{
std::vector<std::string> features;
cmSystemTools::ExpandListArgument(featureProp, features);
target->GetCompileFeatures(features);
for(std::vector<std::string>::const_iterator it = features.begin();
it != features.end(); ++it)
{
@ -1471,7 +1469,6 @@ void cmLocalGenerator::AddCompileOptions(
return;
}
}
}
this->AddCompilerRequirementFlag(flags, target, lang);
}

View File

@ -4521,6 +4521,11 @@ bool cmMakefile::
AddRequiredTargetFeature(cmTarget *target, const std::string& feature,
std::string *error) const
{
if (cmGeneratorExpression::Find(feature) != std::string::npos)
{
target->AppendProperty("COMPILE_FEATURES", feature.c_str());
return true;
}
bool isCxxFeature = std::find_if(cmArrayBegin(CXX_FEATURES) + 1,
cmArrayEnd(CXX_FEATURES), cmStrCmp(feature))
!= cmArrayEnd(CXX_FEATURES);

View File

@ -2616,6 +2616,22 @@ void cmTarget::GetCompileDefinitions(std::vector<std::string> &list,
}
}
//----------------------------------------------------------------------------
void cmTarget::GetCompileFeatures(std::vector<std::string> &features) const
{
assert(this->GetType() != INTERFACE_LIBRARY);
for(std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
si = this->Internal->CompileFeaturesEntries.begin();
si != this->Internal->CompileFeaturesEntries.end(); ++si)
{
cmSystemTools::ExpandListArgument((*si)->ge->Evaluate(this->Makefile,
"",
false,
this),
features);
}
}
//----------------------------------------------------------------------------
void cmTarget::MaybeInvalidatePropertyCache(const std::string& prop)
{

View File

@ -545,6 +545,7 @@ public:
const std::string& config) const;
void GetAutoUicOptions(std::vector<std::string> &result,
const std::string& config) const;
void GetCompileFeatures(std::vector<std::string> &features) const;
bool IsNullImpliedByLinkLibraries(const std::string &p) const;
bool IsLinkInterfaceDependentBoolProperty(const std::string &p,

View File

@ -22,3 +22,8 @@ add_executable(CompileFeatures main.cpp)
set_property(TARGET CompileFeatures
PROPERTY COMPILE_FEATURES "cxx_auto_type"
)
add_executable(GenexCompileFeatures main.cpp)
set_property(TARGET GenexCompileFeatures
PROPERTY COMPILE_FEATURES "$<1:cxx_auto_type>;$<0:not_a_feature>"
)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,2 @@
CMake Error in CMakeLists.txt:
Specified unknown feature "not_a_feature" for target "somelib".

View File

@ -0,0 +1,3 @@
add_library(somelib STATIC empty.cpp)
set_property(TARGET somelib PROPERTY COMPILE_FEATURES "$<1:not_a_feature>")

View File

@ -1,3 +1,4 @@
include(RunCMake)
run_cmake(NotAFeature)
run_cmake(NotAFeatureGenex)