-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
231 lines (194 loc) · 7.56 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
# ----------------------------------------------------------------------------
# Root CMake file for simon and speck
# ----------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.7)
project(simon_speck CXX C)
# ----------------------------------------------------------------------------
# simon speck options
# ----------------------------------------------------------------------------
# simon speck build components
# ===================================================
option(ENABLE_STATIC "Build a static version of the libraries?" OFF)
option(DISABLE_SHARED "Do not build a shared version of the libraries?" OFF)
option(ENABLE_TESTING "Enable ctest?" OFF)
option(ENABLE_BENCHMARK "Enable benchmark?" OFF)
option(ENABLE_CCACHE "Enable ccache?" ON)
# simon speck build options
# ===================================================
option(ENABLE_NEON "Enable NEON instructions" OFF)
option(ENABLE_AVX2 "Enable AXV2 instructions" OFF)
# ----------------------------------------------------------------------------
# detect compiler and target platform architecture
# ----------------------------------------------------------------------------
# include(cmake/OpenCVDetectCXXCompiler.cmake)
# Add these standard paths to the search paths for FIND_LIBRARY
# to find libraries from these locations first
if(UNIX AND NOT ANDROID)
if(X86_64 OR CMAKE_SIZEOF_VOID_P EQUAL 8)
if(EXISTS /lib64)
list(APPEND CMAKE_LIBRARY_PATH /lib64)
else()
list(APPEND CMAKE_LIBRARY_PATH /lib)
endif()
if(EXISTS /usr/lib64)
list(APPEND CMAKE_LIBRARY_PATH /usr/lib64)
else()
list(APPEND CMAKE_LIBRARY_PATH /usr/lib)
endif()
elseif(X86 OR CMAKE_SIZEOF_VOID_P EQUAL 4)
if(EXISTS /lib32)
list(APPEND CMAKE_LIBRARY_PATH /lib32)
else()
list(APPEND CMAKE_LIBRARY_PATH /lib)
endif()
if(EXISTS /usr/lib32)
list(APPEND CMAKE_LIBRARY_PATH /usr/lib32)
else()
list(APPEND CMAKE_LIBRARY_PATH /usr/lib)
endif()
endif()
endif()
# Add these standard paths to the search paths for FIND_PATH
# to find include files from these locations first
if(MINGW)
if(EXISTS /mingw)
list(APPEND CMAKE_INCLUDE_PATH /mingw)
endif()
if(EXISTS /mingw32)
list(APPEND CMAKE_INCLUDE_PATH /mingw32)
endif()
if(EXISTS /mingw64)
list(APPEND CMAKE_INCLUDE_PATH /mingw64)
endif()
endif()
# ----------------------------------------------------------------------------
# ccache
# ----------------------------------------------------------------------------
find_program(CCACHE_EXE ccache)
if(CCACHE_EXE)
if(ENABLE_CCACHE)
message(STATUS "Enable ccache")
if(CMAKE_C_COMPILER_LAUNCHER)
set(CMAKE_C_COMPILER_LAUNCHER "${CMAKE_C_COMPILER_LAUNCHER}" "${CCACHE_EXE}")
else()
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_EXE}")
endif()
if(CMAKE_CXX_COMPILER_LAUNCHER)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CMAKE_CXX_COMPILER_LAUNCHER}" "${CCACHE_EXE}")
else()
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXE}")
endif()
endif()
endif()
# ----------------------------------------------------------------------------
# Detect endianness of build platform
# ----------------------------------------------------------------------------
#if(IOS)
# # test_big_endian needs try_compile, which doesn't work for iOS
# # http://public.kitware.com/Bug/view.php?id=12288
# set(WORDS_BIGENDIAN 0)
#else()
# include(TestBigEndian)
# test_big_endian(WORDS_BIGENDIAN)
#endif()
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 11)
# architectures
# FIXME
if((IOS_ARCH MATCHES "armv7") OR (CMAKE_ANDROID_ARCH_ABI MATCHES armeabi-v7a) OR (CMAKE_C_COMPILER MATCHES ".*arm-linux-gnueabi-gcc$"))
set(ARM ON)
elseif((IOS_ARCH MATCHES "arm64") OR (CMAKE_ANDROID_ARCH_ABI MATCHES arm64-v8a) OR (CMAKE_C_COMPILER MATCHES ".*aarch64-linux-gnu-gcc$"))
set(AARCH64 ON)
endif()
# ARM NEON
if(ENABLE_NEON)
if(ARM OR AARCH64)
if(AARCH64)
set(neon_flags "-O3")
elseif(ARM)
set(neon_flags "-mfloat-abi=softfp -mfpu=neon")
endif()
try_compile(NEON_FOUND "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/cmake/checks/cpu_neon.c"
COMPILE_DEFINITIONS "${neon_flags}")
if(NEON_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${neon_flags}")
set(WITH_NEON ON)
endif()
endif()
endif()
# Intel AVX2
if(ENABLE_AVX2)
if(MSVC)
set(avx2_flags "/arch:AVX2")
else()
set(avx2_flags "-mavx2")
endif()
try_run(AVX_RUN AVX_FOUND "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/cmake/checks/cpu_avx2.c"
COMPILE_DEFINITIONS "${avx2_flags}")
if(AVX_FOUND AND (AVX_RUN EQUAL 0))
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${avx2_flags}")
set(WITH_AVX2 ON)
endif()
endif()
# source
set(libspeck_SRCS ${libspeck_SRCS} src/speck/speck_common.c)
if(WITH_NEON)
set(libspeck_SRCS ${libspeck_SRCS} src/speck/speck_neon.c)
set(libspeck_PRIVATE_HEADER ${libspeck_PRIVATE_HEADER} src/speck/speck_neon_private.h)
set(libspeck_SRCS ${libspeck_SRCS} src/speck/speck_ctr_neon.c)
elseif(WITH_AVX2)
set(libspeck_SRCS ${libspeck_SRCS} src/speck/speck_avx2.c)
set(libspeck_PRIVATE_HEADER ${libspeck_PRIVATE_HEADER} src/speck/speck_avx2_private.h)
set(libspeck_SRCS ${libspeck_SRCS} src/speck/speck_ctr_avx2.c)
else()
set(libspeck_SRCS ${libspeck_SRCS} src/speck/speck.c)
set(libspeck_SRCS ${libspeck_SRCS} src/speck/speck_ctr.c)
endif()
if(WIN32)
set(libspeck_SRCS ${libspeck_SRCS} src/utils/dllmain.c)
endif(WIN32)
# header
set(libspeck_PUBLIC_HEADER include/speck/speck.h)
set(libspeck_PRIVATE_HEADER ${libspeck_PRIVATE_HEADER} src/speck/speck_private.h src/speck/speck_ctr_private.h)
include_directories(${CMAKE_SOURCE_DIR}/include)
set(libspeck_SRCS ${libspeck_SRCS} ${libspeck_PUBLIC_HEADER} ${libspeck_PRIVATE_HEADER})
add_library(speck
SHARED
${libspeck_SRCS}
)
if (WITH_NEON)
target_compile_definitions(speck PRIVATE "-DWITH_NEON")
endif()
if (DISABLE_SHARED)
add_library(libspeck STAIC ${libspeck_SRCS})
else (DISABLE_SHARED)
add_library(libspeck SHARED ${libspeck_SRCS})
endif (DISABLE_SHARED)
SET_TARGET_PROPERTIES(libspeck PROPERTIES OUTPUT_NAME "speck")
#SET_TARGET_PROPERTIES(libspeck PROPERTIES SOVERSION 0) # TODO
#SET_TARGET_PROPERTIES(libspeck PROPERTIES INSTALL_NAME_DIR ${LIB_INSTALL_DIR})
if (ENABLE_STATIC AND NOT DISABLE_SHARED)
add_library(libspeck_static STATIC ${libspeck_SRCS})
set_target_properties(libspeck_static PROPERTIES OUTPUT_NAME "speck")
#set_target_properties(libspeck_static PROPERTIES SOVERSION 0) # TODO
#install(TARGETS libspeck_static LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
endif (ENABLE_STATIC AND NOT DISABLE_SHARED)
if (NOT (IOS OR ANDROID))
add_executable(speck_test sample/speck_test.cpp)
target_link_libraries(speck_test PUBLIC speck)
endif()
if(ENABLE_TESTING)
if(ENABLE_BENCHMARK)
if(TEST_COUNT)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_COUNT=${TEST_COUNT}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_COUNT=${TEST_COUNT}")
endif()
if(TEST_BYTE_LENGTH)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_BYTE_LENGTH=${TEST_BYTE_LENGTH}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_BYTE_LENGTH=${TEST_BYTE_LENGTH}")
endif()
endif()
enable_testing()
add_subdirectory("test")
endif()