redo cmake parts

* add liblokinet.so target
* make every library we build except liblokinet.so static
* wire up parts of liblokinet
This commit is contained in:
Jeff Becker 2021-03-08 14:19:20 -05:00
parent affd2e23f7
commit e4841917ba
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
5 changed files with 78 additions and 11 deletions

View File

@ -38,7 +38,7 @@ option(USE_AVX2 "enable avx2 code" OFF)
option(USE_NETNS "enable networking namespace support. Linux only" OFF)
option(NATIVE_BUILD "optimise for host system and FPU" ON)
option(EMBEDDED_CFG "optimise for older hardware or embedded systems" OFF)
option(BUILD_SHARED_LIBS "build lokinet libraries as shared libraries instead of static" OFF)
option(BUILD_LIBLOKINET "build liblokinet.so" ON)
option(SHADOW "use shadow testing framework. linux only" OFF)
option(XSAN "use sanitiser, if your system has it (requires -DCMAKE_BUILD_TYPE=Debug)" OFF)
option(WITH_JEMALLOC "use jemalloc as allocator" OFF)

View File

@ -1,5 +1,6 @@
add_library(lokinet-cryptography
STATIC
libntrup/src/ntru.cpp
libntrup/src/ref/randomsmall.c
libntrup/src/ref/swap.c
@ -58,10 +59,6 @@ endif()
enable_lto(lokinet-cryptography)
add_log_tag(lokinet-cryptography)
if(BUILD_SHARED_LIBS)
install(TARGETS lokinet-cryptography LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
if (WARNINGS_AS_ERRORS)
target_compile_options(lokinet-cryptography PUBLIC -Wall -Wextra -Werror)
endif()

View File

@ -2,6 +2,7 @@
#define LOKINET_H
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C"

View File

@ -1,6 +1,7 @@
include(Version)
add_library(lokinet-util
STATIC
${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp
util/bencode.cpp
util/buffer.cpp
@ -47,7 +48,8 @@ if(ANDROID)
endif()
add_library(lokinet-platform
# for networking
STATIC
# for networking
ev/ev.cpp
ev/ev_libuv.cpp
net/ip.cpp
@ -91,6 +93,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
endif()
add_library(liblokinet
STATIC
config/config.cpp
config/definition.cpp
config/ini.cpp
@ -230,13 +233,16 @@ target_link_libraries(liblokinet PUBLIC cxxopts lokinet-platform lokinet-util lo
target_link_libraries(liblokinet PRIVATE libunbound)
if(BUILD_SHARED_LIBS)
if(BUILD_LIBLOKINET)
include(GNUInstallDirs)
install(TARGETS lokinet-util lokinet-platform liblokinet LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
add_library(lokinet-shared SHARED lokinet_shared.cpp)
set_target_properties(lokinet-shared PROPERTIES OUTPUT_NAME lokinet)
target_link_libraries(lokinet-shared liblokinet)
install(TARGETS lokinet-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(WIN32)
target_link_libraries(liblokinet PUBLIC ws2_32 iphlpapi)
target_link_libraries(lokinet-shared PUBLIC ws2_32 iphlpapi)
endif()
add_log_tag(lokinet-shared)
endif()
foreach(lokinet_lib liblokinet lokinet-platform lokinet-util lokinet-cryptography)
@ -244,5 +250,5 @@ foreach(lokinet_lib liblokinet lokinet-platform lokinet-util lokinet-cryptograph
endforeach()
file(GLOB_RECURSE docs_SRC */*.hpp *.hpp)
set(DOCS_SRC ${docs_SRC} PARENT_SCOPE)

63
llarp/lokinet_shared.cpp Normal file
View File

@ -0,0 +1,63 @@
#include "lokinet.h"
#include "llarp.hpp"
#include "config/config.hpp"
struct lokinet_context
{
std::shared_ptr<llarp::Context> impl;
std::unique_ptr<std::thread> runner;
lokinet_context() : impl{std::make_shared<llarp::Context>()}
{}
~lokinet_context()
{
if (runner)
runner->join();
}
};
struct lokinet_context g_context
{};
extern "C"
{
struct lokinet_context*
lokinet_default()
{
return &g_context;
}
struct lokinet_context*
lokinet_context_new()
{
return new lokinet_context{};
}
void
lokinet_context_free(struct lokinet_context* ctx)
{
delete ctx;
}
void
lokinet_context_start(struct lokinet_context* ctx)
{
ctx->runner = std::make_unique<std::thread>([ctx]() {
auto config = std::make_shared<llarp::Config>(fs::path{""});
ctx->impl->Configure(config);
const llarp::RuntimeOptions opts{};
ctx->impl->Setup(opts);
});
}
void
lokinet_context_stop(struct lokinet_context* ctx)
{
ctx->impl->CloseAsync();
ctx->impl->Wait();
}
}