Skip to content

Commit

Permalink
DEV-10: Have Conan decide whether to use GMP or not
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-ramos committed Aug 8, 2017
1 parent 5b9d2e2 commit 85167b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 36 deletions.
37 changes: 6 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ set(WITH_ASM "auto" CACHE STRING "Specify assembly optimizations to use (x86_64|
set(WITH_FIELD "auto" CACHE STRING "Specify Field Implementation (64bit|32bit|auto).")
set(WITH_SCALAR "auto" CACHE STRING "Specify scalar implementation (64bit|32bit|auto).")

#TODO: add this option to Conan Scripts
#set(WITH_BIGNUM "auto" CACHE STRING "Specify Bignum Implementation (gmp|no|auto).")

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

include(Secp256k1Tools)
Expand Down Expand Up @@ -96,24 +93,6 @@ elseif (NOT WITH_FIELD STREQUAL "32bit")
message(FATAL_ERROR "Invalid scalar implementation: ${WITH_SCALAR}")
endif()

## Implement --with-bignum
##------------------------------------------------------------------------------
#if (WITH_BIGNUM STREQUAL "auto")
# _check_has_gmp()
# if (HAS_GMP)
# set(WITH_BIGNUM "gmp")
# else()
# set(WITH_BIGNUM "no")
# endif()
#elseif (WITH_BIGNUM STREQUAL "gmp")
# _check_has_gmp()
# if (NOT HAS_GMP)
# message(FATAL_ERROR "gmp bignum explicitly requested but libgmp not available")
# endif()
#elseif (NOT WITH_BIGNUM STREQUAL "no")
# message(FATAL_ERROR "Invalid bignum implementation: ${WITH_BIGNUM}")
#endif()

# Build
#==============================================================================
add_library(secp256k1 STATIC
Expand Down Expand Up @@ -154,20 +133,16 @@ elseif (WITH_SCALAR STREQUAL "32bit")
endif()



#TODO(fernando): See how to add this compile_definitions in the Conan Script
#if (WITH_BIGNUM STREQUAL "gmp")
if (WITH_BIGNUM STREQUAL "gmp")
target_compile_definitions(secp256k1 PUBLIC -DHAVE_LIBGMP=1)
target_compile_definitions(secp256k1 PUBLIC -DUSE_NUM_GMP=1)
target_compile_definitions(secp256k1 PUBLIC -DUSE_FIELD_INV_NUM=1)
target_compile_definitions(secp256k1 PUBLIC -DUSE_SCALAR_INV_NUM=1)
# target_include_directories(secp256k1 PUBLIC ${GMP_INCLUDE_DIR})
# target_link_libraries(secp256k1 ${GMP_LIBRARIES})
#elseif (WITH_BIGNUM STREQUAL "no")
# target_compile_definitions(secp256k1 PUBLIC -DUSE_NUM_NONE=1)
# target_compile_definitions(secp256k1 PUBLIC -DUSE_FIELD_INV_BUILTIN=1)
# target_compile_definitions(secp256k1 PUBLIC -DUSE_SCALAR_INV_BUILTIN=1)
#endif()
elseif (WITH_BIGNUM STREQUAL "no")
target_compile_definitions(secp256k1 PUBLIC -DUSE_NUM_NONE=1)
target_compile_definitions(secp256k1 PUBLIC -DUSE_FIELD_INV_BUILTIN=1)
target_compile_definitions(secp256k1 PUBLIC -DUSE_SCALAR_INV_BUILTIN=1)
endif()

target_link_libraries(secp256k1 PUBLIC ${CONAN_LIBS})

Expand Down
11 changes: 6 additions & 5 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ class Secp256k1Conan(ConanFile):
build_policy = "missing"
exports_sources = "src/*", "include/*", "CMakeLists.txt", "cmake/*", "secp256k1Config.cmake.in", "contrib/*", "test/*"

# package_files = "build/lsecp256k1.a" #TODO!

# requires = (("gmp/6.1.2@bitprim/stable"))

def build_requirements(self):
if self.settings.os == "Linux" or self.settings.os == "Macos":
self.build_requires("gmp/6.1.2@bitprim/stable")

def build(self):
cmake = CMake(self)
cmake.configure(source_dir=self.conanfile_directory)
cmake_args = {}
if self.settings.os == "Windos":
cmake_args = {"-DWITHBIGNUM=no"}
else:
cmake_args = {"-DWITHBIGNUM=gmp"}
cmake.configure(source_dir=self.conanfile_directory, args=cmake_args)
cmake.build()

def package(self):
Expand Down

0 comments on commit 85167b6

Please sign in to comment.