-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
99 lines (82 loc) · 2.67 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Copyright (c) 2020 tevador <[email protected]>
# See LICENSE for licensing information
cmake_minimum_required(VERSION 2.8.8)
set(HASHX_VERSION 1)
set(HASHX_VERSION_MINOR 0)
set(HASHX_VERSION_PATCH 0)
set(HASHX_VERSION_STR "${HASHX_VERSION}.${HASHX_VERSION_MINOR}.${HASHX_VERSION_PATCH}")
project(hashx)
set(hashx_sources
src/blake2.c
src/compiler.c
src/compiler_a64.c
src/compiler_x86.c
src/context.c
src/hashx.c
src/program.c
src/program_exec.c
src/siphash.c
src/siphash_rng.c
src/virtual_memory.c)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
message(STATUS "Setting default build type: ${CMAKE_BUILD_TYPE}")
endif()
option(HASHX_BLOCK_MODE "Hash function for block mode" OFF)
if(HASHX_BLOCK_MODE)
add_definitions(-DHASHX_BLOCK_MODE)
endif()
set(HASHX_SIZE CACHE STRING "Hash function output size in bytes")
if(HASHX_SIZE)
if(HASHX_SIZE GREATER 32)
message(SEND_ERROR "The maximum hash size is 32 bytes")
else()
add_definitions(-DHASHX_SIZE=${HASHX_SIZE})
endif()
endif()
set(HASHX_SALT CACHE STRING "Implementation-specific salt value")
if(HASHX_SALT)
string(LENGTH ${HASHX_SALT} HASHX_SALT_LENGTH)
if(HASHX_SALT_LENGTH GREATER 15)
message(SEND_ERROR "The maximum salt length is 15 characters")
else()
add_definitions(-DHASHX_SALT=${HASHX_SALT})
endif()
endif()
add_library(hashx SHARED ${hashx_sources})
set_property(TARGET hashx PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET hashx PROPERTY PUBLIC_HEADER include/hashx.h)
include_directories(hashx
include/)
target_compile_definitions(hashx PRIVATE HASHX_SHARED)
set_target_properties(hashx PROPERTIES VERSION ${HASHX_VERSION_STR}
SOVERSION ${HASHX_VERSION})
add_library(hashx_static STATIC ${hashx_sources})
set_property(TARGET hashx_static PROPERTY POSITION_INDEPENDENT_CODE ON)
set_target_properties(hashx_static PROPERTIES OUTPUT_NAME hashx)
include(GNUInstallDirs)
install(TARGETS hashx hashx_static
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
add_executable(hashx-tests
src/tests.c)
include_directories(hashx-tests
include/)
target_compile_definitions(hashx-tests PRIVATE HASHX_STATIC)
target_link_libraries(hashx-tests
PRIVATE hashx_static)
if(NOT Threads_FOUND AND UNIX AND NOT APPLE)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
endif()
add_executable(hashx-bench
src/bench.c
src/hashx_thread.c
src/hashx_time.c)
include_directories(hashx-bench
include/)
target_compile_definitions(hashx-bench PRIVATE HASHX_STATIC)
target_link_libraries(hashx-bench
PRIVATE hashx_static
PRIVATE ${CMAKE_THREAD_LIBS_INIT})