Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/CMakeLists.txt
# Copyright (c) 2017 The Bitcoin developers | # Copyright (c) 2017 The Bitcoin developers | ||||
cmake_minimum_required(VERSION 3.13) | cmake_minimum_required(VERSION 3.13) | ||||
project(secp256k1 LANGUAGES C) | project(secp256k1 LANGUAGES C VERSION 0.1.0) | ||||
# Add path for custom modules when building as a standalone project | # Add path for custom modules when building as a standalone project | ||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) | list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) | ||||
include(AddCompilerFlags) | include(AddCompilerFlags) | ||||
# libsecp256k1 use a different set of flags. | # libsecp256k1 use a different set of flags. | ||||
add_c_compiler_flags( | add_c_compiler_flags( | ||||
Show All 19 Lines | include_directories( | ||||
# For the config | # For the config | ||||
${CMAKE_CURRENT_BINARY_DIR}/src | ${CMAKE_CURRENT_BINARY_DIR}/src | ||||
) | ) | ||||
# The library | # The library | ||||
add_library(secp256k1 src/secp256k1.c) | add_library(secp256k1 src/secp256k1.c) | ||||
target_include_directories(secp256k1 PUBLIC include) | target_include_directories(secp256k1 PUBLIC include) | ||||
set(SECP256K1_PUBLIC_HEADERS | |||||
include/secp256k1.h | |||||
include/secp256k1_preallocated.h | |||||
) | |||||
option(SECP256K1_ENABLE_BIGNUM "Use the GMP bignum implementation" OFF) | option(SECP256K1_ENABLE_BIGNUM "Use the GMP bignum implementation" OFF) | ||||
if(SECP256K1_ENABLE_BIGNUM) | if(SECP256K1_ENABLE_BIGNUM) | ||||
# We need to link in GMP | # We need to link in GMP | ||||
find_package(GMP REQUIRED) | find_package(GMP REQUIRED) | ||||
target_include_directories(secp256k1 PUBLIC ${GMP_INCLUDE_DIR}) | target_include_directories(secp256k1 PUBLIC ${GMP_INCLUDE_DIR}) | ||||
target_link_libraries(secp256k1 ${GMP_LIBRARY}) | target_link_libraries(secp256k1 ${GMP_LIBRARY}) | ||||
set(USE_NUM_GMP 1) | set(USE_NUM_GMP 1) | ||||
set(USE_FIELD_INV_NUM 1) | set(USE_FIELD_INV_NUM 1) | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | function(add_secp256k1_bench NAME) | ||||
add_dependencies(bench-secp256k1 ${BENCH_NAME}) | add_dependencies(bench-secp256k1 ${BENCH_NAME}) | ||||
endfunction(add_secp256k1_bench) | endfunction(add_secp256k1_bench) | ||||
# ECDH module | # ECDH module | ||||
option(SECP256K1_ENABLE_MODULE_ECDH "Build libsecp256k1's ECDH module" OFF) | option(SECP256K1_ENABLE_MODULE_ECDH "Build libsecp256k1's ECDH module" OFF) | ||||
if(SECP256K1_ENABLE_MODULE_ECDH) | if(SECP256K1_ENABLE_MODULE_ECDH) | ||||
set(ENABLE_MODULE_ECDH 1) | set(ENABLE_MODULE_ECDH 1) | ||||
add_secp256k1_bench(ecdh src/bench_ecdh.c) | add_secp256k1_bench(ecdh src/bench_ecdh.c) | ||||
list(APPEND SECP256K1_PUBLIC_HEADERS include/secp256k1_ecdh.h) | |||||
endif() | endif() | ||||
# MultiSet module | # MultiSet module | ||||
option(SECP256K1_ENABLE_MODULE_MULTISET "Build libsecp256k1's MULTISET module" ON) | option(SECP256K1_ENABLE_MODULE_MULTISET "Build libsecp256k1's MULTISET module" ON) | ||||
if(SECP256K1_ENABLE_MODULE_MULTISET) | if(SECP256K1_ENABLE_MODULE_MULTISET) | ||||
set(ENABLE_MODULE_MULTISET 1) | set(ENABLE_MODULE_MULTISET 1) | ||||
add_secp256k1_bench(multiset src/bench_multiset.c) | add_secp256k1_bench(multiset src/bench_multiset.c) | ||||
list(APPEND SECP256K1_PUBLIC_HEADERS include/secp256k1_multiset.h) | |||||
endif() | endif() | ||||
# Recovery module | # Recovery module | ||||
option(SECP256K1_ENABLE_MODULE_RECOVERY "Build libsecp256k1's recovery module" ON) | option(SECP256K1_ENABLE_MODULE_RECOVERY "Build libsecp256k1's recovery module" ON) | ||||
if(SECP256K1_ENABLE_MODULE_RECOVERY) | if(SECP256K1_ENABLE_MODULE_RECOVERY) | ||||
set(ENABLE_MODULE_RECOVERY 1) | set(ENABLE_MODULE_RECOVERY 1) | ||||
add_secp256k1_bench(recover src/bench_recover.c) | add_secp256k1_bench(recover src/bench_recover.c) | ||||
list(APPEND SECP256K1_PUBLIC_HEADERS include/secp256k1_recovery.h) | |||||
endif() | endif() | ||||
# Schnorr module | # Schnorr module | ||||
option(SECP256K1_ENABLE_MODULE_SCHNORR "Build libsecp256k1's Schnorr module" ON) | option(SECP256K1_ENABLE_MODULE_SCHNORR "Build libsecp256k1's Schnorr module" ON) | ||||
if(SECP256K1_ENABLE_MODULE_SCHNORR) | if(SECP256K1_ENABLE_MODULE_SCHNORR) | ||||
set(ENABLE_MODULE_SCHNORR 1) | set(ENABLE_MODULE_SCHNORR 1) | ||||
list(APPEND SECP256K1_PUBLIC_HEADERS include/secp256k1_schnorr.h) | |||||
endif() | endif() | ||||
# Endomorphism | # Endomorphism | ||||
option(SECP256K1_ENABLE_ENDOMORPHISM "Enable endomorphism" OFF) | option(SECP256K1_ENABLE_ENDOMORPHISM "Enable endomorphism" OFF) | ||||
if(SECP256K1_ENABLE_ENDOMORPHISM) | if(SECP256K1_ENABLE_ENDOMORPHISM) | ||||
set(USE_ENDOMORPHISM 1) | set(USE_ENDOMORPHISM 1) | ||||
endif() | endif() | ||||
Show All 17 Lines | if(SECP256K1_ECMULT_STATIC_PRECOMPUTATION) | ||||
add_custom_command( | add_custom_command( | ||||
OUTPUT src/ecmult_static_context.h | OUTPUT src/ecmult_static_context.h | ||||
COMMAND gen_context | COMMAND gen_context | ||||
) | ) | ||||
target_sources(secp256k1 PRIVATE src/ecmult_static_context.h) | target_sources(secp256k1 PRIVATE src/ecmult_static_context.h) | ||||
endif() | endif() | ||||
include(InstallationHelper) | |||||
if(BUILD_SHARED_LIBS) | |||||
install_shared_library(secp256k1 PUBLIC_HEADER ${SECP256K1_PUBLIC_HEADERS}) | |||||
else() | |||||
set_property(TARGET secp256k1 PROPERTY PUBLIC_HEADER ${SECP256K1_PUBLIC_HEADERS}) | |||||
install_target(secp256k1) | |||||
endif() | |||||
# Generate the config | # Generate the config | ||||
configure_file(src/libsecp256k1-config.h.cmake.in src/libsecp256k1-config.h ESCAPE_QUOTES) | configure_file(src/libsecp256k1-config.h.cmake.in src/libsecp256k1-config.h ESCAPE_QUOTES) | ||||
target_compile_definitions(secp256k1 PRIVATE HAVE_CONFIG_H SECP256K1_BUILD) | target_compile_definitions(secp256k1 PRIVATE HAVE_CONFIG_H SECP256K1_BUILD) | ||||
# Build the Java binding | # Build the Java binding | ||||
option(SECP256K1_ENABLE_JNI "Enable the Java Native Interface binding" OFF) | option(SECP256K1_ENABLE_JNI "Enable the Java Native Interface binding" OFF) | ||||
if(SECP256K1_ENABLE_JNI) | if(SECP256K1_ENABLE_JNI) | ||||
if(NOT SECP256K1_ENABLE_MODULE_ECDH) | if(NOT SECP256K1_ENABLE_MODULE_ECDH) | ||||
message(FATAL_ERROR "The secp256k1 JNI support requires ECDH. Try again with -DSECP256K1_ENABLE_MODULE_ECDH=ON.") | message(FATAL_ERROR "The secp256k1 JNI support requires ECDH. Try again with -DSECP256K1_ENABLE_MODULE_ECDH=ON.") | ||||
endif() | endif() | ||||
find_package(Java REQUIRED) | find_package(Java REQUIRED) | ||||
find_package(JNI REQUIRED) | find_package(JNI REQUIRED) | ||||
include(UseJava) | include(UseJava) | ||||
add_library(secp256k1_jni SHARED | add_library(secp256k1_jni SHARED | ||||
src/java/org_bitcoin_NativeSecp256k1.c | src/java/org_bitcoin_NativeSecp256k1.c | ||||
src/java/org_bitcoin_Secp256k1Context.c | src/java/org_bitcoin_Secp256k1Context.c | ||||
) | ) | ||||
install_shared_library(secp256k1_jni) | |||||
target_include_directories(secp256k1_jni PUBLIC ${JNI_INCLUDE_DIRS}) | target_include_directories(secp256k1_jni PUBLIC ${JNI_INCLUDE_DIRS}) | ||||
# As per CMake documentation: the POSITION_INDEPENDENT_CODE property is set | # As per CMake documentation: the POSITION_INDEPENDENT_CODE property is set | ||||
# when a target is created. It defaults to True for SHARED or MODULE library | # when a target is created. It defaults to True for SHARED or MODULE library | ||||
# targets and False otherwise. | # targets and False otherwise. | ||||
# The secp256ki_jni library being shared, the property is set and it will | # The secp256ki_jni library being shared, the property is set and it will | ||||
# build with PIC enabled. But the secp256k1 dependency might not have the | # build with PIC enabled. But the secp256k1 dependency might not have the | ||||
# property set, so it's associated source files won't be built with PIC | # property set, so it's associated source files won't be built with PIC | ||||
# enabled. That would cause the linker to fail. | # enabled. That would cause the linker to fail. | ||||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |