2022-08-12 22:57:00 +00:00
if ( NOT APPLE )
return ( )
endif ( )
option ( MACOS_SYSTEM_EXTENSION
" B u i l d t h e n e t w o r k e x t e n s i o n a s a s y s t e m e x t e n s i o n r a t h e r t h a n a p l u g i n . T h i s m u s t b e O N f o r n o n - a p p s t o r e r e l e a s e b u i l d s , a n d m u s t b e O F F f o r d e v b u i l d s a n d M a c A p p S t o r e d i s t r i b u t i o n b u i l d s "
O F F )
option ( CODESIGN "codesign the resulting app and extension" ON )
set ( CODESIGN_ID "" CACHE STRING "codesign the macos app using this key identity; if empty we'll try to guess" )
set ( default_profile_type "dev" )
if ( MACOS_SYSTEM_EXTENSION )
set ( default_profile_type "release" )
endif ( )
set ( CODESIGN_PROFILE "${PROJECT_SOURCE_DIR}/contrib/macos/lokinet.${default_profile_type}.provisionprofile" CACHE FILEPATH
" P a t h t o a . p r o v i s i o n p r o f i l e t o u s e f o r t h e m a i n a p p " )
2022-08-29 18:54:46 +00:00
set ( CODESIGN_EXT_PROFILE "${PROJECT_SOURCE_DIR}/contrib/macos/lokinet-extension.${default_profile_type}.provisionprofile" CACHE FILEPATH
" P a t h t o a . p r o v i s i o n p r o f i l e t o u s e f o r t h e l o k i n e t e x t e n s i o n " )
2022-08-12 22:57:00 +00:00
if ( CODESIGN AND NOT CODESIGN_ID )
if ( MACOS_SYSTEM_EXTENSION )
set ( codesign_cert_pattern "Developer ID Application" )
else ( )
set ( codesign_cert_pattern "Apple Development" )
endif ( )
execute_process (
C O M M A N D s e c u r i t y f i n d - i d e n t i t y - v - p c o d e s i g n i n g
C O M M A N D s e d - n " s / ^ * [ 0 - 9 ] [ 0 - 9 ] * ) * \ \ ( [ A - F 0 - 9 ] \ \ { 4 0 \ \ } \ \ ) * \ " \ \ ( $ { c o d e s i g n _ c e r t _ p a t t e r n } . * \ \ ) \ " \ $ / \ \ 1 \ \ 2 / p "
R E S U L T _ V A R I A B L E f i n d _ i d _ e x i t _ c o d e
O U T P U T _ V A R I A B L E f i n d _ i d _ o u t p u t )
if ( NOT find_id_exit_code EQUAL 0 )
message ( FATAL_ERROR "Finding signing identities with security find-identity failed; try specifying an id using -DCODESIGN_ID=..." )
endif ( )
string ( REGEX MATCHALL "(^|\n)[0-9A-F]+" find_id_sign_id "${find_id_output}" )
if ( NOT find_id_sign_id )
message ( FATAL_ERROR "Did not find any \" ${ codesign_cert_pattern } \" identity; try specifying an id using -DCODESIGN_ID=... " )
endif ( )
if ( find_id_sign_id MATCHES ";" )
message ( FATAL_ERROR "Found multiple \" ${ codesign_cert_pattern } \" identities:\n ${ find_id_output } \nSpecify an identify using -DCODESIGN_ID=... " )
endif ( )
set ( CODESIGN_ID "${find_id_sign_id}" CACHE STRING "" FORCE )
endif ( )
if ( CODESIGN )
message ( STATUS "Codesigning using ${CODESIGN_ID}" )
if ( NOT MACOS_NOTARIZE_USER AND NOT MACOS_NOTARIZE_PASS AND NOT MACOS_NOTARIZE_ASC AND EXISTS "$ENV{HOME}/.notarization.cmake" )
message ( STATUS "Loading notarization info from ~/.notarization.cmake" )
include ( "$ENV{HOME}/.notarization.cmake" )
endif ( )
if ( MACOS_NOTARIZE_USER AND MACOS_NOTARIZE_PASS AND MACOS_NOTARIZE_ASC )
message ( STATUS "Enabling notarization with account ${MACOS_NOTARIZE_ASC}/${MACOS_NOTARIZE_USER}" )
else ( )
message ( WARNING "You have not set one or more of MACOS_NOTARIZE_USER, MACOS_NOTARIZE_PASS, MACOS_NOTARIZE_ASC: notarization will fail; see contrib/macos/README.txt" )
endif ( )
else ( )
message ( WARNING "Codesigning disabled; the resulting build will not run on most macOS systems" )
endif ( )
2022-08-29 18:54:46 +00:00
foreach ( prof IN ITEMS CODESIGN_PROFILE CODESIGN_EXT_PROFILE )
if ( NOT ${ prof } )
message ( WARNING "Missing a ${prof} provisioning profile: Apple will most likely log an uninformative error message to the system log and then kill harmless kittens if you try to run the result" )
elseif ( NOT EXISTS "${${prof}}" )
message ( FATAL_ERROR "Provisioning profile ${${prof}} does not exist; fix your -D${prof} path" )
endif ( )
endforeach ( )
message ( STATUS "Using ${CODESIGN_PROFILE} app provisioning profile" )
message ( STATUS "Using ${CODESIGN_EXT_PROFILE} extension provisioning profile" )
2022-08-12 22:57:00 +00:00
2022-08-29 15:53:08 +00:00
2022-08-30 17:00:58 +00:00
set ( lokinet_installer "${PROJECT_BINARY_DIR}/Lokinet ${PROJECT_VERSION}" )
2022-08-30 18:57:02 +00:00
if ( NOT CODESIGN )
set ( lokinet_installer "${lokinet_installer}-UNSIGNED" )
endif ( )
2022-08-29 15:53:08 +00:00
set ( lokinet_app "${lokinet_installer}/Lokinet.app" )
2022-08-12 22:57:00 +00:00
if ( MACOS_SYSTEM_EXTENSION )
set ( lokinet_ext_dir Contents/Library/SystemExtensions )
else ( )
set ( lokinet_ext_dir Contents/PlugIns )
endif ( )
if ( CODESIGN )
if ( MACOS_SYSTEM_EXTENSION )
set ( LOKINET_ENTITLEMENTS_TYPE sysext )
set ( notarize_py_is_sysext True )
else ( )
set ( LOKINET_ENTITLEMENTS_TYPE plugin )
set ( notarize_py_is_sysext False )
endif ( )
configure_file (
" $ { P R O J E C T _ S O U R C E _ D I R } / c o n t r i b / m a c o s / s i g n . s h . i n "
" $ { P R O J E C T _ B I N A R Y _ D I R } / s i g n . s h "
@ O N L Y )
add_custom_target (
s i g n
D E P E N D S " $ { P R O J E C T _ B I N A R Y _ D I R } / s i g n . s h "
C O M M A N D " $ { P R O J E C T _ B I N A R Y _ D I R } / s i g n . s h "
)
if ( MACOS_NOTARIZE_USER AND MACOS_NOTARIZE_PASS AND MACOS_NOTARIZE_ASC )
configure_file (
" $ { P R O J E C T _ S O U R C E _ D I R } / c o n t r i b / m a c o s / n o t a r i z e . p y . i n "
" $ { P R O J E C T _ B I N A R Y _ D I R } / n o t a r i z e . p y "
@ O N L Y )
add_custom_target (
n o t a r i z e
D E P E N D S " $ { P R O J E C T _ B I N A R Y _ D I R } / n o t a r i z e . p y " s i g n
C O M M A N D " $ { P R O J E C T _ B I N A R Y _ D I R } / n o t a r i z e . p y "
)
else ( )
message ( WARNING "You have not set one or more of MACOS_NOTARIZE_USER, MACOS_NOTARIZE_PASS, MACOS_NOTARIZE_ASC: notarization disabled" )
endif ( )
else ( )
add_custom_target ( sign COMMAND "true" )
add_custom_target ( notarize DEPENDS sign COMMAND "true" )
endif ( )
2022-08-29 15:53:08 +00:00
set ( mac_icon "${PROJECT_BINARY_DIR}/lokinet.icns" )
add_custom_command ( OUTPUT "${mac_icon}"
C O M M A N D $ { P R O J E C T _ S O U R C E _ D I R } / c o n t r i b / m a c o s / m k - i c n s . s h $ { P R O J E C T _ S O U R C E _ D I R } / c o n t r i b / l o k i n e t - m a c . s v g " $ { m a c _ i c o n } "
D E P E N D S $ { P R O J E C T _ S O U R C E _ D I R } / c o n t r i b / l o k i n e t . s v g $ { P R O J E C T _ S O U R C E _ D I R } / c o n t r i b / m a c o s / m k - i c n s . s h )
add_custom_target ( icon DEPENDS "${mac_icon}" )
if ( BUILD_PACKAGE )
2022-08-30 17:00:58 +00:00
add_executable ( seticon "${PROJECT_SOURCE_DIR}/contrib/macos/seticon.swift" )
2022-08-29 15:53:08 +00:00
add_custom_command ( OUTPUT "${lokinet_installer}.dmg"
2022-08-30 17:00:58 +00:00
D E P E N D S n o t a r i z e s e t i c o n
2022-08-29 15:53:08 +00:00
C O M M A N D c r e a t e - d m g
2022-08-30 17:00:58 +00:00
- - v o l n a m e " L o k i n e t $ { P R O J E C T _ V E R S I O N } "
2022-08-29 15:53:08 +00:00
- - v o l i c o n l o k i n e t . i c n s
#--background ... FIXME
- - t e x t - s i z e 1 6
- - i c o n - s i z e 1 2 8
- - w i n d o w - s i z e 5 0 0 3 0 0
- - i c o n L o k i n e t . a p p 1 0 0 1 0 0
- - h i d e - e x t e n s i o n L o k i n e t . a p p
- - a p p - d r o p - l i n k 3 5 0 1 0 0
- - e u l a " $ { P R O J E C T _ S O U R C E _ D I R } / L I C E N S E "
- - n o - i n t e r n e t - e n a b l e
" $ { l o k i n e t _ i n s t a l l e r } . d m g "
" $ { l o k i n e t _ i n s t a l l e r } "
2022-08-30 17:00:58 +00:00
C O M M A N D . / s e t i c o n l o k i n e t . i c n s " $ { l o k i n e t _ i n s t a l l e r } . d m g "
2022-08-29 15:53:08 +00:00
)
add_custom_target ( package DEPENDS "${lokinet_installer}.dmg" )
endif ( )
2022-08-12 22:57:00 +00:00
# Called later to set things up, after the main lokinet targets are set up
function ( macos_target_setup )
if ( MACOS_SYSTEM_EXTENSION )
target_compile_definitions ( lokinet PRIVATE MACOS_SYSTEM_EXTENSION )
endif ( )
set_target_properties ( lokinet
P R O P E R T I E S
O U T P U T _ N A M E L o k i n e t
M A C O S X _ B U N D L E T R U E
M A C O S X _ B U N D L E _ I N F O _ S T R I N G " L o k i n e t I P P a c k e t O n i o n R o u t e r "
M A C O S X _ B U N D L E _ B U N D L E _ N A M E " L o k i n e t "
M A C O S X _ B U N D L E _ B U N D L E _ V E R S I O N " $ { l o k i n e t _ V E R S I O N } "
M A C O S X _ B U N D L E _ L O N G _ V E R S I O N _ S T R I N G " $ { l o k i n e t _ V E R S I O N } "
M A C O S X _ B U N D L E _ S H O R T _ V E R S I O N _ S T R I N G " $ { l o k i n e t _ V E R S I O N _ M A J O R } . $ { l o k i n e t _ V E R S I O N _ M I N O R } "
M A C O S X _ B U N D L E _ G U I _ I D E N T I F I E R " o r g . l o k i n e t "
M A C O S X _ B U N D L E _ I N F O _ P L I S T " $ { P R O J E C T _ S O U R C E _ D I R } / c o n t r i b / m a c o s / l o k i n e t . I n f o . p l i s t . i n "
M A C O S X _ B U N D L E _ C O P Y R I G H T " © 2 0 2 2 , T h e O x e n P r o j e c t "
)
add_custom_target ( copy_bootstrap
D E P E N D S l o k i n e t - e x t e n s i o n
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t $ { P R O J E C T _ S O U R C E _ D I R } / c o n t r i b / b o o t s t r a p / m a i n n e t . s i g n e d
$ < T A R G E T _ B U N D L E _ D I R : l o k i n e t - e x t e n s i o n > / C o n t e n t s / R e s o u r c e s / b o o t s t r a p . s i g n e d
)
add_dependencies ( lokinet lokinet-extension icon )
if ( CODESIGN_PROFILE )
add_custom_target ( copy_prov_prof
D E P E N D S l o k i n e t
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t $ { C O D E S I G N _ P R O F I L E }
$ < T A R G E T _ B U N D L E _ D I R : l o k i n e t > / C o n t e n t s / e m b e d d e d . p r o v i s i o n p r o f i l e
)
else ( )
add_custom_target ( copy_prov_prof COMMAND true )
endif ( )
add_custom_target ( assemble ALL
D E P E N D S l o k i n e t l o k i n e t - e x t e n s i o n i c o n c o p y _ p r o v _ p r o f c o p y _ b o o t s t r a p
2022-08-29 15:53:08 +00:00
C O M M A N D r m - r f " $ { l o k i n e t _ a p p } "
C O M M A N D m k d i r - p " $ { l o k i n e t _ i n s t a l l e r } "
C O M M A N D c p - a $ < T A R G E T _ B U N D L E _ D I R : l o k i n e t > " $ { l o k i n e t _ a p p } "
C O M M A N D m k d i r - p " $ { l o k i n e t _ a p p } / $ { l o k i n e t _ e x t _ d i r } "
C O M M A N D c p - a $ < T A R G E T _ B U N D L E _ D I R : l o k i n e t - e x t e n s i o n > " $ { l o k i n e t _ a p p } / $ { l o k i n e t _ e x t _ d i r } / "
C O M M A N D m k d i r - p " $ { l o k i n e t _ a p p } / C o n t e n t s / R e s o u r c e s "
C O M M A N D c p - a " $ { m a c _ i c o n } " " $ { l o k i n e t _ a p p } / C o n t e n t s / R e s o u r c e s / i c o n . i c n s "
2022-08-12 22:57:00 +00:00
)
2022-08-30 18:57:02 +00:00
if ( BUILD_GUI )
2022-08-29 15:53:08 +00:00
add_dependencies ( sign assemble_gui )
2022-08-30 18:57:02 +00:00
else ( )
2022-08-12 22:57:00 +00:00
add_dependencies ( sign assemble )
endif ( )
endfunction ( )