function(target_copy_dlls target imported_targets)
	if (WIN32)
		set(IMPORTED_LOCATIONS "")
		foreach(imported_target IN LISTS imported_targets)
			STRING(REGEX REPLACE "\\\\" "/" imported_target ${imported_target})
			if (TARGET ${imported_target})
				get_target_property(DLL_PATH ${imported_target} LOCATION) # known issue: need support for multiconfig build
				get_filename_component(EXT ${DLL_PATH} LAST_EXT)
				if (".dll" STREQUAL ${EXT} OR ".exe" STREQUAL ${EXT})
					LIST(APPEND IMPORTED_LOCATIONS ${DLL_PATH})
				endif()
			elseif(EXISTS ${imported_target})
				get_filename_component(EXT ${imported_target} LAST_EXT)
				set(DLL_PATH "")
				if (".dll" STREQUAL ${EXT} OR ".exe" STREQUAL ${EXT})
					set(DLL_PATH ${imported_target})
				else()
					get_filename_component(FILE_DIR ${imported_target} DIRECTORY)
					get_filename_component(FILE_NAME ${imported_target} NAME_WLE)
					string(RANDOM LENGTH 15 RANDOM_SEED 1 TEMP_POSTFIX) # we need to prevent erasing any CACHE variable with a same name
					find_file(DLL_PATH_TEMP_${TEMP_POSTFIX} ${FILE_NAME}.dll PATHS "${FILE_DIR}/" "${FILE_DIR}/../bin/")
					set(DLL_PATH ${DLL_PATH_TEMP_${TEMP_POSTFIX}})
					unset(DLL_PATH_TEMP_${TEMP_POSTFIX} CACHE)
				endif()
				if (EXISTS ${DLL_PATH})
					LIST(APPEND IMPORTED_LOCATIONS ${DLL_PATH})
				else()
					message(FATAL_ERROR "${DLL_PATH} is not a file")
				endif()
			else()
				message(FATAL_ERROR "${imported_target} is not a target or a file")
			endif()
		endforeach()
		if (IMPORTED_LOCATIONS)
			message(STATUS "
				target: ${target}
				imported targets: ${imported_targets}
				locations: ${IMPORTED_LOCATIONS}")
			if(${CMAKE_GENERATOR} MATCHES ".*Visual Studio.*")
				set(OUTPUT_POSTFIX $<CONFIG>)
			else()
				set(OUTPUT_POSTFIX "")
			endif()
			add_custom_command(TARGET ${target} POST_BUILD 
				COMMAND ${CMAKE_COMMAND} -E copy_if_different ${IMPORTED_LOCATIONS} $<TARGET_FILE_DIR:${target}>/${OUTPUT_POSTFIX}
				COMMENT "copying ${IMPORTED_LOCATIONS} into $<TARGET_FILE_DIR:${target}>/${OUTPUT_POSTFIX}")
		endif()
	endif()
endfunction()

function(target_copy_libs target imported_targets)
	if (WIN32)
		set(IMPORTED_LOCATIONS "")
		foreach(imported_target IN LISTS imported_targets)
			STRING(REGEX REPLACE "\\\\" "/" imported_target ${imported_target})
			if (TARGET ${imported_target})
				get_target_property(lib_PATH ${imported_target} LOCATION) # known issue: need support for multiconfig build
				get_filename_component(EXT ${lib_PATH} LAST_EXT)
				if (".lib" STREQUAL ${EXT} OR ".exe" STREQUAL ${EXT})
					LIST(APPEND IMPORTED_LOCATIONS ${lib_PATH})
				endif()
			elseif(EXISTS ${imported_target})
				get_filename_component(EXT ${imported_target} LAST_EXT)
				set(lib_PATH "")
				if (".lib" STREQUAL ${EXT} OR ".exe" STREQUAL ${EXT})
					set(lib_PATH ${imported_target})
				else()
					get_filename_component(FILE_DIR ${imported_target} DIRECTORY)
					get_filename_component(FILE_NAME ${imported_target} NAME_WLE)
					string(RANDOM LENGTH 15 RANDOM_SEED 1 TEMP_POSTFIX) # we need to prevent erasing any CACHE variable with a same name
					find_file(lib_PATH_TEMP_${TEMP_POSTFIX} ${FILE_NAME}.lib PATHS "${FILE_DIR}/" "${FILE_DIR}/../bin/")
					set(lib_PATH ${lib_PATH_TEMP_${TEMP_POSTFIX}})
					unset(lib_PATH_TEMP_${TEMP_POSTFIX} CACHE)
				endif()
				if (EXISTS ${lib_PATH})
					LIST(APPEND IMPORTED_LOCATIONS ${lib_PATH})
				else()
					message(FATAL_ERROR "${lib_PATH} is not a file")
				endif()
			else()
				message(FATAL_ERROR "${imported_target} is not a target or a file")
			endif()
		endforeach()
		if (IMPORTED_LOCATIONS)
			message(STATUS "
				target: ${target}
				imported targets: ${imported_targets}
				locations: ${IMPORTED_LOCATIONS}")
			if(${CMAKE_GENERATOR} MATCHES ".*Visual Studio.*")
				set(OUTPUT_POSTFIX $<CONFIG>)
			else()
				set(OUTPUT_POSTFIX "")
			endif()
			add_custom_command(TARGET ${target} POST_BUILD
					COMMAND ${CMAKE_COMMAND} -E copy_if_different ${IMPORTED_LOCATIONS} $<TARGET_FILE_DIR:${target}>/${OUTPUT_POSTFIX}
					COMMENT "copying ${IMPORTED_LOCATIONS} into $<TARGET_FILE_DIR:${target}>/${OUTPUT_POSTFIX}")
		endif()
	endif()
endfunction()