From ea916734675942ded3a9a352d5576148eb459ea1 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Thu, 29 Feb 2024 02:12:10 +0100 Subject: [PATCH] [rhash] Fix error, revise dllexport/dllimport (#36950) Pass `RHASH_XVERSION` as a number number, not as a string. General error, but detected by Android NDK r26 ~~~ vcpkg/buildtrees/rhash/src/v1.4.4-e609ae2b07.clean/librhash/rhash.c:877:10: error: incompatible pointer to integer conversion returning 'char[1]' from a function with result type 'rhash_uptr_t' (aka 'unsigned int') [-Wint-conversion] return RHASH_XVERSION; ^~~~~~~~~~~~~~ :2:24: note: expanded from macro 'RHASH_XVERSION' #define RHASH_XVERSION "" ^~ 1 error generated. ~~~ Complement `dllexport` with `dllimport` for shared windows, and omit it everywhere else. Add missing pc file as if installed with official build system. --- ports/rhash/CMakeLists.txt | 33 +++++++++++++++++++++++++++++++-- ports/rhash/portfile.cmake | 8 +++++++- ports/rhash/vcpkg.json | 1 + versions/baseline.json | 2 +- versions/r-/rhash.json | 5 +++++ 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/ports/rhash/CMakeLists.txt b/ports/rhash/CMakeLists.txt index 3d4dd189b9..d32e94b158 100644 --- a/ports/rhash/CMakeLists.txt +++ b/ports/rhash/CMakeLists.txt @@ -1,12 +1,24 @@ cmake_minimum_required(VERSION 3.5) project(rhash C) +# cf. configure: RHASH_XVERSION = $(printf "0x%02x%02x%02x%02x" "$_v1" "$_v2" "$_v3" 0) +set(RHASH_VERSION "undefined" CACHE STRING "") +if(NOT RHASH_VERSION MATCHES [[^([0-9]+)[.]([0-9]+)[.]([0-9]+)$]]) + message(FATAL_ERROR "Cannot derive RHASH_XVERSION from '${RHASH_VERSION}'") +endif() +MATH(EXPR RHASH_XVERSION "((${CMAKE_MATCH_1} * 256 + ${CMAKE_MATCH_2}) * 256 + ${CMAKE_MATCH_3}) * 256" OUTPUT_FORMAT HEXADECIMAL) + file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/Makefile RHASH_SOURCES REGEX "^SOURCES = .*$") string(REPLACE "SOURCES = " "" RHASH_SOURCES "${RHASH_SOURCES}") string(REPLACE " " ";" RHASH_SOURCES "${RHASH_SOURCES}") -add_definitions(-DRHASH_XVERSION="${RHASH_XVERSION}") + add_library(rhash ${RHASH_SOURCES}) -set_target_properties(rhash PROPERTIES COMPILE_DEFINITIONS "IN_RHASH" DEFINE_SYMBOL "RHASH_EXPORTS") + +target_compile_definitions(rhash PRIVATE RHASH_XVERSION=${RHASH_XVERSION}) + +if(WIN32 AND BUILD_SHARED_LIBS) + target_compile_definitions(rhash PRIVATE RHASH_EXPORTS) +endif() target_include_directories(rhash INTERFACE $) @@ -25,3 +37,20 @@ install(EXPORT unofficial-rhash-config if(NOT RHASH_SKIP_HEADERS) install(FILES rhash.h rhash_torrent.h DESTINATION include) endif() + +# cf. configure +set(LIBRHASH_PC "${CMAKE_CURRENT_BINARY_DIR}/librhash.pc") +file(WRITE "${LIBRHASH_PC}" +"prefix=fixup +exec_prefix=\${prefix} +libdir=\${prefix}/lib +includedir=\${prefix}/include + +Name: librash +Description: LibRHash shared library +Version: ${RHASH_VERSION} +Cflags: -I\${includedir} +Libs: -L\${libdir} -lrhash +") + +install(FILES "${LIBRHASH_PC}" DESTINATION "lib/pkgconfig") diff --git a/ports/rhash/portfile.cmake b/ports/rhash/portfile.cmake index a274e4dc97..4e07318358 100644 --- a/ports/rhash/portfile.cmake +++ b/ports/rhash/portfile.cmake @@ -1,4 +1,3 @@ -set(RHASH_XVERSION 1.4.2) vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO rhash/RHash @@ -11,6 +10,8 @@ file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH} vcpkg_cmake_configure( SOURCE_PATH "${SOURCE_PATH}/librhash" + OPTIONS + -DRHASH_VERSION=${VERSION} OPTIONS_DEBUG -DRHASH_SKIP_HEADERS=ON ) @@ -18,5 +19,10 @@ vcpkg_cmake_configure( vcpkg_cmake_install() vcpkg_copy_pdbs() vcpkg_cmake_config_fixup(PACKAGE_NAME unofficial-rhash) +vcpkg_fixup_pkgconfig() + +if(VCPKG_TARGET_IS_WINDOWS AND VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic") + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/rhash.h" "# define RHASH_API" "# define RHASH_API __declspec(dllimport)") +endif() file(INSTALL "${SOURCE_PATH}/COPYING" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) diff --git a/ports/rhash/vcpkg.json b/ports/rhash/vcpkg.json index 14c97cdda6..4359431ad2 100644 --- a/ports/rhash/vcpkg.json +++ b/ports/rhash/vcpkg.json @@ -1,6 +1,7 @@ { "name": "rhash", "version": "1.4.4", + "port-version": 1, "description": "C library for computing a wide variety of hash sums", "homepage": "https://github.com/rhash/RHash", "license": "0BSD", diff --git a/versions/baseline.json b/versions/baseline.json index b9d466d6a0..e9e4b488e5 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -7590,7 +7590,7 @@ }, "rhash": { "baseline": "1.4.4", - "port-version": 0 + "port-version": 1 }, "rhasheq": { "baseline": "2023-06-17", diff --git a/versions/r-/rhash.json b/versions/r-/rhash.json index d31d125d13..850235867e 100644 --- a/versions/r-/rhash.json +++ b/versions/r-/rhash.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "a3e224c21215bd63a0404550b6b396254a60635e", + "version": "1.4.4", + "port-version": 1 + }, { "git-tree": "cb7e94fe8d5d109574fd0e304e246c780f0b43c5", "version": "1.4.4",