Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / cmake / extract.cmake
1 # Copyright (C) 2018-2019 Intel Corporation
2 #
3 # SPDX-License-Identifier: Apache-2.0
4 #
5
6 function (extract archive_path unpacked_path folder result)
7   # Slurped from a generated extract-TARGET.cmake file.
8   if (NOT EXISTS ${unpacked_path})
9     get_filename_component(unpacked_dir ${unpacked_path} DIRECTORY)
10
11     file(MAKE_DIRECTORY ${unpacked_path})
12
13     message(STATUS "extracting...
14          src='${archive_path}'
15          dst='${unpacked_path}'")
16
17     if(NOT EXISTS "${archive_path}")
18       message(FATAL_ERROR "error: file to extract does not exist: '${archive_path}'")
19     endif()
20
21     # Extract it:
22     #
23     # in case of archive dont have top level folder lets create it
24     if (${folder})
25       set (unpacked_dir ${unpacked_path})
26       message("unpacked_dir= ${unpacked_dir}")      
27     endif()
28
29     message(STATUS "extracting... [tar xfz]")
30     execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz ${archive_path} 
31       WORKING_DIRECTORY ${unpacked_dir}
32       RESULT_VARIABLE rv
33       ERROR_VARIABLE err)
34
35     if (NOT (err STREQUAL ""))
36       message(STATUS "error: extract of '${archive_path}' failed: ${err}")
37       #invalid archive
38       file(REMOVE_RECURSE "${unpacked_path}")
39       file(REMOVE_RECURSE "${archive_path}")
40       set(${result} 0 PARENT_SCOPE)
41     else()
42       set(${result} 1 PARENT_SCOPE)
43     endif()
44     
45   endif()
46 endfunction (extract)