Преглед изворни кода

Merge topic 'server-target-isGeneratorProvided'

afd9a339 server: return whether or not a target is generator provided

Acked-by: Kitware Robot <[email protected]>
Merge-request: !1475
Brad King пре 8 година
родитељ
комит
08f66764b3

+ 2 - 0
Help/manual/cmake-server.7.rst

@@ -486,6 +486,8 @@ Each target object can have the following keys:
   contains the current source directory.
 "buildDirectory"
   contains the current build directory.
+"isGeneratorProvided"
+  true if the target is auto-created by a generator, false otherwise
 "hasInstallRule"
   true if the target contains any install rules, false otherwise.
 "installPaths"

+ 3 - 3
Source/cmAddCustomTargetCommand.cxx

@@ -209,9 +209,9 @@ bool cmAddCustomTargetCommand::InitialPass(
   // Add the utility target to the makefile.
   bool escapeOldStyle = !verbatim;
   cmTarget* target = this->Makefile->AddUtilityCommand(
-    targetName, excludeFromAll, working_directory.c_str(), byproducts, depends,
-    commandLines, escapeOldStyle, comment, uses_terminal,
-    command_expand_lists);
+    targetName, cmMakefile::TargetOrigin::Project, excludeFromAll,
+    working_directory.c_str(), byproducts, depends, commandLines,
+    escapeOldStyle, comment, uses_terminal, command_expand_lists);
 
   // Add additional user-specified source files to the target.
   target->AddSources(sources);

+ 2 - 2
Source/cmCPluginAPI.cxx

@@ -218,8 +218,8 @@ void CCONV cmAddUtilityCommand(void* arg, const char* utilityName,
   }
 
   // Pass the call to the makefile instance.
-  mf->AddUtilityCommand(utilityName, (all ? false : true), nullptr, depends2,
-                        commandLines);
+  mf->AddUtilityCommand(utilityName, cmMakefile::TargetOrigin::Project,
+                        (all ? false : true), nullptr, depends2, commandLines);
 }
 void CCONV cmAddCustomCommand(void* arg, const char* source,
                               const char* command, int numArgs,

+ 3 - 3
Source/cmGlobalVisualStudio8Generator.cxx

@@ -225,9 +225,9 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
   }
 
   cmCustomCommandLines noCommandLines;
-  cmTarget* tgt =
-    mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
-                          no_working_directory, no_depends, noCommandLines);
+  cmTarget* tgt = mf->AddUtilityCommand(
+    CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmMakefile::TargetOrigin::Generator,
+    false, no_working_directory, no_depends, noCommandLines);
 
   cmGeneratorTarget* gt = new cmGeneratorTarget(tgt, lg);
   lg->AddGeneratorTarget(gt);

+ 2 - 2
Source/cmGlobalVisualStudioGenerator.cxx

@@ -69,8 +69,8 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets()
       // Use no actual command lines so that the target itself is not
       // considered always out of date.
       cmTarget* allBuild = gen[0]->GetMakefile()->AddUtilityCommand(
-        "ALL_BUILD", true, no_working_dir, no_depends, no_commands, false,
-        "Build all projects");
+        "ALL_BUILD", cmMakefile::TargetOrigin::Generator, true, no_working_dir,
+        no_depends, no_commands, false, "Build all projects");
 
       cmGeneratorTarget* gt = new cmGeneratorTarget(allBuild, gen[0]);
       gen[0]->AddGeneratorTarget(gt);

+ 6 - 6
Source/cmGlobalXCodeGenerator.cxx

@@ -440,9 +440,9 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
   // Add ALL_BUILD
   const char* no_working_directory = nullptr;
   std::vector<std::string> no_depends;
-  cmTarget* allbuild =
-    mf->AddUtilityCommand("ALL_BUILD", true, no_depends, no_working_directory,
-                          "echo", "Build all projects");
+  cmTarget* allbuild = mf->AddUtilityCommand(
+    "ALL_BUILD", cmMakefile::TargetOrigin::Generator, true, no_depends,
+    no_working_directory, "echo", "Build all projects");
 
   cmGeneratorTarget* allBuildGt = new cmGeneratorTarget(allbuild, root);
   root->AddGeneratorTarget(allBuildGt);
@@ -464,9 +464,9 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
     std::string file =
       this->ConvertToRelativeForMake(this->CurrentReRunCMakeMakefile.c_str());
     cmSystemTools::ReplaceString(file, "\\ ", " ");
-    cmTarget* check =
-      mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, true, no_depends,
-                            no_working_directory, "make", "-f", file.c_str());
+    cmTarget* check = mf->AddUtilityCommand(
+      CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmMakefile::TargetOrigin::Generator,
+      true, no_depends, no_working_directory, "make", "-f", file.c_str());
 
     cmGeneratorTarget* checkGt = new cmGeneratorTarget(check, root);
     root->AddGeneratorTarget(checkGt);

+ 10 - 9
Source/cmMakefile.cxx

@@ -1007,7 +1007,7 @@ void cmMakefile::AddCustomCommandOldStyle(
 }
 
 cmTarget* cmMakefile::AddUtilityCommand(
-  const std::string& utilityName, bool excludeFromAll,
+  const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
   const std::vector<std::string>& depends, const char* workingDirectory,
   const char* command, const char* arg1, const char* arg2, const char* arg3,
   const char* arg4)
@@ -1031,25 +1031,25 @@ cmTarget* cmMakefile::AddUtilityCommand(
   commandLines.push_back(commandLine);
 
   // Call the real signature of this method.
-  return this->AddUtilityCommand(utilityName, excludeFromAll, workingDirectory,
-                                 depends, commandLines);
+  return this->AddUtilityCommand(utilityName, origin, excludeFromAll,
+                                 workingDirectory, depends, commandLines);
 }
 
 cmTarget* cmMakefile::AddUtilityCommand(
-  const std::string& utilityName, bool excludeFromAll,
+  const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
   const char* workingDirectory, const std::vector<std::string>& depends,
   const cmCustomCommandLines& commandLines, bool escapeOldStyle,
   const char* comment, bool uses_terminal, bool command_expand_lists)
 {
   std::vector<std::string> no_byproducts;
-  return this->AddUtilityCommand(utilityName, excludeFromAll, workingDirectory,
-                                 no_byproducts, depends, commandLines,
-                                 escapeOldStyle, comment, uses_terminal,
-                                 command_expand_lists);
+  return this->AddUtilityCommand(utilityName, origin, excludeFromAll,
+                                 workingDirectory, no_byproducts, depends,
+                                 commandLines, escapeOldStyle, comment,
+                                 uses_terminal, command_expand_lists);
 }
 
 cmTarget* cmMakefile::AddUtilityCommand(
-  const std::string& utilityName, bool excludeFromAll,
+  const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
   const char* workingDirectory, const std::vector<std::string>& byproducts,
   const std::vector<std::string>& depends,
   const cmCustomCommandLines& commandLines, bool escapeOldStyle,
@@ -1057,6 +1057,7 @@ cmTarget* cmMakefile::AddUtilityCommand(
 {
   // Create a target instance for this utility.
   cmTarget* target = this->AddNewTarget(cmStateEnums::UTILITY, utilityName);
+  target->SetIsGeneratorProvided(origin == TargetOrigin::Generator);
   if (excludeFromAll) {
     target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
   }

+ 10 - 3
Source/cmMakefile.h

@@ -183,12 +183,19 @@ public:
                           const std::vector<std::string>& srcs,
                           bool excludeFromAll = false);
 
+  /** Where the target originated from. */
+  enum class TargetOrigin
+  {
+    Project,
+    Generator
+  };
+
   /**
    * Add a utility to the build.  A utiltity target is a command that
    * is run every time the target is built.
    */
   cmTarget* AddUtilityCommand(const std::string& utilityName,
-                              bool excludeFromAll,
+                              TargetOrigin origin, bool excludeFromAll,
                               const std::vector<std::string>& depends,
                               const char* workingDirectory,
                               const char* command, const char* arg1 = nullptr,
@@ -196,13 +203,13 @@ public:
                               const char* arg3 = nullptr,
                               const char* arg4 = nullptr);
   cmTarget* AddUtilityCommand(
-    const std::string& utilityName, bool excludeFromAll,
+    const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
     const char* workingDirectory, const std::vector<std::string>& depends,
     const cmCustomCommandLines& commandLines, bool escapeOldStyle = true,
     const char* comment = nullptr, bool uses_terminal = false,
     bool command_expand_lists = false);
   cmTarget* AddUtilityCommand(
-    const std::string& utilityName, bool excludeFromAll,
+    const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
     const char* workingDirectory, const std::vector<std::string>& byproducts,
     const std::vector<std::string>& depends,
     const cmCustomCommandLines& commandLines, bool escapeOldStyle = true,

+ 6 - 5
Source/cmQtAutoGeneratorInitializer.cxx

@@ -684,8 +684,9 @@ void cmQtAutoGeneratorInitializer::InitCustomTargets()
           ccDepends.push_back(qrc.QrcFile);
 
           cmTarget* autoRccTarget = makefile->AddUtilityCommand(
-            ccName, true, this->DirWork.c_str(), ccOutput, ccDepends,
-            commandLines, false, ccComment.c_str());
+            ccName, cmMakefile::TargetOrigin::Generator, true,
+            this->DirWork.c_str(), ccOutput, ccDepends, commandLines, false,
+            ccComment.c_str());
           // Create autogen generator target
           localGen->AddGeneratorTarget(
             new cmGeneratorTarget(autoRccTarget, localGen));
@@ -852,9 +853,9 @@ void cmQtAutoGeneratorInitializer::InitCustomTargets()
 
       // Create autogen target
       cmTarget* autogenTarget = makefile->AddUtilityCommand(
-        this->AutogenTargetName, true, this->DirWork.c_str(),
-        /*byproducts=*/autogenProvides, autogenDepends, commandLines, false,
-        autogenComment.c_str());
+        this->AutogenTargetName, cmMakefile::TargetOrigin::Generator, true,
+        this->DirWork.c_str(), /*byproducts=*/autogenProvides, autogenDepends,
+        commandLines, false, autogenComment.c_str());
       // Create autogen generator target
       localGen->AddGeneratorTarget(
         new cmGeneratorTarget(autogenTarget, localGen));

+ 1 - 0
Source/cmServerDictionary.h

@@ -95,6 +95,7 @@ static const std::string kCTEST_NAME = "ctestName";
 static const std::string kCTEST_COMMAND = "ctestCommand";
 static const std::string kCTEST_INFO = "ctestInfo";
 static const std::string kMINIMUM_CMAKE_VERSION = "minimumCMakeVersion";
+static const std::string kIS_GENERATOR_PROVIDED_KEY = "isGeneratorProvided";
 
 static const std::string kTARGET_CROSS_REFERENCES_KEY = "crossReferences";
 static const std::string kLINE_NUMBER_KEY = "line";

+ 2 - 0
Source/cmServerProtocol.cxx

@@ -889,6 +889,8 @@ static Json::Value DumpTarget(cmGeneratorTarget* target,
 
   Json::Value result = Json::objectValue;
   result[kNAME_KEY] = target->GetName();
+  result[kIS_GENERATOR_PROVIDED_KEY] =
+    target->Target->GetIsGeneratorProvided();
   result[kTYPE_KEY] = typeName;
   result[kSOURCE_DIRECTORY_KEY] = lg->GetCurrentSourceDirectory();
   result[kBUILD_DIRECTORY_KEY] = lg->GetCurrentBinaryDirectory();

+ 1 - 0
Source/cmTarget.cxx

@@ -176,6 +176,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
                    Visibility vis, cmMakefile* mf)
 {
   assert(mf);
+  this->IsGeneratorProvided = false;
   this->Name = name;
   this->TargetTypeValue = type;
   this->Makefile = mf;

+ 7 - 0
Source/cmTarget.h

@@ -180,6 +180,12 @@ public:
   bool GetHaveInstallRule() const { return this->HaveInstallRule; }
   void SetHaveInstallRule(bool h) { this->HaveInstallRule = h; }
 
+  /**
+  * Get/Set whether this target was auto-created by a generator.
+  */
+  bool GetIsGeneratorProvided() const { return this->IsGeneratorProvided; }
+  void SetIsGeneratorProvided(bool igp) { this->IsGeneratorProvided = igp; }
+
   /** Add a utility on which this project depends. A utility is an executable
    * name as would be specified to the ADD_EXECUTABLE or UTILITY_SOURCE
    * commands. It is not a full path nor does it have an extension.
@@ -284,6 +290,7 @@ private:
                             std::string const& value) const;
 
 private:
+  bool IsGeneratorProvided;
   cmPropertyMap Properties;
   std::set<std::string> SystemIncludeDirectories;
   std::set<std::string> LinkDirectoriesEmmitted;