Sfoglia il codice sorgente

Merge topic 'fileapi-install-generators'

d70a0f8681 fileapi: Fix codemodel target install destination for cross-dir rules

Acked-by: Kitware Robot <[email protected]>
Merge-request: !3639
Brad King 6 anni fa
parent
commit
7eb2fd6ca6

+ 3 - 6
Source/cmFileAPICodemodel.cxx

@@ -1144,12 +1144,9 @@ Json::Value Target::DumpInstallPrefix()
 Json::Value Target::DumpInstallDestinations()
 Json::Value Target::DumpInstallDestinations()
 {
 {
   Json::Value destinations = Json::arrayValue;
   Json::Value destinations = Json::arrayValue;
-  auto installGens = this->GT->Makefile->GetInstallGenerators();
-  for (auto iGen : installGens) {
-    auto itGen = dynamic_cast<cmInstallTargetGenerator*>(iGen);
-    if (itGen != nullptr && itGen->GetTarget() == this->GT) {
-      destinations.append(this->DumpInstallDestination(itGen));
-    }
+  auto installGens = this->GT->Target->GetInstallGenerators();
+  for (auto itGen : installGens) {
+    destinations.append(this->DumpInstallDestination(itGen));
   }
   }
   return destinations;
   return destinations;
 }
 }

+ 3 - 1
Source/cmInstallCommand.cxx

@@ -43,11 +43,13 @@ static cmInstallTargetGenerator* CreateInstallTargetGenerator(
   target.SetHaveInstallRule(true);
   target.SetHaveInstallRule(true);
   const char* component = namelink ? args.GetNamelinkComponent().c_str()
   const char* component = namelink ? args.GetNamelinkComponent().c_str()
                                    : args.GetComponent().c_str();
                                    : args.GetComponent().c_str();
-  return new cmInstallTargetGenerator(
+  auto g = new cmInstallTargetGenerator(
     target.GetName(), destination.c_str(), impLib,
     target.GetName(), destination.c_str(), impLib,
     args.GetPermissions().c_str(), args.GetConfigurations(), component,
     args.GetPermissions().c_str(), args.GetConfigurations(), component,
     message, args.GetExcludeFromAll(), args.GetOptional() || forceOpt,
     message, args.GetExcludeFromAll(), args.GetOptional() || forceOpt,
     backtrace);
     backtrace);
+  target.AddInstallGenerator(g);
+  return g;
 }
 }
 
 
 static cmInstallTargetGenerator* CreateInstallTargetGenerator(
 static cmInstallTargetGenerator* CreateInstallTargetGenerator(

+ 12 - 0
Source/cmTarget.cxx

@@ -180,6 +180,7 @@ public:
   std::vector<cmCustomCommand> PreBuildCommands;
   std::vector<cmCustomCommand> PreBuildCommands;
   std::vector<cmCustomCommand> PreLinkCommands;
   std::vector<cmCustomCommand> PreLinkCommands;
   std::vector<cmCustomCommand> PostBuildCommands;
   std::vector<cmCustomCommand> PostBuildCommands;
+  std::vector<cmInstallTargetGenerator*> InstallGenerators;
   std::set<std::string> SystemIncludeDirectories;
   std::set<std::string> SystemIncludeDirectories;
   cmTarget::LinkLibraryVectorType OriginalLinkLibraries;
   cmTarget::LinkLibraryVectorType OriginalLinkLibraries;
   std::vector<std::string> IncludeDirectoriesEntries;
   std::vector<std::string> IncludeDirectoriesEntries;
@@ -873,6 +874,17 @@ void cmTarget::SetHaveInstallRule(bool hir)
   impl->HaveInstallRule = hir;
   impl->HaveInstallRule = hir;
 }
 }
 
 
+void cmTarget::AddInstallGenerator(cmInstallTargetGenerator* g)
+{
+  impl->InstallGenerators.emplace_back(g);
+}
+
+std::vector<cmInstallTargetGenerator*> const& cmTarget::GetInstallGenerators()
+  const
+{
+  return impl->InstallGenerators;
+}
+
 bool cmTarget::GetIsGeneratorProvided() const
 bool cmTarget::GetIsGeneratorProvided() const
 {
 {
   return impl->IsGeneratorProvided;
   return impl->IsGeneratorProvided;

+ 4 - 0
Source/cmTarget.h

@@ -21,6 +21,7 @@
 
 
 class cmCustomCommand;
 class cmCustomCommand;
 class cmGlobalGenerator;
 class cmGlobalGenerator;
+class cmInstallTargetGenerator;
 class cmMakefile;
 class cmMakefile;
 class cmMessenger;
 class cmMessenger;
 class cmPropertyMap;
 class cmPropertyMap;
@@ -147,6 +148,9 @@ public:
   bool GetHaveInstallRule() const;
   bool GetHaveInstallRule() const;
   void SetHaveInstallRule(bool hir);
   void SetHaveInstallRule(bool hir);
 
 
+  void AddInstallGenerator(cmInstallTargetGenerator* g);
+  std::vector<cmInstallTargetGenerator*> const& GetInstallGenerators() const;
+
   /**
   /**
    * Get/Set whether this target was auto-created by a generator.
    * Get/Set whether this target was auto-created by a generator.
    */
    */

+ 34 - 1
Tests/RunCMake/FileAPI/codemodel-v2-check.py

@@ -2092,7 +2092,40 @@ def gen_check_targets(c, g, inSource):
             ],
             ],
             "build": "^cxx$",
             "build": "^cxx$",
             "source": "^cxx$",
             "source": "^cxx$",
-            "install": None,
+            "install": {
+                "prefix": "^(/usr/local|[A-Za-z]:.*/codemodel-v2)$",
+                "destinations": [
+                    {
+                        "path": "bin",
+                        "backtrace": [
+                            {
+                                "file": "^codemodel-v2\\.cmake$",
+                                "line": 37,
+                                "command": "install",
+                                "hasParent": True,
+                            },
+                            {
+                                "file": "^codemodel-v2\\.cmake$",
+                                "line": None,
+                                "command": None,
+                                "hasParent": True,
+                            },
+                            {
+                                "file": "^CMakeLists\\.txt$",
+                                "line": 3,
+                                "command": "include",
+                                "hasParent": True,
+                            },
+                            {
+                                "file": "^CMakeLists\\.txt$",
+                                "line": None,
+                                "command": None,
+                                "hasParent": False,
+                            },
+                        ],
+                    },
+                ],
+            },
             "link": {
             "link": {
                 "language": "CXX",
                 "language": "CXX",
                 "lto": None,
                 "lto": None,

+ 2 - 0
Tests/RunCMake/FileAPI/codemodel-v2.cmake

@@ -33,3 +33,5 @@ if(_ipo)
   set_property(TARGET c_static_lib PROPERTY INTERPROCEDURAL_OPTIMIZATION ON)
   set_property(TARGET c_static_lib PROPERTY INTERPROCEDURAL_OPTIMIZATION ON)
   file(WRITE "${CMAKE_BINARY_DIR}/ipo_enabled.txt" "")
   file(WRITE "${CMAKE_BINARY_DIR}/ipo_enabled.txt" "")
 endif()
 endif()
+
+install(TARGETS cxx_exe)