From 1a56bffb48cc346152c85464489e62eb6dfaf54e Mon Sep 17 00:00:00 2001
From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
Date: Wed, 24 May 2023 14:44:30 +0100
Subject: [PATCH] build: Disable some targets when external callbacks are
 enabled

The benchmarks, constant-time tests and examples are not supposed to be
built when external callbacks are enabled.
---
 CMakeLists.txt | 7 ++++---
 configure.ac   | 6 ++++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c897022e8e..771be2a579 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -150,11 +150,12 @@ if(SECP256K1_VALGRIND)
   endif()
 endif()
 
-option(SECP256K1_BUILD_BENCHMARK "Build benchmarks." ON)
+include(CMakeDependentOption)
+cmake_dependent_option(SECP256K1_BUILD_BENCHMARK "Build benchmarks." ON "NOT SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS" OFF)
 option(SECP256K1_BUILD_TESTS "Build tests." ON)
 option(SECP256K1_BUILD_EXHAUSTIVE_TESTS "Build exhaustive tests." ON)
-option(SECP256K1_BUILD_CTIME_TESTS "Build constant-time tests." ${SECP256K1_VALGRIND})
-option(SECP256K1_BUILD_EXAMPLES "Build examples." OFF)
+cmake_dependent_option(SECP256K1_BUILD_CTIME_TESTS "Build constant-time tests." ${SECP256K1_VALGRIND} "NOT SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS" OFF)
+cmake_dependent_option(SECP256K1_BUILD_EXAMPLES "Build examples." ON "NOT SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS" OFF)
 
 # Redefine configuration flags.
 # We leave assertions on, because they are only used in the examples, and we want them always on there.
diff --git a/configure.ac b/configure.ac
index 799b51d1f9..12f082b971 100644
--- a/configure.ac
+++ b/configure.ac
@@ -189,6 +189,12 @@ AC_ARG_ENABLE(external_default_callbacks,
     AS_HELP_STRING([--enable-external-default-callbacks],[enable external default callback functions [default=no]]), [],
     [SECP_SET_DEFAULT([enable_external_default_callbacks], [no], [no])])
 
+if test x"$enable_external_default_callbacks" = x"yes"; then
+  enable_benchmark="no"
+  enable_ctime_tests="no"
+  enable_examples="no"
+fi
+
 # Test-only override of the (autodetected by the C code) "widemul" setting.
 # Legal values are:
 #  * int64 (for [u]int64_t),