From 7adc87efe1a4d04d60c271c6d3f63a1505e3bf9d Mon Sep 17 00:00:00 2001 From: Jonas Zaddach Date: Mon, 29 Mar 2021 19:14:39 +0200 Subject: [PATCH] [clamav] Add new port (#14658) * Added ClamAV port * Patch ClamAV's cmake files instead of doing things in portfile * Fix whitespace * Strip down package to really only build libclamav * Fix static build * Fix build on Linux * Remove libcurl linkage * fix copy-paste mistake * Disable static build * update version record Co-authored-by: JackBoosY --- ports/clamav/CONTROL | 6 ++ ports/clamav/build.patch | 26 +++++++ ports/clamav/cmakefiles.patch | 136 ++++++++++++++++++++++++++++++++++ ports/clamav/curl.patch | 38 ++++++++++ ports/clamav/portfile.cmake | 38 ++++++++++ versions/baseline.json | 4 + versions/c-/clamav.json | 9 +++ 7 files changed, 257 insertions(+) create mode 100644 ports/clamav/CONTROL create mode 100644 ports/clamav/build.patch create mode 100644 ports/clamav/cmakefiles.patch create mode 100644 ports/clamav/curl.patch create mode 100644 ports/clamav/portfile.cmake create mode 100644 versions/c-/clamav.json diff --git a/ports/clamav/CONTROL b/ports/clamav/CONTROL new file mode 100644 index 0000000000..3646e75cc1 --- /dev/null +++ b/ports/clamav/CONTROL @@ -0,0 +1,6 @@ +Source: clamav +Version: 0.103.0 +Homepage: https://www.clamav.net +Description: ClamAV is an open-source anti-virus toolkit. +Build-Depends: openssl, json-c, libxml2, pcre2, pthreads, zlib, bzip2 +Supports: !uwp & !static diff --git a/ports/clamav/build.patch b/ports/clamav/build.patch new file mode 100644 index 0000000000..ee94a710bb --- /dev/null +++ b/ports/clamav/build.patch @@ -0,0 +1,26 @@ +diff --git a/cmake/FindCURSES.cmake b/cmake/FindCURSES.cmake +index a0755c697..f60735a91 100644 +--- a/cmake/FindCURSES.cmake ++++ b/cmake/FindCURSES.cmake +@@ -107,7 +107,7 @@ else() + set(CURSES_INCLUDE "") + + find_library(CURSES_LIBRARY +- NAMES curses ++ NAMES curses pdcurses + PATHS ${PC_PDCurses_LIBRARY_DIRS} + ) + +diff --git a/cmake/FindPthreadW32.cmake b/cmake/FindPthreadW32.cmake +index 4fded1eb7..0d44af310 100644 +--- a/cmake/FindPthreadW32.cmake ++++ b/cmake/FindPthreadW32.cmake +@@ -54,7 +54,7 @@ find_path(PThreadW32_INCLUDE_DIR + PATH_SUFFIXES pthreadw32 + ) + find_library(PThreadW32_LIBRARY +- NAMES pthreadVC2 ++ NAMES pthreadVC2 pthreadVC3 + PATHS ${PC_PThreadW32_LIBRARY_DIRS} + ) + diff --git a/ports/clamav/cmakefiles.patch b/ports/clamav/cmakefiles.patch new file mode 100644 index 0000000000..cca4e6effb --- /dev/null +++ b/ports/clamav/cmakefiles.patch @@ -0,0 +1,136 @@ +diff --git a/freshclam/CMakeLists.txt b/freshclam/CMakeLists.txt +index 545d5d4ba..59cbbc4ce 100644 +--- a/freshclam/CMakeLists.txt ++++ b/freshclam/CMakeLists.txt +@@ -28,18 +28,8 @@ target_link_libraries(freshclam-bin + ClamAV::libfreshclam + ClamAV::libclamav + ClamAV::shared ) +-if(WIN32) +- install(TARGETS freshclam-bin DESTINATION ${CMAKE_INSTALL_PREFIX}) +-else() +- install(TARGETS freshclam-bin DESTINATION ${CMAKE_INSTALL_BINDIR}) +-endif() + +-# Install an empty database directory +-if(WIN32) +- INSTALL(CODE "FILE(MAKE_DIRECTORY \${ENV}\${CMAKE_INSTALL_PREFIX}/database)") +-else() +- INSTALL(CODE "FILE(MAKE_DIRECTORY \${ENV}\${CMAKE_INSTALL_PREFIX}/share/clamav)") +-endif() ++install(TARGETS freshclam-bin) + + # now we rename resman-bin executable to resman using target properties + set_target_properties( freshclam-bin +diff --git a/libclamav/CMakeLists.txt b/libclamav/CMakeLists.txt +index bb14510db..136ea308a 100644 +--- a/libclamav/CMakeLists.txt ++++ b/libclamav/CMakeLists.txt +@@ -564,11 +564,7 @@ if(ENABLE_SHARED_LIB) + else() + target_link_libraries( clamav PUBLIC Iconv::Iconv ) + endif() +- if(WIN32) +- install(TARGETS clamav DESTINATION ${CMAKE_INSTALL_PREFIX}) +- else() +- install(TARGETS clamav DESTINATION ${CMAKE_INSTALL_LIBDIR}) +- endif() ++ install(TARGETS clamav) + + if(LLVM_FOUND) + target_link_directories( clamav PRIVATE ${LLVM_LIBRARY_DIRS} ) +@@ -609,11 +605,7 @@ if(ENABLE_STATIC_LIB) + COMPILE_FLAGS "${WARNCFLAGS}" + VERSION ${LIBCLAMAV_VERSION} SOVERSION ${LIBCLAMAV_SOVERSION}) + target_compile_definitions(clamav_static PUBLIC clamav_staticLIB) +- if(WIN32) +- install(TARGETS clamav_static DESTINATION ${CMAKE_INSTALL_PREFIX}) +- else() +- install(TARGETS clamav_static DESTINATION ${CMAKE_INSTALL_LIBDIR}) +- endif() ++ install(TARGETS clamav_static) + + add_library( ClamAV::libclamav_static ALIAS clamav_static ) + endif() +diff --git a/libclammspack/CMakeLists.txt b/libclammspack/CMakeLists.txt +index 1b5edbd4d..bba781d76 100644 +--- a/libclammspack/CMakeLists.txt ++++ b/libclammspack/CMakeLists.txt +@@ -73,11 +73,7 @@ endif() + target_sources( mspack + PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}/mspack/mspack.h" ) +-if(WIN32) +- install(TARGETS mspack DESTINATION ${CMAKE_INSTALL_PREFIX}) +-else() +- install(TARGETS mspack DESTINATION ${CMAKE_INSTALL_LIBDIR}) +-endif() ++install(TARGETS mspack) + + # Public (forwarded) dependencies. + target_link_libraries( mspack +diff --git a/libclamunrar/CMakeLists.txt b/libclamunrar/CMakeLists.txt +index 03dbc3387..267690b1c 100644 +--- a/libclamunrar/CMakeLists.txt ++++ b/libclamunrar/CMakeLists.txt +@@ -90,10 +90,6 @@ target_link_libraries( clamunrar + PUBLIC + unrar_obj ) + +-if(WIN32) +- install(TARGETS clamunrar DESTINATION ${CMAKE_INSTALL_PREFIX}) +-else() +- install(TARGETS clamunrar DESTINATION ${CMAKE_INSTALL_LIBDIR}) +-endif() ++install(TARGETS clamunrar) + + add_library( ClamAV::libclamunrar ALIAS clamunrar ) +diff --git a/libclamunrar_iface/CMakeLists.txt b/libclamunrar_iface/CMakeLists.txt +index 42f81544d..61f21da33 100644 +--- a/libclamunrar_iface/CMakeLists.txt ++++ b/libclamunrar_iface/CMakeLists.txt +@@ -55,11 +55,7 @@ if(ENABLE_UNRAR) + PUBLIC + ClamAV::libclamunrar_iface_iface) + +- if(WIN32) +- install(TARGETS clamunrar_iface DESTINATION ${CMAKE_INSTALL_PREFIX}) +- else() +- install(TARGETS clamunrar_iface DESTINATION ${CMAKE_INSTALL_LIBDIR}) +- endif() ++ install(TARGETS clamunrar_iface) + + add_library( ClamAV::libclamunrar_iface ALIAS clamunrar_iface ) +-endif() +\ No newline at end of file ++endif() +diff --git a/libfreshclam/CMakeLists.txt b/libfreshclam/CMakeLists.txt +index 6fb711818..27321ceb4 100644 +--- a/libfreshclam/CMakeLists.txt ++++ b/libfreshclam/CMakeLists.txt +@@ -65,11 +65,7 @@ if(ENABLE_SHARED_LIB) + set_target_properties(freshclam PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}" + VERSION ${LIBFRESHCLAM_VERSION} SOVERSION ${LIBFRESHCLAM_SOVERSION}) +- if(WIN32) +- install(TARGETS freshclam DESTINATION ${CMAKE_INSTALL_PREFIX}) +- else() +- install(TARGETS freshclam DESTINATION ${CMAKE_INSTALL_LIBDIR}) +- endif() ++ install(TARGETS freshclam) + + add_library( ClamAV::libfreshclam ALIAS freshclam ) + endif() +@@ -88,11 +84,7 @@ if(ENABLE_STATIC_LIB) + COMPILE_FLAGS "${WARNCFLAGS}" + VERSION ${LIBFRESHCLAM_VERSION} SOVERSION ${LIBFRESHCLAM_SOVERSION}) + target_compile_definitions(freshclam_static PUBLIC freshclam_staticLIB) +- if(WIN32) +- install(TARGETS freshclam_static DESTINATION ${CMAKE_INSTALL_PREFIX}) +- else() +- install(TARGETS freshclam_static DESTINATION ${CMAKE_INSTALL_LIBDIR}) +- endif() ++ install(TARGETS freshclam_static) + + add_library( ClamAV::libfreshclam_static ALIAS freshclam_static ) + endif() diff --git a/ports/clamav/curl.patch b/ports/clamav/curl.patch new file mode 100644 index 0000000000..444f61da36 --- /dev/null +++ b/ports/clamav/curl.patch @@ -0,0 +1,38 @@ +commit 59516af244a840aa95a8f15f978ac24ec97178cf +Author: jzaddach +Date: Fri Nov 27 14:24:31 2020 +0100 + + Fix curl usage + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index e85d03e20..9f1cd42c5 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -685,7 +685,7 @@ endif() + + add_subdirectory( libclamav ) + +-if(NOT LIBCLAMAV_ONLY) ++if(NOT ENABLE_LIBCLAMAV_ONLY) + add_subdirectory( shared ) + + add_subdirectory( libfreshclam ) +diff --git a/shared/CMakeLists.txt b/shared/CMakeLists.txt +index d9c8b6bfe..30df5a1a4 100644 +--- a/shared/CMakeLists.txt ++++ b/shared/CMakeLists.txt +@@ -59,9 +59,13 @@ target_link_libraries( shared_obj + PUBLIC + ClamAV::libclamav + ZLIB::ZLIB +- CURL::libcurl + OpenSSL::SSL + OpenSSL::Crypto ) ++if(CURL_FOUND) ++ target_link_libraries( shared_obj ++ PUBLIC ++ CURL::libcurl ) ++endif() + if(WIN32) + target_link_libraries( shared_obj + PUBLIC diff --git a/ports/clamav/portfile.cmake b/ports/clamav/portfile.cmake new file mode 100644 index 0000000000..a7a32f90da --- /dev/null +++ b/ports/clamav/portfile.cmake @@ -0,0 +1,38 @@ +vcpkg_fail_port_install(ON_TARGET "uwp") +vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO Cisco-Talos/clamav-devel + REF clamav-0.103.0 + SHA512 488381202bdcea812c39d611e0a31eaf8f55c9c5d0a6400fd53dfa0da674a95672fdc9b290dc6157cb8f628d9f81846b5cc108eb1e44f6207d3c6f2659ba63c6 + HEAD_REF master + PATCHES + "build.patch" + "cmakefiles.patch" + "curl.patch" +) + +vcpkg_configure_cmake( + SOURCE_PATH ${SOURCE_PATH} + PREFER_NINJA + OPTIONS + -DENABLE_LIBCLAMAV_ONLY=ON + -DENABLE_DOCS=OFF + -DENABLE_SHARED_LIB=ON + -DENABLE_STATIC_LIB=OFF +) + +vcpkg_install_cmake() + +# Handle copyright +file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") + +# On Linux, clamav will still build and install clamav-config +if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin") +endif() + +vcpkg_copy_pdbs() diff --git a/versions/baseline.json b/versions/baseline.json index 79a7494aee..6a4cd93e14 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -1212,6 +1212,10 @@ "baseline": "2019-11-30-1", "port-version": 0 }, + "clamav": { + "baseline": "0.103.0", + "port-version": 0 + }, "clapack": { "baseline": "3.2.1", "port-version": 17 diff --git a/versions/c-/clamav.json b/versions/c-/clamav.json new file mode 100644 index 0000000000..dc6c236ed3 --- /dev/null +++ b/versions/c-/clamav.json @@ -0,0 +1,9 @@ +{ + "versions": [ + { + "git-tree": "30eb9215db50ee898f34f2405682017ac2424e58", + "version-string": "0.103.0", + "port-version": 0 + } + ] +}