forked from bitcoin-core/secp256k1
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconanfile.py
233 lines (192 loc) · 10.1 KB
/
conanfile.py
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
#
# Copyright (c) 2017-2018 Bitprim Inc.
#
# This file is part of Bitprim.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import os
from conans import CMake
from ci_utils import option_on_off, get_version, get_conan_req_version, march_conan_manip, pass_march_to_compiler
from ci_utils import BitprimConanFile
class Secp256k1Conan(BitprimConanFile):
name = "secp256k1"
# version = get_version()
license = "http://www.boost.org/users/license.html"
url = "https://github.com/bitprim/secp256k1"
description = "Optimized C library for EC operations on curve secp256k1"
settings = "os", "compiler", "build_type", "arch"
# if Version(conan_version) < Version(get_conan_req_version()):
# raise Exception ("Conan version should be greater or equal than %s. Detected: %s." % (get_conan_req_version(), conan_version))
#TODO(fernando): See what to do with shared/static option... (not supported yet in Cmake)
options = {"shared": [True, False],
"fPIC": [True, False],
"enable_experimental": [True, False],
"enable_endomorphism": [True, False],
"enable_ecmult_static_precomputation": [True, False],
"enable_module_ecdh": [True, False],
"enable_module_schnorr": [True, False],
"enable_module_recovery": [True, False],
"enable_module_multiset": [True, False],
"with_benchmark": [True, False],
"with_tests": [True, False],
"with_openssl_tests": [True, False],
"with_bignum_lib": [True, False],
"microarchitecture": "ANY", #["x86_64", "haswell", "ivybridge", "sandybridge", "bulldozer", ...]
"fix_march": [True, False],
"verbose": [True, False],
# "with_bignum": ["conan", "auto", "system", "no"]
#TODO(fernando): check what to do with with_asm, with_field and with_scalar
# Check CMake files and libbitcoin and bitcoin core makefiles
# "with_asm": ['x86_64', 'arm', 'no', 'auto'],
# "with_field": ['64bit', '32bit', 'auto'],
# "with_scalar": ['64bit', '32bit', 'auto'],
# "with_bignum": ['gmp', 'no', 'auto'],
}
# default_options = make_default_options_method()
default_options = "shared=False", \
"fPIC=True", \
"enable_experimental=False", \
"enable_endomorphism=False", \
"enable_ecmult_static_precomputation=False", \
"enable_module_ecdh=False", \
"enable_module_schnorr=True", \
"enable_module_recovery=True", \
"enable_module_multiset=True", \
"with_benchmark=False", \
"with_tests=False", \
"with_openssl_tests=False", \
"with_bignum_lib=True", \
"microarchitecture=_DUMMY_", \
"fix_march=False", \
"verbose=False"
# "with_bignum=conan"
# "with_asm='auto'", \
# "with_field='auto'", \
# "with_scalar='auto'"
# "with_bignum='auto'"
generators = "cmake"
exports = "conan_*", "ci_utils/*"
exports_sources = "src/*", "include/*", "CMakeLists.txt", "cmake/*", "secp256k1Config.cmake.in", "contrib/*", "test/*"
build_policy = "missing"
# with_benchmark = False
# with_tests = True
# with_openssl_tests = False
@property
def bignum_lib_name(self):
if self.options.with_bignum_lib:
if self.settings.os == "Windows":
return "mpir"
else:
return "gmp"
else:
return "no"
def requirements(self):
if self.options.with_bignum_lib:
if self.settings.os == "Windows":
self.requires("mpir/3.0.0@bitprim/stable")
else:
self.requires("gmp/6.1.2@bitprim/stable")
def config_options(self):
if self.settings.arch != "x86_64":
self.output.info("microarchitecture is disabled for architectures other than x86_64, your architecture: %s" % (self.settings.arch,))
self.options.remove("microarchitecture")
self.options.remove("fix_march")
if self.settings.compiler == "Visual Studio":
self.options.remove("fPIC")
if self.options.shared and self.msvc_mt_build:
self.options.remove("shared")
def configure(self):
del self.settings.compiler.libcxx #Pure-C Library
BitprimConanFile.configure(self)
if self.settings.arch == "x86_64" and self.options.microarchitecture == "_DUMMY_":
del self.options.fix_march
# self.options.remove("fix_march")
# raise Exception ("fix_march option is for using together with microarchitecture option.")
if self.settings.arch == "x86_64":
march_conan_manip(self)
self.options["*"].microarchitecture = self.options.microarchitecture
def package_id(self):
BitprimConanFile.package_id(self)
self.info.options.with_benchmark = "ANY"
self.info.options.with_tests = "ANY"
self.info.options.with_openssl_tests = "ANY"
self.info.options.verbose = "ANY"
self.info.options.fix_march = "ANY"
# if self.settings.compiler == "Visual Studio":
# self.info.options.microarchitecture = "ANY"
def build(self):
cmake = CMake(self)
cmake.definitions["USE_CONAN"] = option_on_off(True)
cmake.definitions["NO_CONAN_AT_ALL"] = option_on_off(False)
cmake.verbose = self.options.verbose
cmake.definitions["ENABLE_SHARED"] = option_on_off(self.is_shared)
cmake.definitions["ENABLE_POSITION_INDEPENDENT_CODE"] = option_on_off(self.fPIC_enabled)
cmake.definitions["ENABLE_BENCHMARK"] = option_on_off(self.options.with_benchmark)
cmake.definitions["ENABLE_TESTS"] = option_on_off(self.options.with_tests)
cmake.definitions["ENABLE_OPENSSL_TESTS"] = option_on_off(self.options.with_openssl_tests)
# cmake.definitions["ENABLE_BENCHMARK"] = option_on_off(self.with_benchmark)
# cmake.definitions["ENABLE_TESTS"] = option_on_off(self.with_tests)
# cmake.definitions["ENABLE_OPENSSL_TESTS"] = option_on_off(self.with_openssl_tests)
cmake.definitions["ENABLE_EXPERIMENTAL"] = option_on_off(self.options.enable_experimental)
cmake.definitions["ENABLE_ENDOMORPHISM"] = option_on_off(self.options.enable_endomorphism)
cmake.definitions["ENABLE_ECMULT_STATIC_PRECOMPUTATION"] = option_on_off(self.options.enable_ecmult_static_precomputation)
cmake.definitions["ENABLE_MODULE_ECDH"] = option_on_off(self.options.enable_module_ecdh)
cmake.definitions["ENABLE_MODULE_SCHNORR"] = option_on_off(self.options.enable_module_schnorr)
cmake.definitions["ENABLE_MODULE_RECOVERY"] = option_on_off(self.options.enable_module_recovery)
cmake.definitions["ENABLE_MODULE_MULTISET"] = option_on_off(self.options.enable_module_multiset)
# if self.settings.os == "Windows":
# cmake.definitions["WITH_BIGNUM"] = "mpir"
# else:
# cmake.definitions["WITH_BIGNUM"] = "gmp"
cmake.definitions["WITH_BIGNUM"] = self.bignum_lib_name
# cmake.definitions["WITH_ASM"] = option_on_off(self.options.with_asm)
# cmake.definitions["WITH_FIELD"] = option_on_off(self.options.with_field)
# cmake.definitions["WITH_SCALAR"] = option_on_off(self.options.with_scalar)
# cmake.definitions["WITH_BIGNUM"] = option_on_off(self.options.with_bignum)
cmake.definitions["MICROARCHITECTURE"] = self.options.microarchitecture
cmake.definitions["BITPRIM_PROJECT_VERSION"] = self.version
if self.settings.os == "Windows":
if self.settings.compiler == "Visual Studio" and (self.settings.compiler.version != 12):
cmake.definitions["ENABLE_TESTS"] = option_on_off(False) #Workaround. test broke MSVC
# Pure-C Library, No CXX11 ABI
# if self.settings.compiler == "gcc":
# if float(str(self.settings.compiler.version)) >= 5:
# cmake.definitions["NOT_USE_CPP11_ABI"] = option_on_off(False)
# else:
# cmake.definitions["NOT_USE_CPP11_ABI"] = option_on_off(True)
# elif self.settings.compiler == "clang":
# if str(self.settings.compiler.libcxx) == "libstdc++" or str(self.settings.compiler.libcxx) == "libstdc++11":
# cmake.definitions["NOT_USE_CPP11_ABI"] = option_on_off(False)
pass_march_to_compiler(self, cmake)
cmake.configure(source_dir=self.source_folder)
cmake.build()
#TODO(fernando): Cmake Tests and Visual Studio doesn't work
#TODO(fernando): Secp256k1 segfaults al least on Windows
# if self.options.with_tests:
# cmake.test()
# # cmake.test(target="tests")
def package(self):
self.copy("*.h", dst="include", src="include", keep_path=True)
self.copy("*.lib", dst="lib", keep_path=False)
self.copy("*.dll", dst="bin", keep_path=False)
self.copy("*.dylib*", dst="lib", keep_path=False)
self.copy("*.so", dst="lib", keep_path=False)
self.copy("*.a", dst="lib", keep_path=False)
def package_info(self):
self.cpp_info.libs = ["secp256k1"]
if self.package_folder:
self.env_info.CPATH = os.path.join(self.package_folder, "include")
self.env_info.C_INCLUDE_PATH = os.path.join(self.package_folder, "include")
self.env_info.CPLUS_INCLUDE_PATH = os.path.join(self.package_folder, "include")