From 1d3fc1334e531aae2ad893e9caaa393c04437328 Mon Sep 17 00:00:00 2001 From: tevador Date: Tue, 9 Jun 2020 20:59:09 +0200 Subject: [PATCH] Equi-X shared library --- CMakeLists.txt | 25 +++++++++++++++++++++++-- hashx | 2 +- include/equix.h | 31 +++++++++++++++++++++++++++---- src/solver.h | 2 +- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d9bde1..89f15e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,11 @@ cmake_minimum_required(VERSION 2.8.8) +set(EQUIX_VERSION 1) +set(EQUIX_VERSION_MINOR 0) +set(EQUIX_VERSION_PATCH 0) +set(EQUIX_VERSION_STR "${EQUIX_VERSION}.${EQUIX_VERSION_MINOR}.${EQUIX_VERSION_PATCH}") + project(equix) add_definitions(-DHASHX_SIZE=8) @@ -19,11 +24,25 @@ if(NOT CMAKE_BUILD_TYPE) message(STATUS "Setting default build type: ${CMAKE_BUILD_TYPE}") endif() +add_library(equix SHARED ${equix_sources}) +set_property(TARGET equix PROPERTY POSITION_INDEPENDENT_CODE ON) +set_property(TARGET equix PROPERTY PUBLIC_HEADER include/equix.h) +include_directories(equix + include/ + hashx/include/ + hashx/src/) +target_compile_definitions(equix PRIVATE HASHX_STATIC) +target_compile_definitions(equix PRIVATE EQUIX_SHARED) +target_link_libraries(equix + PRIVATE hashx_static) +set_target_properties(equix PROPERTIES VERSION ${EQUIX_VERSION_STR} + SOVERSION ${EQUIX_VERSION}) + add_library(equix_static STATIC ${equix_sources}) set_property(TARGET equix_static PROPERTY POSITION_INDEPENDENT_CODE ON) -set_property(TARGET equix_static PROPERTY PUBLIC_HEADER include/equix.h) set_target_properties(equix_static PROPERTIES OUTPUT_NAME equix) target_compile_definitions(equix_static PRIVATE HASHX_STATIC) +target_compile_definitions(equix_static PRIVATE EQUIX_STATIC) include_directories(equix_static include/ hashx/include/ @@ -32,7 +51,7 @@ target_link_libraries(equix_static PRIVATE hashx_static) include(GNUInstallDirs) -install(TARGETS equix_static +install(TARGETS equix equix_static LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) @@ -41,6 +60,7 @@ add_executable(equix-tests src/tests.c) include_directories(equix-tests include/) +target_compile_definitions(equix-tests PRIVATE EQUIX_STATIC) target_link_libraries(equix-tests PRIVATE equix_static) @@ -55,6 +75,7 @@ add_executable(equix-bench include_directories(equix-bench include/ hashx/src/) +target_compile_definitions(equix-bench PRIVATE EQUIX_STATIC) target_link_libraries(equix-bench PRIVATE equix_static PRIVATE ${CMAKE_THREAD_LIBS_INIT}) diff --git a/hashx b/hashx index 7e2ae35..28e3ab2 160000 --- a/hashx +++ b/hashx @@ -1 +1 @@ -Subproject commit 7e2ae350199f993357f277dc780ca063ffa8ad0d +Subproject commit 28e3ab20ed44c9bce245be0fc5c1eda0e137266d diff --git a/include/equix.h b/include/equix.h index 5e6b383..01ab249 100644 --- a/include/equix.h +++ b/include/equix.h @@ -60,6 +60,29 @@ typedef enum equix_ctx_flags { /* Sentinel value used to indicate unsupported type */ #define EQUIX_NOTSUPP ((equix_ctx*)-1) +#if defined(_WIN32) || defined(__CYGWIN__) +#define EQUIX_WIN +#endif + +/* Shared/static library definitions */ +#ifdef EQUIX_WIN + #ifdef EQUIX_SHARED + #define EQUIX_API __declspec(dllexport) + #elif !defined(EQUIX_STATIC) + #define EQUIX_API __declspec(dllimport) + #else + #define EQUIX_API + #endif + #define EQUIX_PRIVATE +#else + #ifdef EQUIX_SHARED + #define EQUIX_API __attribute__ ((visibility ("default"))) + #else + #define EQUIX_API __attribute__ ((visibility ("hidden"))) + #endif + #define EQUIX_PRIVATE __attribute__ ((visibility ("hidden"))) +#endif + #ifdef __cplusplus extern "C" { #endif @@ -73,14 +96,14 @@ extern "C" { * allocation failure and EQUIX_NOTSUPP if the requested type * is not supported. */ -equix_ctx* equix_alloc(equix_ctx_flags flags); +EQUIX_API equix_ctx* equix_alloc(equix_ctx_flags flags); /* * Free an Equi-X a context. * * @param ctx is a pointer to the context */ -void equix_free(equix_ctx* ctx); +EQUIX_API void equix_free(equix_ctx* ctx); /* * Find Equi-X solutions for the given challenge. @@ -93,7 +116,7 @@ void equix_free(equix_ctx* ctx); * * @return the number of solutions found */ -int equix_solve( +EQUIX_API int equix_solve( equix_ctx* ctx, const void* challenge, size_t challenge_size, @@ -109,7 +132,7 @@ int equix_solve( * * @return verification result */ -equix_result equix_verify( +EQUIX_API equix_result equix_verify( equix_ctx* ctx, const void* challenge, size_t challenge_size, diff --git a/src/solver.h b/src/solver.h index 344b224..ad69951 100644 --- a/src/solver.h +++ b/src/solver.h @@ -25,6 +25,6 @@ static inline bool tree_cmp4(const equix_idx* left, const equix_idx* right) { return load64(left) <= load64(right); } -int equix_solver_solve(hashx_ctx* hash_func, solver_heap* heap, equix_solution output[EQUIX_MAX_SOLS]); +EQUIX_PRIVATE int equix_solver_solve(hashx_ctx* hash_func, solver_heap* heap, equix_solution output[EQUIX_MAX_SOLS]); #endif