@ -41,6 +41,11 @@ function(cpm_utils_message level name message)
message ( ${ level } "[CPMUtil] ${name}: ${message}" )
endfunction ( )
# p r o p a g a t e a v a r i a b l e t o p a r e n t s c o p e
macro ( Propagate var )
set ( ${ var } ${ ${var } } PARENT_SCOPE )
endmacro ( )
function ( array_to_list array length out )
math ( EXPR range "${length} - 1" )
@ -72,6 +77,159 @@ function(get_json_element object out member default)
set ( "${out}" "${outvar}" PARENT_SCOPE )
endfunction ( )
# D e t e r m i n e w h e t h e r o r n o t a p a c k a g e h a s a v i a b l e s y s t e m c a n d i d a t e .
function ( SystemPackageViable JSON_NAME )
string ( JSON object GET "${CPMFILE_CONTENT}" "${JSON_NAME}" )
parse_object ( ${ object } )
string ( REPLACE " " ";" find_args "${find_args}" )
find_package ( ${ package } ${ version } ${ find_args } QUIET NO_POLICY_SCOPE )
set ( ${ pkg } _VIABLE ${ ${package } _FOUND} PARENT_SCOPE )
set ( ${ pkg } _PACKAGE ${ package } PARENT_SCOPE )
endfunction ( )
# A d d s e v e r a l p a c k a g e s s u c h t h a t i f o n e i s b u n d l e d ,
# a l l t h e r e s t m u s t a l s o b e b u n d l e d .
function ( AddDependentPackages )
set ( _some_system OFF )
set ( _some_bundled OFF )
foreach ( pkg ${ ARGN } )
SystemPackageViable ( ${ pkg } )
if ( ${ pkg } _VIABLE )
set ( _some_system ON )
list ( APPEND _system_pkgs ${ ${pkg } _PACKAGE} )
else ( )
set ( _some_bundled ON )
list ( APPEND _bundled_pkgs ${ ${pkg } _PACKAGE} )
endif ( )
endforeach ( )
if ( _some_system AND _some_bundled )
foreach ( pkg ${ ARGN } )
list ( APPEND package_names ${ ${pkg } _PACKAGE} )
endforeach ( )
string ( REPLACE ";" ", " package_names "${package_names}" )
string ( REPLACE ";" ", " bundled_names "${_bundled_pkgs}" )
foreach ( sys ${ _system_pkgs } )
list ( APPEND system_names ${ sys } _FORCE_BUNDLED )
endforeach ( )
string ( REPLACE ";" ", " system_names "${system_names}" )
message ( FATAL_ERROR "Partial dependency installation detected "
" f o r t h e f o l l o w i n g p a c k a g e s : \ n $ { p a c k a g e _ n a m e s } \ n "
" Y o u c a n s o l v e t h i s i n o n e o f t w o w a y s : \ n "
" 1 . I n s t a l l t h e f o l l o w i n g p a c k a g e s t o y o u r s y s t e m i f a v a i l a b l e : "
" \ n \ t $ { b u n d l e d _ n a m e s } \ n "
" 2 . S e t t h e f o l l o w i n g v a r i a b l e s t o O N : "
" \ n \ t $ { s y s t e m _ n a m e s } \ n "
" T h i s m a y a l s o b e c a u s e d b y a v e r s i o n m i s m a t c h , "
" s u c h a s o n e p a c k a g e b e i n g n e w e r t h a n t h e o t h e r . " )
endif ( )
foreach ( pkg ${ ARGN } )
AddJsonPackage ( ${ pkg } )
endforeach ( )
endfunction ( )
# j s o n u t i l
macro ( parse_object object )
get_json_element ( "${object}" package package ${ JSON_NAME } )
get_json_element ( "${object}" repo repo "" )
get_json_element ( "${object}" ci ci OFF )
get_json_element ( "${object}" version version "" )
if ( ci )
get_json_element ( "${object}" name name "${JSON_NAME}" )
get_json_element ( "${object}" extension extension "tar.zst" )
get_json_element ( "${object}" min_version min_version "" )
get_json_element ( "${object}" raw_disabled disabled_platforms "" )
if ( raw_disabled )
array_to_list ( "${raw_disabled}"
$ { r a w _ d i s a b l e d _ L E N G T H } d i s a b l e d _ p l a t f o r m s )
else ( )
set ( disabled_platforms "" )
endif ( )
else ( )
get_json_element ( "${object}" hash hash "" )
get_json_element ( "${object}" hash_suffix hash_suffix "" )
get_json_element ( "${object}" sha sha "" )
get_json_element ( "${object}" url url "" )
get_json_element ( "${object}" key key "" )
get_json_element ( "${object}" tag tag "" )
get_json_element ( "${object}" artifact artifact "" )
get_json_element ( "${object}" git_version git_version "" )
get_json_element ( "${object}" git_host git_host "" )
get_json_element ( "${object}" source_subdir source_subdir "" )
get_json_element ( "${object}" bundled bundled "unset" )
get_json_element ( "${object}" find_args find_args "" )
get_json_element ( "${object}" raw_patches patches "" )
# o k a y h e r e c o m e s t h e f u n p a r t : R E P L A C E M E N T S !
# f i r s t : t a g g e t s % V E R S I O N % r e p l a c e d i f a p p l i c a b l e ,
# w i t h e i t h e r git_version ( preferred ) o r v e r s i o n
# s e c o n d : a r t i f a c t g e t s % V E R S I O N % a n d % T A G % r e p l a c e d
# accordingly ( same rules for VERSION )
if ( git_version )
set ( version_replace ${ git_version } )
else ( )
set ( version_replace ${ version } )
endif ( )
# TODO ( crueter ) : f m t m o d u l e f o r c m a k e
if ( tag )
string ( REPLACE "%VERSION%" "${version_replace}" tag ${ tag } )
endif ( )
if ( artifact )
string ( REPLACE "%VERSION%" "${version_replace}"
a r t i f a c t $ { a r t i f a c t } )
string ( REPLACE "%TAG%" "${tag}" artifact ${ artifact } )
endif ( )
# f o r m a t p a t c h d i r
if ( raw_patches )
math ( EXPR range "${raw_patches_LENGTH} - 1" )
foreach ( IDX RANGE ${ range } )
string ( JSON _patch GET "${raw_patches}" "${IDX}" )
set ( full_patch
" $ { P R O J E C T _ S O U R C E _ D I R } / . p a t c h / $ { J S O N _ N A M E } / $ { _ p a t c h } " )
if ( NOT EXISTS ${ full_patch } )
cpm_utils_message ( FATAL_ERROR ${ JSON_NAME }
" s p e c i f i e s p a t c h $ { f u l l _ p a t c h } w h i c h d o e s n o t e x i s t " )
endif ( )
list ( APPEND patches "${full_patch}" )
endforeach ( )
endif ( )
# e n d f o r m a t p a t c h d i r
# o p t i o n s
get_json_element ( "${object}" raw_options options "" )
if ( raw_options )
array_to_list ( "${raw_options}" ${ raw_options_LENGTH } options )
endif ( )
set ( options ${ options } ${ JSON_OPTIONS } )
# e n d o p t i o n s
# s y s t e m / b u n d l e d
if ( bundled STREQUAL "unset" AND DEFINED JSON_BUNDLED_PACKAGE )
set ( bundled ${ JSON_BUNDLED_PACKAGE } )
endif ( )
endif ( )
endmacro ( )
# T h e p r e f e r r e d u s a g e
function ( AddJsonPackage )
set ( oneValueArgs
@ -80,7 +238,8 @@ function(AddJsonPackage)
# t h e s e a r e o v e r r i d e s t h a t c a n b e g e n e r a t e d a t r u n t i m e ,
# s o c a n b e d e f i n e d s e p a r a t e l y f r o m t h e j s o n
D O W N L O A D _ O N L Y
B U N D L E D _ P A C K A G E )
B U N D L E D _ P A C K A G E
F O R C E _ B U N D L E D _ P A C K A G E )
set ( multiValueArgs OPTIONS )
@ -111,24 +270,9 @@ function(AddJsonPackage)
cpm_utils_message ( FATAL_ERROR ${ JSON_NAME } "Not found in cpmfile" )
endif ( )
get_json_element ( "${object}" package package ${ JSON_NAME } )
get_json_element ( "${object}" repo repo "" )
get_json_element ( "${object}" ci ci OFF )
get_json_element ( "${object}" version version "" )
parse_object ( ${ object } )
if ( ci )
get_json_element ( "${object}" name name "${JSON_NAME}" )
get_json_element ( "${object}" extension extension "tar.zst" )
get_json_element ( "${object}" min_version min_version "" )
get_json_element ( "${object}" raw_disabled disabled_platforms "" )
if ( raw_disabled )
array_to_list ( "${raw_disabled}"
$ { r a w _ d i s a b l e d _ L E N G T H } d i s a b l e d _ p l a t f o r m s )
else ( )
set ( disabled_platforms "" )
endif ( )
AddCIPackage (
V E R S I O N $ { v e r s i o n }
N A M E $ { n a m e }
@ -138,116 +282,38 @@ function(AddJsonPackage)
M I N _ V E R S I O N $ { m i n _ v e r s i o n }
D I S A B L E D _ P L A T F O R M S $ { d i s a b l e d _ p l a t f o r m s } )
# p a s s s t u f f t o p a r e n t s c o p e
set ( ${ package } _ADDED "${${package}_ADDED}"
P A R E N T _ S C O P E )
set ( ${ package } _SOURCE_DIR "${${package}_SOURCE_DIR}"
P A R E N T _ S C O P E )
set ( ${ package } _BINARY_DIR "${${package}_BINARY_DIR}"
P A R E N T _ S C O P E )
return ( )
endif ( )
get_json_element ( "${object}" hash hash "" )
get_json_element ( "${object}" hash_suffix hash_suffix "" )
get_json_element ( "${object}" sha sha "" )
get_json_element ( "${object}" url url "" )
get_json_element ( "${object}" key key "" )
get_json_element ( "${object}" tag tag "" )
get_json_element ( "${object}" artifact artifact "" )
get_json_element ( "${object}" git_version git_version "" )
get_json_element ( "${object}" git_host git_host "" )
get_json_element ( "${object}" source_subdir source_subdir "" )
get_json_element ( "${object}" bundled bundled "unset" )
get_json_element ( "${object}" find_args find_args "" )
get_json_element ( "${object}" raw_patches patches "" )
# o k a y h e r e c o m e s t h e f u n p a r t : R E P L A C E M E N T S !
# f i r s t : t a g g e t s % V E R S I O N % r e p l a c e d i f a p p l i c a b l e ,
# w i t h e i t h e r git_version ( preferred ) o r v e r s i o n
# s e c o n d : a r t i f a c t g e t s % V E R S I O N % a n d % T A G % r e p l a c e d
# accordingly ( same rules for VERSION )
if ( git_version )
set ( version_replace ${ git_version } )
else ( )
set ( version_replace ${ version } )
endif ( )
# TODO ( crueter ) : f m t m o d u l e f o r c m a k e
if ( tag )
string ( REPLACE "%VERSION%" "${version_replace}" tag ${ tag } )
endif ( )
if ( artifact )
string ( REPLACE "%VERSION%" "${version_replace}" artifact ${ artifact } )
string ( REPLACE "%TAG%" "${tag}" artifact ${ artifact } )
endif ( )
# f o r m a t p a t c h d i r
if ( raw_patches )
math ( EXPR range "${raw_patches_LENGTH} - 1" )
foreach ( IDX RANGE ${ range } )
string ( JSON _patch GET "${raw_patches}" "${IDX}" )
set ( full_patch
" $ { P R O J E C T _ S O U R C E _ D I R } / . p a t c h / $ { J S O N _ N A M E } / $ { _ p a t c h } " )
if ( NOT EXISTS ${ full_patch } )
cpm_utils_message ( FATAL_ERROR ${ JSON_NAME }
" s p e c i f i e s p a t c h $ { f u l l _ p a t c h } w h i c h d o e s n o t e x i s t " )
endif ( )
list ( APPEND patches "${full_patch}" )
endforeach ( )
endif ( )
# e n d f o r m a t p a t c h d i r
# o p t i o n s
get_json_element ( "${object}" raw_options options "" )
if ( raw_options )
array_to_list ( "${raw_options}" ${ raw_options_LENGTH } options )
endif ( )
set ( options ${ options } ${ JSON_OPTIONS } )
# e n d o p t i o n s
if ( NOT DEFINED JSON_FORCE_BUNDLED_PACKAGE )
set ( JSON_FORCE_BUNDLED_PACKAGE OFF )
endif ( )
# s y s t e m / b u n d l e d
if ( bundled STREQUAL "unset" AND DEFINED JSON_BUNDLED_PACKAGE )
set ( bundled ${ JSON_BUNDLED_PACKAGE } )
AddPackage (
N A M E " $ { p a c k a g e } "
V E R S I O N " $ { v e r s i o n } "
U R L " $ { u r l } "
H A S H " $ { h a s h } "
H A S H _ S U F F I X " $ { h a s h _ s u f f i x } "
S H A " $ { s h a } "
R E P O " $ { r e p o } "
K E Y " $ { k e y } "
P A T C H E S " $ { p a t c h e s } "
O P T I O N S " $ { o p t i o n s } "
F I N D _ P A C K A G E _ A R G U M E N T S " $ { f i n d _ a r g s } "
B U N D L E D _ P A C K A G E " $ { b u n d l e d } "
F O R C E _ B U N D L E D _ P A C K A G E " $ { J S O N _ F O R C E _ B U N D L E D _ P A C K A G E } "
S O U R C E _ S U B D I R " $ { s o u r c e _ s u b d i r } "
G I T _ V E R S I O N $ { g i t _ v e r s i o n }
G I T _ H O S T $ { g i t _ h o s t }
A R T I F A C T $ { a r t i f a c t }
T A G $ { t a g } )
endif ( )
AddPackage (
N A M E " $ { p a c k a g e } "
V E R S I O N " $ { v e r s i o n } "
U R L " $ { u r l } "
H A S H " $ { h a s h } "
H A S H _ S U F F I X " $ { h a s h _ s u f f i x } "
S H A " $ { s h a } "
R E P O " $ { r e p o } "
K E Y " $ { k e y } "
P A T C H E S " $ { p a t c h e s } "
O P T I O N S " $ { o p t i o n s } "
F I N D _ P A C K A G E _ A R G U M E N T S " $ { f i n d _ a r g s } "
B U N D L E D _ P A C K A G E " $ { b u n d l e d } "
S O U R C E _ S U B D I R " $ { s o u r c e _ s u b d i r } "
G I T _ V E R S I O N $ { g i t _ v e r s i o n }
G I T _ H O S T $ { g i t _ h o s t }
A R T I F A C T $ { a r t i f a c t }
T A G $ { t a g } )
# p a s s s t u f f t o p a r e n t s c o p e
set ( ${ package } _ADDED "${${package}_ADDED}"
P A R E N T _ S C O P E )
set ( ${ package } _SOURCE_DIR "${${package}_SOURCE_DIR}"
P A R E N T _ S C O P E )
set ( ${ package } _BINARY_DIR "${${package}_BINARY_DIR}"
P A R E N T _ S C O P E )
Propagate ( ${ package } _ADDED )
Propagate ( ${ package } _SOURCE_DIR )
Propagate ( ${ package } _BINARY_DIR )
endfunction ( )
function ( AddPackage )
@ -343,7 +409,7 @@ function(AddPackage)
if ( DEFINED PKG_ARGS_ARTIFACT )
set ( pkg_url
$ { p k g _ g i t _ u r l } / r e l e a s e s / d o w n l o a d / $ { P K G _ A R G S _ T A G } / $ { P K G _ A R G S _ A R T I F A C T } )
" $ { p k g _ g i t _ u r l } / r e l e a s e s / d o w n l o a d / $ { P K G _ A R G S _ T A G } / $ { P K G _ A R G S _ A R T I F A C T } " )
else ( )
set ( pkg_url
$ { p k g _ g i t _ u r l } / a r c h i v e / r e f s / t a g s / $ { P K G _ A R G S _ T A G } . t a r . g z )
@ -625,7 +691,8 @@ function(AddCIPackage)
endif ( )
if ( DEFINED pkgname AND NOT "${pkgname}" IN_LIST DISABLED_PLATFORMS )
set ( ARTIFACT "${ARTIFACT_NAME}-${pkgname}-${ARTIFACT_VERSION}.${ARTIFACT_EXT}" )
set ( ARTIFACT
" $ { A R T I F A C T _ N A M E } - $ { p k g n a m e } - $ { A R T I F A C T _ V E R S I O N } . $ { A R T I F A C T _ E X T } " )
AddPackage (
N A M E $ { A R T I F A C T _ P A C K A G E }