From decfa8973c58c335d93fe69ba5a14027c7c4fa60 Mon Sep 17 00:00:00 2001 From: Micah Snyder Date: Thu, 21 Mar 2024 13:29:22 -0400 Subject: [PATCH] libclamav: resolve macOS linker issue with new LHA/LZH feature The delharc crate used to add LZH archive support appears to add a dependency on macOS CoreFoundation library. The error is: [ 78%] Linking C shared library libclamav.dylib Undefined symbols for architecture x86_64: "_CFRelease", referenced from: iana_time_zone::platform::get_timezone_inner::hc7da204717a39974 in libclamav_rust.a(iana_time_zone-bc4762a47da73d72.iana_time_zone.1863eb20d202562a-cgu.0.rcgu.o) ... clang: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [libclamav/libclamav.12.0.2.dylib] Error 1 We already link with CoreFoundation for libfreshclam and clamsubmit, so this commit extends that to libclamav as well. --- CMakeLists.txt | 22 +++++++++++----------- libclamav/CMakeLists.txt | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40494872c4..80de8c7d9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -548,21 +548,21 @@ if(${bytecodeRuntime} STREQUAL "llvm") endif() endif() +if(APPLE) + find_library(APPLE_CORE_FOUNDATION CoreFoundation) + if (NOT APPLE_CORE_FOUNDATION) + message(FATAL_ERROR "Apple CoreFoundation framework not found") + endif() + find_library(APPLE_SECURITY Security) + if (NOT APPLE_SECURITY) + message(FATAL_ERROR "Apple Security framework not found") + endif() +endif() + # libfreshclam & application dependencies if(NOT ENABLE_LIBCLAMAV_ONLY) find_package(CURL REQUIRED) - if(APPLE) - find_library(APPLE_CORE_FOUNDATION CoreFoundation) - if (NOT APPLE_CORE_FOUNDATION) - message(FATAL_ERROR "Apple CoreFoundation framework not found") - endif() - find_library(APPLE_SECURITY Security) - if (NOT APPLE_SECURITY) - message(FATAL_ERROR "Apple Security framework not found") - endif() - endif() - if(ENABLE_APP) find_package(CURSES REQUIRED) diff --git a/libclamav/CMakeLists.txt b/libclamav/CMakeLists.txt index 9b3aed89eb..d20bf71f5b 100644 --- a/libclamav/CMakeLists.txt +++ b/libclamav/CMakeLists.txt @@ -450,6 +450,13 @@ if(ENABLE_SHARED_LIB) ${CMAKE_DL_LIBS} m ) endif() + + if(APPLE) + target_link_libraries( clamav + PUBLIC + ${APPLE_CORE_FOUNDATION} ) + endif() + set_target_properties( clamav PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" VERSION ${LIBCLAMAV_VERSION} SOVERSION ${LIBCLAMAV_SOVERSION} ) @@ -549,6 +556,7 @@ if(ENABLE_STATIC_LIB) if (ENABLE_UNRAR) target_link_libraries( clamav_static PUBLIC ClamAV::libunrar_iface_static ClamAV::libunrar_iface_iface) endif() + if (WIN32) target_link_libraries( clamav_static PUBLIC @@ -563,6 +571,13 @@ if(ENABLE_STATIC_LIB) ${CMAKE_DL_LIBS} m ) endif() + + if(APPLE) + target_link_libraries( clamav_static + PUBLIC + ${APPLE_CORE_FOUNDATION} ) + endif() + set_target_properties( clamav_static PROPERTIES ARCHIVE_OUTPUT_NAME clamav_static COMPILE_FLAGS "${WARNCFLAGS}"