-
Notifications
You must be signed in to change notification settings - Fork 12
/
CMakeLists.txt
250 lines (235 loc) · 8.19 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0003 NEW)
project(SMHasher C CXX)
include(CheckCCompilerFlag)
# Check if the same compile family is used for both C and CXX
if (NOT (CMAKE_C_COMPILER_ID STREQUAL CMAKE_CXX_COMPILER_ID))
message(WARNING "CMAKE_C_COMPILER_ID (${CMAKE_C_COMPILER_ID}) is different "
"from CMAKE_CXX_COMPILER_ID (${CMAKE_CXX_COMPILER_ID}). "
"The final binary may be unusable.")
endif()
IF (CMAKE_MAJOR_VERSION GREATER 2)
cmake_policy(SET CMP0056 OLD)
cmake_policy(SET CMP0065 NEW) # ENABLE_EXPORTS
#cmake_policy(SET CMP0066 OLD)
include (TestBigEndian)
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
if(IS_BIG_ENDIAN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBIG_ENDIAN")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBIG_ENDIAN")
endif()
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release
RelWithDebInfo MinSizeRel."
FORCE)
endif(NOT CMAKE_BUILD_TYPE)
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
EXEC_PROGRAM(cat ARGS "/proc/cpuinfo" OUTPUT_VARIABLE CPUINFO)
STRING(REGEX REPLACE "^.*(sse2).*$" "\\1" SSE_THERE ${CPUINFO})
STRING(COMPARE EQUAL "sse2" "${SSE_THERE}" SSE2_TRUE)
STRING(REGEX REPLACE "^.*(sse4_2).*$" "\\1" SSE_THERE ${CPUINFO})
STRING(COMPARE EQUAL "sse4_2" "${SSE_THERE}" SSE42_TRUE)
set(FALKHASH_OBJ falkhash-elf64.o)
STRING(REGEX REPLACE "^.*(aes).*$" "\\1" AES_THERE ${CPUINFO})
STRING(COMPARE EQUAL "aes" "${AES_THERE}" AES_TRUE)
STRING(REGEX REPLACE "^.*(avx).*$" "\\1" AVX_THERE ${CPUINFO})
STRING(COMPARE EQUAL "avx" "${AVX_THERE}" AVX_TRUE)
STRING(REGEX REPLACE "^.*(avx2).*$" "\\1" AVX2_THERE ${CPUINFO})
STRING(COMPARE EQUAL "avx2" "${AVX2_THERE}" AVX2_TRUE)
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Darwin")
EXEC_PROGRAM("/usr/sbin/sysctl -n machdep.cpu.features" OUTPUT_VARIABLE
CPUINFO)
STRING(REGEX REPLACE "^.*[^S](SSE2).*$" "\\1" SSE_THERE ${CPUINFO})
STRING(COMPARE EQUAL "SSE2" "${SSE_THERE}" SSE2_TRUE)
STRING(REGEX REPLACE "^.*(SSE4.2).*$" "\\1" SSE_THERE ${CPUINFO})
STRING(COMPARE EQUAL "SSE4.2" "${SSE_THERE}" SSE42_TRUE)
set(FALKHASH_OBJ falkhash-macho64.o)
STRING(REGEX REPLACE "^.*(AES).*$" "\\1" AES_THERE ${CPUINFO})
STRING(COMPARE EQUAL "AES" "${AES_THERE}" AES_TRUE)
STRING(REGEX REPLACE "^.*(AVX).*$" "\\1" AVX_THERE ${CPUINFO})
STRING(COMPARE EQUAL "AVX" "${AVX_THERE}" AVX_TRUE)
STRING(REGEX REPLACE "^.*(AVX2).*$" "\\1" AVX2_THERE ${CPUINFO})
STRING(COMPARE EQUAL "AVX2" "${AVX2_THERE}" AVX2_TRUE)
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
EXEC_PROGRAM("grep Features /var/run/dmesg.boot" OUTPUT_VARIABLE
CPUINFO)
STRING(REGEX REPLACE "^.*[^S](SSE2).*$" "\\1" SSE_THERE ${CPUINFO})
STRING(COMPARE EQUAL "SSE2" "${SSE_THERE}" SSE2_TRUE)
STRING(REGEX REPLACE "^.*(SSE4.2).*$" "\\1" SSE_THERE ${CPUINFO})
STRING(COMPARE EQUAL "SSE4.2" "${SSE_THERE}" SSE42_TRUE)
set(FALKHASH_OBJ falkhash-elf64.o)
STRING(REGEX REPLACE "^.*(AES).*$" "\\1" AES_THERE ${CPUINFO})
STRING(COMPARE EQUAL "AES" "${AES_THERE}" AES_TRUE)
STRING(REGEX REPLACE "^.*(AVX).*$" "\\1" AVX_THERE ${CPUINFO})
STRING(COMPARE EQUAL "AVX" "${AVX_THERE}" AVX_TRUE)
STRING(REGEX REPLACE "^.*(AVX2).*$" "\\1" AVX2_THERE ${CPUINFO})
STRING(COMPARE EQUAL "AVX2" "${AVX2_THERE}" AVX2_TRUE)
ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
if (CMAKE_COMPILER_IS_GNUCC
OR (CMAKE_C_COMPILER_ID STREQUAL AppleClang)
OR (CMAKE_C_COMPILER_ID STREQUAL Clang)
OR (CMAKE_C_COMPILER_ID STREQUAL Intel))
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_C_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
IF (SSE2_TRUE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
ENDIF (SSE2_TRUE)
IF (SSE42_TRUE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4")
ENDIF (SSE42_TRUE)
IF (AES_TRUE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes")
ENDIF (AES_TRUE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# using Visual Studio C++
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:SSE2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
else()
message(WARNING "Unknown ${CMAKE_C_COMPILER_ID} compiler")
# TODO: BSD and ARM8 crc detection
# TODO: 32bit filter
endif()
IF (SSE2_TRUE)
set(SSE2_FOUND true CACHE BOOL "SSE2 available")
ELSE (SSE2_TRUE)
set(SSE2_FOUND false CACHE BOOL "SSE2 not available")
ENDIF (SSE2_TRUE)
IF (SSE42_TRUE)
set(SSE4_2_FOUND true CACHE BOOL "SSE4.2 available")
ELSE (SSE42_TRUE)
set(SSE4_2_FOUND false CACHE BOOL "SSE4.2 not available")
ENDIF (SSE42_TRUE)
IF (AES_TRUE)
set(AES_FOUND true CACHE BOOL "AES-NI available")
ELSE (AES_TRUE)
set(AES_FOUND false CACHE BOOL "AES-NI not available")
ENDIF (AES_TRUE)
IF (AES_TRUE)
add_definitions(-DAES_AVAIL=1)
set(AES_FOUND true CACHE BOOL "AES-NI available")
ELSE (AES_TRUE)
set(AES_FOUND false CACHE BOOL "AES-NI not available")
ENDIF (AES_TRUE)
IF (AVX_TRUE)
add_definitions(-DAVX_AVAIL=1)
set(AVX_FOUND true CACHE BOOL "AVX available")
ELSE (AVX_TRUE)
set(AVX_FOUND false CACHE BOOL "AVX not available")
ENDIF (AVX_TRUE)
IF (AVX2_TRUE)
add_definitions(-DAVX2_AVAIL=1)
set(AVX2_FOUND true CACHE BOOL "AVX2 available")
ELSE (AVX2_TRUE)
set(AVX2_FOUND false CACHE BOOL "AVX2 not available")
ENDIF (AVX2_TRUE)
IF(AES_FOUND AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
set(SSE4_OBJ ${FALKHASH_OBJ})
ENDIF()
set(T1HA_SRC t1ha/t1ha0.c t1ha/t1ha1.c t1ha/t1ha2.c t1ha/t1ha0_ia32aes_noavx.c t1ha/t1ha0_ia32aes_avx.c t1ha/t1ha0_ia32aes_avx2.c)
set_source_files_properties(t1ha/t1ha0_ia32aes_noavx.c PROPERTIES COMPILE_FLAGS "-mno-avx2 -mno-avx -maes")
set_source_files_properties(t1ha/t1ha0_ia32aes_avx.c PROPERTIES COMPILE_FLAGS "-mno-avx2 -mavx -maes")
set_source_files_properties(t1ha/t1ha0_ia32aes_avx2.c PROPERTIES COMPILE_FLAGS "-mavx -mavx2 -maes")
IF(SSE4_2_FOUND)
SET(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(SSE2_SRC hasshe2.c)
set(SSE4_SRC crc32_hw.c)
# 64bit only:
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
#enable_language(ASM-NASM)
#set(CMAKE_ASM_FLAGS "-f elf64")
set(SSE4_SRC1 crc32_hw1.c)
set(METROCRC64_SRC metrohash64crc.cpp)
set(METROCRC128_SRC metrohash128crc.cpp)
ENDIF()
set(SIPHASH_SRC siphash_ssse3.c)
ELSEIF(SSE2_FOUND)
set(SSE2_SRC hasshe2.c)
set(SIPHASH_SRC siphash_sse2.c)
ELSE()
set(SIPHASH_SRC siphash.c)
ENDIF(SSE4_2_FOUND)
set(SIPHASH_SRC siphash.c)
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(64ONLY_SRC
xxhash.c metrohash64.cpp metrohash128.cpp farmhash.cc
FarmTest.cc farmhash-c.c farmhash-c-test.cc cmetrohash64.c
opt_cmetrohash64_1.c fasthash.cpp)
ENDIF()
IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/BeagleHashes_test.c")
set(BEAGLE_SRC BeagleHashes_test.c)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_BEAGLE_HASHES")
ENDIF()
IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tsip.c")
set(TSIP_SRC tsip.c)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_TSIP")
ENDIF()
IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/funny_hash.h")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_FUNNY_HASH")
ENDIF()
IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/fanom_hash.h")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_FANOM_HASH")
ENDIF()
add_library(SMHasherSupport
AvalancheTest.cpp
Bitslice.cpp
Bitvec.cpp
DifferentialTest.cpp
KeysetTest.cpp
Platform.cpp
Random.cpp
RunTests.cpp
SpeedTest.cpp
Stats.cpp
TAP.cpp
Types.cpp
Hashes.cpp
City.cpp
CityTest.cpp
MurmurHash1.cpp
MurmurHash2.cpp
MurmurHash3.cpp
PMurHash.c
Spooky.cpp
SpookyTest.cpp
SuperFastHash.cpp
crc.cpp
lookup3.cpp
md5.cpp
mum.cc
sha1.cpp
${T1HA_SRC}
${64ONLY_SRC}
${BEAGLE_SRC}
${METROCRC128_SRC}
${METROCRC64_SRC}
${SIPHASH_SRC}
${SSE2_SRC}
${SSE4_OBJ}
${SSE4_SRC1}
${SSE4_SRC}
${TSIP_SRC}
mum.cc
jody_hash32.c
jody_hash64.c
)
add_executable(
SMHasher
main.cpp
)
target_link_libraries(
SMHasher
SMHasherSupport
${CMAKE_THREAD_LIBS_INIT}
gsl
gslcblas
)