Skip to content

Commit 89ec583

Browse files
build: Clean up handling of module dependencies
This also makes the order in which module options are processed consistent between CMake and autotools (the reverse order of the listing printed to stdout).
1 parent a9db9f2 commit 89ec583

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

CMakeLists.txt

+19-11
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,37 @@ endif()
5151

5252
option(SECP256K1_INSTALL "Enable installation." ${PROJECT_IS_TOP_LEVEL})
5353

54-
option(SECP256K1_ENABLE_MODULE_ECDH "Enable ECDH module." ON)
55-
if(SECP256K1_ENABLE_MODULE_ECDH)
56-
add_compile_definitions(ENABLE_MODULE_ECDH=1)
57-
endif()
54+
## Modules
5855

56+
# We declare all options before processing them, to make sure we can express
57+
# dependendencies while processing.
58+
option(SECP256K1_ENABLE_MODULE_ECDH "Enable ECDH module." ON)
5959
option(SECP256K1_ENABLE_MODULE_RECOVERY "Enable ECDSA pubkey recovery module." OFF)
60-
if(SECP256K1_ENABLE_MODULE_RECOVERY)
61-
add_compile_definitions(ENABLE_MODULE_RECOVERY=1)
62-
endif()
63-
6460
option(SECP256K1_ENABLE_MODULE_EXTRAKEYS "Enable extrakeys module." ON)
6561
option(SECP256K1_ENABLE_MODULE_SCHNORRSIG "Enable schnorrsig module." ON)
62+
option(SECP256K1_ENABLE_MODULE_ELLSWIFT "Enable ElligatorSwift module." ON)
63+
64+
# Processing must be done in a topological sorting of the dependency graph
65+
# (dependent module first).
66+
if(SECP256K1_ENABLE_MODULE_ELLSWIFT)
67+
add_compile_definitions(ENABLE_MODULE_ELLSWIFT=1)
68+
endif()
69+
6670
if(SECP256K1_ENABLE_MODULE_SCHNORRSIG)
6771
set(SECP256K1_ENABLE_MODULE_EXTRAKEYS ON)
6872
add_compile_definitions(ENABLE_MODULE_SCHNORRSIG=1)
6973
endif()
74+
7075
if(SECP256K1_ENABLE_MODULE_EXTRAKEYS)
7176
add_compile_definitions(ENABLE_MODULE_EXTRAKEYS=1)
7277
endif()
7378

74-
option(SECP256K1_ENABLE_MODULE_ELLSWIFT "Enable ElligatorSwift module." ON)
75-
if(SECP256K1_ENABLE_MODULE_ELLSWIFT)
76-
add_compile_definitions(ENABLE_MODULE_ELLSWIFT=1)
79+
if(SECP256K1_ENABLE_MODULE_RECOVERY)
80+
add_compile_definitions(ENABLE_MODULE_RECOVERY=1)
81+
endif()
82+
83+
if(SECP256K1_ENABLE_MODULE_ECDH)
84+
add_compile_definitions(ENABLE_MODULE_ECDH=1)
7785
endif()
7886

7987
option(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS "Enable external default callback functions." OFF)

configure.ac

+13-13
Original file line numberDiff line numberDiff line change
@@ -387,29 +387,29 @@ SECP_CFLAGS="$SECP_CFLAGS $WERROR_CFLAGS"
387387
### Handle module options
388388
###
389389

390-
if test x"$enable_module_ecdh" = x"yes"; then
391-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ECDH=1"
392-
fi
393-
394-
if test x"$enable_module_recovery" = x"yes"; then
395-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_RECOVERY=1"
390+
# Processing must be done in a reverse topological sorting of the dependency graph
391+
# (dependent module first).
392+
if test x"$enable_module_ellswift" = x"yes"; then
393+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ELLSWIFT=1"
396394
fi
397395

398396
if test x"$enable_module_schnorrsig" = x"yes"; then
399-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_SCHNORRSIG=1"
400397
enable_module_extrakeys=yes
398+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_SCHNORRSIG=1"
401399
fi
402400

403-
if test x"$enable_module_ellswift" = x"yes"; then
404-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ELLSWIFT=1"
405-
fi
406-
407-
# Test if extrakeys is set after the schnorrsig module to allow the schnorrsig
408-
# module to set enable_module_extrakeys=yes
409401
if test x"$enable_module_extrakeys" = x"yes"; then
410402
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_EXTRAKEYS=1"
411403
fi
412404

405+
if test x"$enable_module_recovery" = x"yes"; then
406+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_RECOVERY=1"
407+
fi
408+
409+
if test x"$enable_module_ecdh" = x"yes"; then
410+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ECDH=1"
411+
fi
412+
413413
if test x"$enable_external_default_callbacks" = x"yes"; then
414414
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_EXTERNAL_DEFAULT_CALLBACKS=1"
415415
fi

0 commit comments

Comments
 (0)