Skip to content

Commit cba1c6e

Browse files
authored
Fixes for Hunter CI (#21)
* Fixes for hunter Signed-off-by: Bogdan Vaneev <[email protected]> * Remove comments Signed-off-by: Bogdan Vaneev <[email protected]>
1 parent d724fb1 commit cba1c6e

File tree

17 files changed

+186
-118
lines changed

17 files changed

+186
-118
lines changed

CMakeLists.txt

Lines changed: 58 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 3.5)
22

33

44
find_program(CCACHE_FOUND ccache)
5-
if(CCACHE_FOUND)
5+
if (CCACHE_FOUND)
66
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
77
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
8-
endif(CCACHE_FOUND)
8+
endif (CCACHE_FOUND)
99

1010

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

2424
enable_language(ASM)
2525

26-
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
27-
set(CMAKE_C_VISIBILITY_PRESET hidden)
28-
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
29-
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
30-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
26+
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
27+
set(CMAKE_C_VISIBILITY_PRESET hidden)
28+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
29+
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
30+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
3131

32-
set(CMAKE_C_STANDARD 11) # force std=c11
33-
set(CMAKE_C_STANDARD_REQUIRED ON)
34-
set(CMAKE_C_EXTENSIONS OFF)
32+
set(CMAKE_C_STANDARD 11) # force std=c11
33+
set(CMAKE_C_STANDARD_REQUIRED ON)
34+
set(CMAKE_C_EXTENSIONS OFF)
3535

36-
set(CMAKE_CXX_STANDARD 11) # force std=c++11
37-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
38-
set(CMAKE_CXX_EXTENSIONS OFF)
36+
set(CMAKE_CXX_STANDARD 11) # force std=c++11
37+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
38+
set(CMAKE_CXX_EXTENSIONS OFF)
3939

40-
option(TESTING "Enable testing" OFF)
41-
option(COVERAGE "Enable coverage" OFF)
42-
option(BENCHMARKING "Enable benchmarking" OFF)
40+
option(TESTING "Enable testing" OFF)
41+
option(COVERAGE "Enable coverage" OFF)
42+
option(BENCHMARKING "Enable benchmarking" OFF)
4343

4444
include_directories(
4545
${CMAKE_BINARY_DIR}/
@@ -50,57 +50,37 @@ include(GNUInstallDirs)
5050
include(cmake/dependencies.cmake)
5151
include(cmake/functions.cmake)
5252
include(cmake/ed25519_init.cmake)
53-
include(cmake/ed25519_export.cmake)
5453
include(cmake/ed25519_target_link_libraries.cmake)
5554
include(cmake/ed25519_add_library.cmake)
5655
include(cmake/ed25519_merge_libraries.cmake)
5756
include(cmake/ed25519_add_test.cmake)
57+
include(cmake/ed25519_select_supported_impl.cmake)
5858
test_build_amd64(CAN_BUILD_AMD64)
5959

6060
ed25519_init(EDIMPL HASH RANDOM)
6161

62-
# resulting shared/static library will export these symbols as GLOBAL symbols, and
63-
# mark all others as LOCAL (hidden)
64-
ed25519_export(
65-
ed25519_create_keypair
66-
ed25519_derive_public_key
67-
ed25519_sign
68-
ed25519_verify
69-
sha512_init
70-
sha512_final
71-
sha512_update
72-
sha512
73-
sha256_init
74-
sha256_final
75-
sha256_update
76-
sha256
77-
randombytes
78-
)
62+
add_subdirectory(lib)
7963

8064
## DEFAULTS
81-
if(NOT EDIMPL)
82-
set(EDIMPL "ref10")
83-
endif()
84-
if(NOT HASH)
85-
set(HASH "sha3_brainhub")
86-
endif()
87-
if(NOT RANDOM)
65+
if (NOT EDIMPL)
66+
ed25519_select_supported_impl(EDIMPL amd64-64-24k-pic ref10)
67+
endif ()
68+
if (NOT HASH)
69+
ed25519_select_supported_impl(HASH sha2_sphlib sha2_openssl)
70+
endif ()
71+
if (NOT RANDOM)
8872
# https://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/
89-
if(WIN32)
90-
set(RANDOM "bcryptgenrandom")
91-
else()
92-
set(RANDOM "dev_urandom")
93-
endif()
94-
endif()
95-
if(NOT BUILD)
96-
set(BUILD "STATIC")
97-
endif()
98-
99-
100-
if(NOT CMAKE_ASM_COMPILER_WORKS)
73+
ed25519_select_supported_impl(RANDOM dev_urandom bcryptgen rand_openssl)
74+
endif ()
75+
if (NOT BUILD)
76+
set(BUILD "STATIC")
77+
endif ()
78+
79+
80+
if (NOT CMAKE_ASM_COMPILER_WORKS)
10181
message(WARNING "Can not find ASM compiler. Only EDIMPL=ref10 is available.")
10282
set(CAN_BUILD_AMD64 FALSE)
103-
endif()
83+
endif ()
10484

10585

10686
## OPTIONS
@@ -117,64 +97,65 @@ ENUM(RANDOM "${RANDOM}" "RNG implementation"
11797
rand_openssl
11898
dev_random
11999
dev_urandom
120-
bcryptgenrandom
100+
bcryptgen
121101
)
122102
ENUM(BUILD "${BUILD}" "library build type"
123103
SHARED
124104
STATIC
125105
)
126106

127-
add_subdirectory(lib)
128-
129107

130108
ed25519_merge_libraries(ed25519 ${BUILD}
131109
LIBRARIES
132-
${EDIMPL}
133-
${HASH}
134-
${RANDOM}
110+
${EDIMPL}
111+
${HASH}
112+
${RANDOM}
135113
VERSION
136-
VERSION-${SOVERSION}-${EDIMPL}-${HASH}-${RANDOM}-${BUILD}-${CMAKE_BUILD_TYPE}
114+
VERSION-${SOVERSION}-${EDIMPL}-${HASH}-${RANDOM}-${BUILD}-${CMAKE_BUILD_TYPE}
137115
)
138116
set_target_properties(ed25519 PROPERTIES
139-
VERSION ${SOVERSION}
117+
VERSION ${SOVERSION}
140118
SOVERSION ${SOVERSION}
141119
INTERFACE_ed25519_MAJOR_VERSION ${ED25519_MAJOR_VERSION}
142120
)
143121
set_property(
144122
TARGET ed25519
145123
APPEND PROPERTY
146124
COMPATIBLE_INTERFACE_STRING ed25519_MAJOR_VERSION
147-
)
125+
)
148126
install(TARGETS ed25519 EXPORT ed25519Config
149-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
150-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
151-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
152-
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
127+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
128+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
129+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
130+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
153131
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
154-
FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
132+
FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
155133
)
156134
install(
157-
DIRECTORY ${CMAKE_SOURCE_DIR}/include/ed25519
135+
DIRECTORY ${CMAKE_SOURCE_DIR}/include/ed25519
158136
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
159-
)
137+
)
160138
install(
161139
EXPORT ed25519Config
162140
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ed25519
163141
NAMESPACE iroha::
164-
)
142+
)
143+
install(
144+
FILES ${CMAKE_SOURCE_DIR}/linker_exportmap
145+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ed25519
146+
)
165147
export(
166148
TARGETS ed25519
167149
FILE ed25519Config.cmake
168-
)
169-
150+
)
170151

171152

172-
if(TESTING)
153+
if (TESTING)
173154
enable_testing()
174155
add_subdirectory(test)
175-
endif()
156+
endif ()
176157

177158

178-
if(BENCHMARK)
159+
if (BENCHMARK)
179160
add_subdirectory(benchmark)
180-
endif()
161+
endif ()

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ During CMake time, users are able to choose any of these implementations using c
2929
- `rand_openssl`
3030
- `dev_urandom` - default
3131
- `dev_random`
32-
- `bcryptgenrandom` (windows only)
32+
- `bcryptgen` (windows only)
3333
- `BUILD`
3434
- `STATIC`
3535
- `SHARED` - build ed25519 library as shared library (default)
@@ -48,7 +48,7 @@ $ cmake .. -DEDIMPL=amd64-64-24k-pic -DHASH=sha3_brainhub -DRANDOM=dev_urandom -
4848
-- HASH=sha3_brainhub is selected (SHA implementation)
4949
-- RANDOM=dev_urandom is selected (RNG implementation)
5050
-- BUILD=SHARED is selected (library build type)
51-
-- [ed25519] Target RANDOM=rand_bcryptgenrandom is not supported on your platform
51+
-- [ed25519] Target RANDOM=bcryptgen is not supported on your platform
5252
-- Configuring done
5353
-- Generating done
5454
-- Build files have been written to: /Users/bogdan/tools/iroha-ed25519/build
@@ -87,4 +87,4 @@ This repository offers 4 implementations:
8787
- `rand_openssl` uses RAND_bytes from openssl
8888
- `dev_urandom` reads entropy from `/dev/urandom`
8989
- `dev_random` reads entropy from `/dev/random` (blocking call, uses busy waiting when user asks for more entropy than device can offer)
90-
- `bcryptgenrandom` reads entropy from windows preferred entropy source.
90+
- `bcryptgen` reads entropy from windows preferred entropy source.

cmake/ed25519_add_test.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function(ed25519_add_test test_name)
22
add_executable(${test_name} ${ARGN})
3-
target_link_libraries(${test_name}
3+
target_link_libraries(${test_name} PRIVATE
44
GTest::main
55
GTest::gtest
66
)

cmake/ed25519_export.cmake

Lines changed: 0 additions & 6 deletions
This file was deleted.

cmake/ed25519_merge_libraries.cmake

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,35 @@ function(ed25519_merge_libraries TARGET LIBTYPE)
2626
)
2727
target_include_directories(${TARGET}
2828
INTERFACE
29-
$<INSTALL_INTERFACE:include>
29+
$<INSTALL_INTERFACE:include>
3030
)
3131

32-
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
33-
# linux only solution
34-
ed25519_target_link_libraries(${TARGET}
35-
"-Wl,--version-script=${CMAKE_BINARY_DIR}/linker_exportmap"
36-
)
37-
endif()
38-
3932
# check that every static library has PIC enabled
40-
foreach(lib ${ARG_LIBRARIES})
41-
if(TARGET ${lib})
33+
foreach (lib ${ARG_LIBRARIES})
34+
if (TARGET ${lib})
4235
add_dependencies(${TARGET} ${lib})
4336
get_target_property(LIB_TYPE ${lib} TYPE)
44-
if(LIB_TYPE STREQUAL "STATIC_LIBRARY")
37+
38+
if (LIB_TYPE STREQUAL "STATIC_LIBRARY")
4539
get_target_property(PIC ${lib} POSITION_INDEPENDENT_CODE)
46-
if(NOT PIC)
40+
if (NOT PIC)
4741
message(FATAL_ERROR
4842
"Attempted to link non-PIC static library ${LIB} to shared library ${TARGET}\n"
4943
"Please, use ed25519_add_library"
5044
)
51-
endif()
52-
endif()
53-
endif()
54-
endforeach()
45+
endif ()
46+
47+
else()
48+
# it is shared library
49+
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
50+
ed25519_target_link_libraries(amd64-64-24k-pic
51+
"-Wl,--version-script=${CMAKE_SOURCE_DIR}/linker_exportmap"
52+
)
53+
endif ()
54+
55+
endif ()
56+
endif ()
57+
endforeach ()
5558

5659
set_target_properties(${TARGET} PROPERTIES
5760
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ed25519_select_supported_impl works as a priority queue, it will return first known and supported library from ARGN
2+
function(ed25519_select_supported_impl SELECTED)
3+
set(TYPE ${SELECTED})
4+
if(NOT ED25519_SUPPORTED_LIBRARIES_${TYPE} OR NOT ED25519_KNOWN_LIBRARIES_${TYPE})
5+
message(FATAL_ERROR "
6+
ed25519_select_supported_impl is called before all libraries
7+
ED25519_KNOWN_LIBRARIES_${TYPE}: '${ED25519_KNOWN_LIBRARIES_${TYPE}}'
8+
ED25519_SUPPORTED_LIBRARIES_${TYPE}: '${ED25519_SUPPORTED_LIBRARIES_${TYPE}}'
9+
")
10+
endif()
11+
12+
foreach(lib ${ARGN})
13+
if(${lib} IN_LIST ED25519_KNOWN_LIBRARIES_${TYPE})
14+
if(${lib} IN_LIST ED25519_SUPPORTED_LIBRARIES_${TYPE})
15+
set(${SELECTED} ${lib} PARENT_SCOPE)
16+
return()
17+
endif()
18+
else()
19+
message(FATAL_ERROR "${lib} is NOT FOUND in ED25519_KNOWN_LIBRARIES_${TYPE}")
20+
endif()
21+
endforeach()
22+
23+
message(FATAL_ERROR "
24+
Did not find suitable implementation.
25+
ED25519_KNOWN_LIBRARIES_${TYPE}: '${ED25519_KNOWN_LIBRARIES_${TYPE}}'
26+
ED25519_SUPPORTED_LIBRARIES_${TYPE}: '${ED25519_SUPPORTED_LIBRARIES_${TYPE}}'
27+
")
28+
29+
endfunction()

cmake/ed25519_target_link_libraries.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function(ed25519_target_link_libraries _target)
3636
foreach(_lib IN ITEMS ${ARGN})
3737
if(NOT TARGET ${_lib})
3838
# flag
39-
target_link_libraries(${_target} ${_lib})
39+
target_link_libraries(${_target} PRIVATE ${_lib})
4040
else()
4141

4242
get_target_property(_type "${_lib}" TYPE)
@@ -52,7 +52,7 @@ function(ed25519_target_link_libraries _target)
5252
_link_ed25519_dependencies(${_target}
5353
${_lib}
5454
)
55-
target_link_libraries(${_target}
55+
target_link_libraries(${_target} PRIVATE
5656
${_lib}
5757
)
5858
else()

example/sign-verify/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ find_package(ed25519 REQUIRED)
66
add_executable(test1
77
main.c
88
)
9-
target_link_libraries(test1
9+
target_link_libraries(test1 PRIVATE
1010
ed25519
1111
)

include/ed25519/ed25519/unused.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef PROJECT_UNUSED_H_
2+
#define PROJECT_UNUSED_H_
3+
4+
#define UNUSED(x) (void)(x)
5+
6+
#endif

lib/ed25519/amd64-64-24k-pic/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
22
FILE(GLOB sources ${CMAKE_CURRENT_SOURCE_DIR}/*.[cs])
33

44
ed25519_add_library(amd64-64-24k-pic EDIMPL
5-
SOURCES ${sources}
6-
IS_SUPPORTED ${CAN_BUILD_AMD64}
7-
)
5+
SOURCES ${sources}
6+
IS_SUPPORTED ${CAN_BUILD_AMD64}
7+
)

0 commit comments

Comments
 (0)