Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fpelliccioni committed Feb 1, 2018
1 parent 532b202 commit c8d1cba
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 44 deletions.
22 changes: 15 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,24 @@ set(BITPRIM_BUILD_NUMBER "-" CACHE STRING "Specify the Bitprim Build Number.")
# message(${BITPRIM_BUILD_NUMBER})


if (NOT NO_CONAN_AT_ALL)
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
else()
message(WARNING "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first")
endif()
# if (NOT NO_CONAN_AT_ALL)
# if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
# include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
# conan_basic_setup()
# else()
# message(WARNING "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first")
# endif()
# endif()


if(EXISTS ${CMAKE_SOURCE_DIR}/bitprimbuildinfo.cmake)
include(${CMAKE_SOURCE_DIR}/bitprimbuildinfo.cmake)
else()
message( STATUS "bitprimbuildinfo doent exists")
endif()



set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

include(Secp256k1Tools)
Expand Down
42 changes: 42 additions & 0 deletions bitprimbuildinfo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# include(CMakeParseArguments)

# message( STATUS "--------------------------------------------" )
# get_directory_property( DirDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
# foreach( d ${DirDefs} )
# message( STATUS "Found Define: " ${d} )
# endforeach()
# message( STATUS "DirDefs: " ${DirDefs} )
# message( STATUS "--------------------------------------------" )

# message( STATUS "2 NO_CONAN_AT_ALL: " ${NO_CONAN_AT_ALL} )
# message( STATUS "CMAKE_CXX_COMPILER_ID: " ${CMAKE_CXX_COMPILER_ID} )
# message( STATUS "NOT_USE_CPP11_ABI: " ${NOT_USE_CPP11_ABI} )
# message( STATUS "CONAN_CXX_FLAGS: " ${CONAN_CXX_FLAGS} )
# message( STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS} )


if (NOT NO_CONAN_AT_ALL)
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

remove_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
remove_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if (NOT NOT_USE_CPP11_ABI)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
message( STATUS "Bitprim: Using _GLIBCXX_USE_CXX11_ABI=1")
else()
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
message( STATUS "Bitprim: Using _GLIBCXX_USE_CXX11_ABI=0")
endif()
endif()
else()
message(WARNING "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first")
endif()
endif()

# message( STATUS "CONAN_CXX_FLAGS: " ${CONAN_CXX_FLAGS} )
# message( STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS} )

3 changes: 1 addition & 2 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
remotes="https://api.bintray.com/conan/bitprim/bitprim",
archs=["x86_64"])

builder.add_common_builds(shared_option_name="secp256k1:shared")
builder.add_common_builds(shared_option_name="secp256k1:shared", pure_c=True)

filtered_builds = []
for settings, options, env_vars, build_requires in builder.builds:
Expand All @@ -18,7 +18,6 @@
if settings["build_type"] == "Release" \
and not("secp256k1:shared" in options and options["secp256k1:shared"]):


env_vars["BITPRIM_BUILD_NUMBER"] = os.getenv('BITPRIM_BUILD_NUMBER', '-')

filtered_builds.append([settings, options, env_vars, build_requires])
Expand Down
157 changes: 122 additions & 35 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,34 @@
def option_on_off(option):
return "ON" if option else "OFF"

# def make_default_options_method():
# defs = "shared=False", \
# "fPIC=True", \
# "with_benchmark=False", \
# "with_tests=True", \
# "with_openssl_tests=False", \
# "enable_experimental=False", \
# "enable_endomorphism=False", \
# "enable_ecmult_static_precomputation=True", \
# "enable_module_ecdh=False", \
# "enable_module_schnorr=False", \
# "enable_module_recovery=True", \
# "with_bignum=conan"

# # "with_asm='auto'", \
# # "with_field='auto'", \
# # "with_scalar='auto'"
# # "with_bignum='auto'"


# if cpuid_installed:
# gmp_opt = "gmp:microarchitecture=%s" % (''.join(cpuid.cpu_microarchitecture()))
# new_defs = defs + (gmp_opt,)
# return new_defs

# return defs


class Secp256k1Conan(ConanFile):
name = "secp256k1"
version = "0.3"
Expand All @@ -32,8 +60,6 @@ class Secp256k1Conan(ConanFile):

settings = "os", "compiler", "build_type", "arch"

# options = {"shared": [True, False]}
# default_options = "shared=False"

#TODO(fernando): See what to do with shared/static option... (not supported yet in Cmake)

Expand All @@ -45,9 +71,16 @@ class Secp256k1Conan(ConanFile):
"enable_module_ecdh": [True, False],
"enable_module_schnorr": [True, False],
"enable_module_recovery": [True, False],
"enable_benchmark": [True, False],
"enable_tests": [True, False],
"enable_openssl_tests": [True, False],
"with_benchmark": [True, False],
"with_tests": [True, False],
"with_openssl_tests": [True, False],
"with_bignum_lib": [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'],
Expand All @@ -64,54 +97,95 @@ class Secp256k1Conan(ConanFile):
"enable_module_ecdh=False", \
"enable_module_schnorr=False", \
"enable_module_recovery=True", \
"enable_benchmark=False", \
"enable_tests=False", \
"enable_openssl_tests=False"
"with_benchmark=False", \
"with_tests=False", \
"with_openssl_tests=False", \
"with_bignum_lib=True"



# "with_bignum=conan"
# "with_asm='auto'", \
# "with_field='auto'", \
# "with_scalar='auto'"
# "with_bignum='auto'"

generators = "cmake"
build_policy = "missing"
exports_sources = "src/*", "include/*", "CMakeLists.txt", "cmake/*", "secp256k1Config.cmake.in", "contrib/*", "test/*"
exports_sources = "src/*", "include/*", "CMakeLists.txt", "cmake/*", "secp256k1Config.cmake.in", "bitprimbuildinfo.cmake", "contrib/*", "test/*"


# enable_benchmark = False
# enable_tests = False
# enable_openssl_tests = False
# with_benchmark = False
# with_tests = True
# with_openssl_tests = False

def requirements(self):
if self.settings.os == "Windows":
self.requires("mpir/3.0.0@bitprim/stable")

@property
def msvc_mt_build(self):
return "MT" in str(self.settings.compiler.runtime)

@property
def fPIC_enabled(self):
if self.settings.compiler == "Visual Studio":
return False
else:
self.requires("gmp/6.1.2@bitprim/stable")

#TODO(fernando): What happend with FreeBSD?
return self.options.fPIC

@property
def is_shared(self):
if self.options.shared and self.msvc_mt_build:
return False
else:
return self.options.shared

@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.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

def package_id(self):
self.info.options.enable_benchmark = "ANY"
self.info.options.enable_tests = "ANY"
self.info.options.enable_openssl_tests = "ANY"
self.info.options.with_benchmark = "ANY"
self.info.options.with_tests = "ANY"
self.info.options.with_openssl_tests = "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.definitions["CMAKE_VERBOSE_MAKEFILE"] = option_on_off(False)
# cmake.definitions["CMAKE_VERBOSE_MAKEFILE"] = option_on_off(False)
cmake.verbose = True

cmake.definitions["ENABLE_SHARED"] = option_on_off(self.options.shared)
cmake.definitions["ENABLE_POSITION_INDEPENDENT_CODE"] = option_on_off(self.options.fPIC)
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.enable_benchmark)
cmake.definitions["ENABLE_TESTS"] = option_on_off(self.options.enable_tests)
cmake.definitions["ENABLE_OPENSSL_TESTS"] = option_on_off(self.options.enable_openssl_tests)
# cmake.definitions["ENABLE_BENCHMARK"] = option_on_off(self.enable_benchmark)
# cmake.definitions["ENABLE_TESTS"] = option_on_off(self.enable_tests)
# cmake.definitions["ENABLE_OPENSSL_TESTS"] = option_on_off(self.enable_openssl_tests)
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)
Expand All @@ -120,14 +194,27 @@ def build(self):
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)

if self.settings.os == "Windows":
# cmake.definitions["WITH_BIGNUM"] = "no"
cmake.definitions["WITH_BIGNUM"] = "mpir"
# if self.settings.os == "Windows":
# cmake.definitions["WITH_BIGNUM"] = "mpir"
# else:
# cmake.definitions["WITH_BIGNUM"] = "gmp"

cmake.definitions["WITH_BIGNUM"] = self.bignum_lib_name

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
else:
cmake.definitions["WITH_BIGNUM"] = "gmp"

# 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)


# cmake.definitions["WITH_ASM"] = option_on_off(self.options.with_asm)
# cmake.definitions["WITH_FIELD"] = option_on_off(self.options.with_field)
Expand Down

0 comments on commit c8d1cba

Please sign in to comment.