From 2159b92c18bd7d6e7502e0640dacf7c0e29906d4 Mon Sep 17 00:00:00 2001
From: Geoff Viola <geoffrey.viola@asirobots.com>
Date: Mon, 12 Oct 2015 23:00:05 -0600
Subject: [PATCH] GHS MULTI generator link with RUNTIME_OUTPUT_DIRECTORY

---
 Source/cmGhsMultiTargetGenerator.cxx | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx
index 79e3a4c..3f6d168 100644
--- a/Source/cmGhsMultiTargetGenerator.cxx
+++ b/Source/cmGhsMultiTargetGenerator.cxx
@@ -357,13 +357,12 @@ void cmGhsMultiTargetGenerator::WriteIncludes(const std::string &config,
 void cmGhsMultiTargetGenerator::WriteTargetLinkLibraries()
 {
   // library directories
-  cmTargetDependSet tds =
-    this->GetGlobalGenerator()->GetTargetDirectDepends(this->GeneratorTarget);
-  for (cmTargetDependSet::iterator tdsI = tds.begin(); tdsI != tds.end();
-       ++tdsI)
+  const std::vector<std::string>& linkDirs =
+    this->Target->GetLinkDirectories();
+  for (std::vector<std::string>::const_iterator linkDirsI = linkDirs.begin();
+      linkDirsI != linkDirs.end(); ++linkDirsI)
     {
-    const cmTarget *tg = (*tdsI)->Target;
-    *this->GetFolderBuildStreams() << "    -L\"" << GetAbsBuildFilePath(tg)
+    *this->GetFolderBuildStreams() << "    -L\"" << *linkDirsI
                                    << "\"" << std::endl;
     }
   // library targets
@@ -375,12 +374,23 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLibraries()
     std::string libName = llvI->first;
     // if it is a user defined target get the full path to the lib
     cmTarget *tg(GetGlobalGenerator()->FindTarget(libName));
+    std::string outputDirectory;
     if (NULL != tg)
       {
       libName = tg->GetName() + ".a";
+      const char* runtimeOutputDir =
+        tg->GetProperty("RUNTIME_OUTPUT_DIRECTORY");
+      if (NULL != runtimeOutputDir)
+        {
+        outputDirectory = runtimeOutputDir + std::string("/");
+        }
+      else
+        {
+        outputDirectory = GetAbsBuildFilePath(tg);
+        }
       }
-    *this->GetFolderBuildStreams() << "    -l\"" << libName << "\""
-                                   << std::endl;
+    *this->GetFolderBuildStreams() << "    -l\"" << outputDirectory
+                                   << libName << "\"" << std::endl;
     }
 }
 
-- 
1.8.1.msysgit.1

