1 # Copyright (C) 2018-2019 Intel Corporation
3 # SPDX-License-Identifier: Apache-2.0
6 function (DownloadAndApply URL apply_to)
8 if (EXISTS ${apply_to})
9 file(READ ${apply_to} patchFile4Bytes LIMIT 4)
11 debug_message(STATUS "patchFile=" ${apply_to})
12 debug_message(STATUS "patchFile4Bytes=" ${patchFileSize} "\"")
14 if (NOT EXISTS ${apply_to} OR NOT patchFile4Bytes)
16 if (EXISTS ${apply_to})
17 file(REMOVE ${apply_to})
20 DownloadAndCheck(${URL} ${apply_to} TRUE result)
22 set (MIGHT_BE_APPLIED 1)
25 get_filename_component(apply_dir ${apply_to} DIRECTORY)
26 get_filename_component(patch_name ${apply_to} NAME)
28 # git apply silently if file wasnot downloaded :
30 if (NOT DEFINED MIGHT_BE_APPLIED)
31 debug_message(STATUS "applying patch ... ")
35 execute_process(COMMAND git apply --verbose ${patch_name}
36 WORKING_DIRECTORY ${apply_dir}
40 debug_message("git patch: " ${patch_name} " not applied under MINGW, however it downloaded")
43 #TODO:bad patch indicator either it is bad by itself of failed to apply
44 #currently cannot detect what happened
45 if (NOT DEFINED MIGHT_BE_APPLIED AND NOT (rv EQUAL 0))
46 file(REMOVE_RECURSE "${apply_to}")
47 debug_message(FATAL_ERROR "cannot apply patch ${patch_name} " ${err})
50 endfunction(DownloadAndApply)