2019-02-09 17:16:00 +01:00
2020-05-17 21:41:48 +02:00
add_library ( lokinet-cryptography
l i b n t r u p / s r c / n t r u . c p p
2019-02-09 17:16:00 +01:00
l i b n t r u p / s r c / r e f / r a n d o m s m a l l . c
l i b n t r u p / s r c / r e f / s w a p . c
l i b n t r u p / s r c / r e f / r q _ r o u n d 3 . c
l i b n t r u p / s r c / r e f / r q _ r e c i p 3 . c
l i b n t r u p / s r c / r e f / s m a l l . c
l i b n t r u p / s r c / r e f / r q _ m u l t . c
l i b n t r u p / s r c / r e f / r a n d o m w e i g h t w . c
l i b n t r u p / s r c / r e f / r a n d o m 3 2 . c
l i b n t r u p / s r c / r e f / d e c . c
l i b n t r u p / s r c / r e f / r 3 _ m u l t . c
l i b n t r u p / s r c / r e f / r 3 _ r e c i p . c
l i b n t r u p / s r c / r e f / k e y p a i r . c
l i b n t r u p / s r c / r e f / r q _ r o u n d e d . c
l i b n t r u p / s r c / r e f / e n c . c
l i b n t r u p / s r c / r e f / i n t 3 2 _ s o r t . c
l i b n t r u p / s r c / r e f / r q . c
)
2020-05-17 21:41:48 +02:00
target_include_directories ( lokinet-cryptography PUBLIC libntrup/include )
2019-10-31 20:30:02 +01:00
2020-01-07 23:25:44 +01:00
# The avx implementation uses runtime CPU feature detection to enable itself, so we *always* want to
2020-05-17 21:41:48 +02:00
# compile it with avx2/fma support when supported by the compiler even if we aren't compiling with
# general AVX2 enabled.
set ( NTRU_AVX_SRC
l i b n t r u p / s r c / a v x / r a n d o m s m a l l . c
l i b n t r u p / s r c / a v x / w e i g h t . c
l i b n t r u p / s r c / a v x / s w a p . c
l i b n t r u p / s r c / a v x / r q _ r o u n d 3 . c
l i b n t r u p / s r c / a v x / r q _ r e c i p 3 . c
l i b n t r u p / s r c / a v x / s m a l l . c
l i b n t r u p / s r c / a v x / r a n d o m w e i g h t w . c
l i b n t r u p / s r c / a v x / d e c . c
l i b n t r u p / s r c / a v x / r 3 _ r e c i p . c
l i b n t r u p / s r c / a v x / k e y p a i r . c
l i b n t r u p / s r c / a v x / r q _ r o u n d e d . c
l i b n t r u p / s r c / a v x / m u l t . c
l i b n t r u p / s r c / a v x / e n c . c
l i b n t r u p / s r c / a v x / i n t 3 2 _ s o r t . c
l i b n t r u p / s r c / a v x / r q . c
l i b n t r u p / s r c / a v x / r q _ m o d 3 . c
)
2020-05-18 00:59:17 +02:00
include ( CheckCXXCompilerFlag )
check_cxx_compiler_flag ( -mavx2 COMPILER_SUPPORTS_AVX2 )
check_cxx_compiler_flag ( -mfma COMPILER_SUPPORTS_FMA )
if ( COMPILER_SUPPORTS_AVX2 AND COMPILER_SUPPORTS_FMA )
2020-05-17 21:41:48 +02:00
target_sources ( lokinet-cryptography PRIVATE ${ NTRU_AVX_SRC } )
2020-05-18 00:59:17 +02:00
set_property ( SOURCE ${ NTRU_AVX_SRC } APPEND PROPERTY COMPILE_FLAGS "-mavx2 -mfma" )
message ( STATUS "Building libntrup with runtime AVX2/FMA support" )
2020-01-07 23:25:44 +01:00
else ( )
2020-05-18 00:59:17 +02:00
target_sources ( lokinet-cryptography PRIVATE libntrup/src/noavx-stubs.c )
message ( STATUS "Not building with libntrup runtime AVX2/FMA support (either this architecture doesn't support them, or your compile doesn't support the -mavx2 -mfma flags" )
2020-01-07 23:25:44 +01:00
endif ( )
2020-05-17 21:41:48 +02:00
enable_lto ( lokinet-cryptography )
add_log_tag ( lokinet-cryptography )
if ( BUILD_SHARED_LIBS )
install ( TARGETS lokinet-cryptography LIBRARY DESTINATION lib )
endif ( )
if ( WARNINGS_AS_ERRORS )
target_compile_options ( lokinet-cryptography PUBLIC -Wall -Wextra -Werror )
endif ( )
2020-01-07 23:25:44 +01:00
2019-12-17 01:50:02 +01:00
option ( DOWNLOAD_SODIUM "Allow libsodium to be downloaded and built locally if not found on the system" OFF )
2019-10-31 20:30:02 +01:00
2020-02-06 21:28:35 +01:00
# Allow -DDOWNLOAD_SODIUM=FORCE to download without even checking for a local libsodium
2020-06-17 00:17:41 +02:00
if ( ( NOT BUILD_STATIC_DEPS ) AND ( NOT DOWNLOAD_SODIUM STREQUAL "FORCE" ) )
2020-02-06 21:28:35 +01:00
find_package ( Sodium 1.0.18 )
endif ( )
2019-12-17 01:50:02 +01:00
2020-06-17 00:17:41 +02:00
if ( sodium_FOUND OR BUILD_STATIC_DEPS )
2020-05-17 21:41:48 +02:00
target_link_libraries ( lokinet-cryptography PUBLIC sodium )
2019-12-17 01:50:02 +01:00
elseif ( DOWNLOAD_SODIUM )
2020-02-02 21:34:51 +01:00
message ( STATUS "Sodium >= 1.0.18 not found, but DOWNLOAD_SODIUM specified, so downloading it" )
2019-12-17 01:50:02 +01:00
include ( DownloadLibSodium )
2020-05-17 21:41:48 +02:00
target_link_libraries ( lokinet-cryptography PUBLIC sodium_vendor )
2019-12-17 01:50:02 +01:00
else ( )
2020-02-02 21:34:51 +01:00
message ( FATAL_ERROR "Could not find libsodium >= 1.0.18; either install it on your system or use -DDOWNLOAD_SODIUM=ON to download and build an internal copy" )
2019-10-29 17:01:58 +01:00
endif ( )
2019-02-09 17:16:00 +01:00