-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
123 lines (103 loc) · 3.94 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
cmake_minimum_required(VERSION 2.6)
project(Argon2 C)
set(ARGON2_VERSION 1.0)
set(BINARY_INSTALL_DIR /usr/local/bin)
set(LIBRARY_INSTALL_DIR /usr/local/lib)
set(INCLUDE_INSTALL_DIR /usr/local/include)
set(CMAKE_C_STANDARD 90)
set(CMAKE_C_STANDARD_REQUIRED ON)
enable_testing()
include(CheckCSourceCompiles)
find_package(Threads REQUIRED)
add_library(argon2-interface INTERFACE)
target_include_directories(argon2-interface INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
add_library(argon2-internal INTERFACE)
target_include_directories(argon2-internal INTERFACE lib lib/blake2)
target_link_libraries(argon2-internal INTERFACE argon2-interface)
add_library(argon2 SHARED
lib/argon2.c
lib/core.c
lib/encoding.c
lib/genkat.c
lib/impl-select.c
lib/thread.c
lib/blake2/blake2.c
)
target_link_libraries(argon2
PUBLIC argon2-interface ${CMAKE_THREAD_LIBS_INIT}
PRIVATE argon2-internal
)
set_property(TARGET argon2 PROPERTY VERSION ${Upstream_VERSION})
set_property(TARGET argon2 PROPERTY SOVERSION 1)
set_property(TARGET argon2 PROPERTY INTERFACE_ARGON2_MAJOR_VERSION 1)
set_property(TARGET argon2 APPEND PROPERTY
COMPATIBLE_INTERFACE_STRING ARGON2_MAJOR_VERSION
)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
function(add_feature_impl FEATURE GCC_FLAG DEF)
add_library(argon2-${FEATURE} STATIC
arch/x86_64/lib/argon2-${FEATURE}.c
)
target_link_libraries(argon2-${FEATURE} PRIVATE argon2-internal)
set_target_properties(argon2-${FEATURE}
PROPERTIES POSITION_INDEPENDENT_CODE True
)
message("-- Detecting feature '${FEATURE}'...")
file(READ arch/x86_64/src/test-feature-${FEATURE}.c SOURCE_CODE)
# try without flag:
check_c_source_compiles("${SOURCE_CODE}" FEATURE_${FEATURE}_NOFLAG)
set(HAS_FEATURE ${FEATURE_${FEATURE}_NOFLAG})
if(NOT "${HAS_FEATURE}")
# try with -m<feature> flag:
set(CMAKE_REQUIRED_FLAGS ${GCC_FLAG})
check_c_source_compiles("${SOURCE_CODE}" FEATURE_${FEATURE}_FLAG)
set(CMAKE_REQUIRED_FLAGS "")
set(HAS_FEATURE ${FEATURE_${FEATURE}_FLAG})
if(${HAS_FEATURE})
target_compile_options(argon2-${FEATURE} PRIVATE ${GCC_FLAG})
endif()
endif()
if(${HAS_FEATURE})
message("-- Feature '${FEATURE}' detected!")
target_compile_definitions(argon2-${FEATURE} PRIVATE ${DEF})
endif()
target_link_libraries(argon2 PUBLIC argon2-${FEATURE})
endfunction()
target_include_directories(argon2-internal INTERFACE arch/x86_64/lib)
add_feature_impl(sse2 -msse2 HAVE_SSE2)
add_feature_impl(ssse3 -mssse3 HAVE_SSSE3)
add_feature_impl(xop -mxop HAVE_XOP)
add_feature_impl(avx2 -mavx2 HAVE_AVX2)
add_feature_impl(avx512f -mavx512f HAVE_AVX512F)
target_sources(argon2 PRIVATE
arch/x86_64/lib/argon2-arch.c
arch/x86_64/lib/cpu-flags.c
)
else()
target_sources(argon2 PRIVATE
arch/generic/lib/argon2-arch.c
)
endif()
add_executable(argon2-exec src/run.c)
target_link_libraries(argon2-exec argon2 argon2-internal)
target_include_directories(argon2-exec PRIVATE src)
set_target_properties(argon2-exec PROPERTIES OUTPUT_NAME argon2)
add_executable(argon2-genkat src/genkat.c)
target_include_directories(argon2-genkat PRIVATE src)
target_link_libraries(argon2-genkat argon2)
add_executable(argon2-bench2 src/bench2.c)
target_include_directories(argon2-bench2 PRIVATE src)
target_link_libraries(argon2-bench2 argon2 -lrt)
add_executable(argon2-test tests/test.c)
target_include_directories(argon2-test PRIVATE tests)
target_link_libraries(argon2-test argon2)
add_test(test argon2-test)
install(TARGETS argon2 DESTINATION ${LIBRARY_INSTALL_DIR})
install(FILES
include/argon2.h
DESTINATION ${INCLUDE_INSTALL_DIR}
)
install(TARGETS argon2-exec DESTINATION ${BINARY_INSTALL_DIR})