From 4120ff1efa72dfdbdf7df8b318a577330f6c7093 Mon Sep 17 00:00:00 2001
From: Andreas Schenk <andreas_schenk@hms.harvard.edu>
Date: Thu, 16 Apr 2015 17:40:06 -0400
Subject: [PATCH] fix in CopyDependencies.cmake dependency resolution

takes care of the case where the resolution of the path of a dependency already point to a library within the bundle
---
 cmake_support/CopyDependencies.cmake | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/cmake_support/CopyDependencies.cmake b/cmake_support/CopyDependencies.cmake
index f742bc84b..a146c16e9 100644
--- a/cmake_support/CopyDependencies.cmake
+++ b/cmake_support/CopyDependencies.cmake
@@ -325,17 +325,21 @@ function(change_install_names_for_item keys_var key)
       # Each referenced item's key is "rkey" in the loop:
       get_filename_component(exepath ${${key}_RESOLVED_EMBEDDED_ITEM} PATH)
       resolve_item( ${${key}_RESOLVED_EMBEDDED_ITEM} ${pr} exepath resolved_pr)
-      get_item_key("${resolved_pr}" rkey)
-      list(FIND ${keys_var} ${rkey} r_found)
-      if(r_found EQUAL -1)
-        MESSAGE(FATAL_ERROR "Key: '${rkey}' not found in dependency list. Cannot change install name.")
-      endif(r_found EQUAL -1)
-      if(NOT ${${rkey}_SYSTEMFLAG})
-        get_filename_component(ref_exepath ${${rkey}_RESOLVED_EMBEDDED_ITEM} PATH)
-        string(REPLACE ${CMAKE_INSTALL_PREFIX} "" ref_rel_path ${ref_exepath})
-        set(diff_path @loader_path${inv_rel_path}${ref_rel_path}/)
-        set(changes ${changes} "-change" "${pr}" "${diff_path}${${rkey}_ITEM}")
-      endif(NOT ${${rkey}_SYSTEMFLAG})
+      # If dependency already resolves to library within install directory we don't have to do anything.
+      if(NOT (${resolved_pr} MATCHES ${CMAKE_INSTALL_PREFIX}) AND EXISTS "${resolved_pr}" )
+        get_item_key("${resolved_pr}" rkey)
+        list(FIND ${keys_var} ${rkey} r_found)
+        if(r_found EQUAL -1)
+          message("Error while trying to get dependencies for ${${key}_RESOLVED_EMBEDDED_ITEM}.")
+          MESSAGE(FATAL_ERROR "Key: '${rkey}' not found in dependency list. Cannot change install name.")
+        endif(r_found EQUAL -1)
+        if(NOT ${${rkey}_SYSTEMFLAG})
+          get_filename_component(ref_exepath ${${rkey}_RESOLVED_EMBEDDED_ITEM} PATH)
+          string(REPLACE ${CMAKE_INSTALL_PREFIX} "" ref_rel_path ${ref_exepath})
+          set(diff_path @loader_path${inv_rel_path}${ref_rel_path}/)
+          set(changes ${changes} "-change" "${pr}" "${diff_path}${${rkey}_ITEM}")
+        endif(NOT ${${rkey}_SYSTEMFLAG})
+      endif(NOT (${resolved_pr} MATCHES ${CMAKE_INSTALL_PREFIX}) AND EXISTS "${resolved_pr}" )
     endforeach(pr)
      
     execute_process(COMMAND chmod u+w "${${key}_RESOLVED_EMBEDDED_ITEM}")
-- 
GitLab