Browse Source

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.
Brad King 16 years ago
parent
commit
1e48243591

+ 20 - 0
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<std::string> options;
+    cmSystemTools::ExpandListArgument(optionList, options);
+    for(std::vector<std::string>::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,

+ 4 - 0
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

+ 25 - 0
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)
 {

+ 2 - 0
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; };
 

+ 12 - 0
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

+ 4 - 0
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

+ 20 - 0
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)
 {

+ 2 - 0
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