Skip to content

Commit c3f3d16

Browse files
committed
Fixing build for static binary
1 parent 37dd3bd commit c3f3d16

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,41 @@ pkg_check_modules(MPFR REQUIRED IMPORTED_TARGET mpfr)
395395
if(BUILD_PYTHON_EXTENSION AND UNIX AND NOT APPLE)
396396
set(CMAKE_FIND_LIBRARY_SUFFIXES "${_saved_find_suffixes}")
397397
endif()
398+
# pkg_check_modules resolves libraries via pkg-config, which ignores
399+
# CMAKE_FIND_LIBRARY_SUFFIXES and may return .so paths even when we need
400+
# .a for a fully static binary. Override GMP and MPFR targets here.
401+
if(STATIC_BINARY)
402+
# MPFR: its interface is just the mpfr library itself.
403+
find_library(_MPFR_STATIC_LIB NAMES libmpfr.a
404+
HINTS /usr/local/lib ${MPFR_LIBRARY_DIRS} NO_DEFAULT_PATH)
405+
if(NOT _MPFR_STATIC_LIB)
406+
find_library(_MPFR_STATIC_LIB NAMES libmpfr.a HINTS ${MPFR_LIBRARY_DIRS})
407+
endif()
408+
if(_MPFR_STATIC_LIB)
409+
set_property(TARGET PkgConfig::MPFR PROPERTY INTERFACE_LINK_LIBRARIES "${_MPFR_STATIC_LIB}")
410+
message(STATUS "Static MPFR: ${_MPFR_STATIC_LIB}")
411+
else()
412+
message(WARNING "Static libmpfr.a not found; static link may fail")
413+
endif()
414+
# GMP: its interface is [gmpxx, gmp]. Find static gmp and rebuild the list,
415+
# keeping the already-resolved gmpxx path (which find_library got right via suffix order).
416+
find_library(_GMP_STATIC_LIB NAMES libgmp.a
417+
HINTS /usr/local/lib ${GMP_LIBRARY_DIRS} NO_DEFAULT_PATH)
418+
if(NOT _GMP_STATIC_LIB)
419+
find_library(_GMP_STATIC_LIB NAMES libgmp.a HINTS ${GMP_LIBRARY_DIRS})
420+
endif()
421+
if(_GMP_STATIC_LIB)
422+
if(GMPXX_LIBRARY)
423+
set_property(TARGET PkgConfig::GMP PROPERTY INTERFACE_LINK_LIBRARIES
424+
"${GMPXX_LIBRARY}" "${_GMP_STATIC_LIB}")
425+
else()
426+
set_property(TARGET PkgConfig::GMP PROPERTY INTERFACE_LINK_LIBRARIES "${_GMP_STATIC_LIB}")
427+
endif()
428+
message(STATUS "Static GMP: ${_GMP_STATIC_LIB}")
429+
else()
430+
message(WARNING "Static libgmp.a not found; static link may fail")
431+
endif()
432+
endif()
398433

399434
include(FetchContent)
400435
# FetchContent_Populate with declared details is deprecated in CMake 3.30+ (CMP0169).
@@ -404,6 +439,21 @@ if(POLICY CMP0169)
404439
endif()
405440

406441

442+
# ---- cadical / cadiback (transitive deps of arjun/cryptominisat) ----
443+
# These are not used directly by approxmc, but arjun's exported target lists
444+
# them in its INTERFACE_LINK_LIBRARIES. Import them here so CMake resolves
445+
# them to actual library paths rather than bare -l flags.
446+
set(cadical_DIR "" CACHE PATH "cadical build dir containing cadicalConfig.cmake")
447+
if(cadical_DIR AND NOT TARGET cadical)
448+
find_package(cadical CONFIG REQUIRED HINTS "${cadical_DIR}")
449+
message(STATUS "cadical: using pre-built at ${cadical_DIR}")
450+
endif()
451+
set(cadiback_DIR "" CACHE PATH "cadiback build dir containing cadibackConfig.cmake")
452+
if(cadiback_DIR AND NOT TARGET cadiback)
453+
find_package(cadiback CONFIG REQUIRED HINTS "${cadiback_DIR}")
454+
message(STATUS "cadiback: using pre-built at ${cadiback_DIR}")
455+
endif()
456+
407457
# ---- CryptoMiniSat5 ----
408458
set(cryptominisat5_DIR "" CACHE PATH "cryptominisat5 install/build prefix (contains lib/cmake/cryptominisat5/). Auto-resolved if empty.")
409459
if(NOT TARGET cryptominisat5)

0 commit comments

Comments
 (0)