2021-11-11 14:13:22 +08:00
function ( z_vcpkg_find_acquire_program_version_check out_var )
cmake_parse_arguments ( PARSE_ARGV 1 arg
2021-11-13 03:52:32 +08:00
" E X A C T _ V E R S I O N _ M A T C H "
2021-11-11 14:13:22 +08:00
" M I N _ V E R S I O N ; P R O G R A M _ N A M E "
" C O M M A N D "
2020-06-19 06:42:20 +08:00
)
2021-11-11 14:13:22 +08:00
vcpkg_execute_in_download_mode (
C O M M A N D $ { a r g _ C O M M A N D }
W O R K I N G _ D I R E C T O R Y " $ { V C P K G _ R O O T _ D I R } "
O U T P U T _ V A R I A B L E p r o g r a m _ v e r s i o n _ o u t p u t
2019-07-10 14:17:17 +08:00
)
2021-11-11 14:13:22 +08:00
string ( STRIP "${program_version_output}" program_version_output )
#TODO: REGEX MATCH case for more complex cases!
2021-11-13 03:52:32 +08:00
set ( version_compare VERSION_GREATER_EQUAL )
set ( version_compare_msg "at least" )
if ( arg_EXACT_VERSION_MATCH )
set ( version_compare VERSION_EQUAL )
set ( version_compare_msg "exact" )
endif ( )
if ( NOT "${program_version_output}" ${ version_compare } "${arg_MIN_VERSION}" )
message ( STATUS "Found ${arg_PROGRAM_NAME}('${program_version_output}') but ${version_compare_msg} version ${arg_MIN_VERSION} is required! Trying to use internal version if possible!" )
2021-11-11 14:13:22 +08:00
set ( "${out_var}" OFF PARENT_SCOPE )
2019-05-03 13:57:43 +08:00
else ( )
2021-11-11 14:13:22 +08:00
message ( STATUS "Found external ${arg_PROGRAM_NAME}('${program_version_output}')." )
set ( "${out_var}" ON PARENT_SCOPE )
2019-05-03 13:57:43 +08:00
endif ( )
2021-11-11 14:13:22 +08:00
endfunction ( )
function ( z_vcpkg_find_acquire_program_find_external program )
cmake_parse_arguments ( PARSE_ARGV 1 arg
2021-11-13 03:52:32 +08:00
" E X A C T _ V E R S I O N _ M A T C H "
2021-11-11 14:13:22 +08:00
" I N T E R P R E T E R ; M I N _ V E R S I O N ; P R O G R A M _ N A M E "
" N A M E S ; V E R S I O N _ C O M M A N D "
2020-01-28 06:44:33 +08:00
)
2021-11-13 03:52:32 +08:00
if ( arg_EXACT_VERSION_MATCH )
set ( arg_EXACT_VERSION_MATCH EXACT_VERSION_MATCH )
endif ( )
2021-11-11 14:13:22 +08:00
if ( "${arg_INTERPRETER}" STREQUAL "" )
find_program ( "${program}" NAMES ${ arg_NAMES } )
2018-03-31 07:59:59 +08:00
else ( )
2021-12-03 07:48:34 +08:00
find_file ( SCRIPT_ ${ arg_PROGRAM_NAME } NAMES ${ arg_NAMES } )
if ( SCRIPT_ ${ arg_PROGRAM_NAME } )
vcpkg_list ( SET program_tmp ${ ${interpreter } } ${ SCRIPT_${arg_PROGRAM_NAME } } )
2021-11-11 14:13:22 +08:00
set ( "${program}" "${program_tmp}" CACHE INTERNAL "" )
2021-12-03 07:48:34 +08:00
else ( )
set ( "${program}" "" CACHE INTERNAL "" )
2021-11-11 14:13:22 +08:00
endif ( )
2021-12-03 07:48:34 +08:00
unset ( SCRIPT_ ${ arg_PROGRAM_NAME } CACHE )
2018-03-31 07:59:59 +08:00
endif ( )
2021-11-11 14:13:22 +08:00
if ( "${version_command}" STREQUAL "" )
set ( version_is_good ON ) # can't check for the version being good, so assume it is
2021-12-03 07:48:34 +08:00
elseif ( ${ program } ) # only do a version check if ${program} has a value
2021-11-11 14:13:22 +08:00
z_vcpkg_find_acquire_program_version_check ( version_is_good
2021-11-13 03:52:32 +08:00
$ { a r g _ E X A C T _ V E R S I O N _ M A T C H }
2021-11-11 14:13:22 +08:00
C O M M A N D $ { $ { p r o g r a m } } $ { a r g _ V E R S I O N _ C O M M A N D }
M I N _ V E R S I O N " $ { a r g _ M I N _ V E R S I O N } "
P R O G R A M _ N A M E " $ { a r g _ P R O G R A M _ N A M E } "
)
2018-08-23 05:04:20 +08:00
endif ( )
2021-01-13 11:49:40 +08:00
2021-11-11 14:13:22 +08:00
if ( NOT version_is_good )
unset ( "${program}" PARENT_SCOPE )
2021-11-13 03:52:32 +08:00
unset ( "${program}" CACHE )
2020-10-23 15:29:35 +08:00
endif ( )
2021-11-11 14:13:22 +08:00
endfunction ( )
2020-10-23 15:29:35 +08:00
2021-11-11 14:13:22 +08:00
function ( z_vcpkg_find_acquire_program_find_internal program )
cmake_parse_arguments ( PARSE_ARGV 1 arg
" "
" I N T E R P R E T E R "
" N A M E S ; P A T H S "
)
if ( "${arg_INTERPRETER}" STREQUAL "" )
find_program ( ${ program }
N A M E S $ { a r g _ N A M E S }
P A T H S $ { a r g _ P A T H S }
N O _ D E F A U L T _ P A T H )
2019-08-21 03:13:26 +08:00
else ( )
2021-11-11 14:13:22 +08:00
vcpkg_find_acquire_program ( "${arg_INTERPRETER}" )
find_file ( SCRIPT_ ${ program }
N A M E S $ { a r g _ N A M E S }
P A T H S $ { a r g _ P A T H S }
N O _ D E F A U L T _ P A T H )
if ( SCRIPT_ ${ program } )
2024-01-12 07:32:36 +08:00
if ( arg_INTERPRETER MATCHES "PYTHON" )
set ( "${program}" ${ ${arg_INTERPRETER } } -I ${ SCRIPT_${program } } CACHE INTERNAL "" )
else ( )
set ( "${program}" ${ ${arg_INTERPRETER } } ${ SCRIPT_${program } } CACHE INTERNAL "" )
endif ( )
2021-11-11 14:13:22 +08:00
endif ( )
2021-11-13 03:52:32 +08:00
unset ( SCRIPT_ ${ program } CACHE )
2019-08-21 03:13:26 +08:00
endif ( )
2021-11-11 14:13:22 +08:00
endfunction ( )
function ( vcpkg_find_acquire_program program )
if ( ${ program } )
return ( )
2020-08-19 03:16:39 +08:00
endif ( )
2016-09-19 11:50:08 +08:00
2021-11-11 14:13:22 +08:00
set ( raw_executable "OFF" )
set ( program_name "" )
set ( program_version "" )
set ( search_names "" )
set ( download_urls "" )
set ( download_filename "" )
set ( download_sha512 "" )
set ( rename_binary_to "" )
set ( tool_subdirectory "" )
set ( interpreter "" )
set ( post_install_command "" )
set ( paths_to_search "" )
set ( version_command "" )
vcpkg_list ( SET sourceforge_args )
set ( brew_package_name "" )
set ( apt_package_name "" )
2023-04-14 17:19:52 +08:00
set ( program_information "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/vcpkg_find_acquire_program(${program}).cmake" )
if ( program MATCHES "^[A-Z0-9]+\$" AND EXISTS "${program_information}" )
include ( "${program_information}" )
2021-11-11 14:13:22 +08:00
else ( )
2022-08-19 01:38:09 +08:00
message ( FATAL_ERROR "unknown tool ${program} -- unable to acquire." )
2017-02-10 01:13:52 +08:00
endif ( )
2021-11-11 14:13:22 +08:00
if ( "${program_name}" STREQUAL "" )
message ( FATAL_ERROR "Internal error: failed to initialize program_name for program ${program}" )
endif ( )
2020-08-26 09:41:56 +08:00
2021-11-11 14:13:22 +08:00
set ( full_subdirectory "${DOWNLOADS}/tools/${program_name}/${tool_subdirectory}" )
if ( NOT "${tool_subdirectory}" STREQUAL "" )
list ( APPEND paths_to_search ${ full_subdirectory } )
endif ( )
if ( "${full_subdirectory}" MATCHES [[^(.* ) [ / \ \ ] + $ ] ] )
# remove trailing slashes, which may turn into a trailing `\` which CMake _does not like_
set ( full_subdirectory "${CMAKE_MATCH_1}" )
2018-03-07 02:07:39 +08:00
endif ( )
2021-11-11 14:13:22 +08:00
if ( "${search_names}" STREQUAL "" )
set ( search_names "${program_name}" )
endif ( )
2020-07-14 04:43:39 +08:00
2021-11-11 14:13:22 +08:00
z_vcpkg_find_acquire_program_find_internal ( "${program}"
I N T E R P R E T E R " $ { i n t e r p r e t e r } "
P A T H S $ { p a t h s _ t o _ s e a r c h }
N A M E S $ { s e a r c h _ n a m e s }
)
if ( NOT ${ program } )
z_vcpkg_find_acquire_program_find_external ( "${program}"
2021-11-13 03:52:32 +08:00
$ { e x t r a _ s e a r c h _ a r g s }
2021-11-11 14:13:22 +08:00
P R O G R A M _ N A M E " $ { p r o g r a m _ n a m e } "
M I N _ V E R S I O N " $ { p r o g r a m _ v e r s i o n } "
I N T E R P R E T E R " $ { i n t e r p r e t e r } "
N A M E S $ { s e a r c h _ n a m e s }
V E R S I O N _ C O M M A N D $ { v e r s i o n _ c o m m a n d }
)
endif ( )
if ( NOT ${ program } )
2023-11-15 06:01:08 +08:00
if ( "${download_urls}" STREQUAL "" AND "${sourceforge_args}" STREQUAL "" )
2021-11-11 14:13:22 +08:00
set ( example "." )
if ( NOT "${brew_package_name}" STREQUAL "" AND VCPKG_HOST_IS_OSX )
set ( example ":\n brew install ${brew_package_name}" )
elseif ( NOT "${apt_package_name}" STREQUAL "" AND VCPKG_HOST_IS_LINUX )
set ( example ":\n sudo apt-get install ${apt_package_name}" )
endif ( )
message ( FATAL_ERROR "Could not find ${program_name}. Please install it via your package manager${example}" )
2020-07-14 04:43:39 +08:00
endif ( )
2021-11-11 14:13:22 +08:00
2023-11-15 06:01:08 +08:00
if ( "${sourceforge_args}" STREQUAL "" )
2021-11-11 14:13:22 +08:00
vcpkg_download_distfile ( archive_path
U R L S $ { d o w n l o a d _ u r l s }
S H A 5 1 2 " $ { d o w n l o a d _ s h a 5 1 2 } "
F I L E N A M E " $ { d o w n l o a d _ f i l e n a m e } "
)
2023-11-15 06:01:08 +08:00
else ( )
vcpkg_download_sourceforge ( archive_path
$ { s o u r c e f o r g e _ a r g s }
S H A 5 1 2 " $ { d o w n l o a d _ s h a 5 1 2 } "
F I L E N A M E " $ { d o w n l o a d _ f i l e n a m e } "
)
endif ( )
if ( raw_executable )
2021-11-11 14:13:22 +08:00
file ( MAKE_DIRECTORY "${full_subdirectory}" )
2023-11-15 06:01:08 +08:00
if ( "${rename_binary_to}" STREQUAL "" )
file ( COPY "${archive_path}"
D E S T I N A T I O N " $ { f u l l _ s u b d i r e c t o r y } "
F I L E _ P E R M I S S I O N S
O W N E R _ R E A D O W N E R _ W R I T E O W N E R _ E X E C U T E
G R O U P _ R E A D G R O U P _ E X E C U T E
W O R L D _ R E A D W O R L D _ E X E C U T E
)
2021-11-11 14:13:22 +08:00
else ( )
2023-11-15 06:01:08 +08:00
file ( INSTALL "${archive_path}"
D E S T I N A T I O N " $ { f u l l _ s u b d i r e c t o r y } "
R E N A M E " $ { r e n a m e _ b i n a r y _ t o } "
F I L E _ P E R M I S S I O N S
O W N E R _ R E A D O W N E R _ W R I T E O W N E R _ E X E C U T E
G R O U P _ R E A D G R O U P _ E X E C U T E
W O R L D _ R E A D W O R L D _ E X E C U T E
)
2021-11-11 14:13:22 +08:00
endif ( )
2023-11-15 06:01:08 +08:00
else ( )
vcpkg_extract_archive ( ARCHIVE "${archive_path}" DESTINATION "${full_subdirectory}" )
2020-07-14 04:43:39 +08:00
endif ( )
2016-09-19 11:50:08 +08:00
2021-11-11 14:13:22 +08:00
if ( NOT "${post_install_command}" STREQUAL "" )
vcpkg_execute_required_process (
A L L O W _ I N _ D O W N L O A D _ M O D E
C O M M A N D $ { p o s t _ i n s t a l l _ c o m m a n d }
W O R K I N G _ D I R E C T O R Y " $ { f u l l _ s u b d i r e c t o r y } "
L O G N A M E " $ { p r o g r a m } - t o o l - p o s t - i n s t a l l "
)
endif ( )
2021-11-13 03:52:32 +08:00
unset ( "${program}" )
2021-11-11 14:13:22 +08:00
unset ( "${program}" CACHE )
z_vcpkg_find_acquire_program_find_internal ( "${program}"
I N T E R P R E T E R " $ { i n t e r p r e t e r } "
P A T H S $ { p a t h s _ t o _ s e a r c h }
N A M E S $ { s e a r c h _ n a m e s }
)
if ( NOT ${ program } )
message ( FATAL_ERROR "Unable to find ${program}" )
endif ( )
2020-08-17 03:07:17 +08:00
endif ( )
2016-09-19 11:50:08 +08:00
2021-11-11 14:13:22 +08:00
set ( "${program}" "${${program}}" PARENT_SCOPE )
2016-09-19 11:50:08 +08:00
endfunction ( )