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:
parent
f97bf4370c
commit
baff44345c
@ -5,3 +5,7 @@ Compiler features enabled for this target.
|
|||||||
|
|
||||||
The list of features in this property are a subset of the features listed
|
The list of features in this property are a subset of the features listed
|
||||||
in the :variable:`CMAKE_CXX_COMPILE_FEATURES` variable.
|
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.
|
||||||
|
@ -1459,10 +1459,8 @@ void cmLocalGenerator::AddCompileOptions(
|
|||||||
this->AppendFlagEscape(flags, *i);
|
this->AppendFlagEscape(flags, *i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (const char* featureProp = target->GetProperty("COMPILE_FEATURES"))
|
|
||||||
{
|
|
||||||
std::vector<std::string> features;
|
std::vector<std::string> features;
|
||||||
cmSystemTools::ExpandListArgument(featureProp, features);
|
target->GetCompileFeatures(features);
|
||||||
for(std::vector<std::string>::const_iterator it = features.begin();
|
for(std::vector<std::string>::const_iterator it = features.begin();
|
||||||
it != features.end(); ++it)
|
it != features.end(); ++it)
|
||||||
{
|
{
|
||||||
@ -1471,7 +1469,6 @@ void cmLocalGenerator::AddCompileOptions(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
this->AddCompilerRequirementFlag(flags, target, lang);
|
this->AddCompilerRequirementFlag(flags, target, lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4521,6 +4521,11 @@ bool cmMakefile::
|
|||||||
AddRequiredTargetFeature(cmTarget *target, const std::string& feature,
|
AddRequiredTargetFeature(cmTarget *target, const std::string& feature,
|
||||||
std::string *error) const
|
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,
|
bool isCxxFeature = std::find_if(cmArrayBegin(CXX_FEATURES) + 1,
|
||||||
cmArrayEnd(CXX_FEATURES), cmStrCmp(feature))
|
cmArrayEnd(CXX_FEATURES), cmStrCmp(feature))
|
||||||
!= cmArrayEnd(CXX_FEATURES);
|
!= cmArrayEnd(CXX_FEATURES);
|
||||||
|
@ -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)
|
void cmTarget::MaybeInvalidatePropertyCache(const std::string& prop)
|
||||||
{
|
{
|
||||||
|
@ -545,6 +545,7 @@ public:
|
|||||||
const std::string& config) const;
|
const std::string& config) const;
|
||||||
void GetAutoUicOptions(std::vector<std::string> &result,
|
void GetAutoUicOptions(std::vector<std::string> &result,
|
||||||
const std::string& config) const;
|
const std::string& config) const;
|
||||||
|
void GetCompileFeatures(std::vector<std::string> &features) const;
|
||||||
|
|
||||||
bool IsNullImpliedByLinkLibraries(const std::string &p) const;
|
bool IsNullImpliedByLinkLibraries(const std::string &p) const;
|
||||||
bool IsLinkInterfaceDependentBoolProperty(const std::string &p,
|
bool IsLinkInterfaceDependentBoolProperty(const std::string &p,
|
||||||
|
@ -22,3 +22,8 @@ add_executable(CompileFeatures main.cpp)
|
|||||||
set_property(TARGET CompileFeatures
|
set_property(TARGET CompileFeatures
|
||||||
PROPERTY COMPILE_FEATURES "cxx_auto_type"
|
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>"
|
||||||
|
)
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
1
|
@ -0,0 +1,2 @@
|
|||||||
|
CMake Error in CMakeLists.txt:
|
||||||
|
Specified unknown feature "not_a_feature" for target "somelib".
|
3
Tests/RunCMake/CompileFeatures/NotAFeatureGenex.cmake
Normal file
3
Tests/RunCMake/CompileFeatures/NotAFeatureGenex.cmake
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
add_library(somelib STATIC empty.cpp)
|
||||||
|
set_property(TARGET somelib PROPERTY COMPILE_FEATURES "$<1:not_a_feature>")
|
@ -1,3 +1,4 @@
|
|||||||
include(RunCMake)
|
include(RunCMake)
|
||||||
|
|
||||||
run_cmake(NotAFeature)
|
run_cmake(NotAFeature)
|
||||||
|
run_cmake(NotAFeatureGenex)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user