Skip to content

Commit

Permalink
[metrohash] support more triplets by excluding 128 CRC source (#16553)
Browse files Browse the repository at this point in the history
* [metrohash] exclude CRC for x86

* the change will allow x86 triplets
* update port SHA

* [metrohash] remove fail_port_install

* update ci.baseline.txt

* [metrohash] sync portfile and CMakeLists.txt

* make both file use 'VCPKG_TARGET_TRIPLET' to make ease of comparison

* [metrohash] Use try_compile helpers

Co-authored-by: Robert Schumacher <[email protected]>
  • Loading branch information
luncliff and ras0219-msft authored Mar 19, 2021
1 parent 9e681d5 commit 96403d0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 29 deletions.
28 changes: 22 additions & 6 deletions ports/metrohash/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.5)
project(metrohash LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 11)

add_library(metrohash
src/metrohash64.cpp
src/metrohash128.cpp
)
list(APPEND metro_headers src/metrohash.h src/metrohash64.h src/metrohash128.h)

if(NOT ANDROID AND NOT IOS)
list(APPEND metro_headers src/metrohash128crc.h)
target_sources(metrohash PRIVATE src/metrohash128crc.cpp)
if(CMAKE_CXX_COMPILER_ID MATCHES Clang)
include(CheckCXXSourceCompiles)
include(CheckCXXCompilerFlag)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_cxx_compiler_flag("-msse4.2" HAS_MSSE42)
if(HAS_MSSE42)
target_compile_options(metrohash PRIVATE -msse4.2)
string(APPEND CMAKE_REQUIRED_FLAGS " -msse4.2")
endif()
endif()

check_cxx_source_compiles(
"#include <nmmintrin.h>
int main() {
_mm_crc32_u64(0, 0);
return 0;
}"
HAS_mm_crc32_u64)

if(HAS_mm_crc32_u64)
list(APPEND metro_headers src/metrohash128crc.h)
target_sources(metrohash PRIVATE src/metrohash128crc.cpp)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES GNU)
target_compile_options(metrohash PRIVATE -march=native)
endif()
Expand Down
29 changes: 15 additions & 14 deletions ports/metrohash/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
vcpkg_fail_port_install(ON_TARGET "UWP" ON_TARGET "x86" "arm" "aarch64")
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO jandrewrogers/MetroHash
REF v1.1.3
SHA512 02b6316e5ebf3d81465eea8a068565452be642394ddf5a53350affbbc9b9bfe1c3d182f7e8f7d49895351c48e11929e465777535e4354e01b6d0ba459e583ac5
HEAD_REF master
OUT_SOURCE_PATH SOURCE_PATH
REPO jandrewrogers/MetroHash
REF v1.1.3
SHA512 02b6316e5ebf3d81465eea8a068565452be642394ddf5a53350affbbc9b9bfe1c3d182f7e8f7d49895351c48e11929e465777535e4354e01b6d0ba459e583ac5
HEAD_REF master
)
if(VCPKG_TARGET_IS_ANDROID)
vcpkg_replace_string(${SOURCE_PATH}/src/metrohash.h
"#include \"metrohash128crc.h\""
"//#include \"metrohash128crc.h\" // It can't be supported for Android")
endif()
configure_file(${CURRENT_PORT_DIR}/CMakeLists.txt ${SOURCE_PATH}/CMakeLists.txt COPYONLY)

file(COPY ${CURRENT_PORT_DIR}/CMakeLists.txt DESTINATION ${SOURCE_PATH})
configure_file(${CURRENT_PORT_DIR}/Config.cmake.in ${SOURCE_PATH}/cmake/Config.cmake.in COPYONLY)

vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
)

vcpkg_install_cmake()
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake/${PORT})
vcpkg_copy_pdbs()

if(NOT EXISTS "${CURRENT_PACKAGES_DIR}/include/metrohash128crc.h")
vcpkg_replace_string(${CURRENT_PACKAGES_DIR}/include/metrohash.h
"#include \"metrohash128crc.h\""
"//#include \"metrohash128crc.h\" // The target platform does not support _mm_crc32_u64")
endif()

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
7 changes: 3 additions & 4 deletions ports/metrohash/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "metrohash",
"version-string": "1.1.3",
"port-version": 3,
"version": "1.1.3",
"port-version": 4,
"description": "MetroHash is a set of state-of-the-art hash functions for non-cryptographic use cases",
"homepage": "https://github.com/jandrewrogers/MetroHash",
"supports": "!(uwp | arm | x86)"
"homepage": "https://github.com/jandrewrogers/MetroHash"
}
4 changes: 0 additions & 4 deletions scripts/ci.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -910,10 +910,6 @@ meschach:x64-osx=fail
meschach:x64-uwp=fail
metis:arm-uwp=fail
metis:x64-uwp=fail
metrohash:arm-uwp=fail
metrohash:x64-uwp=fail
metrohash:x86-windows=fail
metrohash:arm64-windows=fail
mhook:arm64-windows=fail
mhook:arm-uwp=fail
mhook:x64-linux=fail
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -3798,7 +3798,7 @@
},
"metrohash": {
"baseline": "1.1.3",
"port-version": 3
"port-version": 4
},
"mgnlibs": {
"baseline": "2019-09-29",
Expand Down
5 changes: 5 additions & 0 deletions versions/m-/metrohash.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "777a0ee61fdc53dcad0971184232d29b58e52f63",
"version": "1.1.3",
"port-version": 4
},
{
"git-tree": "33078163f0311cfecce47b42c304650b602c9ddf",
"version-string": "1.1.3",
Expand Down

0 comments on commit 96403d0

Please sign in to comment.