Skip to content

Commit b92cdce

Browse files
committed
Implemented CMake build system
1 parent 690a521 commit b92cdce

File tree

10 files changed

+92
-11
lines changed

10 files changed

+92
-11
lines changed

CMakeLists.txt

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
# CMakeLists.txt
3+
#
4+
# Copyright 2015-2019 J. Andrew Rogers
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
cmake_minimum_required(VERSION 3.1)
19+
20+
project(MetroHash VERSION 1.0.0 LANGUAGES CXX)
21+
22+
23+
add_library(metrohash STATIC "")
24+
25+
target_include_directories(metrohash PUBLIC inc)
26+
27+
target_sources(metrohash PRIVATE inc/metrohash/MetroHash.h
28+
inc/metrohash/MetroHash64.h
29+
inc/metrohash/MetroHash128.h
30+
inc/metrohash/MetroHash128crc.h
31+
src/MetroHash64.cpp
32+
src/MetroHash128.cpp
33+
src/MetroHash128crc.cpp
34+
src/Platform.h
35+
src/TestVector.h)
36+
37+
38+
set_target_properties(metrohash PROPERTIES CXX_STANDARD 98
39+
CXX_STANDARD_REQUIRED ON
40+
CXX_EXTENSIONS OFF)
41+
42+
43+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
44+
45+
# [GCC] x86 Options
46+
# https://gcc.gnu.org/onlinedocs/gcc-8.1.0/gcc/x86-Options.html
47+
target_compile_options(metrohash PRIVATE
48+
-msse4.2) # Enable the use of SSE4.2 instructions.
49+
50+
# [GCC] Options to Request or Suppress Warnings
51+
# https://gcc.gnu.org/onlinedocs/gcc-8.1.0/gcc/Warning-Options.html
52+
target_compile_options(metrohash PRIVATE
53+
-Wall
54+
-Wextra
55+
-Wpedantic
56+
-Werror)
57+
58+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
59+
60+
# [MSVC] Minimum CPU Architecture
61+
# https://docs.microsoft.com/en-us/cpp/build/reference/arch-x86
62+
# https://docs.microsoft.com/en-us/cpp/build/reference/arch-x64
63+
# For x64 CPUs SSE4.2 instructions are enabled by default.
64+
65+
# [MSVC] Warning Level
66+
# https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level
67+
target_compile_options(metrohash PRIVATE
68+
/W4 # Enable warning level 4.
69+
/WX) # Treat warnings as errors.
70+
71+
else()
72+
message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER_ID} is not supported!")
73+
endif()
74+
75+
76+
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
77+
78+
message(FATAL_ERROR "MetroHash supports only 64-bit builds!")
79+
80+
endif()

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The project has been re-licensed under Apache License v2.0. The purpose of this
2222

2323
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.
2424

25-
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".
25+
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".
2626

2727
*Note: an incremental version of the 128-bit CRC version is on its way but is not included in this push.*
2828

src/metrohash.h renamed to inc/metrohash/MetroHash.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#ifndef METROHASH_METROHASH_H
1818
#define METROHASH_METROHASH_H
1919

20-
#include "metrohash64.h"
21-
#include "metrohash128.h"
22-
#include "metrohash128crc.h"
20+
#include <metrohash/MetroHash64.h>
21+
#include <metrohash/MetroHash128.h>
22+
#include <metrohash/MetroHash128crc.h>
2323

2424
#endif // #ifndef METROHASH_METROHASH_H
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/metrohash128.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
// limitations under the License.
1616

1717
#include <string.h>
18-
#include "platform.h"
19-
#include "metrohash128.h"
18+
#include "Platform.h"
19+
#include <metrohash/MetroHash128.h>
2020

2121
const char * MetroHash128::test_string = "012345678901234567890123456789012345678901234567890123456789012";
2222

src/metrohash128crc.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
// limitations under the License.
1616

1717

18+
// SSE4.2 -> https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_crc32_u64
1819
#include <nmmintrin.h>
1920
#include <string.h>
20-
#include "metrohash.h"
21-
#include "platform.h"
21+
#include <metrohash/MetroHash128crc.h>
22+
#include "Platform.h"
2223

2324

2425
void metrohash128crc_1(const uint8_t * key, uint64_t len, uint32_t seed, uint8_t * out)

src/metrohash64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17-
#include "platform.h"
18-
#include "metrohash64.h"
17+
#include "Platform.h"
18+
#include <metrohash/MetroHash64.h>
1919

2020
#include <cstring>
2121

src/testvector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifndef METROHASH_TESTVECTOR_H
1818
#define METROHASH_TESTVECTOR_H
1919

20-
#include "metrohash.h"
20+
#include <metrohash/MetroHash.h>
2121

2222

2323
typedef void (*HashFunction) (const uint8_t * key, uint64_t len, uint32_t seed, uint8_t * hash);

0 commit comments

Comments
 (0)