]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/tools/vcpkg/scripts/cmake/vcpkg_from_sourceforge.cmake
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / tools / vcpkg / scripts / cmake / vcpkg_from_sourceforge.cmake
1 #[===[.md:
2 # vcpkg_from_sourceforge
3
4 Download and extract a project from sourceforge.
5
6 ## Usage:
7 ```cmake
8 vcpkg_from_sourceforge(
9 OUT_SOURCE_PATH SOURCE_PATH
10 REPO <cunit/CUnit>
11 [REF <2.1-3>]
12 SHA512 <547b417109332...>
13 FILENAME <CUnit-2.1-3.tar.bz2>
14 [DISABLE_SSL]
15 [NO_REMOVE_ONE_LEVEL]
16 [PATCHES <patch1.patch> <patch2.patch>...]
17 )
18 ```
19
20 ## Parameters:
21 ### OUT_SOURCE_PATH
22 Specifies the out-variable that will contain the extracted location.
23
24 This should be set to `SOURCE_PATH` by convention.
25
26 ### REPO
27 The organization or user and repository (optional) on sourceforge.
28
29 ### REF
30 A stable version number that will not change contents.
31
32 ### FILENAME
33 The local name for the file. Files are shared between ports, so the file may need to be renamed to make it clearly attributed to this port and avoid conflicts.
34
35 For example, we can get the download link:
36 https://sourceforge.net/settings/mirror_choices?projectname=mad&filename=libmad/0.15.1b/libmad-0.15.1b.tar.gz&selected=nchc
37 So the REPO is `mad/libmad`, the REF is `0.15.1b`, and the FILENAME is `libmad-0.15.1b.tar.gz`
38
39 For some special links:
40 https://sourceforge.net/settings/mirror_choices?projectname=soxr&filename=soxr-0.1.3-Source.tar.xz&selected=nchc
41 The REPO is `soxr`, REF is not exist, and the FILENAME is `soxr-0.1.3-Source.tar.xz`
42
43 ### SHA512
44 The SHA512 hash that should match the archive.
45
46 ### WORKING_DIRECTORY
47 If specified, the archive will be extracted into the working directory instead of `${CURRENT_BUILDTREES_DIR}/src/`.
48
49 Note that the archive will still be extracted into a subfolder underneath that directory (`${WORKING_DIRECTORY}/${REF}-${HASH}/`).
50
51 ### PATCHES
52 A list of patches to be applied to the extracted sources.
53
54 Relative paths are based on the port directory.
55
56 ### DISABLE_SSL
57 Disable ssl when downloading source.
58
59 ### NO_REMOVE_ONE_LEVEL
60 Specifies that the default removal of the top level folder should not occur.
61
62 ## Examples:
63
64 * [cunit](https://github.com/Microsoft/vcpkg/blob/master/ports/cunit/portfile.cmake)
65 * [polyclipping](https://github.com/Microsoft/vcpkg/blob/master/ports/polyclipping/portfile.cmake)
66 * [tinyfiledialogs](https://github.com/Microsoft/vcpkg/blob/master/ports/tinyfiledialogs/portfile.cmake)
67 #]===]
68
69 function(vcpkg_from_sourceforge)
70 macro(check_file_content)
71 if (EXISTS ${ARCHIVE})
72 file(SIZE ${ARCHIVE} DOWNLOAD_FILE_SIZE)
73 if (DOWNLOAD_FILE_SIZE LESS_EQUAL 1024)
74 file(READ ${ARCHIVE} _FILE_CONTENT_)
75 string(FIND "${_FILE_CONTENT_}" "the Sourceforge site is currently in Disaster Recovery mode." OUT_CONTENT)
76 message("OUT_CONTENT: ${OUT_CONTENT}")
77 if (OUT_CONTENT EQUAL -1)
78 set(download_success 1)
79 else()
80 file(REMOVE ${ARCHIVE})
81 endif()
82 endif()
83 endif()
84 endmacro()
85
86 macro(check_file_sha512)
87 file(SHA512 ${ARCHIVE} FILE_HASH)
88 if(NOT FILE_HASH STREQUAL _vdus_SHA512)
89 message(FATAL_ERROR
90 "\nFile does not have expected hash:\n"
91 " File path: [ ${ARCHIVE} ]\n"
92 " Expected hash: [ ${_vdus_SHA512} ]\n"
93 " Actual hash: [ ${FILE_HASH} ]\n"
94 "${CUSTOM_ERROR_ADVICE}\n")
95 endif()
96 endmacro()
97
98 set(booleanValueArgs DISABLE_SSL NO_REMOVE_ONE_LEVEL)
99 set(oneValueArgs OUT_SOURCE_PATH REPO REF SHA512 FILENAME WORKING_DIRECTORY)
100 set(multipleValuesArgs PATCHES)
101 # parse parameters such that semicolons in options arguments to COMMAND don't get erased
102 cmake_parse_arguments(PARSE_ARGV 0 _vdus "${booleanValueArgs}" "${oneValueArgs}" "${multipleValuesArgs}")
103
104 if(NOT DEFINED _vdus_OUT_SOURCE_PATH)
105 message(FATAL_ERROR "OUT_SOURCE_PATH must be specified.")
106 endif()
107
108 if(NOT DEFINED _vdus_SHA512)
109 message(FATAL_ERROR "SHA512 must be specified.")
110 endif()
111
112 if(NOT DEFINED _vdus_REPO)
113 message(FATAL_ERROR "The sourceforge repository must be specified.")
114 endif()
115
116 if(DEFINED _vdus_WORKING_DIRECTORY)
117 set(WORKING_DIRECTORY WORKING_DIRECTORY "${_vdus_WORKING_DIRECTORY}")
118 else()
119 set(WORKING_DIRECTORY)
120 endif()
121
122 if (_vdus_DISABLE_SSL)
123 set(URL_PROTOCOL http:)
124 else()
125 set(URL_PROTOCOL https:)
126 endif()
127
128 set(SOURCEFORGE_HOST ${URL_PROTOCOL}//sourceforge.net/projects)
129
130 string(FIND ${_vdus_REPO} "/" FOUND_ORG)
131 if (NOT FOUND_ORG EQUAL -1)
132 string(SUBSTRING "${_vdus_REPO}" 0 ${FOUND_ORG} ORG_NAME)
133 math(EXPR FOUND_ORG "${FOUND_ORG} + 1") # skip the slash
134 string(SUBSTRING "${_vdus_REPO}" ${FOUND_ORG} -1 REPO_NAME)
135 if (REPO_NAME MATCHES "/")
136 message(FATAL_ERROR "REPO should contain at most one slash (found ${_vdus_REPO}).")
137 endif()
138 set(ORG_NAME ${ORG_NAME}/)
139 else()
140 set(ORG_NAME ${_vdus_REPO}/)
141 set(REPO_NAME )
142 endif()
143
144 if (DEFINED _vdus_REF)
145 set(URL "${SOURCEFORGE_HOST}/${ORG_NAME}files/${REPO_NAME}/${_vdus_REF}/${_vdus_FILENAME}")
146 else()
147 set(URL "${SOURCEFORGE_HOST}/${ORG_NAME}${REPO_NAME}/files/${_vdus_FILENAME}")
148 endif()
149
150 set(NO_REMOVE_ONE_LEVEL )
151 if (_vdus_NO_REMOVE_ONE_LEVEL)
152 set(NO_REMOVE_ONE_LEVEL "NO_REMOVE_ONE_LEVEL")
153 endif()
154
155 string(SUBSTRING "${_vdus_SHA512}" 0 10 SANITIZED_REF)
156
157 list(APPEND SOURCEFORGE_MIRRORS
158 cfhcable # United States
159 pilotfiber # New York, NY
160 gigenet # Chicago, IL
161 versaweb # Las Vegas, NV
162 ayera # Modesto, CA
163 netactuate # Durham, NC
164 phoenixnap # Tempe, AZ
165 astuteinternet # Vancouver, BC
166 freefr # Paris, France
167 netcologne # Cologne, Germany
168 deac-riga # Latvia
169 excellmedia # Hyderabad, India
170 iweb # Montreal, QC
171 jaist # Nomi, Japan
172 jztkft # Mezotur, Hungary
173 managedway # Detroit, MI
174 nchc # Taipei, Taiwan
175 netix # Bulgaria
176 ufpr # Curitiba, Brazil
177 tenet # Wynberg, South Africa
178 )
179
180 # Try to use auto-select first
181 set(DOWNLOAD_URL ${URL}/download)
182 message(STATUS "Trying auto-select mirror...")
183 vcpkg_download_distfile(ARCHIVE
184 URLS "${DOWNLOAD_URL}"
185 SKIP_SHA512
186 FILENAME "${_vdus_FILENAME}"
187 SILENT_EXIT
188 )
189 check_file_content()
190 if (download_success)
191 check_file_sha512()
192 else()
193 message(STATUS "The default mirror is in Disaster Recovery mode, trying other mirrors...")
194 endif()
195
196 if (NOT download_success EQUAL 1)
197 foreach(SOURCEFORGE_MIRROR ${SOURCEFORGE_MIRRORS})
198 set(DOWNLOAD_URL ${URL}/download?use_mirror=${SOURCEFORGE_MIRROR})
199 message(STATUS "Trying mirror ${SOURCEFORGE_MIRROR}...")
200 vcpkg_download_distfile(ARCHIVE
201 URLS "${DOWNLOAD_URL}"
202 SKIP_SHA512
203 FILENAME "${_vdus_FILENAME}"
204 SILENT_EXIT
205 )
206
207 if (EXISTS ${ARCHIVE})
208 set(download_success 1)
209 check_file_content()
210 if (download_success)
211 check_file_sha512()
212 else()
213 message(STATUS "Mirror ${SOURCEFORGE_MIRROR} is in Disaster Recovery mode, trying other mirrors...")
214 endif()
215 break()
216 endif()
217 endforeach()
218 endif()
219
220 if (NOT download_success)
221 message(FATAL_ERROR [[
222 Couldn't download source from any of the sourceforge mirrors, please check your network.
223 If you use a proxy, please set the HTTPS_PROXY and HTTP_PROXY environment
224 variables to "http[s]://user:password@your-proxy-ip-address:port/".
225 Otherwise, please submit an issue at https://github.com/Microsoft/vcpkg/issues
226 ]])
227 endif()
228
229 vcpkg_extract_source_archive_ex(
230 OUT_SOURCE_PATH SOURCE_PATH
231 ARCHIVE "${ARCHIVE}"
232 REF "${SANITIZED_REF}"
233 ${NO_REMOVE_ONE_LEVEL}
234 ${WORKING_DIRECTORY}
235 PATCHES ${_vdus_PATCHES}
236 )
237
238 set(${_vdus_OUT_SOURCE_PATH} "${SOURCE_PATH}" PARENT_SCOPE)
239 endfunction()