1 # Copyright (C) 2018-2019 Intel Corporation
2 # SPDX-License-Identifier: Apache-2.0
5 function (DownloadAndApply URL apply_to)
7 if (EXISTS ${apply_to})
8 file(READ ${apply_to} patchFile4Bytes LIMIT 4)
10 debug_message(STATUS "patchFile=" ${apply_to})
11 debug_message(STATUS "patchFile4Bytes=" ${patchFileSize} "\"")
13 if (NOT EXISTS ${apply_to} OR NOT patchFile4Bytes)
15 if (EXISTS ${apply_to})
16 file(REMOVE ${apply_to})
19 DownloadAndCheck(${URL} ${apply_to} TRUE result)
21 set (MIGHT_BE_APPLIED 1)
24 get_filename_component(apply_dir ${apply_to} DIRECTORY)
25 get_filename_component(patch_name ${apply_to} NAME)
27 # git apply silently if file wasnot downloaded :
29 if (NOT DEFINED MIGHT_BE_APPLIED)
30 debug_message(STATUS "applying patch ... ")
34 execute_process(COMMAND git apply --verbose ${patch_name}
35 WORKING_DIRECTORY ${apply_dir}
39 debug_message("git patch: " ${patch_name} " not applied under MINGW, however it downloaded")
42 #TODO:bad patch indicator either it is bad by itself of failed to apply
43 #currently cannot detect what happened
44 if (NOT DEFINED MIGHT_BE_APPLIED AND NOT (rv EQUAL 0))
45 file(REMOVE_RECURSE "${apply_to}")
46 debug_message(FATAL_ERROR "cannot apply patch ${patch_name} " ${err})
49 endfunction(DownloadAndApply)