Ver Fonte

Add a SYSTEM parameter to target_include_directories (#14180)

This is similar to the include_directories(SYSTEM) signature
in that it allows telling the compiler to ignore warnings from
such headers.
Stephen Kelly há 12 anos atrás
pai
commit
1925cffa08

+ 1 - 1
Source/cmTargetCompileDefinitionsCommand.cxx

@@ -60,7 +60,7 @@ std::string cmTargetCompileDefinitionsCommand
 //----------------------------------------------------------------------------
 void cmTargetCompileDefinitionsCommand
 ::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
-                                   bool)
+                                   bool, bool)
 {
   tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
 }

+ 1 - 1
Source/cmTargetCompileDefinitionsCommand.h

@@ -82,7 +82,7 @@ private:
 
   virtual void HandleDirectContent(cmTarget *tgt,
                                    const std::vector<std::string> &content,
-                                   bool prepend);
+                                   bool prepend, bool system);
   virtual std::string Join(const std::vector<std::string> &content);
 };
 

+ 1 - 1
Source/cmTargetCompileOptionsCommand.cxx

@@ -53,7 +53,7 @@ std::string cmTargetCompileOptionsCommand
 //----------------------------------------------------------------------------
 void cmTargetCompileOptionsCommand
 ::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
-                                   bool)
+                                   bool, bool)
 {
   cmListFileBacktrace lfbt;
   this->Makefile->GetBacktrace(lfbt);

+ 1 - 1
Source/cmTargetCompileOptionsCommand.h

@@ -83,7 +83,7 @@ private:
 
   virtual void HandleDirectContent(cmTarget *tgt,
                                    const std::vector<std::string> &content,
-                                   bool prepend);
+                                   bool prepend, bool system);
   virtual std::string Join(const std::vector<std::string> &content);
 };
 

+ 21 - 2
Source/cmTargetIncludeDirectoriesCommand.cxx

@@ -15,7 +15,8 @@
 bool cmTargetIncludeDirectoriesCommand
 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
 {
-  return this->HandleArguments(args, "INCLUDE_DIRECTORIES", PROCESS_BEFORE);
+  return this->HandleArguments(args, "INCLUDE_DIRECTORIES",
+                               ArgumentFlags(PROCESS_BEFORE | PROCESS_SYSTEM));
 }
 
 //----------------------------------------------------------------------------
@@ -65,10 +66,28 @@ std::string cmTargetIncludeDirectoriesCommand
 //----------------------------------------------------------------------------
 void cmTargetIncludeDirectoriesCommand
 ::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
-                      bool prepend)
+                      bool prepend, bool system)
 {
   cmListFileBacktrace lfbt;
   this->Makefile->GetBacktrace(lfbt);
   cmValueWithOrigin entry(this->Join(content), lfbt);
   tgt->InsertInclude(entry, prepend);
+  if (system)
+    {
+    tgt->AddSystemIncludeDirectories(content);
+    }
+}
+
+//----------------------------------------------------------------------------
+void cmTargetIncludeDirectoriesCommand
+::HandleInterfaceContent(cmTarget *tgt,
+                         const std::vector<std::string> &content,
+                         bool prepend, bool system)
+{
+  if (system)
+    {
+    // Error.
+    }
+  cmTargetPropCommandBase::HandleInterfaceContent(tgt, content,
+                                                  prepend, system);
 }

+ 6 - 2
Source/cmTargetIncludeDirectoriesCommand.h

@@ -54,7 +54,7 @@ public:
   virtual const char* GetFullDocumentation() const
     {
     return
-      "  target_include_directories(<target> [BEFORE] "
+      "  target_include_directories(<target> [SYSTEM] [BEFORE] "
       "<INTERFACE|PUBLIC|PRIVATE> [items1...]\n"
       "    [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])\n"
       "Specify include directories or targets to use when compiling a given "
@@ -87,7 +87,11 @@ private:
 
   virtual void HandleDirectContent(cmTarget *tgt,
                                    const std::vector<std::string> &content,
-                                   bool prepend);
+                                   bool prepend, bool system);
+  virtual void HandleInterfaceContent(cmTarget *tgt,
+                                   const std::vector<std::string> &content,
+                                   bool prepend, bool system);
+
   virtual std::string Join(const std::vector<std::string> &content);
 };
 

+ 20 - 8
Source/cmTargetPropCommandBase.cxx

@@ -48,8 +48,20 @@ bool cmTargetPropCommandBase
     return false;
     }
 
+  bool system = false;
   unsigned int argIndex = 1;
 
+  if ((flags & PROCESS_SYSTEM) && args[argIndex] == "SYSTEM")
+    {
+    if (args.size() < 4)
+      {
+      this->SetError("called with incorrect number of arguments");
+      return false;
+      }
+    system = true;
+    ++argIndex;
+    }
+
   bool prepend = false;
   if ((flags & PROCESS_BEFORE) && args[argIndex] == "BEFORE")
     {
@@ -66,7 +78,7 @@ bool cmTargetPropCommandBase
 
   while (argIndex < args.size())
     {
-    if (!this->ProcessContentArgs(args, argIndex, prepend))
+    if (!this->ProcessContentArgs(args, argIndex, prepend, system))
       {
       return false;
       }
@@ -77,7 +89,7 @@ bool cmTargetPropCommandBase
 //----------------------------------------------------------------------------
 bool cmTargetPropCommandBase
 ::ProcessContentArgs(std::vector<std::string> const& args,
-                     unsigned int &argIndex, bool prepend)
+                     unsigned int &argIndex, bool prepend, bool system)
 {
   const std::string scope = args[argIndex];
 
@@ -105,12 +117,12 @@ bool cmTargetPropCommandBase
         || args[i] == "PRIVATE"
         || args[i] == "INTERFACE" )
       {
-      this->PopulateTargetProperies(scope, content, prepend);
+      this->PopulateTargetProperies(scope, content, prepend, system);
       return true;
       }
     content.push_back(args[i]);
     }
-  this->PopulateTargetProperies(scope, content, prepend);
+  this->PopulateTargetProperies(scope, content, prepend, system);
   return true;
 }
 
@@ -118,22 +130,22 @@ bool cmTargetPropCommandBase
 void cmTargetPropCommandBase
 ::PopulateTargetProperies(const std::string &scope,
                           const std::vector<std::string> &content,
-                          bool prepend)
+                          bool prepend, bool system)
 {
   if (scope == "PRIVATE" || scope == "PUBLIC")
     {
-    this->HandleDirectContent(this->Target, content, prepend);
+    this->HandleDirectContent(this->Target, content, prepend, system);
     }
   if (scope == "INTERFACE" || scope == "PUBLIC")
     {
-    this->HandleInterfaceContent(this->Target, content, prepend);
+    this->HandleInterfaceContent(this->Target, content, prepend, system);
     }
 }
 
 //----------------------------------------------------------------------------
 void cmTargetPropCommandBase::HandleInterfaceContent(cmTarget *tgt,
                                   const std::vector<std::string> &content,
-                                  bool prepend)
+                                  bool prepend, bool)
 {
   if (prepend)
     {

+ 7 - 5
Source/cmTargetPropCommandBase.h

@@ -25,7 +25,8 @@ public:
 
   enum ArgumentFlags {
     NO_FLAGS = 0,
-    PROCESS_BEFORE = 1
+    PROCESS_BEFORE = 1,
+    PROCESS_SYSTEM = 2
   };
 
   bool HandleArguments(std::vector<std::string> const& args,
@@ -38,21 +39,22 @@ protected:
 
   virtual void HandleInterfaceContent(cmTarget *tgt,
                                    const std::vector<std::string> &content,
-                                   bool prepend);
+                                   bool prepend, bool system);
 private:
   virtual void HandleImportedTarget(const std::string &tgt) = 0;
   virtual void HandleMissingTarget(const std::string &name) = 0;
 
   virtual void HandleDirectContent(cmTarget *tgt,
                                    const std::vector<std::string> &content,
-                                   bool prepend) = 0;
+                                   bool prepend, bool system) = 0;
+
   virtual std::string Join(const std::vector<std::string> &content) = 0;
 
   bool ProcessContentArgs(std::vector<std::string> const& args,
-                          unsigned int &argIndex, bool prepend);
+                          unsigned int &argIndex, bool prepend, bool system);
   void PopulateTargetProperies(const std::string &scope,
                                const std::vector<std::string> &content,
-                               bool prepend);
+                               bool prepend, bool system);
 };
 
 #endif