This repository has been archived by the owner on Oct 28, 2024. It is now read-only.
forked from barryWhiteHat/semaphore
-
Notifications
You must be signed in to change notification settings - Fork 57
/
CMakeLists.txt
282 lines (225 loc) · 6.29 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
cmake_minimum_required(VERSION 2.8)
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
project(ethsnarks)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13")
cmake_policy(SET CMP0077 NEW) # ENABLE CMP0077: option() honors normal variables
endif()
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.9")
cmake_policy(SET CMP0069 NEW) # Enable IPO for compilers other than only Intel C++ on Linux
endif()
option(ETHSNARKS_DISABLE_TESTS "Disable ethsnarks tests" OFF)
option(ETHSNARKS_DISABLE_UTILS "Disable ethsnarks utilties" ON)
option(ETHSNARKS_DISABLE_PINOCCHIO "Disable pinocchio / xjsnark compatibility" OFF)
option(ETHSNARKS_NO_THREADS "Disable testing for threads support" OFF)
if( NOT ${ETHSNARKS_NO_THREADS} )
find_package(Threads REQUIRED)
endif()
if (CMAKE_VERSION VERSION_GREATER "3.0")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
else()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
endif()
if( NOT ${ETHSNARKS_DISABLE_TESTS} )
include(CTest)
enable_testing()
endif()
set(SHA3_USE_KECCAK ON)
add_definitions(-DSHA3_USE_KECCAK=1)
set(
CURVE
"ALT_BN128"
CACHE
STRING
"Default curve: one of ALT_BN128, BN128, EDWARDS, MNT4, MNT6"
)
set(
DEPENDS_DIR
"${CMAKE_CURRENT_SOURCE_DIR}/depends"
CACHE
STRING
"Optionally specify the dependency installation directory relative to the source directory (default: inside dependency folder)"
)
set(
DEPENDS_DIR_LIBSNARK
"${CMAKE_CURRENT_SOURCE_DIR}/depends/libsnark/"
CACHE
STRING
"Optionally specify the dependency installation directory relative to the source directory (default: inside dependency folder)"
)
set(
DEPENDS_DIR_LIBFF
"${DEPENDS_DIR_LIBSNARK}/depends/libff/"
CACHE
STRING
"Optionally specify the dependency installation directory relative to the source directory (default: inside dependency folder)"
)
set(
DEPENDS_DIR_LIBFQFFT
"${DEPENDS_DIR}/libfqfft/"
CACHE
STRING
"Optionally specify the dependency installation directory relative to the source directory (default: inside dependency folder)"
)
set(
OPT_FLAGS
""
CACHE
STRING
"Override C++ compiler optimization flags"
)
option(
MULTICORE
"Enable parallelized execution, using OpenMP"
OFF
)
option(
USE_MIXED_ADDITION
"Convert each element of the key pair to affine coordinates"
OFF
)
option(
BINARY_OUTPUT
"Use binary output for serialisation"
ON
)
option(
MONTGOMERY_OUTPUT
"Serialize Fp elements as their Montgomery representations (faster but not human-readable)"
ON
)
option(
USE_ASM
"Use architecture-specific optimized assembly code"
ON
)
option(
PERFORMANCE
"Enable link-time and aggressive optimizations"
OFF
)
option(
WITH_PROCPS
"Use procps for memory profiling"
OFF
)
option(
DEBUG
"Enable debugging mode"
OFF
)
option(
CPPDEBUG
"Enable debugging of C++ STL (does not imply DEBUG)"
OFF
)
add_definitions(-DCURVE_${CURVE})
if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options(-fPIC)
endif()
if(${CURVE} STREQUAL "BN128")
add_definitions(-DBN_SUPPORT_SNARK=1)
endif()
if("${MULTICORE}")
find_package(OpenMP REQUIRED)
add_definitions(-DMULTICORE=1)
endif()
if("${USE_ASM}")
add_definitions(-DUSE_ASM)
endif()
if("${BINARY_OUTPUT}")
add_definitions(-DBINARY_OUTPUT)
endif()
if("${MONTGOMERY_OUTPUT}")
add_definitions(-DMONTGOMERY_OUTPUT)
endif()
if(NOT "${USE_PT_COMPRESSION}")
add_definitions(-DNO_PT_COMPRESSION=1)
endif()
if("${PERFORMANCE}")
include(CheckIPOSupported)
check_ipo_supported()
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
if("${USE_MIXED_ADDITION}")
add_definitions(-DUSE_MIXED_ADDITION=1)
endif()
if("${CPPDEBUG}")
add_definitions(-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC)
endif()
include(FindPkgConfig)
if("${WITH_PROCPS}")
pkg_check_modules(
PROCPS
REQUIRED
libprocps
)
else()
add_definitions(
-DNO_PROCPS
)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# Common compilation flags and warning configuration
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-variable")
# Default optimizations flags (to override, use -DOPT_FLAGS=...)
endif()
# Locate the gmp library and its includes
find_path(GMP_INCLUDE_DIR NAMES gmp.h)
find_library(GMP_LIBRARY gmp)
if(GMP_LIBRARY MATCHES ${CMAKE_SHARED_LIBRARY_SUFFIX})
set(gmp_library_type SHARED)
else()
set(gmp_library_type STATIC)
endif()
message(STATUS "GMP: ${GMP_LIBRARY}, ${GMP_INCLUDE_DIR}")
add_library(gmp ${gmp_library_type} IMPORTED)
set_target_properties(
gmp PROPERTIES
IMPORTED_LOCATION ${GMP_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${GMP_INCLUDE_DIR}
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPT_FLAGS}")
include(FindPkgConfig)
if("${WITH_PROCPS}")
pkg_check_modules(PROCPS REQUIRED libprocps)
else()
add_definitions(-DNO_PROCPS)
endif()
add_library(
ff
STATIC
${DEPENDS_DIR_LIBFF}/libff/algebra/curves/alt_bn128/alt_bn128_g1.cpp
${DEPENDS_DIR_LIBFF}/libff/algebra/curves/alt_bn128/alt_bn128_g2.cpp
${DEPENDS_DIR_LIBFF}/libff/algebra/curves/alt_bn128/alt_bn128_init.cpp
${DEPENDS_DIR_LIBFF}/libff/algebra/curves/alt_bn128/alt_bn128_pairing.cpp
${DEPENDS_DIR_LIBFF}/libff/algebra/curves/alt_bn128/alt_bn128_pp.cpp
${DEPENDS_DIR_LIBFF}/libff/common/double.cpp
${DEPENDS_DIR_LIBFF}/libff/common/profiling.cpp
${DEPENDS_DIR_LIBFF}/libff/common/utils.cpp
)
target_include_directories(ff PUBLIC
${GMP_INCLUDE_DIR}
${DEPENDS_DIR_LIBSNARK} ${DEPENDS_DIR_LIBFF} ${DEPENDS_DIR_LIBFQFFT})
set_property(TARGET ff PROPERTY CXX_STANDARD 11)
if("${DEBUG}" OR "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
add_definitions(-DDEBUG=1)
target_compile_definitions(ff PUBLIC DEBUG=1)
endif()
target_include_directories(ff INTERFACE
${GMP_INCLUDE_DIR}
${DEPENDS_DIR_LIBSNARK} ${DEPENDS_DIR_LIBFF} ${DEPENDS_DIR_LIBFQFFT})
target_link_libraries(ff ${GMP_LIBRARY} ${PROCPS_LIBRARIES})
if(OpenMP_CXX_FOUND)
target_link_libraries(ff OpenMP::OpenMP_CXX)
endif()
add_subdirectory(src)
add_subdirectory(depends)