2020-06-27 06:06:30 +08:00
## # vcpkg_from_sourceforge
##
## Download and extract a project from sourceforge.
##
## ## Usage:
## ```cmake
## vcpkg_from_sourceforge(
## OUT_SOURCE_PATH SOURCE_PATH
## REPO <cunit/CUnit>
## [REF <2.1-3>]
## SHA512 <547b417109332...>
## FILENAME <CUnit-2.1-3.tar.bz2>
## [DISABLE_SSL]
## [NO_REMOVE_ONE_LEVEL]
## [PATCHES <patch1.patch> <patch2.patch>...]
## )
## ```
##
## ## Parameters:
## ### OUT_SOURCE_PATH
## Specifies the out-variable that will contain the extracted location.
##
## This should be set to `SOURCE_PATH` by convention.
##
## ### REPO
## The organization or user and repository (optional) on sourceforge.
##
## ### REF
## A stable version number that will not change contents.
##
## ### FILENAME
## 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.
##
## For example, we can get the download link:
## https://sourceforge.net/settings/mirror_choices?projectname=mad&filename=libmad/0.15.1b/libmad-0.15.1b.tar.gz&selected=nchc
## So the REPO is `mad/libmad`, the REF is `0.15.1b`, and the FILENAME is `libmad-0.15.1b.tar.gz`
##
## For some special links:
## https://sourceforge.net/settings/mirror_choices?projectname=soxr&filename=soxr-0.1.3-Source.tar.xz&selected=nchc
## The REPO is `soxr`, REF is not exist, and the FILENAME is `soxr-0.1.3-Source.tar.xz`
##
## ### SHA512
## The SHA512 hash that should match the archive.
##
2020-07-14 04:43:39 +08:00
## ### WORKING_DIRECTORY
## If specified, the archive will be extracted into the working directory instead of `${CURRENT_BUILDTREES_DIR}/src/`.
##
## Note that the archive will still be extracted into a subfolder underneath that directory (`${WORKING_DIRECTORY}/${REF}-${HASH}/`).
##
2020-06-27 06:06:30 +08:00
## ### PATCHES
## A list of patches to be applied to the extracted sources.
##
## Relative paths are based on the port directory.
##
## ### DISABLE_SSL
## Disable ssl when downloading source.
##
## ### NO_REMOVE_ONE_LEVEL
## Specifies that the default removal of the top level folder should not occur.
##
## ## Examples:
##
## * [cunit](https://github.com/Microsoft/vcpkg/blob/master/ports/cunit/portfile.cmake)
## * [polyclipping](https://github.com/Microsoft/vcpkg/blob/master/ports/polyclipping/portfile.cmake)
## * [tinyfiledialogs](https://github.com/Microsoft/vcpkg/blob/master/ports/tinyfiledialogs/portfile.cmake)
function ( vcpkg_from_sourceforge )
2020-08-28 13:00:24 +08:00
macro ( check_file_content )
if ( EXISTS ${ ARCHIVE } )
file ( SIZE ${ ARCHIVE } DOWNLOAD_FILE_SIZE )
if ( DOWNLOAD_FILE_SIZE LESS_EQUAL 1024 )
file ( READ ${ ARCHIVE } _FILE_CONTENT_ )
string ( FIND "${_FILE_CONTENT_}" "the Sourceforge site is currently in Disaster Recovery mode." OUT_CONTENT )
message ( "OUT_CONTENT: ${OUT_CONTENT}" )
if ( OUT_CONTENT EQUAL -1 )
set ( download_success 1 )
else ( )
file ( REMOVE ${ ARCHIVE } )
endif ( )
endif ( )
endif ( )
endmacro ( )
macro ( check_file_sha512 )
file ( SHA512 ${ ARCHIVE } FILE_HASH )
if ( NOT FILE_HASH STREQUAL _vdus_SHA512 )
message ( FATAL_ERROR
" \ n F i l e d o e s n o t h a v e e x p e c t e d h a s h : \ n "
" F i l e p a t h : [ $ { A R C H I V E } ] \ n "
" E x p e c t e d h a s h : [ $ { _ v d u s _ S H A 5 1 2 } ] \ n "
" A c t u a l h a s h : [ $ { F I L E _ H A S H } ] \ n "
" $ { C U S T O M _ E R R O R _ A D V I C E } \ n " )
endif ( )
endmacro ( )
2020-06-27 06:06:30 +08:00
set ( booleanValueArgs DISABLE_SSL NO_REMOVE_ONE_LEVEL )
2020-07-14 04:43:39 +08:00
set ( oneValueArgs OUT_SOURCE_PATH REPO REF SHA512 FILENAME WORKING_DIRECTORY )
2020-06-27 06:06:30 +08:00
set ( multipleValuesArgs PATCHES )
cmake_parse_arguments ( _vdus "${booleanValueArgs}" "${oneValueArgs}" "${multipleValuesArgs}" ${ ARGN } )
if ( NOT DEFINED _vdus_OUT_SOURCE_PATH )
message ( FATAL_ERROR "OUT_SOURCE_PATH must be specified." )
endif ( )
if ( NOT DEFINED _vdus_SHA512 )
message ( FATAL_ERROR "SHA512 must be specified." )
endif ( )
if ( NOT DEFINED _vdus_REPO )
message ( FATAL_ERROR "The sourceforge repository must be specified." )
endif ( )
2020-07-14 04:43:39 +08:00
if ( DEFINED _vdus_WORKING_DIRECTORY )
set ( WORKING_DIRECTORY WORKING_DIRECTORY "${_vdus_WORKING_DIRECTORY}" )
else ( )
set ( WORKING_DIRECTORY )
endif ( )
2020-06-27 06:06:30 +08:00
if ( _vdus_DISABLE_SSL )
set ( URL_PROTOCOL http: )
else ( )
set ( URL_PROTOCOL https: )
endif ( )
2020-07-04 00:36:40 +08:00
set ( SOURCEFORGE_HOST ${ URL_PROTOCOL } //sourceforge.net/projects )
2020-06-27 06:06:30 +08:00
string ( FIND ${ _vdus_REPO } "/" FOUND_ORG )
if ( NOT FOUND_ORG EQUAL -1 )
string ( SUBSTRING "${_vdus_REPO}" 0 ${ FOUND_ORG } ORG_NAME )
math ( EXPR FOUND_ORG "${FOUND_ORG} + 1" ) # skip the slash
string ( SUBSTRING "${_vdus_REPO}" ${ FOUND_ORG } -1 REPO_NAME )
if ( REPO_NAME MATCHES "/" )
message ( FATAL_ERROR "REPO should contain at most one slash (found ${_vdus_REPO})." )
endif ( )
set ( ORG_NAME ${ ORG_NAME } / )
else ( )
2020-07-04 00:36:40 +08:00
set ( ORG_NAME ${ _vdus_REPO } / )
set ( REPO_NAME )
2020-06-27 06:06:30 +08:00
endif ( )
if ( DEFINED _vdus_REF )
2020-07-04 00:36:40 +08:00
set ( URL "${SOURCEFORGE_HOST}/${ORG_NAME}files/${REPO_NAME}/${_vdus_REF}/${_vdus_FILENAME}" )
2020-06-27 06:06:30 +08:00
else ( )
2020-07-04 00:36:40 +08:00
set ( URL "${SOURCEFORGE_HOST}/${ORG_NAME}${REPO_NAME}/files/${_vdus_FILENAME}" )
2020-06-27 06:06:30 +08:00
endif ( )
set ( NO_REMOVE_ONE_LEVEL )
if ( _vdus_NO_REMOVE_ONE_LEVEL )
set ( NO_REMOVE_ONE_LEVEL "NO_REMOVE_ONE_LEVEL" )
endif ( )
string ( SUBSTRING "${_vdus_SHA512}" 0 10 SANITIZED_REF )
2020-07-04 00:36:40 +08:00
list ( APPEND SOURCEFORGE_MIRRORS
c f h c a b l e # United States
p i l o t f i b e r # New York, NY
g i g e n e t # Chicago, IL
v e r s a w e b # Las Vegas, NV
a y e r a # Modesto, CA
n e t a c t u a t e # Durham, NC
p h o e n i x n a p # Tempe, AZ
a s t u t e i n t e r n e t # Vancouver, BC
f r e e f r # Paris, France
n e t c o l o g n e # Cologne, Germany
d e a c - r i g a # Latvia
e x c e l l m e d i a # Hyderabad, India
i w e b # Montreal, QC
j a i s t # Nomi, Japan
j z t k f t # Mezotur, Hungary
m a n a g e d w a y # Detroit, MI
n c h c # Taipei, Taiwan
n e t i x # Bulgaria
u f p r # Curitiba, Brazil
t e n e t # Wynberg, South Africa
)
# Try to use auto-select first
set ( DOWNLOAD_URL ${ URL } /download )
message ( STATUS "Trying auto-select mirror..." )
2020-06-27 06:06:30 +08:00
vcpkg_download_distfile ( ARCHIVE
2020-07-04 00:36:40 +08:00
U R L S " $ { D O W N L O A D _ U R L } "
2020-08-28 13:00:24 +08:00
S K I P _ S H A 5 1 2
2020-06-27 06:06:30 +08:00
F I L E N A M E " $ { _ v d u s _ F I L E N A M E } "
2020-07-04 00:36:40 +08:00
S I L E N T _ E X I T
2020-06-27 06:06:30 +08:00
)
2020-08-28 13:00:24 +08:00
check_file_content ( )
if ( download_success )
check_file_sha512 ( )
else ( )
message ( STATUS "The default mirror is in Disaster Recovery mode, trying other mirrors..." )
2020-07-04 00:36:40 +08:00
endif ( )
if ( NOT download_success EQUAL 1 )
foreach ( SOURCEFORGE_MIRROR ${ SOURCEFORGE_MIRRORS } )
set ( DOWNLOAD_URL ${ URL } /download?use_mirror= ${ SOURCEFORGE_MIRROR } )
message ( STATUS "Trying mirror ${SOURCEFORGE_MIRROR}..." )
vcpkg_download_distfile ( ARCHIVE
U R L S " $ { D O W N L O A D _ U R L } "
2020-08-28 13:00:24 +08:00
S K I P _ S H A 5 1 2
2020-07-04 00:36:40 +08:00
F I L E N A M E " $ { _ v d u s _ F I L E N A M E } "
S I L E N T _ E X I T
)
if ( EXISTS ${ ARCHIVE } )
set ( download_success 1 )
2020-08-28 13:00:24 +08:00
check_file_content ( )
if ( download_success )
check_file_sha512 ( )
else ( )
message ( STATUS "Mirror ${SOURCEFORGE_MIRROR} is in Disaster Recovery mode, trying other mirrors..." )
endif ( )
2020-07-04 00:36:40 +08:00
break ( )
endif ( )
endforeach ( )
endif ( )
2020-06-27 06:06:30 +08:00
2020-07-04 00:36:40 +08:00
if ( NOT download_success )
message ( FATAL_ERROR [[
C o u l d n ' t d o w n l o a d s o u r c e f r o m a n y o f t h e s o u r c e f o r g e m i r r o r s , p l e a s e c h e c k y o u r n e t w o r k .
I f y o u u s e a p r o x y , p l e a s e s e t t h e H T T P S _ P R O X Y a n d H T T P _ P R O X Y e n v i r o n m e n t
v a r i a b l e s t o " h t t p [ s ] : / / u s e r : p a s s w o r d @ y o u r - p r o x y - i p - a d d r e s s : p o r t / " .
O t h e r w i s e , p l e a s e s u b m i t a n i s s u e a t h t t p s : / / g i t h u b . c o m / M i c r o s o f t / v c p k g / i s s u e s
] ] )
endif ( )
2020-06-27 06:06:30 +08:00
vcpkg_extract_source_archive_ex (
O U T _ S O U R C E _ P A T H S O U R C E _ P A T H
A R C H I V E " $ { A R C H I V E } "
R E F " $ { S A N I T I Z E D _ R E F } "
$ { N O _ R E M O V E _ O N E _ L E V E L }
2020-07-14 04:43:39 +08:00
$ { W O R K I N G _ D I R E C T O R Y }
2020-06-27 06:06:30 +08:00
P A T C H E S $ { _ v d u s _ P A T C H E S }
)
set ( ${ _vdus_OUT_SOURCE_PATH } "${SOURCE_PATH}" PARENT_SCOPE )
endfunction ( )