Repository navigation
Expand file tree
/
Copy pathacquire-deps.cmake
More file actions
104 lines (74 loc) · 3.41 KB
/
Copy pathacquire-deps.cmake
File metadata and controls
104 lines (74 loc) · 3.41 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
cmake_minimum_required(VERSION 3.22)
set(ROOT ${CMAKE_CURRENT_LIST_DIR})
set(URL https://download.brisklib.com/brisk-deps/{TRIPLET}-{DEP_HASH}.tar.xz)
if (NOT DEFINED VCPKG_TARGET_TRIPLET)
message(STATUS "VCPKG_TARGET_TRIPLET is not defined, checking environment...")
if (DEFINED ENV{VCPKG_TARGET_TRIPLET})
set(VCPKG_TARGET_TRIPLET $ENV{VCPKG_TARGET_TRIPLET})
message(STATUS "Using VCPKG_TARGET_TRIPLET environment variable (${VCPKG_TARGET_TRIPLET})")
else ()
if (DEFINED ENV{VCPKG_DEFAULT_TRIPLET})
set(VCPKG_TARGET_TRIPLET $ENV{VCPKG_DEFAULT_TRIPLET})
message(STATUS "Using VCPKG_DEFAULT_TRIPLET environment variable (${VCPKG_TARGET_TRIPLET})")
else ()
message(
FATAL_ERROR
"Set VCPKG_TARGET_TRIPLET cmake variable or VCPKG_TARGET_TRIPLET or VCPKG_DEFAULT_TRIPLET environment variable"
)
endif ()
endif ()
endif ()
include(${ROOT}/cmake/get_triplet.cmake)
include(${ROOT}/cmake/dep-hash.cmake)
# Define the URL and destination file for download
string(REPLACE "{DEP_HASH}" "${DEP_HASH}" URL "${URL}")
string(REPLACE "{TRIPLET}" "${VCPKG_TARGET_TRIPLET}" URL "${URL}")
set(DEST_FILE ${ROOT}/Brisk-Dependencies-${DEP_HASH}-${VCPKG_TARGET_TRIPLET}.tar.xz)
if (NOT EXISTS ${DEST_FILE})
message(STATUS "Downloading ${URL}")
# Download the file
file(
DOWNLOAD ${URL} ${DEST_FILE}
SHOW_PROGRESS
STATUS DOWNLOAD_STATUS)
list(GET DOWNLOAD_STATUS 0 DOWNLOAD_STATUS_CODE)
if (NOT DOWNLOAD_STATUS_CODE EQUAL 0)
if (DEFINED DEP_BUILD AND NOT DEP_BUILD)
message(FATAL_ERROR "Download failed (Status ${DOWNLOAD_STATUS_CODE}), exit")
endif ()
message(WARNING "Download failed, dependencies will be built using vcpkg (Status ${DOWNLOAD_STATUS_CODE})")
find_program(VCPKG_EXECUTABLE vcpkg)
if (NOT VCPKG_EXECUTABLE)
message(FATAL_ERROR "vcpkg not found. Please ensure vcpkg is installed and accessible in your PATH.")
endif ()
execute_process(COMMAND ${VCPKG_EXECUTABLE} install --x-install-root ${ROOT}/vcpkg_installed
${EXTRA_VCPKG_ARGS} WORKING_DIRECTORY ${ROOT} COMMAND_ERROR_IS_FATAL ANY)
endif ()
file(REMOVE_RECURSE ${ROOT}/vcpkg_exported)
else ()
message(STATUS "File ${DEST_FILE} already exists. Remove it to force re-download")
endif ()
if (DEFINED ENV{EXPORTED_DIR})
set(EXPORTED_DIR $ENV{EXPORTED_DIR})
else ()
set(EXPORTED_DIR ${ROOT}/vcpkg_exported)
endif ()
if (NOT EXISTS ${EXPORTED_DIR})
message(STATUS "Extracting archive")
# Create the vcpkg_exported directory
file(MAKE_DIRECTORY ${EXPORTED_DIR})
# Extract the archive
file(ARCHIVE_EXTRACT INPUT "${DEST_FILE}" DESTINATION "${EXPORTED_DIR}" VERBOSE)
if (NOT DEFINED INSTALL OR INSTALL)
file(GLOB VCPKG_INSTALLED_CONTENTS ${ROOT}/vcpkg_installed/*)
if (NOT VCPKG_INSTALLED_CONTENTS STREQUAL "")
message(
FATAL_ERROR "${ROOT}/vcpkg_installed is not empty. Remove it and run the script again to install dependencies")
endif ()
file(REMOVE_RECURSE ${ROOT}/vcpkg_installed)
file(RENAME ${EXPORTED_DIR}/installed ${ROOT}/vcpkg_installed)
endif ()
else ()
message(STATUS "Directory ${EXPORTED_DIR} already exists. Remove it to force extraction from the archive")
endif ()
message(STATUS "All operations finished")