Skip to content

Commit

Permalink
Adds CMake build configuration
Browse files Browse the repository at this point in the history
Major updates
    + Adds CMake configuration file
    + Adds three CMake targets: gost15 library, selftests and benchmark
    + gost15 library can be built in one of three versions: compact, optimised and SIMD

Minor updates
    + Adds support for GCC and Clang compilers
    + Forces strict language C99 dialect via C_EXTENSIONS and COMPILE_FEATURES
  • Loading branch information
Arseny Aprelev committed Apr 17, 2016
1 parent b3bedd9 commit c96361d
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
cmake_minimum_required(VERSION 3.2)

# gosthopper project declaration
project(gosthopper VERSION 0.3.5 LANGUAGES C)

# Setting gosthopper global options
option(ENABLE_PRECALCULATIONS "Use optimised implementation with precalculated tables" OFF)
option(ENABLE_SIMD "Enable SIMD code optimisations" OFF)


##########################################################################################
## ##
## gost15 library ##
## ##
##########################################################################################
## Setting up gost15 library sources and compiler features
add_library(gost15)
add_library(gosthopper::gost15 ALIAS gost15)

if (ENABLE_PRECALCULATIONS AND ENABLE_SIMD)
message(WARNING "Building SIMD implementation version.")
target_sources(gost15 PRIVATE src/SIMD.c src/tables.c src/SIMD_tables.c)
elseif(ENABLE_PRECALCULATIONS)
message(WARNING "Building optimised implementation version.")
target_sources(gost15 PRIVATE src/optimised.c src/tables.c src/optimised_tables.c)
else()
message(WARNING "Building compact implementation version.")
target_sources(gost15 PRIVATE src/compact.c src/tables.c)
endif()

target_include_directories(gost15 PUBLIC include PRIVATE src)
target_compile_features(gost15 PUBLIC c_restrict)
set_target_properties(gost15 PROPERTIES C_EXTENSIONS OFF)

## Selecting implementation version
if(ENABLE_PRECALCULATIONS)
target_compile_definitions(gost15 PRIVATE USE_OPTIMISED_IMPLEMENTATION)
endif()

## Setting GCC specific flags
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
target_compile_options(gost15 PRIVATE $<$<CONFIG:Debug>:-march=native -pedantic -Wall -Wextra -Werror -Wno-unused-function -g -O0>)
target_compile_options(gost15 PRIVATE $<$<CONFIG:Release>:-march=native -O3>)

if(NOT ENABLE_SIMD)
message(WARNING "Disabling SIMD instructions optimisation.")
target_compile_options(gost15 PRIVATE -mno-sse)
endif()

## Setting Clang specific flags
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
target_compile_options(gost15 PRIVATE $<$<CONFIG:DEBUG>:-march=native -Weverything -Werror -Wno-unused-function -Wno-cast-align -g -O0>)
target_compile_options(gost15 PRIVATE $<$<CONFIG:RELEASE>:-march=native -O3>)

if(NOT ENABLE_SIMD)
message(WARNING "Disabling SIMD instructions optimisation.")
target_compile_options(gost15 PRIVATE -mno-sse)
endif()

get_target_property(GOST15_COMPILE_OPTIONS gost15 COMPILE_OPTIONS)
endif()



##########################################################################################
## ##
## Selftests ##
## ##
##########################################################################################
## Selftests currently are just a target
## (CTest support in the future?)
add_executable(selftests tests/selftests_gost.c)
target_link_libraries(selftests PUBLIC gosthopper::gost15)



##########################################################################################
## ##
## Benchmark ##
## ##
##########################################################################################
add_executable(benchmark tests/benchmark.c)
target_link_libraries(benchmark PUBLIC gosthopper::gost15)

0 comments on commit c96361d

Please sign in to comment.