macro (copy_dlls target)
if (BUNDLE_LIBRARIES AND WIN32)
add_custom_command(TARGET ${target} POST_BUILD
- COMMAND bash
- ARGS -c "ldd '$<TARGET_FILE:${target}>' | egrep -i '\\.dll ' | grep -iv '/c/Windows' | awk '{ print $1 }' | while read dll; do dllbasename=\"$(which \"$dll\")\"; [ -f \"${PROJECT_BINARY_DIR}/$dllbasename\" ] || cp --preserve=timestamps \"$dllbasename\" '${PROJECT_BINARY_DIR}'; done"
+ COMMAND "${PROJECT_SOURCE_DIR}/library-bundler"
+ ARGS "windows" "$<TARGET_FILE:${target}>" "${PROJECT_BINARY_DIR}"
VERBATIM
- )
+ )
endif ()
endmacro ()
--- /dev/null
+#! /usr/bin/env bash
+
+system_name="${1}"
+exe_file="${2}"
+bundle_dir="${3}"
+
+case "${system_name}" in
+ 'windows')
+ bundle_dir="$(cygpath --unix "${bundle_dir}")"
+ exe_file="$(cygpath --unix "${exe_file}")"
+ ldd "${exe_file}" \
+ | egrep -i '\.dll => /mingw64/' \
+ | sed -e 's/ (0x[0-9a-f]*)$//;s/^.* => //' \
+ | while read dll_file
+ do
+ dll_basename="$(basename "${dll_file}")"
+ cp -n --preserve=timestamps "${dll_file}" "${bundle_dir}/${dll_basename}"
+ done
+ ;;
+ *)
+ printf 'ERROR: unsupported system: %s\n' "${system_name}" >&2
+ exit 1
+ ;;
+esac