CMAKE: moved GNA var setting to proper place; removed find_package when build python...
[platform/upstream/dldt.git] / inference-engine / cmake / download_and_apply.cmake
1 # Copyright (C) 2018-2019 Intel Corporation
2 # SPDX-License-Identifier: Apache-2.0
3 #
4
5 function (DownloadAndApply URL apply_to)
6
7   if (EXISTS ${apply_to})
8     file(READ ${apply_to} patchFile4Bytes LIMIT 4)
9   endif()
10   debug_message(STATUS "patchFile=" ${apply_to})
11   debug_message(STATUS "patchFile4Bytes=" ${patchFileSize} "\"")
12
13   if (NOT EXISTS ${apply_to} OR NOT patchFile4Bytes)
14     #remove empty file
15     if (EXISTS ${apply_to})
16       file(REMOVE ${apply_to})
17     endif()
18     
19     DownloadAndCheck(${URL} ${apply_to} TRUE result)
20   else ()
21     set (MIGHT_BE_APPLIED 1)
22   endif()
23
24     get_filename_component(apply_dir ${apply_to} DIRECTORY)
25     get_filename_component(patch_name ${apply_to} NAME)
26
27     # git apply silently if file wasnot downloaded :
28     #
29     if (NOT DEFINED MIGHT_BE_APPLIED)
30         debug_message(STATUS "applying patch ... ")
31     endif()
32
33 if (NOT MINGW)
34     execute_process(COMMAND git apply --verbose  ${patch_name}
35       WORKING_DIRECTORY ${apply_dir}
36       RESULT_VARIABLE rv
37       ERROR_VARIABLE err)
38 else()
39     debug_message("git patch: " ${patch_name} " not applied under MINGW, however it downloaded")
40 endif()
41
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})
47     endif()
48   
49 endfunction(DownloadAndApply)