Skip to content

Commit 38e6ea9

Browse files
committed
Merge bitcoin/bitcoin#33101: cmake: Proactively avoid use of SECP256K1_DISABLE_SHARED
b093a19 cmake: Proactively avoid use of `SECP256K1_DISABLE_SHARED` (Hennadii Stepanov) eb59a19 cmake, refactor: Encapsulate adding secp256k1 subtree in function (Hennadii Stepanov) Pull request description: The `SECP256K1_DISABLE_SHARED` CMake variable has been [removed](bitcoin-core/secp256k1#1688) upstream. This PR removes its usage ahead of the next `secp256k1` subtree update to prevent breakage and simplify integration. ACKs for top commit: fanquake: ACK b093a19 Tree-SHA512: a87cee71cf356f458f68d3163253ca5c4f86e56d268006b6b8e1d4b2c009ba436148a07a6b67b89ddbb2d0e3c1113ab4b4906c5fc5624cb3082b20e916e0e82b
2 parents c92115d + b093a19 commit 38e6ea9

File tree

2 files changed

+53
-48
lines changed

2 files changed

+53
-48
lines changed

cmake/secp256k1.cmake

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright (c) 2023-present The Bitcoin Core developers
2+
# Distributed under the MIT software license, see the accompanying
3+
# file COPYING or https://opensource.org/license/mit/.
4+
5+
function(add_secp256k1 subdir)
6+
message("")
7+
message("Configuring secp256k1 subtree...")
8+
set(BUILD_SHARED_LIBS OFF)
9+
set(CMAKE_EXPORT_COMPILE_COMMANDS OFF)
10+
set(SECP256K1_ENABLE_MODULE_ECDH OFF CACHE BOOL "" FORCE)
11+
set(SECP256K1_ENABLE_MODULE_RECOVERY ON CACHE BOOL "" FORCE)
12+
set(SECP256K1_ENABLE_MODULE_MUSIG ON CACHE BOOL "" FORCE)
13+
set(SECP256K1_BUILD_BENCHMARK OFF CACHE BOOL "" FORCE)
14+
set(SECP256K1_BUILD_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
15+
set(SECP256K1_BUILD_EXHAUSTIVE_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
16+
if(NOT BUILD_TESTS)
17+
# Always skip the ctime tests, if we are building no other tests.
18+
# Otherwise, they are built if Valgrind is available. See SECP256K1_VALGRIND.
19+
set(SECP256K1_BUILD_CTIME_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
20+
endif()
21+
set(SECP256K1_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
22+
include(GetTargetInterface)
23+
# -fsanitize and related flags apply to both C++ and C,
24+
# so we can pass them down to libsecp256k1 as CFLAGS and LDFLAGS.
25+
get_target_interface(SECP256K1_APPEND_CFLAGS "" sanitize_interface COMPILE_OPTIONS)
26+
string(STRIP "${SECP256K1_APPEND_CFLAGS} ${APPEND_CPPFLAGS}" SECP256K1_APPEND_CFLAGS)
27+
string(STRIP "${SECP256K1_APPEND_CFLAGS} ${APPEND_CFLAGS}" SECP256K1_APPEND_CFLAGS)
28+
set(SECP256K1_APPEND_CFLAGS ${SECP256K1_APPEND_CFLAGS} CACHE STRING "" FORCE)
29+
get_target_interface(SECP256K1_APPEND_LDFLAGS "" sanitize_interface LINK_OPTIONS)
30+
string(STRIP "${SECP256K1_APPEND_LDFLAGS} ${APPEND_LDFLAGS}" SECP256K1_APPEND_LDFLAGS)
31+
set(SECP256K1_APPEND_LDFLAGS ${SECP256K1_APPEND_LDFLAGS} CACHE STRING "" FORCE)
32+
# We want to build libsecp256k1 with the most tested RelWithDebInfo configuration.
33+
enable_language(C)
34+
foreach(config IN LISTS CMAKE_BUILD_TYPE CMAKE_CONFIGURATION_TYPES)
35+
if(config STREQUAL "")
36+
continue()
37+
endif()
38+
string(TOUPPER "${config}" config)
39+
set(CMAKE_C_FLAGS_${config} "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
40+
endforeach()
41+
# If the CFLAGS environment variable is defined during building depends
42+
# and configuring this build system, its content might be duplicated.
43+
if(DEFINED ENV{CFLAGS})
44+
deduplicate_flags(CMAKE_C_FLAGS)
45+
endif()
46+
47+
add_subdirectory(${subdir})
48+
set_target_properties(secp256k1 PROPERTIES
49+
EXCLUDE_FROM_ALL TRUE
50+
)
51+
endfunction()

src/CMakeLists.txt

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,54 +23,8 @@ if (ENABLE_IPC AND NOT WITH_EXTERNAL_LIBMULTIPROCESS)
2323
include(../cmake/libmultiprocess.cmake)
2424
add_libmultiprocess(ipc/libmultiprocess)
2525
endif()
26-
#=============================
27-
# secp256k1 subtree
28-
#=============================
29-
message("")
30-
message("Configuring secp256k1 subtree...")
31-
set(SECP256K1_DISABLE_SHARED ON CACHE BOOL "" FORCE)
32-
set(SECP256K1_ENABLE_MODULE_ECDH OFF CACHE BOOL "" FORCE)
33-
set(SECP256K1_ENABLE_MODULE_RECOVERY ON CACHE BOOL "" FORCE)
34-
set(SECP256K1_ENABLE_MODULE_MUSIG ON CACHE BOOL "" FORCE)
35-
set(SECP256K1_BUILD_BENCHMARK OFF CACHE BOOL "" FORCE)
36-
set(SECP256K1_BUILD_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
37-
set(SECP256K1_BUILD_EXHAUSTIVE_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
38-
if(NOT BUILD_TESTS)
39-
# Always skip the ctime tests, if we are building no other tests.
40-
# Otherwise, they are built if Valgrind is available. See SECP256K1_VALGRIND.
41-
set(SECP256K1_BUILD_CTIME_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
42-
endif()
43-
set(SECP256K1_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
44-
include(GetTargetInterface)
45-
# -fsanitize and related flags apply to both C++ and C,
46-
# so we can pass them down to libsecp256k1 as CFLAGS and LDFLAGS.
47-
get_target_interface(SECP256K1_APPEND_CFLAGS "" sanitize_interface COMPILE_OPTIONS)
48-
string(STRIP "${SECP256K1_APPEND_CFLAGS} ${APPEND_CPPFLAGS}" SECP256K1_APPEND_CFLAGS)
49-
string(STRIP "${SECP256K1_APPEND_CFLAGS} ${APPEND_CFLAGS}" SECP256K1_APPEND_CFLAGS)
50-
set(SECP256K1_APPEND_CFLAGS ${SECP256K1_APPEND_CFLAGS} CACHE STRING "" FORCE)
51-
get_target_interface(SECP256K1_APPEND_LDFLAGS "" sanitize_interface LINK_OPTIONS)
52-
string(STRIP "${SECP256K1_APPEND_LDFLAGS} ${APPEND_LDFLAGS}" SECP256K1_APPEND_LDFLAGS)
53-
set(SECP256K1_APPEND_LDFLAGS ${SECP256K1_APPEND_LDFLAGS} CACHE STRING "" FORCE)
54-
# We want to build libsecp256k1 with the most tested RelWithDebInfo configuration.
55-
enable_language(C)
56-
foreach(config IN LISTS CMAKE_BUILD_TYPE CMAKE_CONFIGURATION_TYPES)
57-
if(config STREQUAL "")
58-
continue()
59-
endif()
60-
string(TOUPPER "${config}" config)
61-
set(CMAKE_C_FLAGS_${config} "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
62-
endforeach()
63-
# If the CFLAGS environment variable is defined during building depends
64-
# and configuring this build system, its content might be duplicated.
65-
if(DEFINED ENV{CFLAGS})
66-
deduplicate_flags(CMAKE_C_FLAGS)
67-
endif()
68-
set(CMAKE_EXPORT_COMPILE_COMMANDS OFF)
69-
add_subdirectory(secp256k1)
70-
set_target_properties(secp256k1 PROPERTIES
71-
EXCLUDE_FROM_ALL TRUE
72-
)
73-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
26+
include(../cmake/secp256k1.cmake)
27+
add_secp256k1(secp256k1)
7428

7529
# Set top-level target output locations.
7630
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)

0 commit comments

Comments
 (0)