Skip to content

Commit da406e9

Browse files
committed
ExternalProject for secp256k1
1 parent 5127b74 commit da406e9

5 files changed

+1383
-0
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ include(ProjectBoost)
5252
include(ProjectCryptopp)
5353
include(ProjectJsonCpp)
5454
include(ProjectJsonRpcCpp)
55+
include(ProjectSecp256k1)
5556

5657

5758

cmake/ProjectSecp256k1.cmake

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
include(ExternalProject)
2+
3+
if (MSVC)
4+
set(_only_release_configuration -DCMAKE_CONFIGURATION_TYPES=Release)
5+
endif()
6+
7+
ExternalProject_Add(ep-secp256k1
8+
PREFIX ${CMAKE_SOURCE_DIR}/deps
9+
DOWNLOAD_NAME secp256k1-9d560f99.tar.gz
10+
DOWNLOAD_NO_PROGRESS 1
11+
URL https://github.com/bitcoin-core/secp256k1/archive/9d560f992db26612ce2630b194aef5f44d63a530.tar.gz
12+
URL_HASH SHA256=910b2535bdbb5d235e9212c92050e0f9b327e05129b449f8f3d3c6d558121284
13+
PATCH_COMMAND ${CMAKE_COMMAND} -E copy_directory
14+
${CMAKE_CURRENT_LIST_DIR}/secp256k1
15+
<SOURCE_DIR>
16+
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
17+
-DCMAKE_POSITION_INDEPENDENT_CODE=${BUILD_SHARED_LIBS}
18+
${_only_release_configuration}
19+
LOG_CONFIGURE 1
20+
LOG_INSTALL 1
21+
)
22+
23+
# Create imported library
24+
ExternalProject_Get_Property(ep-secp256k1 INSTALL_DIR)
25+
add_library(Secp256k1 STATIC IMPORTED)
26+
set(SECP256K1_LIBRARY ${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}secp256k1${CMAKE_STATIC_LIBRARY_SUFFIX})
27+
set(SECP256K1_INCLUDE_DIR ${INSTALL_DIR}/include)
28+
file(MAKE_DIRECTORY ${SECP256K1_INCLUDE_DIR}) # Must exist.
29+
set_property(TARGET Secp256k1 PROPERTY IMPORTED_LOCATION ${SECP256K1_LIBRARY})
30+
set_property(TARGET Secp256k1 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${SECP256K1_INCLUDE_DIR})
31+
add_dependencies(Secp256k1 ep-secp256k1)
32+
unset(INSTALL_DIR)

cmake/secp256k1/CMakeLists.txt

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This is copy of secp256k1 project from https://github.com/bitcoin-core/secp256k1
2+
# Commit: https://github.com/bitcoin-core/secp256k1/commit/9d560f992db26612ce2630b194aef5f44d63a530
3+
#
4+
# It has been configured following official docs with following options:
5+
#
6+
# ./configure --disable-shared --disable-tests --disable-coverage --disable-openssl-tests --disable-exhaustive-tests --disable-jni --with-bignum=no --with-field=64bit --with-scalar=64bit --with-asm=no
7+
#
8+
# Build static context:
9+
# make src/ecmult_static_context.h
10+
#
11+
# Copy src and include dirs.
12+
#
13+
# Copy CFLAGS from Makefile to COMPILE_OPTIONS.
14+
15+
cmake_minimum_required(VERSION 3.4)
16+
project(secp256k1 LANGUAGES C)
17+
18+
if (NOT MSVC)
19+
# Use default Release flags on MSVC.
20+
set(COMPILE_OPTIONS -O3 -W -std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings -fvisibility=hidden)
21+
endif()
22+
23+
add_library(secp256k1 STATIC src/secp256k1.c)
24+
target_compile_definitions(secp256k1 PRIVATE HAVE_CONFIG_H)
25+
target_include_directories(secp256k1 PRIVATE . src)
26+
target_compile_options(secp256k1 PRIVATE ${COMPILE_OPTIONS})
27+
install(TARGETS secp256k1 ARCHIVE DESTINATION lib)
28+
install(DIRECTORY include/ DESTINATION include)

0 commit comments

Comments
 (0)