Skip to content

Commit

Permalink
Fixes for Hunter CI (#21)
Browse files Browse the repository at this point in the history
* Fixes for hunter

Signed-off-by: Bogdan Vaneev <[email protected]>

* Remove comments

Signed-off-by: Bogdan Vaneev <[email protected]>
  • Loading branch information
Warchant authored Feb 17, 2019
1 parent d724fb1 commit cba1c6e
Show file tree
Hide file tree
Showing 17 changed files with 186 additions and 118 deletions.
135 changes: 58 additions & 77 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 3.5)


find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
if (CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
endif (CCACHE_FOUND)


include("cmake/Hunter/init.cmake")
Expand All @@ -23,23 +23,23 @@ project(ed25519 VERSION ${SOVERSION} LANGUAGES C CXX)

enable_language(ASM)

set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_C_STANDARD 11) # force std=c11
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 11) # force std=c11
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)

set(CMAKE_CXX_STANDARD 11) # force std=c++11
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 11) # force std=c++11
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

option(TESTING "Enable testing" OFF)
option(COVERAGE "Enable coverage" OFF)
option(BENCHMARKING "Enable benchmarking" OFF)
option(TESTING "Enable testing" OFF)
option(COVERAGE "Enable coverage" OFF)
option(BENCHMARKING "Enable benchmarking" OFF)

include_directories(
${CMAKE_BINARY_DIR}/
Expand All @@ -50,57 +50,37 @@ include(GNUInstallDirs)
include(cmake/dependencies.cmake)
include(cmake/functions.cmake)
include(cmake/ed25519_init.cmake)
include(cmake/ed25519_export.cmake)
include(cmake/ed25519_target_link_libraries.cmake)
include(cmake/ed25519_add_library.cmake)
include(cmake/ed25519_merge_libraries.cmake)
include(cmake/ed25519_add_test.cmake)
include(cmake/ed25519_select_supported_impl.cmake)
test_build_amd64(CAN_BUILD_AMD64)

ed25519_init(EDIMPL HASH RANDOM)

# resulting shared/static library will export these symbols as GLOBAL symbols, and
# mark all others as LOCAL (hidden)
ed25519_export(
ed25519_create_keypair
ed25519_derive_public_key
ed25519_sign
ed25519_verify
sha512_init
sha512_final
sha512_update
sha512
sha256_init
sha256_final
sha256_update
sha256
randombytes
)
add_subdirectory(lib)

## DEFAULTS
if(NOT EDIMPL)
set(EDIMPL "ref10")
endif()
if(NOT HASH)
set(HASH "sha3_brainhub")
endif()
if(NOT RANDOM)
if (NOT EDIMPL)
ed25519_select_supported_impl(EDIMPL amd64-64-24k-pic ref10)
endif ()
if (NOT HASH)
ed25519_select_supported_impl(HASH sha2_sphlib sha2_openssl)
endif ()
if (NOT RANDOM)
# https://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/
if(WIN32)
set(RANDOM "bcryptgenrandom")
else()
set(RANDOM "dev_urandom")
endif()
endif()
if(NOT BUILD)
set(BUILD "STATIC")
endif()


if(NOT CMAKE_ASM_COMPILER_WORKS)
ed25519_select_supported_impl(RANDOM dev_urandom bcryptgen rand_openssl)
endif ()
if (NOT BUILD)
set(BUILD "STATIC")
endif ()


if (NOT CMAKE_ASM_COMPILER_WORKS)
message(WARNING "Can not find ASM compiler. Only EDIMPL=ref10 is available.")
set(CAN_BUILD_AMD64 FALSE)
endif()
endif ()


## OPTIONS
Expand All @@ -117,64 +97,65 @@ ENUM(RANDOM "${RANDOM}" "RNG implementation"
rand_openssl
dev_random
dev_urandom
bcryptgenrandom
bcryptgen
)
ENUM(BUILD "${BUILD}" "library build type"
SHARED
STATIC
)

add_subdirectory(lib)


ed25519_merge_libraries(ed25519 ${BUILD}
LIBRARIES
${EDIMPL}
${HASH}
${RANDOM}
${EDIMPL}
${HASH}
${RANDOM}
VERSION
VERSION-${SOVERSION}-${EDIMPL}-${HASH}-${RANDOM}-${BUILD}-${CMAKE_BUILD_TYPE}
VERSION-${SOVERSION}-${EDIMPL}-${HASH}-${RANDOM}-${BUILD}-${CMAKE_BUILD_TYPE}
)
set_target_properties(ed25519 PROPERTIES
VERSION ${SOVERSION}
VERSION ${SOVERSION}
SOVERSION ${SOVERSION}
INTERFACE_ed25519_MAJOR_VERSION ${ED25519_MAJOR_VERSION}
)
set_property(
TARGET ed25519
APPEND PROPERTY
COMPATIBLE_INTERFACE_STRING ed25519_MAJOR_VERSION
)
)
install(TARGETS ed25519 EXPORT ed25519Config
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
)
install(
DIRECTORY ${CMAKE_SOURCE_DIR}/include/ed25519
DIRECTORY ${CMAKE_SOURCE_DIR}/include/ed25519
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
)
install(
EXPORT ed25519Config
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ed25519
NAMESPACE iroha::
)
)
install(
FILES ${CMAKE_SOURCE_DIR}/linker_exportmap
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ed25519
)
export(
TARGETS ed25519
FILE ed25519Config.cmake
)

)


if(TESTING)
if (TESTING)
enable_testing()
add_subdirectory(test)
endif()
endif ()


if(BENCHMARK)
if (BENCHMARK)
add_subdirectory(benchmark)
endif()
endif ()
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ During CMake time, users are able to choose any of these implementations using c
- `rand_openssl`
- `dev_urandom` - default
- `dev_random`
- `bcryptgenrandom` (windows only)
- `bcryptgen` (windows only)
- `BUILD`
- `STATIC`
- `SHARED` - build ed25519 library as shared library (default)
Expand All @@ -48,7 +48,7 @@ $ cmake .. -DEDIMPL=amd64-64-24k-pic -DHASH=sha3_brainhub -DRANDOM=dev_urandom -
-- HASH=sha3_brainhub is selected (SHA implementation)
-- RANDOM=dev_urandom is selected (RNG implementation)
-- BUILD=SHARED is selected (library build type)
-- [ed25519] Target RANDOM=rand_bcryptgenrandom is not supported on your platform
-- [ed25519] Target RANDOM=bcryptgen is not supported on your platform
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/bogdan/tools/iroha-ed25519/build
Expand Down Expand Up @@ -87,4 +87,4 @@ This repository offers 4 implementations:
- `rand_openssl` uses RAND_bytes from openssl
- `dev_urandom` reads entropy from `/dev/urandom`
- `dev_random` reads entropy from `/dev/random` (blocking call, uses busy waiting when user asks for more entropy than device can offer)
- `bcryptgenrandom` reads entropy from windows preferred entropy source.
- `bcryptgen` reads entropy from windows preferred entropy source.
2 changes: 1 addition & 1 deletion cmake/ed25519_add_test.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function(ed25519_add_test test_name)
add_executable(${test_name} ${ARGN})
target_link_libraries(${test_name}
target_link_libraries(${test_name} PRIVATE
GTest::main
GTest::gtest
)
Expand Down
6 changes: 0 additions & 6 deletions cmake/ed25519_export.cmake

This file was deleted.

35 changes: 19 additions & 16 deletions cmake/ed25519_merge_libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,35 @@ function(ed25519_merge_libraries TARGET LIBTYPE)
)
target_include_directories(${TARGET}
INTERFACE
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:include>
)

if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# linux only solution
ed25519_target_link_libraries(${TARGET}
"-Wl,--version-script=${CMAKE_BINARY_DIR}/linker_exportmap"
)
endif()

# check that every static library has PIC enabled
foreach(lib ${ARG_LIBRARIES})
if(TARGET ${lib})
foreach (lib ${ARG_LIBRARIES})
if (TARGET ${lib})
add_dependencies(${TARGET} ${lib})
get_target_property(LIB_TYPE ${lib} TYPE)
if(LIB_TYPE STREQUAL "STATIC_LIBRARY")

if (LIB_TYPE STREQUAL "STATIC_LIBRARY")
get_target_property(PIC ${lib} POSITION_INDEPENDENT_CODE)
if(NOT PIC)
if (NOT PIC)
message(FATAL_ERROR
"Attempted to link non-PIC static library ${LIB} to shared library ${TARGET}\n"
"Please, use ed25519_add_library"
)
endif()
endif()
endif()
endforeach()
endif ()

else()
# it is shared library
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
ed25519_target_link_libraries(amd64-64-24k-pic
"-Wl,--version-script=${CMAKE_SOURCE_DIR}/linker_exportmap"
)
endif ()

endif ()
endif ()
endforeach ()

set_target_properties(${TARGET} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
Expand Down
29 changes: 29 additions & 0 deletions cmake/ed25519_select_supported_impl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ed25519_select_supported_impl works as a priority queue, it will return first known and supported library from ARGN
function(ed25519_select_supported_impl SELECTED)
set(TYPE ${SELECTED})
if(NOT ED25519_SUPPORTED_LIBRARIES_${TYPE} OR NOT ED25519_KNOWN_LIBRARIES_${TYPE})
message(FATAL_ERROR "
ed25519_select_supported_impl is called before all libraries
ED25519_KNOWN_LIBRARIES_${TYPE}: '${ED25519_KNOWN_LIBRARIES_${TYPE}}'
ED25519_SUPPORTED_LIBRARIES_${TYPE}: '${ED25519_SUPPORTED_LIBRARIES_${TYPE}}'
")
endif()

foreach(lib ${ARGN})
if(${lib} IN_LIST ED25519_KNOWN_LIBRARIES_${TYPE})
if(${lib} IN_LIST ED25519_SUPPORTED_LIBRARIES_${TYPE})
set(${SELECTED} ${lib} PARENT_SCOPE)
return()
endif()
else()
message(FATAL_ERROR "${lib} is NOT FOUND in ED25519_KNOWN_LIBRARIES_${TYPE}")
endif()
endforeach()

message(FATAL_ERROR "
Did not find suitable implementation.
ED25519_KNOWN_LIBRARIES_${TYPE}: '${ED25519_KNOWN_LIBRARIES_${TYPE}}'
ED25519_SUPPORTED_LIBRARIES_${TYPE}: '${ED25519_SUPPORTED_LIBRARIES_${TYPE}}'
")

endfunction()
4 changes: 2 additions & 2 deletions cmake/ed25519_target_link_libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function(ed25519_target_link_libraries _target)
foreach(_lib IN ITEMS ${ARGN})
if(NOT TARGET ${_lib})
# flag
target_link_libraries(${_target} ${_lib})
target_link_libraries(${_target} PRIVATE ${_lib})
else()

get_target_property(_type "${_lib}" TYPE)
Expand All @@ -52,7 +52,7 @@ function(ed25519_target_link_libraries _target)
_link_ed25519_dependencies(${_target}
${_lib}
)
target_link_libraries(${_target}
target_link_libraries(${_target} PRIVATE
${_lib}
)
else()
Expand Down
2 changes: 1 addition & 1 deletion example/sign-verify/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ find_package(ed25519 REQUIRED)
add_executable(test1
main.c
)
target_link_libraries(test1
target_link_libraries(test1 PRIVATE
ed25519
)
6 changes: 6 additions & 0 deletions include/ed25519/ed25519/unused.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef PROJECT_UNUSED_H_
#define PROJECT_UNUSED_H_

#define UNUSED(x) (void)(x)

#endif
6 changes: 3 additions & 3 deletions lib/ed25519/amd64-64-24k-pic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
FILE(GLOB sources ${CMAKE_CURRENT_SOURCE_DIR}/*.[cs])

ed25519_add_library(amd64-64-24k-pic EDIMPL
SOURCES ${sources}
IS_SUPPORTED ${CAN_BUILD_AMD64}
)
SOURCES ${sources}
IS_SUPPORTED ${CAN_BUILD_AMD64}
)
Loading

0 comments on commit cba1c6e

Please sign in to comment.