瀏覽代碼

ENH: Allow users to specify macro-like #include line transforms for dependency scanning.

  - Define IMPLICIT_DEPENDS_INCLUDE_TRANSFORM property on targets and directories.
  - Make the directory version inherited.
  - See issue #6648.
Brad King 17 年之前
父節點
當前提交
a1bb7e90ef
共有 3 個文件被更改,包括 70 次插入0 次删除
  1. 26 0
      Source/cmLocalUnixMakefileGenerator3.cxx
  2. 26 0
      Source/cmMakefile.cxx
  3. 18 0
      Source/cmTarget.cxx

+ 26 - 0
Source/cmLocalUnixMakefileGenerator3.cxx

@@ -1875,6 +1875,32 @@ void cmLocalUnixMakefileGenerator3
     cmakefileStream
     cmakefileStream
       << "  )\n";
       << "  )\n";
     }
     }
+
+  // Store include transform rule properties.  Write the directory
+  // rules first because they may be overridden by later target rules.
+  std::vector<std::string> transformRules;
+  if(const char* xform =
+     this->Makefile->GetProperty("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM"))
+    {
+    cmSystemTools::ExpandListArgument(xform, transformRules);
+    }
+  if(const char* xform =
+     target.GetProperty("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM"))
+    {
+    cmSystemTools::ExpandListArgument(xform, transformRules);
+    }
+  if(!transformRules.empty())
+    {
+    cmakefileStream
+      << "SET(CMAKE_INCLUDE_TRANSFORMS\n";
+    for(std::vector<std::string>::const_iterator tri = transformRules.begin();
+        tri != transformRules.end(); ++tri)
+      {
+      cmakefileStream << "  " << this->EscapeForCMake(tri->c_str()) << "\n";
+      }
+    cmakefileStream
+      << "  )\n";
+    }
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------

+ 26 - 0
Source/cmMakefile.cxx

@@ -1294,6 +1294,12 @@ void cmMakefile::InitializeFromParent()
   // define flags
   // define flags
   this->DefineFlags = parent->DefineFlags;
   this->DefineFlags = parent->DefineFlags;
 
 
+  // Include transform property.  There is no per-config version.
+  {
+  const char* prop = "IMPLICIT_DEPENDS_INCLUDE_TRANSFORM";
+  this->SetProperty(prop, parent->GetProperty(prop));
+  }
+
   // compile definitions property and per-config versions
   // compile definitions property and per-config versions
   {
   {
   this->SetProperty("COMPILE_DEFINITIONS",
   this->SetProperty("COMPILE_DEFINITIONS",
@@ -3208,6 +3214,26 @@ void cmMakefile::DefineProperties(cmake *cm)
      "This property will be initialized in each directory by its value "
      "This property will be initialized in each directory by its value "
      "in the directory's parent.\n");
      "in the directory's parent.\n");
 
 
+  cm->DefineProperty
+    ("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM", cmProperty::DIRECTORY,
+     "Specify #include line transforms for dependencies in a directory.",
+     "This property specifies rules to transform macro-like #include lines "
+     "during implicit dependency scanning of C and C++ source files.  "
+     "The list of rules must be semicolon-separated with each entry of "
+     "the form \"A_MACRO(%)=value-with-%\" (the % must be literal).  "
+     "During dependency scanning occurrences of A_MACRO(...) on #include "
+     "lines will be replaced by the value given with the macro argument "
+     "substituted for '%'.  For example, the entry\n"
+     "  MYDIR(%)=<mydir/%>\n"
+     "will convert lines of the form\n"
+     "  #include MYDIR(myheader.h)\n"
+     "to\n"
+     "  #include <mydir/myheader.h>\n"
+     "allowing the dependency to be followed.\n"
+     "This property applies to sources in all targets within a directory.  "
+     "The property value is initialized in each directory by its value "
+     "in the directory's parent.");
+
   cm->DefineProperty
   cm->DefineProperty
     ("EXCLUDE_FROM_ALL", cmProperty::DIRECTORY,
     ("EXCLUDE_FROM_ALL", cmProperty::DIRECTORY,
      "Exclude the directory from the all target of its parent.",
      "Exclude the directory from the all target of its parent.",

+ 18 - 0
Source/cmTarget.cxx

@@ -158,6 +158,24 @@ void cmTarget::DefineProperties(cmake *cm)
      "C++ linker (and C++ runtime libraries) for linking even if the "
      "C++ linker (and C++ runtime libraries) for linking even if the "
      "target has no C++ code in it.");
      "target has no C++ code in it.");
 
 
+  cm->DefineProperty
+    ("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM", cmProperty::TARGET,
+     "Specify #include line transforms for dependencies in a target.",
+     "This property specifies rules to transform macro-like #include lines "
+     "during implicit dependency scanning of C and C++ source files.  "
+     "The list of rules must be semicolon-separated with each entry of "
+     "the form \"A_MACRO(%)=value-with-%\" (the % must be literal).  "
+     "During dependency scanning occurrences of A_MACRO(...) on #include "
+     "lines will be replaced by the value given with the macro argument "
+     "substituted for '%'.  For example, the entry\n"
+     "  MYDIR(%)=<mydir/%>\n"
+     "will convert lines of the form\n"
+     "  #include MYDIR(myheader.h)\n"
+     "to\n"
+     "  #include <mydir/myheader.h>\n"
+     "allowing the dependency to be followed.\n"
+     "This property applies to sources in the target on which it is set.");
+
   cm->DefineProperty
   cm->DefineProperty
     ("IMPORT_PREFIX", cmProperty::TARGET,
     ("IMPORT_PREFIX", cmProperty::TARGET,
      "What comes before the import library name.",
      "What comes before the import library name.",