This repository has been archived by the owner on Feb 6, 2019. It is now read-only.
forked from relic-toolkit/relic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
416 lines (344 loc) · 13.4 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
cmake_minimum_required(VERSION 3.1)
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.1")
cmake_policy(SET CMP0054 NEW)
endif()
project(RELIC C CXX)
set(PROJECT_VERSION_MAJOR "0")
set(PROJECT_VERSION_MINOR "4")
set(PROJECT_VERSION_PATCH "1")
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
set(VERSION ${PROJECT_VERSION})
set(INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include/low)
include_directories(${INCLUDE})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(WFLAGS "-Wall")
message("\n-- Configuring ${PROJECT_NAME} ${PROJECT_VERSION}...\n")
message(STATUS "Available switches (default = CHECK, VERBS, DOCUM):\n")
message(" DEBUG=[off|on] Build with debugging support.")
message(" PROFL=[off|on] Build with profiling support.")
message(" CHECK=[off|on] Build with error-checking support.")
message(" VERBS=[off|on] Build with detailed error messages.")
message(" TRACE=[off|on] Build with tracing support.")
message(" OVERH=[off|on] Build with overhead estimation.")
message(" DOCUM=[off|on] Build documentation.")
message(" STRIP=[off|on] Build only selected algorithms.")
message(" QUIET=[off|on] Build with printing disabled.")
message(" COLOR=[off|on] Build with colored output.")
message(" BIGED=[off|on] Build with big-endian support.")
message(" SHLIB=[off|on] Build shared library.")
message(" STLIB=[off|on] Build static library.")
message(" STBIN=[off|on] Build static binaries.")
message(" AMALG=[off|on] Build amalgamation for better performance.\n")
option(DEBUG "Build with debugging support" off)
option(PROFL "Build with profiling support" off)
option(CHECK "Build with error-checking support" on)
option(VERBS "Build with detailed error messages" on)
option(TRACE "Build with tracing support" off)
option(OVERH "Build with overhead estimation" off)
option(DOCUM "Build documentation" on)
option(STRIP "Build only the selected algorithms" off)
option(QUIET "Build with printing disabled" off)
option(COLOR "Build with colored output" on)
option(BIGED "Build with big-endian support" off)
option(SHLIB "Build shared library" on)
option(STLIB "Build static library" on)
option(STBIN "Build static binaries" off)
option(AMALG "Build amalgamation" off)
message(STATUS "Number of times each test or benchmark is ran (default = 50, 1000):\n")
message(" TESTS=n If n > 0, build automated tests and run them n times.")
message(" BENCH=n If n > 0, build automated benchmarks and run them n * n times.\n")
message(STATUS "Number of available processor cores (default = 1):\n")
message(" CORES=n If n > 1, please enable multithreading support.\n")
message(STATUS "Available modules (default = ALL)\n")
message(" WITH=BN Multiple precision arithmetic.")
message(" WITH=DV Temporary double-precision digit vectors.")
message(" WITH=FP Prime field arithmetic.")
message(" WITH=FPX Prime extension field arithmetic.")
message(" WITH=FB Binary field arithmetic.")
message(" WITH=EP Elliptic curves over prime fields.")
message(" WITH=EPX Elliptic curves over quadratic extensions of prime fields.")
message(" WITH=EB Elliptic curves over binary fields.")
message(" WITH=ED Elliptic Edwards curves over prime fields.")
message(" WTTH=EC Elliptic curve cryptography.")
message(" WITH=PB Pairings over binary elliptic curves.")
message(" WITH=PP Pairings over prime elliptic curves.")
message(" WTTH=PC Pairing-based cryptography.")
message(" WITH=BC Block ciphers (symmetric encryption).")
message(" WITH=MD Message digests (hash functions).")
message(" WITH=CP Cryptographic protocols.")
message(" WITH=ALL All of the above.")
message(" Note: the programmer is responsible for not using unselected modules.\n")
message(STATUS "Available arithmetic backends (default = easy):\n")
message(" ARITH=easy Easy-to-understand implementation.")
message(" ARITH=gmp GNU Multiple Precision library.\n")
message(STATUS "Available memory-allocation policies (default = AUTO):\n")
message(" ALLOC=AUTO All memory is automatically allocated.")
message(" ALLOC=STATIC All memory is allocated statically once.")
message(" ALLOC=DYNAMIC All memory is allocated dynamically on demand.")
message(" ALLOC=STACK All memory is allocated from the stack.\n")
message(STATUS "Supported operating systems (default = LINUX):\n")
message(" OPSYS= Undefined/No specific operating system.")
message(" OPSYS=LINUX GNU/Linux operating system.")
message(" OPSYS=FREEBSD FreeBSD operating system.")
message(" OPSYS=MACOSX Mac OS X operating system.")
message(" OPSYS=WINDOWS Windows operating system.")
message(" OPSYS=DROID Android operating system.")
message(" OPSYS=DUINO Arduino platform.\n")
message(STATUS "Supported multithreading APIs (default = UNDEF):\n")
message(" MULTI= No multithreading support.")
message(" MULTI=OPENMP Open Multi-Processing.")
message(" MULTI=PTHREAD POSIX threads.\n")
message(STATUS "Supported timers (default = HPROC):\n")
message(" TIMER= No timer.")
message(" TIMER=HREAL GNU/Linux realtime high-resolution timer.")
message(" TIMER=HPROC GNU/Linux per-process high-resolution timer.")
message(" TIMER=HTHRD GNU/Linux per-thread high-resolution timer.")
message(" TIMER=ANSI ANSI-compatible timer.")
message(" TIMER=POSIX POSIX-compatible timer.")
message(" TIMER=CYCLE Cycle-counting timer. (architecture-dependant)\n")
message(STATUS "Prefix to identify this build of the library (default = \"\"):\n")
message(" LABEL=relic\n")
include(cmake/arch.cmake)
include(cmake/bn.cmake)
include(cmake/fp.cmake)
include(cmake/fpx.cmake)
include(cmake/fb.cmake)
include(cmake/ep.cmake)
include(cmake/eb.cmake)
include(cmake/ed.cmake)
include(cmake/ec.cmake)
include(cmake/pp.cmake)
include(cmake/md.cmake)
include(cmake/cp.cmake)
include(cmake/rand.cmake)
# Number of tests and benchmarks
set(BENCH 100 CACHE INTEGER "Number of times each benchmark is ran.")
set(TESTS 100 CACHE INTEGER "Number of times each test is ran.")
# Number of cores.
set(CORES 1 CACHE INTEGER "Number of available processor cores.")
# Default modules.
set(WITH "ALL" CACHE STRING "Selected modules")
LIST(FIND WITH "ALL" TEMP)
if(TEMP GREATER -1)
set(WITH_BN 1)
set(WITH_DV 1)
set(WITH_FP 1)
set(WITH_FPX 1)
set(WITH_FB 1)
set(WITH_FBX 1)
set(WITH_FT 1)
set(WITH_EP 1)
set(WITH_EPX 1)
set(WITH_EB 1)
set(WITH_ED 1)
set(WITH_EC 1)
set(WITH_PP 1)
set(WITH_PB 1)
set(WITH_PC 1)
set(WITH_BC 1)
set(WITH_MD 1)
set(WITH_CP 1)
endif(TEMP GREATER -1)
# Check if multiple precision integer arithmetic is required.
LIST(FIND WITH "BN" TEMP)
if(TEMP GREATER -1)
set(WITH_BN 1)
endif(TEMP GREATER -1)
# Check if temporary vectors are required.
LIST(FIND WITH "DV" TEMP)
if(TEMP GREATER -1)
set(WITH_DV 1)
endif(TEMP GREATER -1)
# Check if prime field arithmetic is required.
LIST(FIND WITH "FP" TEMP)
if(TEMP GREATER -1)
set(WITH_FP 1)
endif(TEMP GREATER -1)
# Check if prime extension field arithmetic is required.
LIST(FIND WITH "FPX" TEMP)
if(TEMP GREATER -1)
set(WITH_FPX 1)
endif(TEMP GREATER -1)
# Check if binary field arithmetic is required.
LIST(FIND WITH "FB" TEMP)
if(TEMP GREATER -1)
set(WITH_FB 1)
endif(TEMP GREATER -1)
# Check if binary extension field arithmetic is required.
LIST(FIND WITH "FBX" TEMP)
if(TEMP GREATER -1)
set(WITH_FBX 1)
endif(TEMP GREATER -1)
# Check if prime elliptic curve support is required.
LIST(FIND WITH "EP" TEMP)
if(TEMP GREATER -1)
set(WITH_EP 1)
endif(TEMP GREATER -1)
#Check if support for elliptic curves defined over prime field extensions is required.
LIST(FIND WITH "EPX" TEMP)
if (TEMP GREATER -1)
set(WITH_EPX 1)
endif(TEMP GREATER -1)
# Check if binary elliptic curve support is required.
LIST(FIND WITH "EB" TEMP)
if(TEMP GREATER -1)
set(WITH_EB 1)
endif(TEMP GREATER -1)
# Check if binary elliptic curve support is required.
LIST(FIND WITH "ED" TEMP)
if(TEMP GREATER -1)
set(WITH_ED 1)
endif(TEMP GREATER -1)
# Check if elliptic curve cryptography support is required.
LIST(FIND WITH "EC" TEMP)
if(TEMP GREATER -1)
set(WITH_EC 1)
endif(TEMP GREATER -1)
# Check if support for pairings over prime curves is required.
LIST(FIND WITH "PP" TEMP)
if(TEMP GREATER -1)
set(WITH_PP 1)
endif(TEMP GREATER -1)
# Check if support for pairings over binary curves is required.
LIST(FIND WITH "PB" TEMP)
if(TEMP GREATER -1)
set(WITH_PB 1)
endif(TEMP GREATER -1)
# Check if elliptic curve cryptography support is required.
LIST(FIND WITH "PC" TEMP)
if(TEMP GREATER -1)
set(WITH_PC 1)
endif(TEMP GREATER -1)
# Check if support for block ciphers is required.
LIST(FIND WITH "BC" TEMP)
if(TEMP GREATER -1)
set(WITH_BC 1)
endif(TEMP GREATER -1)
# Check if support for hash functions is required.
LIST(FIND WITH "MD" TEMP)
if(TEMP GREATER -1)
set(WITH_MD 1)
endif(TEMP GREATER -1)
# Check if support for crptographic protocols is required.
LIST(FIND WITH "CP" TEMP)
if(TEMP GREATER -1)
set(WITH_CP 1)
endif(TEMP GREATER -1)
# Choose the arithmetic backend.
set(ARITH "easy" CACHE STRING "Arithmetic backend")
# Choose the memory-allocation policy.
set(ALLOC "AUTO" CACHE STRING "Allocation policy")
# Compiler flags.
if("$ENV{COMP}" STREQUAL "")
set(COMP "-O2 -funroll-loops -fomit-frame-pointer" CACHE STRING "User-chosen compiler flags.")
else("$ENV{COMP}" STREQUAL "")
set(COMP "$ENV{COMP}" CACHE STRING "User-chosen compiler flags.")
endif("$ENV{COMP}" STREQUAL "")
# Simulator of the target platform.
set(SIMUL "$ENV{SIMUL}" CACHE STRING "Path to call a simulator of the target platform.")
set(SIMAR "$ENV{SIMAR}" CACHE STRING "Arguments to call a simulator of the target platform.")
string(REPLACE " " ";" SIMAR "${SIMAR}")
# Linker flags.
string(TOLOWER ${ARITH} LFLAGS)
set(LFLAGS "-L${CMAKE_CURRENT_SOURCE_DIR}/src/low/${LFLAGS}/")
set(LINK "$ENV{LINK}" CACHE STRING "User-chosen linker flags.")
set(LFLAGS "${LFLAGS} ${LINK}")
if(STBIN)
set(LFLAGS "${LFLAGS} -static")
endif(STBIN)
# Discover the operating system.
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(OPSYS "LINUX" CACHE STRING "Operating system")
else(CMAKE_SYSTEM_NAME STREQUAL Linux)
if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(OPSYS "FREEBSD" CACHE STRING "Operating system")
else(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(OPSYS "MACOSX" CACHE STRING "Operating system")
else(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(OPSYS "RELIC_NONE" CACHE STRING "Operating system")
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
endif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
endif(CMAKE_SYSTEM_NAME STREQUAL Linux)
if(OPSYS STREQUAL LINUX)
add_definitions(-D_GNU_SOURCE)
endif(OPSYS STREQUAL LINUX)
message(STATUS "Configured operating system: ${OPSYS}")
if(OPSYS STREQUAL LINUX)
set(TIMER "HPROC" CACHE STRING "Timer")
else(OPSYS STREQUAL LINUX)
set(TIMER "ANSI" CACHE STRING "Timer")
endif(OPSYS STREQUAL LINUX)
if(DEBUG)
# If the user did not specify compile flags, we turn off all optimizations.
set(CFLAGS "-O0 -fno-omit-frame-pointer")
set(DFLAGS "-ggdb")
else(DEBUG)
# If the user did not specify compile flags, we use sane defaults.
set(CFLAGS "${COMP}")
set(DFLAGS "")
endif(DEBUG)
if(MULTI STREQUAL OPENMP)
find_package(OpenMP REQUIRED)
set(CFLAGS "${CFLAGS} -fopenmp")
set(MULTI "OPENMP" CACHE STRING "Multithreading interface")
else(MULTI STREQUAL OPENMP)
if(MULTI STREQUAL PTHREAD)
find_package(Threads REQUIRED)
set(CFLAGS "${CFLAGS} -pthread")
set(MULTI "PTHREAD" CACHE STRING "Multithreading interface")
else(MULTI STREQUAL PTHREAD)
set(MULTI "RELIC_NONE" CACHE STRING "Operating system")
endif(MULTI STREQUAL PTHREAD)
endif(MULTI STREQUAL OPENMP)
if(PROFL)
set(PFLAGS "-pg -fno-omit-frame-pointer")
else(PROFL)
set(PFLAGS "")
endif(PROFL)
if(TRACE)
set(DFLAGS "${DFLAGS} -fPIC -finstrument-functions")
endif(TRACE)
if(ARITH STREQUAL "gmp" OR ARITH STREQUAL "gmp-sec")
include(cmake/gmp.cmake)
if(GMP_FOUND)
include_directories(${GMP_INCLUDE_DIR})
set(ARITH_LIBS ${GMP_LIBRARIES})
endif(GMP_FOUND)
endif(ARITH STREQUAL "gmp" OR ARITH STREQUAL "gmp-sec")
set(CMAKE_C_FLAGS "-pipe -std=c99 ${AFLAGS} ${WFLAGS} ${DFLAGS} ${PFLAGS} ${CFLAGS}")
set(CMAKE_EXE_LINKER_FLAGS ${LFLAGS})
message(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")
message(STATUS "Linker flags: ${LFLAGS}")
string(TOUPPER ${ARITH} ARITH)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/relic_conf.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/relic_conf.h @ONLY)
message(STATUS "Configured ${CMAKE_CURRENT_SOURCE_DIR}/include/relic_conf.h.in")
string(TOLOWER ${ARITH} ARITH)
if (LABEL)
set(RELIC "relic_${LABEL}")
set(RELIC_S "relic_s_${LABEL}")
else(LABEL)
set(RELIC "relic")
set(RELIC_S "relic_s")
endif(LABEL)
# Choose the arithmetic backend.
set(LABEL "" CACHE STRING "Build label")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
file(GLOB includes "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
install(FILES ${includes} DESTINATION include/${RELIC})
file(GLOB includes "${CMAKE_CURRENT_SOURCE_DIR}/include/low/*.h")
install(FILES ${includes} DESTINATION include/${RELIC}/low)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include/" DESTINATION include/${RELIC})
install(FILES cmake/relic-config.cmake DESTINATION cmake/)
if(DOCUM)
include(cmake/doxygen.cmake)
endif(DOCUM)
if(TESTS GREATER 0)
enable_testing()
add_subdirectory(test)
endif(TESTS GREATER 0)
if(BENCH GREATER 0)
add_subdirectory(bench)
endif(BENCH GREATER 0)