1 # Copyright (C) 2018 Intel Corporation
3 # SPDX-License-Identifier: Apache-2.0
6 cmake_minimum_required (VERSION 2.8)
8 function (DownloadAndApply URL apply_to)
10 if (EXISTS ${apply_to})
11 file(READ ${apply_to} patchFile4Bytes LIMIT 4)
13 debug_message(STATUS "patchFile=" ${apply_to})
14 debug_message(STATUS "patchFile4Bytes=" ${patchFileSize} "\"")
16 if (NOT EXISTS ${apply_to} OR NOT patchFile4Bytes)
18 if (EXISTS ${apply_to})
19 file(REMOVE ${apply_to})
22 DownloadAndCheck(${URL} ${apply_to} TRUE result)
24 set (MIGHT_BE_APPLIED 1)
27 get_filename_component(apply_dir ${apply_to} DIRECTORY)
28 get_filename_component(patch_name ${apply_to} NAME)
30 # git apply silently if file wasnot downloaded :
32 if (NOT DEFINED MIGHT_BE_APPLIED)
33 debug_message(STATUS "applying patch ... ")
37 execute_process(COMMAND git apply --verbose ${patch_name}
38 WORKING_DIRECTORY ${apply_dir}
42 debug_message("git patch: " ${patch_name} " not applied under MINGW, however it downloaded")
45 #TODO:bad patch indicator either it is bad by itself of failed to apply
46 #currently cannot detect what happened
47 if (NOT DEFINED MIGHT_BE_APPLIED AND NOT (rv EQUAL 0))
48 file(REMOVE_RECURSE "${apply_to}")
49 debug_message(FATAL_ERROR "cannot apply patch ${patch_name} " ${err})
52 endfunction(DownloadAndApply)