Skip to content

Commit

Permalink
gmp: fix gmp link on OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
aleflm committed Feb 10, 2025
1 parent 3589b59 commit bfd478c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ option(BUILD_UTIL "Build ${FIRO_UTIL_NAME} executable and library." ${BUILD_TEST
option(BUILD_UTIL_CHAINSTATE "Build experimental firo-chainstate executable." OFF)
option(BUILD_KERNEL_LIB "Build experimental firokernel library." ${BUILD_UTIL_CHAINSTATE})

option(ENABLE_WALLET "Enable wallet." ON)
option(ENABLE_WALLET "Enable wallet." OFF)
option(WITH_BDB "Enable Berkeley DB (BDB) wallet support." OFF)
cmake_dependent_option(WARN_INCOMPATIBLE_BDB "Warn when using a Berkeley DB (BDB) version other than 4.8." ON "WITH_BDB" OFF)
if(WITH_BDB)
Expand Down Expand Up @@ -421,6 +421,9 @@ find_library(MINIUPNP_LIBRARY
REQUIRED
)

# Find GMP library
find_package(GMP 6.2.1 REQUIRED)

# Find zlib library
find_library(ZLIB_LIBRARY
NAMES z
Expand Down
31 changes: 22 additions & 9 deletions src/secp256k1/cmake/FindGMP.cmake → cmake/module/FindGMP.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_GMP QUIET gmp)
endif()
# Try to find the GNU Multiple Precision Arithmetic Library (GMP)
# See http://gmplib.org/

if (GMP_INCLUDES AND GMP_LIBRARIES)
set(GMP_FIND_QUIETLY TRUE)
endif (GMP_INCLUDES AND GMP_LIBRARIES)

find_path(GMP_INCLUDES
NAMES
gmp.h
HINTS
$ENV{GMPDIR}
${INCLUDE_INSTALL_DIR}
${PC_GMP_INCLUDE_DIRS}
/usr/include
/usr/local/include
${LIB_INSTALL_DIR}
${PC_GMP_LIBRARY_DIRS}
/usr/lib
/usr/local/lib
)

find_library(GMP_LIBRARIES
Expand All @@ -24,7 +27,10 @@ find_library(GMP_LIBRARIES
/usr/local/lib
)

if(GMP_INCLUDES)

if(GMP_LIBRARIES AND GMP_INCLUDES)
message(STATUS "Found GMP: ${GMP_LIBRARIES}")
message(STATUS "GMP includes: ${GMP_INCLUDES}")
file(STRINGS "${GMP_INCLUDES}/gmp.h" gmp_version_str REGEX "^#define[\t ]+__GNU_MP_VERSION[\t ]+[0-9]+")
string(REGEX REPLACE "^#define[\t ]+__GNU_MP_VERSION[\t ]+([0-9]+).*" "\\1" GMP_VERSION_MAJOR "${gmp_version_str}")

Expand All @@ -34,4 +40,11 @@ if(GMP_INCLUDES)
set(GMP_VERSION "${GMP_VERSION_MAJOR}.${GMP_VERSION_MINOR}")
message(STATUS "GMP_VERSION_MAJOR : ${GMP_VERSION_MAJOR}")
message(STATUS "GMP_VERSION_MINOR : ${GMP_VERSION_MINOR}")
endif()
else()
message(FATAL_ERROR "Could not find GMP")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GMP DEFAULT_MSG
GMP_INCLUDES GMP_LIBRARIES)
mark_as_advanced(GMP_INCLUDES GMP_LIBRARIES)
1 change: 0 additions & 1 deletion doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ find_package(Doxygen COMPONENTS dot)

if(DOXYGEN_FOUND)
set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(Doxyfile.in ${doxyfile} USE_SOURCE_PERMISSIONS)

# In CMake 3.27, The FindDoxygen module's doxygen_add_docs()
# command gained a CONFIG_FILE option to specify a custom doxygen
Expand Down
16 changes: 10 additions & 6 deletions src/secp256k1/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set_property(TARGET secp256k1 PROPERTY POSITION_INDEPENDENT_CODE ON)

target_link_libraries(secp256k1
PUBLIC
gmp
${GMP_LIBRARIES}
PRIVATE
OpenSSL::Crypto
)
Expand Down Expand Up @@ -51,7 +51,11 @@ add_library(secp256k1pp
set_property(TARGET secp256k1pp PROPERTY POSITION_INDEPENDENT_CODE ON)

target_link_libraries(secp256k1pp
PUBLIC secp256k1 gmp
PUBLIC secp256k1 ${GMP_LIBRARIES}
)

target_include_directories(secp256k1pp
PUBLIC ${GMP_INCLUDES}
)

add_library(secp256k1_asm INTERFACE)
Expand Down Expand Up @@ -128,26 +132,26 @@ if(SECP256K1_BUILD_BENCHMARK)
add_executable(bench_verify bench_verify.c)
target_link_libraries(bench_verify PUBLIC secp256k1)
add_executable(bench_internal bench_internal.c)
target_link_libraries(bench_internal PUBLIC secp256k1_asm gmp)
target_link_libraries(bench_internal PUBLIC secp256k1_asm ${GMP_LIBRARIES})
endif()

if(SECP256K1_BUILD_TESTS)
add_executable(noverify_tests tests.c)
target_compile_definitions(noverify_tests PRIVATE VERIFY)
target_link_libraries(noverify_tests secp256k1_asm gmp)
target_link_libraries(noverify_tests secp256k1_asm ${GMP_LIBRARIES})
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_asm gmp)
target_link_libraries(tests secp256k1_asm ${GMP_LIBRARIES})
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 gmp)
target_link_libraries(exhaustive_tests secp256k1_asm ${GMP_LIBRARIES})
target_compile_definitions(exhaustive_tests PRIVATE $<$<NOT:$<CONFIG:Coverage>>:VERIFY>)
add_test(NAME secp256k1_exhaustive_tests COMMAND exhaustive_tests)
endif()
Expand Down

0 comments on commit bfd478c

Please sign in to comment.