Skip to content

Commit

Permalink
[cityhash] Add feature sse for non-x86-Windows (#20999)
Browse files Browse the repository at this point in the history
* [cityhash] Add feature sse for non-x86-Windows

* version

* Add missing dependencies.

* version
  • Loading branch information
JackBoosY authored Oct 28, 2021
1 parent 7c10f98 commit 843e0ba
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 18 deletions.
46 changes: 45 additions & 1 deletion ports/cityhash/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,52 @@
cmake_minimum_required(VERSION 3.13)
project(cityhash CXX)

option(ENABLE_SSE "Build CityHash variants that depend on the _mm_crc32_u64 intrinsic." OFF)

set(CMAKE_CXX_STANDARD 11)

if (ENABLE_SSE)
include (CMakePushCheckState)
cmake_push_check_state()
if (MSVC)
include(CheckCXXSourceCompiles)

check_cxx_source_compiles(
"#include <nmmintrin.h>
int main() {
_mm_crc32_u64(0, 0);
return 0;
}"
USE_SSE)
else()
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag ("-msse4.2" USE_SSE)
if (USE_SSE)
set (SSE2_FLAG "-msse4.2")
endif()
endif()

cmake_pop_check_state()

if (NOT USE_SSE)
message(FATAL_ERROR "This platform doesn't support feature SSE4.2")
endif()
else()
set(USE_SSE OFF)
endif()

add_library(cityhash STATIC src/city.cc)

list(APPEND CITY_HEADERS src/city.h)
if (USE_SSE)
list(APPEND CITY_HEADERS src/citycrc.h)

target_compile_options(cityhash PRIVATE ${SSE2_FLAG})
if (MSVC)
target_compile_definitions(cityhash PRIVATE __SSE4_2__)
endif()
endif()

target_include_directories(cityhash PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
Expand All @@ -15,4 +59,4 @@ install(TARGETS cityhash EXPORT cityhash-config
)

install(EXPORT cityhash-config DESTINATION share/cmake/cityhash)
install(FILES src/city.h DESTINATION include)
install(FILES ${CITY_HEADERS} DESTINATION include)
36 changes: 23 additions & 13 deletions ports/cityhash/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,40 @@ vcpkg_from_github(
HEAD_REF master
)

file(COPY ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt DESTINATION ${SOURCE_PATH})
file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")

if(VCPKG_TARGET_IS_WINDOWS)
file(COPY ${CMAKE_CURRENT_LIST_DIR}/config.h DESTINATION ${SOURCE_PATH}/src)
file(COPY "${CMAKE_CURRENT_LIST_DIR}/config.h" DESTINATION "${SOURCE_PATH}/src")
else()
file(MAKE_DIRECTORY ${SOURCE_PATH}/out)
file(MAKE_DIRECTORY "${SOURCE_PATH}/out")
vcpkg_execute_required_process(
COMMAND ${SOURCE_PATH}/configure
WORKING_DIRECTORY ${SOURCE_PATH}/out
COMMAND "${SOURCE_PATH}/configure"
WORKING_DIRECTORY "${SOURCE_PATH}/out"
LOGNAME configure-${TARGET_TRIPLET}
)
file(COPY ${SOURCE_PATH}/out/config.h DESTINATION ${SOURCE_PATH}/src)
file(COPY "${SOURCE_PATH}/out/config.h" DESTINATION "${SOURCE_PATH}/src")
endif()

vcpkg_configure_cmake(
if (VCPKG_TARGET_IS_WINDOWS AND VCPKG_TARGET_ARCHITECTURE STREQUAL "x86" AND "sse" IN_LIST FEATURES)
message(FATAL_ERROR "Feature 'sse' does not support Windows x86 triplet.")
endif()

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
"sse" ENABLE_SSE
)

vcpkg_cmake_configure(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS
${FEATURE_OPTIONS}
)

vcpkg_install_cmake()
vcpkg_cmake_install()
vcpkg_copy_pdbs()
vcpkg_fixup_cmake_targets(CONFIG_PATH share/cmake/cityhash)
vcpkg_cmake_config_fixup(CONFIG_PATH share/cmake/cityhash)

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include"
"${CURRENT_PACKAGES_DIR}/debug/share")

configure_file(${SOURCE_PATH}/COPYING ${CURRENT_PACKAGES_DIR}/share/cityhash/copyright COPYONLY)
configure_file("${SOURCE_PATH}/COPYING" "${CURRENT_PACKAGES_DIR}/share/cityhash/copyright" COPYONLY)
21 changes: 18 additions & 3 deletions ports/cityhash/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
{
"name": "cityhash",
"version-string": "2013-01-08",
"port-version": 1,
"version-date": "2013-01-08",
"port-version": 2,
"description": "CityHash, a family of hash functions for strings.",
"homepage": "https://github.com/google/cityhash"
"homepage": "https://github.com/google/cityhash",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
],
"features": {
"sse": {
"description": "Build CityHash variants that depend on the _mm_crc32_u64 intrinsic."
}
}
}
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@
},
"cityhash": {
"baseline": "2013-01-08",
"port-version": 1
"port-version": 2
},
"civetweb": {
"baseline": "1.15",
Expand Down
5 changes: 5 additions & 0 deletions versions/c-/cityhash.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "9c1b6eaaf15c06d436ce42331b84566abd931f53",
"version-date": "2013-01-08",
"port-version": 2
},
{
"git-tree": "423306e7029cfac62069d751bb612e10b3777c13",
"version-string": "2013-01-08",
Expand Down

0 comments on commit 843e0ba

Please sign in to comment.