include(BundleUtilities)

function(gp_item_default_embedded_path_override item default_embedded_path_var)
  set(${default_embedded_path_var} "@executable_path/../lib" PARENT_SCOPE)
endfunction(gp_item_default_embedded_path_override)

set(K3D_BUNDLE_DYLIBS "")
file(GLOB_RECURSE dylib_list "${CMAKE_INSTALL_PREFIX}/*.so" "${CMAKE_INSTALL_PREFIX}/*.dylib" "${CMAKE_INSTALL_PREFIX}/*.module")
foreach(lib ${dylib_list})
  if(NOT IS_SYMLINK ${lib})
    list(APPEND K3D_BUNDLE_DYLIBS ${lib})
  endif()
endforeach()

set(DEP_LIB_DIRS "/opt/local/lib")
message("prefix path: ${CMAKE_PREFIX_PATH}")
foreach(prefix_path @CMAKE_PREFIX_PATH@)
  list(APPEND DEP_LIB_DIRS "${prefix_path}/lib" )
endforeach()
list(APPEND DEP_LIB_DIRS @BOOST_ROOT@)

message("Getting dependencies from ${DEP_LIB_DIRS}")

fixup_bundle(${CMAKE_INSTALL_PREFIX}/bin/k3d "${K3D_BUNDLE_DYLIBS}" "${DEP_LIB_DIRS}")
verify_bundle_prerequisites(${CMAKE_INSTALL_PREFIX} verify_result verify_info)
message("Bundle verify returned ${verify_result} with info ${verify_info}")