mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-02 17:56:16 +00:00
b9313c6e1a Merge bitcoin-core/secp256k1#1708: release cleanup: bump version after 0.7.0 a660a4976e Merge bitcoin-core/secp256k1#1707: release: Prepare for 0.7.0 7ab8b0cc01 release cleanup: bump version after 0.7.0 a3e742d947 release: Prepare for 0.7.0 f67b0ac1a0 ci: Don't hardcode ABI version 020ee60495 Merge bitcoin-core/secp256k1#1706: musig/tests: initialize keypair cde4130898 musig/tests: initialize keypair 6037833c9e Merge bitcoin-core/secp256k1#1702: changelog: update 40b4a06520 changelog: update 5e74086dc8 Merge bitcoin-core/secp256k1#1705: musig/test: Remove dead code 7c3380423c Merge bitcoin-core/secp256k1#1696: build: Refactor visibility logic and add override 8d967a602b musig/test: Remove dead code 983711cd6d musig/tests: Refactor vectors_signverify 73a695958a Merge bitcoin-core/secp256k1#1704: cmake: Make `secp256k1_objs` inherit interface defines from `secp256k1` bf082221ff cmake: Make `secp256k1_objs` inherit interface defines from `secp256k1` c82d84bb86 build: add CMake option for disabling symbol visibility attributes ce7923874f build: Add SECP256K1_NO_API_VISIBILITY_ATTRIBUTES e5297f6d79 build: Refactor visibility logic cbbbf3bd6e Merge bitcoin-core/secp256k1#1699: ci: enable musig module for native macOS arm64 job 943479a7a3 Merge bitcoin-core/secp256k1#1694: Revert "cmake: configure libsecp256k1.pc during install" 3352f9d667 ci: enable musig module for native macOS arm64 job ad60ef7ea7 Merge bitcoin-core/secp256k1#1689: ci: Convert `arm64` Cirrus tasks to GHA jobs c498779096 Merge bitcoin-core/secp256k1#1687: cmake: support the use of launchers in ctest -S scripts 44b205e9ee Revert "cmake: configure libsecp256k1.pc during install" 0dfe387dbe cmake: support the use of launchers in ctest -S scripts 89096c234d Merge bitcoin-core/secp256k1#1692: cmake: configure libsecp256k1.pc during install 7106dce6fd cmake: configure libsecp256k1.pc during install 29e73f4ba5 Merge bitcoin-core/secp256k1#1685: cmake: Emulate Libtool's behavior on FreeBSD 746e36b141 Merge bitcoin-core/secp256k1#1678: cmake: add a helper for linking into static libs a28c2ffa5c Merge bitcoin-core/secp256k1#1683: README: add link to musig example 2a9d374735 Merge bitcoin-core/secp256k1#1690: ci: Bump GCC snapshot major version to 16 add146e101 ci: Bump GCC snapshot major version to 16 004f57fcd8 ci: Move Valgrind build for `arm64` from Cirrus to GHA 5fafdfc30f ci: Move `gcc-snapshot` build for `arm64` from Cirrus to GHA e814b79a8b ci: Switch `arm64_debian` from QEMU to native `arm64` Docker image bcf77346b9 ci: Add `arm64` architecture to `docker_cache` job b77aae9226 ci: Rename Docker image tag to reflect architecture 145ae3e28d cmake: add a helper for linking into static libs 819210974b README: add link to musig example, generalize module enabling hint 95db29b144 Merge bitcoin-core/secp256k1#1679: cmake: Use `PUBLIC_HEADER` target property in installation logic 37dd422b5c cmake: Emulate Libtool's behavior on FreeBSD f24b838bed Merge bitcoin-core/secp256k1#1680: doc: Promote "Building with CMake" to standard procedure 3f31ac43e0 doc: Promote "Building with CMake" to standard procedure 6f67151ee2 cmake: Use `PUBLIC_HEADER` target property c32715b2a0 cmake, move-only: Move module option processing to `src/CMakeLists.txt` 201b2b8f06 Merge bitcoin-core/secp256k1#1675: cmake: Bump minimum required CMake version to 3.22 3af71987a8 cmake: Bump minimum required CMake version to 3.22 92394476e9 Merge bitcoin-core/secp256k1#1673: Assert field magnitude at control-flow join 3a4f448cb4 Assert field magnitude at control-flow join 9fab425256 Merge bitcoin-core/secp256k1#1668: bench_ecmult: add benchmark for ecmult_const_xonly 05445377f4 bench_ecmult: add benchmark for ecmult_const_xonly bb597b3d39 Merge bitcoin-core/secp256k1#1670: tests: update wycheproof files d73ed99479 tests: update wycheproof files git-subtree-dir: src/secp256k1 git-subtree-split: b9313c6e1a6082a66b4c75777e18ca4b176fcf9d
206 lines
8.2 KiB
CMake
206 lines
8.2 KiB
CMake
add_library(secp256k1)
|
|
|
|
set_property(TARGET secp256k1 PROPERTY PUBLIC_HEADER
|
|
${PROJECT_SOURCE_DIR}/include/secp256k1.h
|
|
${PROJECT_SOURCE_DIR}/include/secp256k1_preallocated.h
|
|
)
|
|
|
|
# Processing must be done in a topological sorting of the dependency graph
|
|
# (dependent module first).
|
|
if(SECP256K1_ENABLE_MODULE_ELLSWIFT)
|
|
add_compile_definitions(ENABLE_MODULE_ELLSWIFT=1)
|
|
set_property(TARGET secp256k1 APPEND PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/secp256k1_ellswift.h)
|
|
endif()
|
|
|
|
if(SECP256K1_ENABLE_MODULE_MUSIG)
|
|
if(DEFINED SECP256K1_ENABLE_MODULE_SCHNORRSIG AND NOT SECP256K1_ENABLE_MODULE_SCHNORRSIG)
|
|
message(FATAL_ERROR "Module dependency error: You have disabled the schnorrsig module explicitly, but it is required by the musig module.")
|
|
endif()
|
|
set(SECP256K1_ENABLE_MODULE_SCHNORRSIG ON)
|
|
add_compile_definitions(ENABLE_MODULE_MUSIG=1)
|
|
set_property(TARGET secp256k1 APPEND PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/secp256k1_musig.h)
|
|
endif()
|
|
|
|
if(SECP256K1_ENABLE_MODULE_SCHNORRSIG)
|
|
if(DEFINED SECP256K1_ENABLE_MODULE_EXTRAKEYS AND NOT SECP256K1_ENABLE_MODULE_EXTRAKEYS)
|
|
message(FATAL_ERROR "Module dependency error: You have disabled the extrakeys module explicitly, but it is required by the schnorrsig module.")
|
|
endif()
|
|
set(SECP256K1_ENABLE_MODULE_EXTRAKEYS ON)
|
|
add_compile_definitions(ENABLE_MODULE_SCHNORRSIG=1)
|
|
set_property(TARGET secp256k1 APPEND PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/secp256k1_schnorrsig.h)
|
|
endif()
|
|
|
|
if(SECP256K1_ENABLE_MODULE_EXTRAKEYS)
|
|
add_compile_definitions(ENABLE_MODULE_EXTRAKEYS=1)
|
|
set_property(TARGET secp256k1 APPEND PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/secp256k1_extrakeys.h)
|
|
endif()
|
|
|
|
if(SECP256K1_ENABLE_MODULE_RECOVERY)
|
|
add_compile_definitions(ENABLE_MODULE_RECOVERY=1)
|
|
set_property(TARGET secp256k1 APPEND PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/secp256k1_recovery.h)
|
|
endif()
|
|
|
|
if(SECP256K1_ENABLE_MODULE_ECDH)
|
|
add_compile_definitions(ENABLE_MODULE_ECDH=1)
|
|
set_property(TARGET secp256k1 APPEND PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/secp256k1_ecdh.h)
|
|
endif()
|
|
|
|
add_library(secp256k1_precomputed OBJECT EXCLUDE_FROM_ALL
|
|
precomputed_ecmult.c
|
|
precomputed_ecmult_gen.c
|
|
)
|
|
|
|
# Add objects explicitly rather than linking to the object libs to keep them
|
|
# from being exported.
|
|
target_sources(secp256k1 PRIVATE secp256k1.c $<TARGET_OBJECTS:secp256k1_precomputed>)
|
|
|
|
if(NOT SECP256K1_ENABLE_API_VISIBILITY_ATTRIBUTES)
|
|
target_compile_definitions(secp256k1 PRIVATE SECP256K1_NO_API_VISIBILITY_ATTRIBUTES)
|
|
endif()
|
|
|
|
# Create a helper lib that parent projects can use to link secp256k1 into a
|
|
# static lib.
|
|
add_library(secp256k1_objs INTERFACE)
|
|
target_sources(secp256k1_objs INTERFACE $<TARGET_OBJECTS:secp256k1> $<TARGET_OBJECTS:secp256k1_precomputed>)
|
|
|
|
add_library(secp256k1_asm INTERFACE)
|
|
if(SECP256K1_ASM STREQUAL "arm32")
|
|
add_library(secp256k1_asm_arm OBJECT EXCLUDE_FROM_ALL)
|
|
target_sources(secp256k1_asm_arm PUBLIC
|
|
asm/field_10x26_arm.s
|
|
)
|
|
target_sources(secp256k1 PRIVATE $<TARGET_OBJECTS:secp256k1_asm_arm>)
|
|
target_sources(secp256k1_objs INTERFACE $<TARGET_OBJECTS:secp256k1_asm_arm>)
|
|
target_link_libraries(secp256k1_asm INTERFACE secp256k1_asm_arm)
|
|
endif()
|
|
|
|
if(WIN32)
|
|
# Define our export symbol only for shared libs.
|
|
set_target_properties(secp256k1 PROPERTIES DEFINE_SYMBOL SECP256K1_DLL_EXPORT)
|
|
target_compile_definitions(secp256k1 INTERFACE $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:SECP256K1_STATIC>)
|
|
endif()
|
|
|
|
# Object libs don't know if they're being built for a shared or static lib.
|
|
# Grab the PIC property from secp256k1 which knows.
|
|
get_target_property(use_pic secp256k1 POSITION_INDEPENDENT_CODE)
|
|
set_target_properties(secp256k1_precomputed PROPERTIES POSITION_INDEPENDENT_CODE ${use_pic})
|
|
|
|
# Add the include path for parent projects so that they don't have to manually add it.
|
|
target_include_directories(secp256k1 INTERFACE
|
|
$<BUILD_INTERFACE:$<$<NOT:$<BOOL:${PROJECT_IS_TOP_LEVEL}>>:${PROJECT_SOURCE_DIR}/include>>
|
|
)
|
|
set_target_properties(secp256k1_objs PROPERTIES
|
|
INTERFACE_COMPILE_DEFINITIONS "$<TARGET_PROPERTY:secp256k1,INTERFACE_COMPILE_DEFINITIONS>"
|
|
INTERFACE_INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:secp256k1,INTERFACE_INCLUDE_DIRECTORIES>"
|
|
)
|
|
|
|
# This emulates Libtool to make sure Libtool and CMake agree on the ABI version,
|
|
# see below "Calculate the version variables" in build-aux/ltmain.sh.
|
|
math(EXPR ${PROJECT_NAME}_soversion "${${PROJECT_NAME}_LIB_VERSION_CURRENT} - ${${PROJECT_NAME}_LIB_VERSION_AGE}")
|
|
set_target_properties(secp256k1 PROPERTIES
|
|
SOVERSION ${${PROJECT_NAME}_soversion}
|
|
)
|
|
if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|FreeBSD)$")
|
|
set_target_properties(secp256k1 PROPERTIES
|
|
VERSION ${${PROJECT_NAME}_soversion}.${${PROJECT_NAME}_LIB_VERSION_AGE}.${${PROJECT_NAME}_LIB_VERSION_REVISION}
|
|
)
|
|
elseif(APPLE)
|
|
math(EXPR ${PROJECT_NAME}_compatibility_version "${${PROJECT_NAME}_LIB_VERSION_CURRENT} + 1")
|
|
set_target_properties(secp256k1 PROPERTIES
|
|
MACHO_COMPATIBILITY_VERSION ${${PROJECT_NAME}_compatibility_version}
|
|
MACHO_CURRENT_VERSION ${${PROJECT_NAME}_compatibility_version}.${${PROJECT_NAME}_LIB_VERSION_REVISION}
|
|
)
|
|
unset(${PROJECT_NAME}_compatibility_version)
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
|
set(${PROJECT_NAME}_windows "secp256k1")
|
|
if(MSVC)
|
|
set(${PROJECT_NAME}_windows "${PROJECT_NAME}")
|
|
endif()
|
|
set_target_properties(secp256k1 PROPERTIES
|
|
ARCHIVE_OUTPUT_NAME "${${PROJECT_NAME}_windows}"
|
|
RUNTIME_OUTPUT_NAME "${${PROJECT_NAME}_windows}-${${PROJECT_NAME}_soversion}"
|
|
)
|
|
unset(${PROJECT_NAME}_windows)
|
|
endif()
|
|
unset(${PROJECT_NAME}_soversion)
|
|
|
|
if(SECP256K1_BUILD_BENCHMARK)
|
|
add_executable(bench bench.c)
|
|
target_link_libraries(bench secp256k1)
|
|
add_executable(bench_internal bench_internal.c)
|
|
target_link_libraries(bench_internal secp256k1_precomputed secp256k1_asm)
|
|
add_executable(bench_ecmult bench_ecmult.c)
|
|
target_link_libraries(bench_ecmult secp256k1_precomputed secp256k1_asm)
|
|
endif()
|
|
|
|
if(SECP256K1_BUILD_TESTS)
|
|
add_executable(noverify_tests tests.c)
|
|
target_link_libraries(noverify_tests secp256k1_precomputed secp256k1_asm)
|
|
add_test(NAME secp256k1_noverify_tests COMMAND noverify_tests)
|
|
if(NOT CMAKE_BUILD_TYPE STREQUAL "Coverage")
|
|
add_executable(tests tests.c)
|
|
target_compile_definitions(tests PRIVATE VERIFY)
|
|
target_link_libraries(tests secp256k1_precomputed secp256k1_asm)
|
|
add_test(NAME secp256k1_tests COMMAND tests)
|
|
endif()
|
|
endif()
|
|
|
|
if(SECP256K1_BUILD_EXHAUSTIVE_TESTS)
|
|
# Note: do not include secp256k1_precomputed in exhaustive_tests (it uses runtime-generated tables).
|
|
add_executable(exhaustive_tests tests_exhaustive.c)
|
|
target_link_libraries(exhaustive_tests secp256k1_asm)
|
|
target_compile_definitions(exhaustive_tests PRIVATE $<$<NOT:$<CONFIG:Coverage>>:VERIFY>)
|
|
add_test(NAME secp256k1_exhaustive_tests COMMAND exhaustive_tests)
|
|
endif()
|
|
|
|
if(SECP256K1_BUILD_CTIME_TESTS)
|
|
add_executable(ctime_tests ctime_tests.c)
|
|
target_link_libraries(ctime_tests secp256k1)
|
|
endif()
|
|
|
|
if(SECP256K1_INSTALL)
|
|
include(GNUInstallDirs)
|
|
target_include_directories(secp256k1 INTERFACE
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
|
)
|
|
install(TARGETS secp256k1
|
|
EXPORT ${PROJECT_NAME}-targets
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
)
|
|
|
|
install(EXPORT ${PROJECT_NAME}-targets
|
|
FILE ${PROJECT_NAME}-targets.cmake
|
|
NAMESPACE ${PROJECT_NAME}::
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
|
)
|
|
|
|
include(CMakePackageConfigHelpers)
|
|
configure_package_config_file(
|
|
${PROJECT_SOURCE_DIR}/cmake/config.cmake.in
|
|
${PROJECT_NAME}-config.cmake
|
|
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
|
NO_SET_AND_CHECK_MACRO
|
|
)
|
|
write_basic_package_version_file(${PROJECT_NAME}-config-version.cmake
|
|
COMPATIBILITY SameMinorVersion
|
|
)
|
|
|
|
install(
|
|
FILES
|
|
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
|
|
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
|
)
|
|
|
|
include(GeneratePkgConfigFile)
|
|
generate_pkg_config_file(${PROJECT_SOURCE_DIR}/libsecp256k1.pc.in)
|
|
install(
|
|
FILES
|
|
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
|
|
)
|
|
endif()
|