-
Notifications
You must be signed in to change notification settings - Fork 187
/
CMakeLists.txt
244 lines (185 loc) · 7.6 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
project(highwayhash C CXX)
cmake_minimum_required(VERSION 3.18)
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to make
# it prominent in the GUI.
option(BUILD_SHARED_LIBS "Build library as shared." OFF)
# Force PIC on unix when building shared libs
# see: https://en.wikipedia.org/wiki/Position-independent_code
if(BUILD_SHARED_LIBS AND UNIX)
option(CMAKE_POSITION_INDEPENDENT_CODE "Build with Position Independant Code." ON)
endif()
set(PROCESSOR_IS_ARM FALSE)
set(PROCESSOR_IS_AARCH64 FALSE)
set(PROCESSOR_IS_X86 FALSE)
set(PROCESSOR_IS_POWER FALSE)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)")
set(PROCESSOR_IS_AARCH64 TRUE)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
set(PROCESSOR_IS_ARM TRUE)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(AMD64|amd64)|(^i.86$)")
set(PROCESSOR_IS_X86 TRUE)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)")
set(PROCESSOR_IS_POWER TRUE)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -O3 -fPIC -pthread -Wno-maybe-uninitialized")
if(PROCESSOR_IS_ARM)
# aarch64 and ARM use the same code, although ARM usually needs an extra flag for NEON.
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=hard -march=armv7-a -mfpu=neon")
endif()
endif()
#
# library : highwayhash
#
set(HH_INCLUDES
${PROJECT_SOURCE_DIR}/highwayhash/c_bindings.h
${PROJECT_SOURCE_DIR}/highwayhash/highwayhash.h
)
set(HH_SOURCES
${PROJECT_SOURCE_DIR}/highwayhash/c_bindings.cc
${PROJECT_SOURCE_DIR}/highwayhash/hh_portable.cc
${PROJECT_SOURCE_DIR}/highwayhash/arch_specific.cc
${PROJECT_SOURCE_DIR}/highwayhash/scalar_sip_tree_hash.cc
${PROJECT_SOURCE_DIR}/highwayhash/sip_hash.cc
${PROJECT_SOURCE_DIR}/highwayhash/sip_tree_hash.cc
${PROJECT_SOURCE_DIR}/highwayhash/hh_portable.h
${PROJECT_SOURCE_DIR}/highwayhash/state_helpers.h
${PROJECT_SOURCE_DIR}/highwayhash/arch_specific.h
${PROJECT_SOURCE_DIR}/highwayhash/compiler_specific.h
${PROJECT_SOURCE_DIR}/highwayhash/load3.h
${PROJECT_SOURCE_DIR}/highwayhash/vector128.h
${PROJECT_SOURCE_DIR}/highwayhash/vector256.h
${PROJECT_SOURCE_DIR}/highwayhash/endianess.h
${PROJECT_SOURCE_DIR}/highwayhash/iaca.h
${PROJECT_SOURCE_DIR}/highwayhash/hh_types.h
${PROJECT_SOURCE_DIR}/highwayhash/hh_buffer.h
${PROJECT_SOURCE_DIR}/highwayhash/scalar_sip_tree_hash.h
${PROJECT_SOURCE_DIR}/highwayhash/sip_hash.h
${PROJECT_SOURCE_DIR}/highwayhash/sip_tree_hash.h
)
if(PROCESSOR_IS_ARM OR PROCESSOR_IS_AARCH64)
list(APPEND HH_SOURCES ${PROJECT_SOURCE_DIR}/highwayhash/hh_neon.cc)
list(APPEND HH_SOURCES ${PROJECT_SOURCE_DIR}/highwayhash/hh_neon.h)
elseif(PROCESSOR_IS_POWER)
list(APPEND HH_SOURCES ${PROJECT_SOURCE_DIR}/highwayhash/hh_vsx.cc)
list(APPEND HH_SOURCES ${PROJECT_SOURCE_DIR}/highwayhash/hh_vsx.h)
set_source_files_properties(
${PROJECT_SOURCE_DIR}/highwayhash/benchmark.cc
PROPERTIES COMPILE_FLAGS -mvsx)
set_source_files_properties(
${PROJECT_SOURCE_DIR}/highwayhash/hh_vsx.cc
PROPERTIES COMPILE_FLAGS -mvsx)
elseif(PROCESSOR_IS_X86)
list(APPEND HH_SOURCES ${PROJECT_SOURCE_DIR}/highwayhash/hh_avx2.cc)
list(APPEND HH_SOURCES ${PROJECT_SOURCE_DIR}/highwayhash/hh_sse41.cc)
list(APPEND HH_SOURCES ${PROJECT_SOURCE_DIR}/highwayhash/hh_avx2.h)
list(APPEND HH_SOURCES ${PROJECT_SOURCE_DIR}/highwayhash/hh_sse41.h)
# TODO: Portability: Have AVX2 be optional so benchmarking can be done on older machines.
set_source_files_properties(
${PROJECT_SOURCE_DIR}/highwayhash/benchmark.cc
PROPERTIES COMPILE_FLAGS -mavx2)
set_source_files_properties(
${PROJECT_SOURCE_DIR}/highwayhash/sip_tree_hash.cc
PROPERTIES COMPILE_FLAGS -mavx2)
set_source_files_properties(
${PROJECT_SOURCE_DIR}/highwayhash/hh_avx2.cc
PROPERTIES COMPILE_FLAGS -mavx2)
set_source_files_properties(
${PROJECT_SOURCE_DIR}/highwayhash/hh_sse41.cc
PROPERTIES COMPILE_FLAGS -msse4.1)
set_source_files_properties(
${PROJECT_SOURCE_DIR}/highwayhash/hh_portable.cc
PROPERTIES COMPILE_FLAGS -DHH_TARGET_NAME=Portable)
else()
# Unknown architecture.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHH_DISABLE_TARGET_SPECIFIC")
endif()
add_library(highwayhash ${HH_INCLUDES} ${HH_SOURCES})
set_target_properties(highwayhash PROPERTIES PUBLIC_HEADER "${HH_INCLUDES}")
target_include_directories(highwayhash
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
)
target_include_directories(highwayhash
PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/highwayhash>
)
if(NOT WIN32 AND NOT ANDROID)
target_link_libraries(highwayhash pthread)
endif()
add_library(highwayhash::highwayhash ALIAS highwayhash)
#
# Tests & Similar
#
add_library(nanobenchmark OBJECT
${PROJECT_SOURCE_DIR}/highwayhash/nanobenchmark.h
${PROJECT_SOURCE_DIR}/highwayhash/nanobenchmark.cc
${PROJECT_SOURCE_DIR}/highwayhash/instruction_sets.h
${PROJECT_SOURCE_DIR}/highwayhash/os_specific.h
${PROJECT_SOURCE_DIR}/highwayhash/profiler.h
${PROJECT_SOURCE_DIR}/highwayhash/tsc_timer.h
${PROJECT_SOURCE_DIR}/highwayhash/instruction_sets.cc
${PROJECT_SOURCE_DIR}/highwayhash/os_specific.cc
)
target_include_directories(nanobenchmark PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(highwayhash_test)
target_sources(highwayhash_test PRIVATE
${PROJECT_SOURCE_DIR}/highwayhash/highwayhash_test.cc
${PROJECT_SOURCE_DIR}/highwayhash/highwayhash_test_portable.cc
${PROJECT_SOURCE_DIR}/highwayhash/highwayhash_test_target.h
)
target_link_libraries(highwayhash_test highwayhash nanobenchmark)
add_executable(vector_test)
target_sources(vector_test PRIVATE
${PROJECT_SOURCE_DIR}/highwayhash/vector_test.cc
${PROJECT_SOURCE_DIR}/highwayhash/vector_test_portable.cc
${PROJECT_SOURCE_DIR}/highwayhash/vector_test_target.h
)
target_link_libraries(vector_test highwayhash nanobenchmark)
if(PROCESSOR_IS_ARM OR PROCESSOR_IS_AARCH64)
target_sources(highwayhash_test PRIVATE
${PROJECT_SOURCE_DIR}/highwayhash/highwayhash_test_neon.cc
)
target_sources(vector_test PRIVATE
${PROJECT_SOURCE_DIR}/highwayhash/vector_test_neon.cc
)
elseif(PROCESSOR_IS_X86)
target_sources(highwayhash_test PRIVATE
${PROJECT_SOURCE_DIR}/highwayhash/highwayhash_test_avx2.cc
${PROJECT_SOURCE_DIR}/highwayhash/highwayhash_test_sse41.cc
)
target_sources(vector_test PRIVATE
${PROJECT_SOURCE_DIR}/highwayhash/vector_test_avx2.cc
${PROJECT_SOURCE_DIR}/highwayhash/vector_test_sse41.cc
)
set_source_files_properties(
${PROJECT_SOURCE_DIR}/highwayhash/highwayhash_test_avx2.cc
PROPERTIES COMPILE_FLAGS -mavx2)
set_source_files_properties(
${PROJECT_SOURCE_DIR}/highwayhash/highwayhash_test_sse41.cc
PROPERTIES COMPILE_FLAGS -msse4.1)
set_source_files_properties(
${PROJECT_SOURCE_DIR}/highwayhash/vector_test_avx2.cc
PROPERTIES COMPILE_FLAGS -mavx2)
set_source_files_properties(
${PROJECT_SOURCE_DIR}/highwayhash/vector_test_sse41.cc
PROPERTIES COMPILE_FLAGS -msse4.1)
elseif(PROCESSOR_IS_POWER)
target_sources(highwayhash_test PRIVATE
${PROJECT_SOURCE_DIR}/highwayhash/highwayhash_test_vsx.cc
)
set_source_files_properties(
${PROJECT_SOURCE_DIR}/highwayhash/highwayhash_test_vsx.cc
PROPERTIES COMPILE_FLAGS -mvsx)
set_source_files_properties(
${PROJECT_SOURCE_DIR}/highwayhash/vector_test.cc
PROPERTIES COMPILE_FLAGS -DHH_DISABLE_TARGET_SPECIFIC)
endif()
add_executable(sip_hash_test)
target_sources(sip_hash_test PRIVATE
${PROJECT_SOURCE_DIR}/highwayhash/sip_hash_test.cc
)
target_link_libraries(sip_hash_test highwayhash)
add_executable(example)
target_sources(example PRIVATE
${PROJECT_SOURCE_DIR}/highwayhash/example.cc
)
target_link_libraries(example highwayhash)