Skip to content

Commit

Permalink
Merge pull request #2 from uilianries/blake2/20190723
Browse files Browse the repository at this point in the history
Blake2/20190723
  • Loading branch information
ericriff authored Feb 14, 2020
2 parents e6fbe4e + 920b2ef commit b94376b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 49 deletions.
50 changes: 47 additions & 3 deletions recipes/blake2/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
project(cmake_wrapper)
cmake_minimum_required(VERSION 3.1)
project(blake2 C)

include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
include("conanbuildinfo.cmake")
conan_basic_setup()

add_subdirectory("source_subfolder")
if(WIN32 AND BUILD_SHARED_LIBS AND MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

option(USE_SSE "Optimized for speed on CPUs supporting SSE2, SSSE3, SSE4.1, AVX, or XOP" OFF)
option(USE_NEON "Optimiced for arm CPUs" OFF)

if (USE_NEON)
message(STATUS "Using neon sources")
set(SOURCE_FILES source_subfolder/neon/blake2b.c
source_subfolder/neon/blake2bp.c
source_subfolder/neon/blake2s-neon.c
source_subfolder/neon/blake2xb.c
source_subfolder/neon/blake2b-neon.c
source_subfolder/neon/blake2s.c
source_subfolder/neon/blake2sp.c
source_subfolder/neon/blake2xs.c)
elseif (USE_SSE)
message(STATUS "Using sse sources")
set(SOURCE_FILES source_subfolder/sse/blake2b.c
source_subfolder/sse/blake2bp.c
source_subfolder/sse/blake2s.c
source_subfolder/sse/blake2sp.c
source_subfolder/sse/blake2xb.c
source_subfolder/sse/blake2xs.c)
else ()
message(STATUS "Using ref sources")
set(SOURCE_FILES source_subfolder/ref/blake2bp-ref.c
source_subfolder/ref/blake2b-ref.c
source_subfolder/ref/blake2sp-ref.c
source_subfolder/ref/blake2s-ref.c
source_subfolder/ref/blake2xb-ref.c
source_subfolder/ref/blake2xs-ref.c)
endif()

add_library(${CMAKE_PROJECT_NAME} ${SOURCE_FILES})
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES PUBLIC_HEADER source_subfolder/ref/blake2.h)

install(TARGETS ${CMAKE_PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME}
)

25 changes: 0 additions & 25 deletions recipes/blake2/all/CMakeLists_build.txt

This file was deleted.

46 changes: 25 additions & 21 deletions recipes/blake2/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,58 @@
import os
import stat
import shutil
import glob
from conans import ConanFile, tools, CMake
from conans.errors import ConanInvalidConfiguration

class blake2Conan(ConanFile):
name = "blake2"
version = "20190723" #BLAKE2 doesn't have versions so we use the last commit date instead
version = "20190723"
license = ["CC0-1.0", "OpenSSL", "APSL-2.0"]
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/BLAKE2/BLAKE2"
description = ("BLAKE2 is a cryptographic hash function faster than MD5, \
SHA-1, SHA-2, and SHA-3, yet is at least as secure as the latest standard SHA-3")
settings = "os", "arch", "compiler", "build_type"
topics = ("conan", "blake2", "hash")
exports_sources = ["CMakeLists.txt", "CMakeLists_build.txt"] #The first file is the conan wrapper, the second one is the actual CMakeList that builds the project
exports_sources = ["CMakeLists.txt"]
generators = ["cmake"]
options = {"fPIC": [True, False], "use_sse": [True, False], "use_neon": [True, False]}
default_options = {"fPIC": True, "use_sse": False, "use_neon": False}
_source_subfolder = "source_subfolder"
options = {"fPIC": [True, False], "shared": [True, False], "use_sse": [True, False], "use_neon": [True, False]}
default_options = {"fPIC": True, "shared": True, "use_sse": False, "use_neon": False}
_cmake = None

def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
self._cmake.definitions["USE_SSE"] = self.options.use_sse
self._cmake.definitions["USE_NEON"] = self.options.use_neon
self._cmake.configure()
return self._cmake
@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def configure(self):
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
if self.options.use_neon and not "arm" in self.settings.arch:
raise ConanInvalidConfiguration("Neon sources only supported on arm-based CPUs")
if self.options.use_neon and self.options.use_sse:
raise ConanInvalidConfiguration("Neon and SSE can not be used together.")

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def source(self):
tools.get(**self.conan_data["sources"][self.version])
#Get te extracted folder name. Its BLAKE2-githubCommit
listdir = os.listdir()
extracted_dir = [i for i in listdir if "BLAKE2-" in i][0]
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = glob.glob(self.name.upper() + "-*")[0]
os.rename(extracted_dir, self._source_subfolder)

def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
self._cmake.definitions["USE_SSE"] = self.options.use_sse
self._cmake.definitions["USE_NEON"] = self.options.use_neon
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def build(self):
#Move makefile into _source_subfolder.
shutil.move(src=os.path.join(self.source_folder, "CMakeLists_build.txt"), dst=os.path.join(self.source_folder,self._source_subfolder, "CMakeLists.txt"))
cmake = self._configure_cmake()
cmake.build()

Expand All @@ -59,4 +63,4 @@ def package(self):

def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.includedirs = ["include",os.path.join("include","blake2")]
self.cpp_info.includedirs = ["include", os.path.join("include","blake2")]

0 comments on commit b94376b

Please sign in to comment.