Skip to content

Commit

Permalink
Merge pull request #13 from hyperledger/feature/cmake-fixes
Browse files Browse the repository at this point in the history
Add tests generation for all combinations
  • Loading branch information
Warchant authored Jun 7, 2018
2 parents 616d5fd + f704578 commit 08c58c9
Show file tree
Hide file tree
Showing 34 changed files with 543 additions and 309 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ build
external

example/build
.vs
35 changes: 21 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

sudo: true

language: cpp
Expand All @@ -15,8 +14,8 @@ matrix:
sources: ['ubuntu-toolchain-r-test']
packages: ['gcc-5', 'g++-5']
env:
- COMPILERCC=gcc-5
- COMPILERCXX=g++-5
- _CC=gcc-5
- _CXX=g++-5

- os: linux
dist: trusty
Expand All @@ -26,27 +25,35 @@ matrix:
sources: ['llvm-toolchain-trusty-4.0']
packages: ['clang-4.0']
env:
- COMPILERCC=clang-4.0
- COMPILERCXX=clang++-4.0
- _CC=clang-4.0
- _CXX=clang++-4.0


- os: osx
compiler: gcc
env:
- COMPILERCC=gcc
- COMPILERCXX=g++
- _CC=gcc
- _CXX=g++

- os: osx
compiler: clang
env:
- COMPILERCC=clang
- COMPILERCXX=clang++
- _CC=clang
- _CXX=clang++


script:
- mkdir build
- cd build
- export CC=$COMPILERCC; export CXX=$COMPILERCXX
- cmake .. -DEDIMPL=ref10 -DHASH=sha3_brainhub -DRANDOM=dev_urandom
- export CC=$_CC
- export CXX=$_CXX
# build and test ed25519
- mkdir build && cd build
- cmake .. -DTESTING=ON
- make -j2 -k
- ctest
- sudo make install
# build and execute example
- cd ../example/sign-verify
- mkdir build && cd build
- cmake .. -DCMAKE_BUILD_TYPE=Release
- make
- ctest
- ./test1
124 changes: 101 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,51 +1,74 @@
cmake_minimum_required(VERSION 3.5)

set(ED25519_MAJOR_VERSION 1)
set(ED25519_MINOR_VERSION 3)
set(ED25519_PATCH_VERSION 0)
set(SOVERSION "${ED25519_MAJOR_VERSION}.${ED25519_MINOR_VERSION}.${ED25519_PATCH_VERSION}")
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 TRUE)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin")
set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}")
set(ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")

set(CMAKE_C_STANDARD 11) # force std=c11
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -DNDEBUG")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0 -fdiagnostics-color ")

set(CMAKE_CXX_STANDARD 11) # force std=c++11
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -fdiagnostics-color")

add_compile_options(-Wall)
add_compile_options(-Wextra)
add_compile_options(-Wpedantic)
#add_compile_options(-Wall)
#add_compile_options(-Wextra)
#add_compile_options(-Wpedantic)

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

if(COVERAGE)
if(CMAKE_BUILD_TYPE STREQUAL Release)
message(FATAL_ERROR "Can't collect coverage in Release mode")
endif()
include(cmake/coverage.cmake)
endif()
include_directories(
${CMAKE_BINARY_DIR}/
${CMAKE_SOURCE_DIR}/include/
)

include(GNUInstallDirs)
include(GenerateExportHeader)
include(cmake/dependencies.cmake)
include(cmake/functions.cmake)
enable_language(ASM)
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)
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
SHA_512_CONTEXT_SIZE
sha256_init
sha256_final
sha256_update
sha256
SHA_256_CONTEXT_SIZE
randombytes
)

## DEFAULTS
if(NOT EDIMPL)
Expand All @@ -65,6 +88,13 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
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()


## OPTIONS
ENUM(EDIMPL "${EDIMPL}" "Ed25519 implementation"
ref10
Expand All @@ -89,21 +119,69 @@ ENUM(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" "cmake build type"
Debug
)


if(BUILD STREQUAL "SHARED" AND EDIMPL STREQUAL "amd64-64-24k")
message(FATAL_ERROR
"EDIMPL=amd64-64-24k implementation has no PIC fixes, "
"therefore SHARED library can not be built. "
"Use EDIMPL=amd64-64-24k-pic or BUILD=STATIC")
endif()

include_directories(${CMAKE_SOURCE_DIR}/include)

add_subdirectory(lib)
if(BENCHMARKING)
add_subdirectory(benchmark)
endif()
#if(BENCHMARKING)
# add_subdirectory(benchmark)
#endif()


ed25519_merge_libraries(ed25519 ${BUILD}
LIBRARIES
${EDIMPL}
${HASH}
${RANDOM}
VERSION
VERSION-${SOVERSION}-${EDIMPL}-${HASH}-${RANDOM}-${BUILD}-${CMAKE_BUILD_TYPE}
)
set(_export_file ${CMAKE_BINARY_DIR}/ed25519_export.h)
generate_export_header(ed25519
EXPORT_FILE_NAME ${_export_file}
)
install(
FILES ${_export_file}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ed25519/ed25519/
)
set_target_properties(ed25519 PROPERTIES
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}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
)
install(
DIRECTORY ${CMAKE_SOURCE_DIR}/include/ed25519
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
EXPORT ed25519Config
DESTINATION share/ed25519/cmake
)
export(
TARGETS ed25519
FILE ed25519Config.cmake
)


add_subdirectory(src)

if(TESTING)
enable_testing()
Expand Down
1 change: 1 addition & 0 deletions cmake/configurable_file_content.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@CMAKE_CONFIGURABLE_FILE_CONTENT@
67 changes: 67 additions & 0 deletions cmake/ed25519_add_library.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
function(ed25519_add_library LIBNAME TYPE)
set(options "")
set(oneValueArgs "IS_SUPPORTED")
set(multiValueArgs SOURCES INCLUDES LINK_LIBRARIES COMPILE_OPTIONS)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(ARG_IS_SUPPORTED STREQUAL "")
message(FATAL_ERROR "Specify IS_SUPPORTED:BOOL for ed25519_add_library")
endif()

get_property (ED25519_TYPES GLOBAL PROPERTY ED25519_TYPES)
if (NOT TYPE IN_LIST ED25519_TYPES)
message(FATAL_ERROR "Invalid TYPE=${TYPE} for ${LIBNAME}. Not one of ${ED25519_TYPES}")
else()
# store current library in KNOWN libraries set
if(NOT LIBNAME IN_LIST ED25519_KNOWN_LIBRARIES_${TYPE})
set(ED25519_KNOWN_LIBRARIES_${TYPE}
${ED25519_KNOWN_LIBRARIES_${TYPE}} ${LIBNAME}
CACHE INTERNAL "" FORCE)
endif()

# store current library in SUPPORTED libraries set, if it is supported
if(ARG_IS_SUPPORTED AND NOT LIBNAME IN_LIST ED25519_SUPPORTED_LIBRARIES_${TYPE})
set(ED25519_SUPPORTED_LIBRARIES_${TYPE}
${ED25519_SUPPORTED_LIBRARIES_${TYPE}} ${LIBNAME}
CACHE INTERNAL "" FORCE)
endif()
endif()

# for every sourcefile, replace relative path with absolute path to source file
foreach(file ${ARG_SOURCES})
get_filename_component(abspath ${file} REALPATH)
list(APPEND ARG_SOURCES ${abspath})
list(REMOVE_AT ARG_SOURCES 0)
endforeach()

if(ARG_IS_SUPPORTED)
add_library(${LIBNAME} OBJECT
${ARG_SOURCES}
)
ed25519_target_link_libraries(${LIBNAME}
${ARG_LINK_LIBRARIES}
)
target_compile_options(${LIBNAME} PUBLIC
${ARG_COMPILE_OPTIONS}
-Ded25519_EXPORTS
)
target_include_directories(${LIBNAME}
PUBLIC
${ARG_INCLUDES}
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_BINARY_DIR}
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/;${CMAKE_SOURCE_DIR}/include/>
)
set_target_properties(${LIBNAME} PROPERTIES
EXCLUDE_FROM_ALL ON
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
ARCHIVE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/archive_output_directory
LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/library_output_directory
POSITION_INDEPENDENT_CODE ON
)

else()
message(STATUS "[ed25519] Target ${TYPE}=${LIBNAME} is not supported on your platform")
endif()
endfunction(ed25519_add_library)
16 changes: 16 additions & 0 deletions cmake/ed25519_add_test.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function(ed25519_add_test test_name)
add_executable(${test_name} ${ARGN})
target_link_libraries(${test_name}
gtest
gmock
)
add_test(
NAME ${test_name}
COMMAND $<TARGET_FILE:${test_name}>
)
set_target_properties(${test_name} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test_bin
ARCHIVE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/test_lib
LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/test_lib
)
endfunction()
6 changes: 6 additions & 0 deletions cmake/ed25519_export.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function(ed25519_export)
set_property (GLOBAL PROPERTY ED25519_EXPORTED "${ARGN}")

JOIN("${ARGN}" ";\n" _ED25519_EXPORTED)
configure_file_content("{\nglobal: \n${_ED25519_EXPORTED}; \nlocal: *;\n};\n" ${CMAKE_BINARY_DIR}/linker_exportmap)
endfunction(ed25519_export)
7 changes: 7 additions & 0 deletions cmake/ed25519_init.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function(ed25519_init)
set_property (GLOBAL PROPERTY ED25519_TYPES "${ARGN}")
foreach(type ${ARGN})
set(ED25519_KNOWN_LIBRARIES_${TYPE} PARENT_SCOPE)
set(ED25519_SUPPORTED_LIBRARIES_${TYPE} PARENT_SCOPE)
endforeach()
endfunction(ed25519_init)
Loading

0 comments on commit 08c58c9

Please sign in to comment.