Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1cmake_minimum_required(VERSION 3.22)3#=============================4# Project / Package metadata5#=============================6project(libsecp256k17# The package (a.k.a. release) version is based on semantic versioning 2.0.0 of8# the API. All changes in experimental modules are treated as9# backwards-compatible and therefore at most increase the minor version.10VERSION 0.8.111DESCRIPTION "Optimized C library for ECDSA signatures and secret/public key operations on curve secp256k1."12HOMEPAGE_URL "https://github.com/bitcoin-core/secp256k1"13LANGUAGES C14)15enable_testing()16include(CTestUseLaunchers) # Allow users to set CTEST_USE_LAUNCHERS in custom `ctest -S` scripts.17list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)19# The library version is based on libtool versioning of the ABI. The set of20# rules for updating the version can be found here:21# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html22# All changes in experimental modules are treated as if they don't affect the23# interface and therefore only increase the revision.24set(${PROJECT_NAME}_LIB_VERSION_CURRENT 7)25set(${PROJECT_NAME}_LIB_VERSION_REVISION 1)26set(${PROJECT_NAME}_LIB_VERSION_AGE 0)28#=============================29# Language setup30#=============================31set(CMAKE_C_STANDARD 90)32set(CMAKE_C_EXTENSIONS OFF)34#=============================35# Configurable options36#=============================37if(libsecp256k1_IS_TOP_LEVEL)38option(BUILD_SHARED_LIBS "Build shared libraries." ON)39endif()41option(SECP256K1_INSTALL "Enable installation." ${PROJECT_IS_TOP_LEVEL})43option(SECP256K1_ENABLE_API_VISIBILITY_ATTRIBUTES "Enable visibility attributes in the API." ON)45## Modules47# We declare all options before processing them, to make sure we can express48# dependencies while processing.49option(SECP256K1_ENABLE_MODULE_ECDH "Enable ECDH module." ON)50option(SECP256K1_ENABLE_MODULE_RECOVERY "Enable ECDSA pubkey recovery module." OFF)51option(SECP256K1_ENABLE_MODULE_EXTRAKEYS "Enable extrakeys module." ON)52option(SECP256K1_ENABLE_MODULE_SCHNORRSIG "Enable schnorrsig module." ON)53option(SECP256K1_ENABLE_MODULE_MUSIG "Enable musig module." ON)54option(SECP256K1_ENABLE_MODULE_ELLSWIFT "Enable ElligatorSwift module." ON)55option(SECP256K1_ENABLE_MODULE_SILENTPAYMENTS "Enable Silent Payments module." ON)57option(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS "Enable external default callback functions." OFF)58if(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS)59add_compile_definitions(USE_EXTERNAL_DEFAULT_CALLBACKS=1)60endif()62set(SECP256K1_ECMULT_WINDOW_SIZE 15 CACHE STRING "Window size for ecmult precomputation for verification, specified as integer in range [2..24]. The default value is a reasonable setting for desktop machines (currently 15). [default=15]")63set_property(CACHE SECP256K1_ECMULT_WINDOW_SIZE PROPERTY STRINGS 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24)64include(CheckStringOptionValue)65check_string_option_value(SECP256K1_ECMULT_WINDOW_SIZE)66add_compile_definitions(ECMULT_WINDOW_SIZE=${SECP256K1_ECMULT_WINDOW_SIZE})68set(SECP256K1_ECMULT_GEN_KB 86 CACHE STRING "The size of the precomputed table for signing in multiples of 1024 bytes (on typical platforms). Larger values result in possibly better signing or key generation performance at the cost of a larger table. Valid choices are 2, 22, 86. The default value is a reasonable setting for desktop machines (currently 86). [default=86]")69set_property(CACHE SECP256K1_ECMULT_GEN_KB PROPERTY STRINGS 2 22 86)70check_string_option_value(SECP256K1_ECMULT_GEN_KB)71if(SECP256K1_ECMULT_GEN_KB EQUAL 2)72add_compile_definitions(COMB_BLOCKS=2)73add_compile_definitions(COMB_TEETH=5)74elseif(SECP256K1_ECMULT_GEN_KB EQUAL 22)75add_compile_definitions(COMB_BLOCKS=11)76add_compile_definitions(COMB_TEETH=6)77elseif(SECP256K1_ECMULT_GEN_KB EQUAL 86)78add_compile_definitions(COMB_BLOCKS=43)79add_compile_definitions(COMB_TEETH=6)80endif()82set(SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY "OFF" CACHE STRING "Test-only override of the (autodetected by the C code) \"widemul\" setting. Legal values are: \"OFF\", \"int128_struct\", \"int128\" or \"int64\". [default=OFF]")83set_property(CACHE SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY PROPERTY STRINGS "OFF" "int128_struct" "int128" "int64")84check_string_option_value(SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY)85if(SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY)86string(TOUPPER "${SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY}" widemul_upper_value)87add_compile_definitions(USE_FORCE_WIDEMUL_${widemul_upper_value}=1)88endif()89mark_as_advanced(FORCE SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY)91set(SECP256K1_ASM "AUTO" CACHE STRING "Assembly to use: \"AUTO\", \"OFF\", \"x86_64\" or \"arm32\" (experimental). [default=AUTO]")92set_property(CACHE SECP256K1_ASM PROPERTY STRINGS "AUTO" "OFF" "x86_64" "arm32")93check_string_option_value(SECP256K1_ASM)94if(SECP256K1_ASM STREQUAL "arm32")95enable_language(ASM)96include(CheckArm32Assembly)97check_arm32_assembly()98if(HAVE_ARM32_ASM)99add_compile_definitions(USE_EXTERNAL_ASM=1)100else()101message(FATAL_ERROR "ARM32 assembly requested but not available.")102endif()103elseif(SECP256K1_ASM)104include(CheckX86_64Assembly)105check_x86_64_assembly()106if(HAVE_X86_64_ASM)107set(SECP256K1_ASM "x86_64")108add_compile_definitions(USE_ASM_X86_64=1)109elseif(SECP256K1_ASM STREQUAL "AUTO")110set(SECP256K1_ASM "OFF")111else()112message(FATAL_ERROR "x86_64 assembly requested but not available.")113endif()114endif()116option(SECP256K1_EXPERIMENTAL "Allow experimental configuration options." OFF)117if(NOT SECP256K1_EXPERIMENTAL)118if(SECP256K1_ASM STREQUAL "arm32")119message(FATAL_ERROR "ARM32 assembly is experimental. Use -DSECP256K1_EXPERIMENTAL=ON to allow.")120endif()121endif()123set(SECP256K1_VALGRIND "AUTO" CACHE STRING "Build with extra checks for running inside Valgrind. [default=AUTO]")124set_property(CACHE SECP256K1_VALGRIND PROPERTY STRINGS "AUTO" "OFF" "ON")125check_string_option_value(SECP256K1_VALGRIND)126if(SECP256K1_VALGRIND)127find_package(Valgrind MODULE)128if(Valgrind_FOUND)129set(SECP256K1_VALGRIND ON)130include_directories(${Valgrind_INCLUDE_DIR})131add_compile_definitions(VALGRIND)132elseif(SECP256K1_VALGRIND STREQUAL "AUTO")133set(SECP256K1_VALGRIND OFF)134else()135message(FATAL_ERROR "Valgrind support requested but valgrind/memcheck.h header not available.")136endif()137endif()139option(SECP256K1_BUILD_BENCHMARK "Build benchmarks." ON)140option(SECP256K1_BUILD_TESTS "Build tests." ON)141option(SECP256K1_BUILD_EXHAUSTIVE_TESTS "Build exhaustive tests." ON)142option(SECP256K1_BUILD_CTIME_TESTS "Build constant-time tests." ${SECP256K1_VALGRIND})143option(SECP256K1_BUILD_EXAMPLES "Build examples." OFF)145# Redefine configuration flags.146# We leave assertions on, because they are only used in the examples, and we want them always on there.147if(MSVC)148string(REGEX REPLACE "/DNDEBUG[ \t\r\n]*" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")149string(REGEX REPLACE "/DNDEBUG[ \t\r\n]*" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")150string(REGEX REPLACE "/DNDEBUG[ \t\r\n]*" "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")151# Match GCC/Clang's size-optimization macro for the inline guard152add_compile_definitions($<$<CONFIG:MinSizeRel>:__OPTIMIZE_SIZE__=1>)153else()154string(REGEX REPLACE "-DNDEBUG[ \t\r\n]*" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")155string(REGEX REPLACE "-DNDEBUG[ \t\r\n]*" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")156string(REGEX REPLACE "-DNDEBUG[ \t\r\n]*" "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")157# Prefer -O2 optimization level. (-O3 is CMake's default for Release for many compilers.)158string(REGEX REPLACE "-O3( |$)" "-O2\\1" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")159endif()161# Define custom "Coverage" build type.162set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O0 -DCOVERAGE=1 --coverage" CACHE STRING163"Flags used by the C compiler during \"Coverage\" builds."164FORCE165)166set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} --coverage" CACHE STRING167"Flags used for linking binaries during \"Coverage\" builds."168FORCE169)170set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} --coverage" CACHE STRING171"Flags used by the shared libraries linker during \"Coverage\" builds."172FORCE173)174mark_as_advanced(175CMAKE_C_FLAGS_COVERAGE176CMAKE_EXE_LINKER_FLAGS_COVERAGE177CMAKE_SHARED_LINKER_FLAGS_COVERAGE178)180if(PROJECT_IS_TOP_LEVEL)181get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)182set(default_build_type "RelWithDebInfo")183if(is_multi_config)184set(CMAKE_CONFIGURATION_TYPES "${default_build_type}" "Release" "Debug" "MinSizeRel" "Coverage" CACHE STRING185"Supported configuration types."186FORCE187)188else()189set_property(CACHE CMAKE_BUILD_TYPE PROPERTY190STRINGS "${default_build_type}" "Release" "Debug" "MinSizeRel" "Coverage"191)192if(NOT CMAKE_BUILD_TYPE)193message(STATUS "Setting build type to \"${default_build_type}\" as none was specified")194set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING195"Choose the type of build."196FORCE197)198endif()199endif()200endif()202include(TryAppendCFlags)203if(MSVC)204# For both cl and clang-cl compilers.205try_append_c_flags(/W3) # Production quality warning level.206# Eliminate deprecation warnings for the older, less secure functions.207add_compile_definitions(_CRT_SECURE_NO_WARNINGS)208else()209try_append_c_flags(-Wall) # GCC >= 2.95 and probably many other compilers.210endif()211if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")212# Keep the following commands ordered lexicographically.213try_append_c_flags(/wd4146) # Disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned".214try_append_c_flags(/wd4244) # Disable warning C4244 "'conversion' conversion from 'type1' to 'type2', possible loss of data".215try_append_c_flags(/wd4267) # Disable warning C4267 "'var' : conversion from 'size_t' to 'type', possible loss of data".216else()217# Keep the following commands ordered lexicographically.218try_append_c_flags(-pedantic)219try_append_c_flags(-Wcast-align) # GCC >= 2.95.220try_append_c_flags(-Wcast-align=strict) # GCC >= 8.0.221try_append_c_flags(-Wconditional-uninitialized) # Clang >= 3.0 only.222try_append_c_flags(-Wextra) # GCC >= 3.4, this is the newer name of -W, which we don't use because older GCCs will warn about unused functions.223try_append_c_flags(-Wleading-whitespace=spaces) # GCC >= 15.0224try_append_c_flags(-Wnested-externs)225try_append_c_flags(-Wno-long-long) # GCC >= 3.0, -Wlong-long is implied by -pedantic.226try_append_c_flags(-Wno-overlength-strings) # GCC >= 4.2, -Woverlength-strings is implied by -pedantic.227try_append_c_flags(-Wno-unused-function) # GCC >= 3.0, -Wunused-function is implied by -Wall.228try_append_c_flags(-Wreserved-identifier) # Clang >= 13.0 only.229try_append_c_flags(-Wshadow)230try_append_c_flags(-Wstrict-prototypes)231try_append_c_flags(-Wtrailing-whitespace=any) # GCC >= 15.0232try_append_c_flags(-Wundef)233endif()235set(print_msan_notice)236if(SECP256K1_BUILD_CTIME_TESTS)237include(CheckMemorySanitizer)238check_memory_sanitizer(msan_enabled)239if(msan_enabled)240try_append_c_flags(-fno-sanitize-memory-param-retval)241set(print_msan_notice YES)242endif()243unset(msan_enabled)244endif()246set(SECP256K1_APPEND_CFLAGS "" CACHE STRING "Compiler flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds.")247if(SECP256K1_APPEND_CFLAGS)248# Appending to this low-level rule variable is the only way to249# guarantee that the flags appear at the end of the command line.250string(APPEND CMAKE_C_COMPILE_OBJECT " ${SECP256K1_APPEND_CFLAGS}")
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.