diff options
-rw-r--r-- | Help/prop_tgt/COMPILE_FEATURES.rst | 4 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 15 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 5 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 16 | ||||
-rw-r--r-- | Source/cmTarget.h | 1 | ||||
-rw-r--r-- | Tests/CompileFeatures/CMakeLists.txt | 5 | ||||
-rw-r--r-- | Tests/RunCMake/CompileFeatures/NotAFeatureGenex-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/CompileFeatures/NotAFeatureGenex-stderr.txt | 2 | ||||
-rw-r--r-- | Tests/RunCMake/CompileFeatures/NotAFeatureGenex.cmake | 3 | ||||
-rw-r--r-- | Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake | 1 |
10 files changed, 44 insertions, 9 deletions
diff --git a/Help/prop_tgt/COMPILE_FEATURES.rst b/Help/prop_tgt/COMPILE_FEATURES.rst index b2c6145655..dc328259ca 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 0f8e7dcb4d..f58180698a 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<std::string> features; + target->GetCompileFeatures(features); + for(std::vector<std::string>::const_iterator it = features.begin(); + it != features.end(); ++it) { - std::vector<std::string> features; - cmSystemTools::ExpandListArgument(featureProp, features); - for(std::vector<std::string>::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 0b3c43e22f..5004a0893f 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 6f53009bb5..09e3339b8a 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -2617,6 +2617,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) { // Wipe out maps caching information affected by this property. diff --git a/Source/cmTarget.h b/Source/cmTarget.h index da9d0a1b56..fe3ea2b6ec 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -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, diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index 471b560c25..2114f94bb3 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 0000000000..d00491fd7e --- /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 0000000000..ff60e50a59 --- /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 0000000000..ad2bd371d1 --- /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 3c999e67d8..da9477d6a9 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) |