From b92cdce3aff7334d1c799012238d0be3959a5a11 Mon Sep 17 00:00:00 2001 From: mtezych Date: Wed, 30 Jan 2019 12:45:14 +0100 Subject: [PATCH] Implemented CMake build system --- CMakeLists.txt | 80 +++++++++++++++++++ README.md | 2 +- src/metrohash.h => inc/metrohash/MetroHash.h | 6 +- .../metrohash/MetroHash128.h | 0 .../metrohash/MetroHash128crc.h | 0 .../metrohash/MetroHash64.h | 0 src/metrohash128.cpp | 4 +- src/metrohash128crc.cpp | 5 +- src/metrohash64.cpp | 4 +- src/testvector.h | 2 +- 10 files changed, 92 insertions(+), 11 deletions(-) create mode 100644 CMakeLists.txt rename src/metrohash.h => inc/metrohash/MetroHash.h (86%) rename src/metrohash128.h => inc/metrohash/MetroHash128.h (100%) rename src/metrohash128crc.h => inc/metrohash/MetroHash128crc.h (100%) rename src/metrohash64.h => inc/metrohash/MetroHash64.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..50f7c2e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,80 @@ + +# CMakeLists.txt +# +# Copyright 2015-2019 J. Andrew Rogers +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.1) + +project(MetroHash VERSION 1.0.0 LANGUAGES CXX) + + +add_library(metrohash STATIC "") + +target_include_directories(metrohash PUBLIC inc) + +target_sources(metrohash PRIVATE inc/metrohash/MetroHash.h + inc/metrohash/MetroHash64.h + inc/metrohash/MetroHash128.h + inc/metrohash/MetroHash128crc.h + src/MetroHash64.cpp + src/MetroHash128.cpp + src/MetroHash128crc.cpp + src/Platform.h + src/TestVector.h) + + +set_target_properties(metrohash PROPERTIES CXX_STANDARD 98 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF) + + +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + + # [GCC] x86 Options + # https://gcc.gnu.org/onlinedocs/gcc-8.1.0/gcc/x86-Options.html + target_compile_options(metrohash PRIVATE + -msse4.2) # Enable the use of SSE4.2 instructions. + + # [GCC] Options to Request or Suppress Warnings + # https://gcc.gnu.org/onlinedocs/gcc-8.1.0/gcc/Warning-Options.html + target_compile_options(metrohash PRIVATE + -Wall + -Wextra + -Wpedantic + -Werror) + +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + + # [MSVC] Minimum CPU Architecture + # https://docs.microsoft.com/en-us/cpp/build/reference/arch-x86 + # https://docs.microsoft.com/en-us/cpp/build/reference/arch-x64 + # For x64 CPUs SSE4.2 instructions are enabled by default. + + # [MSVC] Warning Level + # https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level + target_compile_options(metrohash PRIVATE + /W4 # Enable warning level 4. + /WX) # Treat warnings as errors. + +else() + message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER_ID} is not supported!") +endif() + + +if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8) + + message(FATAL_ERROR "MetroHash supports only 64-bit builds!") + +endif() diff --git a/README.md b/README.md index 2ac16b1..0db39ea 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ The project has been re-licensed under Apache License v2.0. The purpose of this Two new 64-bit and 128-bit algorithms add the ability to construct hashes incrementally. In addition to supporting incremental construction, the algorithms are slightly superior to the prior versions. -A big change is that these new algorithms are implemented as C++ classes that support both incremental and stateless hashing. These classes also have a static method for verifying the implementation against the test vectors built into the classes. Implementations are now fully contained by their respective headers e.g. "metrohash128.h". +A big change is that these new algorithms are implemented as C++ classes that support both incremental and stateless hashing. These classes also have a static method for verifying the implementation against the test vectors built into the classes. Implementations are now fully contained by their respective headers e.g. "metrohash/MetroHash128.h". *Note: an incremental version of the 128-bit CRC version is on its way but is not included in this push.* diff --git a/src/metrohash.h b/inc/metrohash/MetroHash.h similarity index 86% rename from src/metrohash.h rename to inc/metrohash/MetroHash.h index ffab032..3b2472a 100644 --- a/src/metrohash.h +++ b/inc/metrohash/MetroHash.h @@ -17,8 +17,8 @@ #ifndef METROHASH_METROHASH_H #define METROHASH_METROHASH_H -#include "metrohash64.h" -#include "metrohash128.h" -#include "metrohash128crc.h" +#include +#include +#include #endif // #ifndef METROHASH_METROHASH_H diff --git a/src/metrohash128.h b/inc/metrohash/MetroHash128.h similarity index 100% rename from src/metrohash128.h rename to inc/metrohash/MetroHash128.h diff --git a/src/metrohash128crc.h b/inc/metrohash/MetroHash128crc.h similarity index 100% rename from src/metrohash128crc.h rename to inc/metrohash/MetroHash128crc.h diff --git a/src/metrohash64.h b/inc/metrohash/MetroHash64.h similarity index 100% rename from src/metrohash64.h rename to inc/metrohash/MetroHash64.h diff --git a/src/metrohash128.cpp b/src/metrohash128.cpp index 5c143db..bf616e2 100644 --- a/src/metrohash128.cpp +++ b/src/metrohash128.cpp @@ -15,8 +15,8 @@ // limitations under the License. #include -#include "platform.h" -#include "metrohash128.h" +#include "Platform.h" +#include const char * MetroHash128::test_string = "012345678901234567890123456789012345678901234567890123456789012"; diff --git a/src/metrohash128crc.cpp b/src/metrohash128crc.cpp index 775a9a9..065b1c1 100644 --- a/src/metrohash128crc.cpp +++ b/src/metrohash128crc.cpp @@ -15,10 +15,11 @@ // limitations under the License. +// SSE4.2 -> https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_crc32_u64 #include #include -#include "metrohash.h" -#include "platform.h" +#include +#include "Platform.h" void metrohash128crc_1(const uint8_t * key, uint64_t len, uint32_t seed, uint8_t * out) diff --git a/src/metrohash64.cpp b/src/metrohash64.cpp index 7b5ec7f..e9ef8c6 100644 --- a/src/metrohash64.cpp +++ b/src/metrohash64.cpp @@ -14,8 +14,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "platform.h" -#include "metrohash64.h" +#include "Platform.h" +#include #include diff --git a/src/testvector.h b/src/testvector.h index e400618..f99a280 100644 --- a/src/testvector.h +++ b/src/testvector.h @@ -17,7 +17,7 @@ #ifndef METROHASH_TESTVECTOR_H #define METROHASH_TESTVECTOR_H -#include "metrohash.h" +#include typedef void (*HashFunction) (const uint8_t * key, uint64_t len, uint32_t seed, uint8_t * hash);