From 1e482435912f44e05b5e67f19b1bc14ff58a3169 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 2 Oct 2009 13:52:01 -0400 Subject: [PATCH] Introduce "build feature" lookup framework This creates cmTarget::GetFeature and cmMakefile::GetFeature methods to query "build feature" properties. These methods handle local-to-global scope and per-configuration property lookup. Specific build features will be defined later. --- Source/cmLocalGenerator.cxx | 20 ++++++++++++++++++++ Source/cmLocalGenerator.h | 4 ++++ Source/cmMakefile.cxx | 25 +++++++++++++++++++++++++ Source/cmMakefile.h | 2 ++ Source/cmMakefileTargetGenerator.cxx | 12 ++++++++++++ Source/cmMakefileTargetGenerator.h | 4 ++++ Source/cmTarget.cxx | 20 ++++++++++++++++++++ Source/cmTarget.h | 2 ++ 8 files changed, 89 insertions(+) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index ee5595753..1d5aba4d5 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2082,6 +2082,26 @@ void cmLocalGenerator::AppendDefines(std::string& defines, } } +//---------------------------------------------------------------------------- +void cmLocalGenerator::AppendFeatureOptions( + std::string& flags, const char* lang, const char* feature) +{ + std::string optVar = "CMAKE_"; + optVar += lang; + optVar += "_COMPILE_OPTIONS_"; + optVar += feature; + if(const char* optionList = this->Makefile->GetDefinition(optVar.c_str())) + { + std::vector options; + cmSystemTools::ExpandListArgument(optionList, options); + for(std::vector::const_iterator oi = options.begin(); + oi != options.end(); ++oi) + { + this->AppendFlags(flags, this->EscapeForShell(oi->c_str()).c_str()); + } + } +} + //---------------------------------------------------------------------------- std::string cmLocalGenerator::ConstructComment(const cmCustomCommand& cc, diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 840e5d31f..d2082e422 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -149,6 +149,10 @@ public: void AppendDefines(std::string& defines, const char* defines_list, const char* lang); + /** Lookup and append options associated with a particular feature. */ + void AppendFeatureOptions(std::string& flags, const char* lang, + const char* feature); + /** Translate a dependency as given in CMake code to the name to appear in a generated build file. If the given name is that of a CMake target it will be transformed to the real output diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 7aa1202bc..afe53241a 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -3311,6 +3311,31 @@ bool cmMakefile::GetPropertyAsBool(const char* prop) return cmSystemTools::IsOn(this->GetProperty(prop)); } +//---------------------------------------------------------------------------- +const char* cmMakefile::GetFeature(const char* feature, const char* config) +{ + // TODO: Define accumulation policy for features (prepend, append, replace). + // Currently we always replace. + if(config && *config) + { + std::string featureConfig = feature; + featureConfig += "_"; + featureConfig += cmSystemTools::UpperCase(config); + if(const char* value = this->GetProperty(featureConfig.c_str())) + { + return value; + } + } + if(const char* value = this->GetProperty(feature)) + { + return value; + } + if(cmLocalGenerator* parent = this->LocalGenerator->GetParent()) + { + return parent->GetMakefile()->GetFeature(feature, config); + } + return 0; +} cmTarget* cmMakefile::FindTarget(const char* name) { diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 485d9e24d..cb180ba06 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -793,6 +793,8 @@ public: const char *GetProperty(const char *prop, cmProperty::ScopeType scope); bool GetPropertyAsBool(const char *prop); + const char* GetFeature(const char* feature, const char* config); + // Get the properties cmPropertyMap &GetProperties() { return this->Properties; }; diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 719aa5025..e353c3dcd 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -1761,6 +1761,18 @@ void cmMakefileTargetGenerator::AddModuleDefinitionFlag(std::string& flags) this->LocalGenerator->AppendFlags(flags, flag.c_str()); } +//---------------------------------------------------------------------------- +const char* cmMakefileTargetGenerator::GetFeature(const char* feature) +{ + return this->Target->GetFeature(feature, this->ConfigName); +} + +//---------------------------------------------------------------------------- +bool cmMakefileTargetGenerator::GetFeatureAsBool(const char* feature) +{ + return cmSystemTools::IsOn(this->GetFeature(feature)); +} + //---------------------------------------------------------------------------- void cmMakefileTargetGenerator::AddFeatureFlags( std::string& flags, const char* lang diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index d72bdcec8..4ee2b39b6 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -223,6 +223,10 @@ protected: // Add language feature flags. void AddFeatureFlags(std::string& flags, const char* lang); + // Feature query methods. + const char* GetFeature(const char* feature); + bool GetFeatureAsBool(const char* feature); + //================================================================== // Convenience routines that do nothing more than forward to // implementaitons diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 8510b5925..9233a1dec 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -2244,6 +2244,26 @@ void cmTarget::GetTargetVersion(bool soversion, } } +//---------------------------------------------------------------------------- +const char* cmTarget::GetFeature(const char* feature, const char* config) +{ + if(config && *config) + { + std::string featureConfig = feature; + featureConfig += "_"; + featureConfig += cmSystemTools::UpperCase(config); + if(const char* value = this->GetProperty(featureConfig.c_str())) + { + return value; + } + } + if(const char* value = this->GetProperty(feature)) + { + return value; + } + return this->Makefile->GetFeature(feature, config); +} + //---------------------------------------------------------------------------- const char *cmTarget::GetProperty(const char* prop) { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index e0e258d99..7f44bb5c8 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -232,6 +232,8 @@ public: bool GetPropertyAsBool(const char *prop); void CheckProperty(const char* prop, cmMakefile* context); + const char* GetFeature(const char* feature, const char* config); + bool IsImported() const {return this->IsImportedTarget;} /** The link interface specifies transitive library dependencies and