summaryrefslogtreecommitdiff
path: root/Modules/ExternalProject/verify.cmake.in
blob: cd34ba95ea8bd656159481a966d305001b985c50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

cmake_minimum_required(VERSION 3.5)

set(quiet "@quiet@")
set(script_dir "@CMAKE_CURRENT_FUNCTION_LIST_DIR@/ExternalProject")
include(${script_dir}/captured_process_setup.cmake)

if("@LOCAL@" STREQUAL "")
  message(FATAL_ERROR "LOCAL can't be empty")
endif()

if(NOT EXISTS "@LOCAL@")
  message(FATAL_ERROR "File not found: @LOCAL@")
endif()

function(do_verify)
  if("@ALGO@" STREQUAL "")
    _ep_message_quiet_capture(WARNING
      "File will not be verified since no URL_HASH specified"
    )
    set(accumulated_output "${accumulated_output}" PARENT_SCOPE)
    return()
  endif()

  if("@EXPECT_VALUE@" STREQUAL "")
    _ep_message_quiet_capture(FATAL_ERROR "EXPECT_VALUE can't be empty")
  endif()

  _ep_message_quiet_capture(STATUS
"verifying file...
     file='@LOCAL@'"
  )
  set(accumulated_output "${accumulated_output}" PARENT_SCOPE)

  file("@ALGO@" "@LOCAL@" actual_value)

  if(NOT "${actual_value}" STREQUAL "@EXPECT_VALUE@")
    _ep_message_quiet_capture(FATAL_ERROR
"error: @ALGO@ hash of
  @LOCAL@
does not match expected value
  expected: '@EXPECT_VALUE@'
    actual: '${actual_value}'
")
  endif()

  _ep_message_quiet_capture(STATUS "verifying file... done")
  set(accumulated_output "${accumulated_output}" PARENT_SCOPE)
endfunction()

do_verify()

set(extract_script "@extract_script_filename@")
if(NOT "${extract_script}" STREQUAL "")
  include("${extract_script}")
endif()