From baff44345cff8e635766e020d316da514616c16e Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 22 Oct 2013 15:05:49 +0200 Subject: 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. --- Help/prop_tgt/COMPILE_FEATURES.rst | 4 ++++ Source/cmLocalGenerator.cxx | 15 ++++++--------- Source/cmMakefile.cxx | 5 +++++ Source/cmTarget.cxx | 16 ++++++++++++++++ Source/cmTarget.h | 1 + Tests/CompileFeatures/CMakeLists.txt | 5 +++++ .../RunCMake/CompileFeatures/NotAFeatureGenex-result.txt | 1 + .../RunCMake/CompileFeatures/NotAFeatureGenex-stderr.txt | 2 ++ Tests/RunCMake/CompileFeatures/NotAFeatureGenex.cmake | 3 +++ Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake | 1 + 10 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 Tests/RunCMake/CompileFeatures/NotAFeatureGenex-result.txt create mode 100644 Tests/RunCMake/CompileFeatures/NotAFeatureGenex-stderr.txt create mode 100644 Tests/RunCMake/CompileFeatures/NotAFeatureGenex.cmake diff --git a/Help/prop_tgt/COMPILE_FEATURES.rst b/Help/prop_tgt/COMPILE_FEATURES.rst index b2c6145..dc32825 100644 --- a/Help/prop_tgt/COMPILE_FEATURES.rst +++ b/Help/prop_tgt/COMPILE_FEATURES.rst @@ -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. diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 0f8e7dc..f581806 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1459,17 +1459,14 @@ void cmLocalGenerator::AddCompileOptions( this->AppendFlagEscape(flags, *i); } } - if (const char* featureProp = target->GetProperty("COMPILE_FEATURES")) + std::vector features; + target->GetCompileFeatures(features); + for(std::vector::const_iterator it = features.begin(); + it != features.end(); ++it) { - std::vector features; - cmSystemTools::ExpandListArgument(featureProp, features); - for(std::vector::const_iterator it = features.begin(); - it != features.end(); ++it) + if (!this->Makefile->AddRequiredTargetFeature(target, *it)) { - if (!this->Makefile->AddRequiredTargetFeature(target, *it)) - { - return; - } + return; } } this->AddCompilerRequirementFlag(flags, target, lang); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 0b3c43e..5004a08 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -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); diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 6f53009..09e3339 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -2617,6 +2617,22 @@ void cmTarget::GetCompileDefinitions(std::vector &list, } //---------------------------------------------------------------------------- +void cmTarget::GetCompileFeatures(std::vector &features) const +{ + assert(this->GetType() != INTERFACE_LIBRARY); + for(std::vector::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) { // Wipe out maps caching information affected by this property. diff --git a/Source/cmTarget.h b/Source/cmTarget.h index da9d0a1..fe3ea2b 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -545,6 +545,7 @@ public: const std::string& config) const; void GetAutoUicOptions(std::vector &result, const std::string& config) const; + void GetCompileFeatures(std::vector &features) const; bool IsNullImpliedByLinkLibraries(const std::string &p) const; bool IsLinkInterfaceDependentBoolProperty(const std::string &p, diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index 471b560..2114f94 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -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>" +) diff --git a/Tests/RunCMake/CompileFeatures/NotAFeatureGenex-result.txt b/Tests/RunCMake/CompileFeatures/NotAFeatureGenex-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/NotAFeatureGenex-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CompileFeatures/NotAFeatureGenex-stderr.txt b/Tests/RunCMake/CompileFeatures/NotAFeatureGenex-stderr.txt new file mode 100644 index 0000000..ff60e50 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/NotAFeatureGenex-stderr.txt @@ -0,0 +1,2 @@ +CMake Error in CMakeLists.txt: + Specified unknown feature "not_a_feature" for target "somelib". diff --git a/Tests/RunCMake/CompileFeatures/NotAFeatureGenex.cmake b/Tests/RunCMake/CompileFeatures/NotAFeatureGenex.cmake new file mode 100644 index 0000000..ad2bd37 --- /dev/null +++ b/Tests/RunCMake/CompileFeatures/NotAFeatureGenex.cmake @@ -0,0 +1,3 @@ + +add_library(somelib STATIC empty.cpp) +set_property(TARGET somelib PROPERTY COMPILE_FEATURES "$<1:not_a_feature>") diff --git a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake index 3c999e6..da9477d 100644 --- a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake +++ b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake @@ -1,3 +1,4 @@ include(RunCMake) run_cmake(NotAFeature) +run_cmake(NotAFeatureGenex) -- cgit v0.12