Skip to content

Commit

Permalink
[metrohash] Use try_compile helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
ras0219-msft committed Mar 16, 2021
1 parent 5bd6ba0 commit 1c8c750
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
33 changes: 24 additions & 9 deletions ports/metrohash/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.5)
project(metrohash LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)

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

if(VCPKG_TARGET_ARCHITECTURE MATCHES arm OR VCPKG_TARGET_ARCHITECTURE STREQUAL x86)
message(WARNING "MetroHash's 128 CRC requires SSE 4.2 intrinsic. The functions will be excluded.")
else()
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
11 changes: 6 additions & 5 deletions ports/metrohash/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ vcpkg_from_github(
HEAD_REF master
)

if(VCPKG_TARGET_ARCHITECTURE MATCHES arm OR VCPKG_TARGET_ARCHITECTURE STREQUAL x86)
vcpkg_replace_string(${SOURCE_PATH}/src/metrohash.h
"#include \"metrohash128crc.h\""
"//#include \"metrohash128crc.h\" // It can't be supported for ARM or x86")
endif()
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)

Expand All @@ -25,5 +20,11 @@ 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)
2 changes: 1 addition & 1 deletion ports/metrohash/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metrohash",
"version-string": "1.1.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"
Expand Down
4 changes: 2 additions & 2 deletions versions/m-/metrohash.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"versions": [
{
"git-tree": "9b4c8680069f3dcab66bbce4c70a5530b2f303b5",
"version-string": "1.1.3",
"git-tree": "777a0ee61fdc53dcad0971184232d29b58e52f63",
"version": "1.1.3",
"port-version": 4
},
{
Expand Down

0 comments on commit 1c8c750

Please sign in to comment.