set ( exetargets lokinet )
if ( APPLE )
add_executable ( lokinet lokinet.swift )
else ( )
add_executable ( lokinet lokinet.cpp )
endif ( )
add_executable ( lokinet-vpn lokinet-vpn.cpp )
enable_lto ( lokinet lokinet-vpn )
list ( APPEND exetargets lokinet-vpn )
if ( WITH_BOOTSTRAP )
add_executable ( lokinet-bootstrap lokinet-bootstrap.cpp )
list ( APPEND exetargets lokinet-bootstrap )
enable_lto ( lokinet-bootstrap )
endif ( )
if ( TRACY_ROOT )
target_sources ( lokinet PRIVATE ${ TRACY_ROOT } /TracyClient.cpp )
endif ( )
set ( should_install ON )
set ( SETCAP )
if ( CMAKE_SYSTEM_NAME MATCHES "Linux" )
option ( WITH_SETCAP "use setcap when installing" ON )
if ( WITH_SETCAP )
find_program ( SETCAP NAMES setcap HINTS /sbin /usr/sbin )
if ( SETCAP )
message ( STATUS "Found setcap binary: ${SETCAP}" )
else ( )
message ( WARNING "cannot find setcap binary you will not be able use the install targets unless you use -DWITH_SETCAP=OFF" )
set ( should_install OFF )
endif ( )
endif ( )
endif ( )
if ( WITH_BOOTSTRAP )
target_link_libraries ( lokinet-bootstrap PUBLIC cpr::cpr )
if ( NOT WIN32 )
find_package ( OpenSSL REQUIRED )
# because debian sid's curl doesn't link against openssl for some godawful cursed reason
target_link_libraries ( lokinet-bootstrap PUBLIC OpenSSL::SSL OpenSSL::Crypto )
endif ( )
endif ( )
foreach ( exe ${ exetargets } )
if ( WIN32 AND NOT MSVC_VERSION )
target_sources ( ${ exe } PRIVATE ${ CMAKE_BINARY_DIR } / ${ exe } .rc )
target_link_libraries ( ${ exe } PRIVATE -static-libstdc++ -static-libgcc --static -Wl,--pic-executable,-e,mainCRTStartup,--subsystem,console:5.00 )
target_link_libraries ( ${ exe } PRIVATE ws2_32 iphlpapi )
elseif ( CMAKE_SYSTEM_NAME MATCHES "FreeBSD" )
target_link_directories ( ${ exe } PRIVATE /usr/local/lib )
endif ( )
target_link_libraries ( ${ exe } PUBLIC liblokinet )
target_include_directories ( ${ exe } PUBLIC "${PROJECT_SOURCE_DIR}" )
if ( should_install )
if ( APPLE )
install ( TARGETS ${ exe }
B U N D L E D E S T I N A T I O N " $ { P R O J E C T _ B I N A R Y _ D I R } "
R U N T I M E D E S T I N A T I O N " . "
C O M P O N E N T l o k i n e t )
else ( )
install ( TARGETS ${ exe } RUNTIME DESTINATION bin COMPONENT lokinet )
endif ( )
endif ( )
endforeach ( )
if ( APPLE )
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 " )
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 e x t e n s i o n " )
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}" )
else ( )
message ( WARNING "Codesigning disabled; the resulting build will not run on most macOS systems" )
endif ( )
if ( MACOS_SYSTEM_EXTENSION )
set ( lokinet_ext_dir Contents/Library/SystemExtensions )
target_compile_definitions ( lokinet PRIVATE MACOS_SYSTEM_EXTENSION )
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 ( )
set ( lokinet_ext_dir Contents/PlugIns )
endif ( )
foreach ( var CODESIGN_PROFILE CODESIGN_EXT_PROFILE )
if ( NOT ${ var } )
message ( WARNING "Missing a ${var} provisioning profile, and not building a system extension: 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" )
endif ( )
if ( NOT EXISTS "${${var}}" )
message ( FATAL_ERROR "Provisioning profile ${${var}} does not exist; fix your -D${var} path" )
endif ( )
endforeach ( )
message ( STATUS "Using ${CODESIGN_PROFILE} provisioning profile" )
message ( STATUS "Using ${CODESIGN_EXT_PROFILE} extension provisioning profile" )
set ( mac_icon ${ CMAKE_CURRENT_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 . 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 ( icons DEPENDS ${ mac_icon } )
add_dependencies ( lokinet icons lokinet-extension )
set ( post_build_pp )
if ( CODESIGN AND CODESIGN_PROFILE )
set ( post_build_pp COMMAND ${ CMAKE_COMMAND } -E copy_if_different ${ CODESIGN_PROFILE }
$ < 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 )
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 _ I C O N _ F I L E " $ { m a c _ i c o 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 "
R U N T I M E _ O U T P U T _ D I R E C T O R Y " $ { P R O J E C T _ B I N A R Y _ D I R } "
)
add_custom_target ( assemble
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
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
C O M M A N D m k d i r - p $ < 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 _ 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 > $ < 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 _ e x t _ d i r }
$ { p o s t _ b u i l d _ p p } )
if ( TARGET lokinet-gui )
add_custom_target ( copy_gui
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 l o k i n e t - g u i
# FIXME: we really shouldn't be building inside the source directory but this is npm...
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ d i r e c t o r y $ { P R O J E C T _ S O U R C E _ D I R } / l o k i n e t - g u i / r e l e a s e / m a c / l o k i n e t - g u i . a p p $ < T A R G E T _ B U N D L E _ D I R : l o k i n e t >
)
add_dependencies ( assemble copy_gui )
endif ( )
if ( NOT CODESIGN )
message ( STATUS "codesigning disabled" )
add_custom_target (
s i g n
D E P E N D S a s s e m b l e
C O M M A N D " t r u e " )
elseif ( CODESIGN )
set ( SIGN_TARGET "${PROJECT_BINARY_DIR}/Lokinet.app" )
if ( MACOS_SYSTEM_EXTENSION )
set ( LOKINET_ENTITLEMENTS_TYPE sysext )
else ( )
set ( LOKINET_ENTITLEMENTS_TYPE plugin )
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 " a s s e m b l e
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 ( NOT ( MACOS_NOTARIZE_USER AND MACOS_NOTARIZE_PASS AND MACOS_NOTARIZE_ASC ) )
message ( WARNING "You have not set one or more of MACOS_NOTARIZE_USER, MACOS_NOTARIZE_PASS, MACOS_NOTARIZE_ASC: notarization disabled" )
endif ( )
if ( MACOS_SYSTEM_EXTENSION )
set ( notarize_py_is_sysext True )
else ( )
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 / 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 ( FATAL_ERROR "CODESIGN_APP (=${CODESIGN_APP}) and/or CODESIGN_EXT (=${CODESIGN_EXT}) are not set. To disable code signing use -DCODESIGN=OFF" )
endif ( )
endif ( )
if ( SETCAP )
install ( CODE "execute_process(COMMAND ${SETCAP} cap_net_admin,cap_net_bind_service=+eip ${CMAKE_INSTALL_PREFIX}/bin/lokinet)" )
endif ( )