diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,5 @@ # Copyright (c) 2017 The Bitcoin developers +add_subdirectory(config) +add_subdirectory(crypto) add_subdirectory(univalue) diff --git a/src/config/CMakeLists.txt b/src/config/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/src/config/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copyright (c) 2017 The Bitcoin developers + +# This generates config.h which provides numerous defines +# about the state of the plateform we are building on. + +include(CheckIncludeFiles) +include(CheckSymbolExists) + +# Endianness +check_include_files("endian.h" HAVE_ENDIAN_H) +check_include_files("sys/endian.h" HAVE_SYS_ENDIAN_H) + +if(HAVE_ENDIAN_H) + set(ENDIAN_FILE "endian.h") +elseif(HAVE_SYS_ENDIAN_H) + set(ENDIAN_FILE "sys/endian.h") +else() +endif() + +if(ENDIAN_FILE) + check_symbol_exists(htole16 ${ENDIAN_FILE} HAVE_DECL_HTOLE16) + check_symbol_exists(htobe16 ${ENDIAN_FILE} HAVE_DECL_HTOBE16) + check_symbol_exists(be16toh ${ENDIAN_FILE} HAVE_DECL_BE16TOH) + check_symbol_exists(le16toh ${ENDIAN_FILE} HAVE_DECL_LE16TOH) + check_symbol_exists(htobe32 ${ENDIAN_FILE} HAVE_DECL_HTOBE32) + check_symbol_exists(htole32 ${ENDIAN_FILE} HAVE_DECL_HTOLE32) + check_symbol_exists(be32toh ${ENDIAN_FILE} HAVE_DECL_BE32TOH) + check_symbol_exists(le32toh ${ENDIAN_FILE} HAVE_DECL_LE32TOH) + check_symbol_exists(htobe64 ${ENDIAN_FILE} HAVE_DECL_HTOBE64) + check_symbol_exists(htole64 ${ENDIAN_FILE} HAVE_DECL_HTOLE64) + check_symbol_exists(be64toh ${ENDIAN_FILE} HAVE_DECL_BE64TOH) + check_symbol_exists(le64toh ${ENDIAN_FILE} HAVE_DECL_LE64TOH) +endif() + +# Byte swap +check_include_files("byteswap.h" HAVE_BYTESWAP_H) + +check_symbol_exists(bswap_16 "byteswap.h" HAVE_DECL_BSWAP_16) +check_symbol_exists(bswap_32 "byteswap.h" HAVE_DECL_BSWAP_32) +check_symbol_exists(bswap_64 "byteswap.h" HAVE_DECL_BSWAP_64) + +# Bitmanip intrinsics +check_symbol_exists(__builtin_clz "" HAVE_DECL___BUILTIN_CLZ) +check_symbol_exists(__builtin_clzl "" HAVE_DECL___BUILTIN_CLZL) +check_symbol_exists(__builtin_clzll "" HAVE_DECL___BUILTIN_CLZLL) + + +# Generate the config +configure_file(bitcoin-config.h.cmake.in bitcoin-config.h) diff --git a/src/config/bitcoin-config.h.cmake.in b/src/config/bitcoin-config.h.cmake.in new file mode 100644 --- /dev/null +++ b/src/config/bitcoin-config.h.cmake.in @@ -0,0 +1,32 @@ +// Copyright (c) 2017 The Bitcoin developers + +#ifndef BITCOIN_CONFIG_BITCOIN_CONFIG_H +#define BITCOIN_CONFIG_BITCOIN_CONFIG_H + +#cmakedefine HAVE_ENDIAN_H @HAVE_ENDIAN_H@ +#cmakedefine HAVE_SYS_ENDIAN_H @HAVE_SYS_ENDIAN_H@ + +#cmakedefine HAVE_DECL_HTOLE16 @HAVE_DECL_HTOLE16@ +#cmakedefine HAVE_DECL_HTOBE16 @HAVE_DECL_HTOBE16@ +#cmakedefine HAVE_DECL_BE16TOH @HAVE_DECL_BE16TOH@ +#cmakedefine HAVE_DECL_LE16TOH @HAVE_DECL_LE16TOH@ +#cmakedefine HAVE_DECL_HTOBE32 @HAVE_DECL_HTOBE32@ +#cmakedefine HAVE_DECL_HTOLE32 @HAVE_DECL_HTOLE32@ +#cmakedefine HAVE_DECL_BE32TOH @HAVE_DECL_BE32TOH@ +#cmakedefine HAVE_DECL_LE32TOH @HAVE_DECL_LE32TOH@ +#cmakedefine HAVE_DECL_HTOBE64 @HAVE_DECL_HTOBE64@ +#cmakedefine HAVE_DECL_HTOLE64 @HAVE_DECL_HTOLE64@ +#cmakedefine HAVE_DECL_BE64TOH @HAVE_DECL_BE64TOH@ +#cmakedefine HAVE_DECL_LE64TOH @HAVE_DECL_LE64TOH@ + +#cmakedefine HAVE_BYTESWAP_H @HAVE_BYTESWAP_H@ + +#cmakedefine HAVE_DECL_BSWAP_16 @HAVE_DECL_BSWAP_16@ +#cmakedefine HAVE_DECL_BSWAP_32 @HAVE_DECL_BSWAP_32@ +#cmakedefine HAVE_DECL_BSWAP_64 @HAVE_DECL_BSWAP_64@ + +#cmakedefine HAVE_DECL___BUILTIN_CLZ @HAVE_DECL___BUILTIN_CLZ@ +#cmakedefine HAVE_DECL___BUILTIN_CLZL @HAVE_DECL___BUILTIN_CLZL@ +#cmakedefine HAVE_DECL___BUILTIN_CLZLL @HAVE_DECL___BUILTIN_CLZLL@ + +#endif // BITCOIN_BITCOIN_CONFIG_H diff --git a/src/crypto/CMakeLists.txt b/src/crypto/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/src/crypto/CMakeLists.txt @@ -0,0 +1,27 @@ +# Copyright (c) 2017 The Bitcoin developers + +project(crypto) + +set(CMAKE_CXX_STANDARD 11) + +include_directories( + .. + # To access the config. + # TODO: Make compat its own lib and just import it. + ${CMAKE_CURRENT_BINARY_DIR}/.. + ${CMAKE_CURRENT_BINARY_DIR}/../config +) + +# The library +add_library(crypto + aes.cpp + chacha20.cpp + hmac_sha256.cpp + hmac_sha512.cpp + ripemd160.cpp + sha1.cpp + sha256.cpp + sha512.cpp +) + +target_compile_definitions(crypto PUBLIC HAVE_CONFIG_H)