2 # vcpkg_from_sourceforge
4 Download and extract a project from sourceforge.
8 vcpkg_from_sourceforge(
9 OUT_SOURCE_PATH SOURCE_PATH
12 SHA512 <547b417109332...>
13 FILENAME <CUnit-2.1-3.tar.bz2>
16 [PATCHES <patch1.patch> <patch2.patch>...]
22 Specifies the out-variable that will contain the extracted location.
24 This should be set to `SOURCE_PATH` by convention.
27 The organization or user and repository (optional) on sourceforge.
30 A stable version number that will not change contents.
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.
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`
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`
44 The SHA512 hash that should match the archive.
47 If specified, the archive will be extracted into the working directory instead of `${CURRENT_BUILDTREES_DIR}/src/`.
49 Note that the archive will still be extracted into a subfolder underneath that directory (`${WORKING_DIRECTORY}/${REF}-${HASH}/`).
52 A list of patches to be applied to the extracted sources.
54 Relative paths are based on the port directory.
57 Disable ssl when downloading source.
59 ### NO_REMOVE_ONE_LEVEL
60 Specifies that the default removal of the top level folder should not occur.
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)
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)
80 file(REMOVE ${ARCHIVE})
86 macro(check_file_sha512)
87 file(SHA512 ${ARCHIVE} FILE_HASH)
88 if(NOT FILE_HASH STREQUAL _vdus_SHA512)
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")
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}")
104 if(NOT DEFINED _vdus_OUT_SOURCE_PATH)
105 message(FATAL_ERROR "OUT_SOURCE_PATH must be specified.")
108 if(NOT DEFINED _vdus_SHA512)
109 message(FATAL_ERROR "SHA512 must be specified.")
112 if(NOT DEFINED _vdus_REPO)
113 message(FATAL_ERROR "The sourceforge repository must be specified.")
116 if(DEFINED _vdus_WORKING_DIRECTORY)
117 set(WORKING_DIRECTORY WORKING_DIRECTORY "${_vdus_WORKING_DIRECTORY}")
119 set(WORKING_DIRECTORY)
122 if (_vdus_DISABLE_SSL)
123 set(URL_PROTOCOL http:)
125 set(URL_PROTOCOL https:)
128 set(SOURCEFORGE_HOST ${URL_PROTOCOL}//sourceforge.net/projects)
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}).")
138 set(ORG_NAME ${ORG_NAME}/)
140 set(ORG_NAME ${_vdus_REPO}/)
144 if (DEFINED _vdus_REF)
145 set(URL "${SOURCEFORGE_HOST}/${ORG_NAME}files/${REPO_NAME}/${_vdus_REF}/${_vdus_FILENAME}")
147 set(URL "${SOURCEFORGE_HOST}/${ORG_NAME}${REPO_NAME}/files/${_vdus_FILENAME}")
150 set(NO_REMOVE_ONE_LEVEL )
151 if (_vdus_NO_REMOVE_ONE_LEVEL)
152 set(NO_REMOVE_ONE_LEVEL "NO_REMOVE_ONE_LEVEL")
155 string(SUBSTRING "${_vdus_SHA512}" 0 10 SANITIZED_REF)
157 list(APPEND SOURCEFORGE_MIRRORS
158 cfhcable # United States
159 pilotfiber # New York, NY
160 gigenet # Chicago, IL
161 versaweb # Las Vegas, NV
163 netactuate # Durham, NC
164 phoenixnap # Tempe, AZ
165 astuteinternet # Vancouver, BC
166 freefr # Paris, France
167 netcologne # Cologne, Germany
169 excellmedia # Hyderabad, India
172 jztkft # Mezotur, Hungary
173 managedway # Detroit, MI
174 nchc # Taipei, Taiwan
176 ufpr # Curitiba, Brazil
177 tenet # Wynberg, South Africa
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}"
186 FILENAME "${_vdus_FILENAME}"
190 if (download_success)
193 message(STATUS "The default mirror is in Disaster Recovery mode, trying other mirrors...")
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}"
203 FILENAME "${_vdus_FILENAME}"
207 if (EXISTS ${ARCHIVE})
208 set(download_success 1)
210 if (download_success)
213 message(STATUS "Mirror ${SOURCEFORGE_MIRROR} is in Disaster Recovery mode, trying other mirrors...")
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
229 vcpkg_extract_source_archive_ex(
230 OUT_SOURCE_PATH SOURCE_PATH
232 REF "${SANITIZED_REF}"
233 ${NO_REMOVE_ONE_LEVEL}
235 PATCHES ${_vdus_PATCHES}
238 set(${_vdus_OUT_SOURCE_PATH} "${SOURCE_PATH}" PARENT_SCOPE)