1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/crypto/CMakeLists.txt
Jason Rhinelander b81f7025c9
Replace logging with oxen-logger
Replaces custom logging system with spdlog-based oxen logging.  This
commit mainly replaces the backend logging with the spdlog-based system,
but doesn't (yet) convert all the existing LogWarn, etc. to use the new
format-based logging.

New logging statements will look like:

    llarp::log::warning(cat, "blah: {}", val);

where `cat` should be set up in each .cpp or cluster of .cpp files, as
described in the oxen-logging README.

As part of spdlog we get fmt, which gives us nice format strings, where
are applied generously in this commit.

Making types printable now requires two steps:
- add a ToString() method
- add this specialization:

      template <>
      constexpr inline bool llarp::IsToStringFormattable<llarp::Whatever> = true;

This will then allow the type to be printed as a "{}" value in a
fmt::format string.  This is applied to all our printable types here,
and all of the `operator<<` are removed.

This commit also:
- replaces various uses of `operator<<` to ToString()
- replaces various uses of std::stringstream with either fmt::format or
  plain std::string
- Rename some to_string and toString() methods to ToString() for
  consistency (and to work with fmt)
- Replace `stringify(...)` and `make_exception` usage with fmt::format
  (and remove stringify/make_exception from util/str.hpp).
2022-07-15 22:17:59 -03:00

67 lines
2.2 KiB
CMake

add_library(lokinet-cryptography
STATIC
libntrup/src/ntru.cpp
libntrup/src/ref/randomsmall.c
libntrup/src/ref/swap.c
libntrup/src/ref/rq_round3.c
libntrup/src/ref/rq_recip3.c
libntrup/src/ref/small.c
libntrup/src/ref/rq_mult.c
libntrup/src/ref/randomweightw.c
libntrup/src/ref/random32.c
libntrup/src/ref/dec.c
libntrup/src/ref/r3_mult.c
libntrup/src/ref/r3_recip.c
libntrup/src/ref/keypair.c
libntrup/src/ref/rq_rounded.c
libntrup/src/ref/enc.c
libntrup/src/ref/int32_sort.c
libntrup/src/ref/rq.c
)
target_include_directories(lokinet-cryptography PUBLIC libntrup/include)
# The avx implementation uses runtime CPU feature detection to enable itself, so we *always* want to
# 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
libntrup/src/avx/randomsmall.c
libntrup/src/avx/weight.c
libntrup/src/avx/swap.c
libntrup/src/avx/rq_round3.c
libntrup/src/avx/rq_recip3.c
libntrup/src/avx/small.c
libntrup/src/avx/randomweightw.c
libntrup/src/avx/dec.c
libntrup/src/avx/r3_recip.c
libntrup/src/avx/keypair.c
libntrup/src/avx/rq_rounded.c
libntrup/src/avx/mult.c
libntrup/src/avx/enc.c
libntrup/src/avx/int32_sort.c
libntrup/src/avx/rq.c
libntrup/src/avx/rq_mod3.c
)
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 AND (NOT ANDROID))
target_sources(lokinet-cryptography PRIVATE ${NTRU_AVX_SRC})
set_property(SOURCE ${NTRU_AVX_SRC} APPEND PROPERTY COMPILE_FLAGS "-mavx2 -mfma")
message(STATUS "Building libntrup with runtime AVX2/FMA support")
else()
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")
endif()
enable_lto(lokinet-cryptography)
if (WARNINGS_AS_ERRORS)
target_compile_options(lokinet-cryptography PUBLIC -Wall -Wextra -Werror)
endif()
target_link_libraries(lokinet-cryptography PUBLIC sodium)