Skip to content

Cross compiling fixes and improvements #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@ include("cmake/Hunter/init.cmake")
cmake_policy(SET CMP0048 NEW)
project(libp2p VERSION 0.0.1 LANGUAGES C CXX)

include(cmake/print.cmake)
print("C flags: ${CMAKE_C_FLAGS}")
print("CXX flags: ${CMAKE_CXX_FLAGS}")
print("Using CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")

include(CheckCXXCompilerFlag)
include(cmake/install.cmake)
include(cmake/libp2p_add_library.cmake)
include(cmake/dependencies.cmake)
include(cmake/functions.cmake)
include(cmake/san.cmake)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

option(TESTING "Build tests" ON)
Expand All @@ -44,6 +32,18 @@ option(TSAN "Enable thread sanitizer" OFF)
option(UBSAN "Enable UB sanitizer" OFF)
option(EXPOSE_MOCKS "Make mocks header files visible for child projects" OFF)

include(cmake/print.cmake)
print("C flags: ${CMAKE_C_FLAGS}")
print("CXX flags: ${CMAKE_CXX_FLAGS}")
print("Using CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")

include(CheckCXXCompilerFlag)
include(cmake/install.cmake)
include(cmake/libp2p_add_library.cmake)
include(cmake/dependencies.cmake)
include(cmake/functions.cmake)
include(cmake/san.cmake)


## setup compilation flags
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(AppleClang|Clang|GNU)$")
Expand Down
15 changes: 11 additions & 4 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# https://docs.hunter.sh/en/latest/packages/pkg/GTest.html
hunter_add_package(GTest)
find_package(GTest CONFIG REQUIRED)
find_package(GMock CONFIG REQUIRED)
#
# Copyright Soramitsu Co., Ltd. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#

if (TESTING)
# https://docs.hunter.sh/en/latest/packages/pkg/GTest.html
hunter_add_package(GTest)
find_package(GTest CONFIG REQUIRED)
find_package(GMock CONFIG REQUIRED)
endif()

# https://docs.hunter.sh/en/latest/packages/pkg/Boost.html
hunter_add_package(Boost COMPONENTS random filesystem program_options)
Expand Down
11 changes: 8 additions & 3 deletions cmake/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ function(add_flag flag)
endfunction()

function(compile_proto_to_cpp PROTO_LIBRARY_NAME PB_H PB_CC PROTO)
get_target_property(Protobuf_INCLUDE_DIR protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc IMPORTED_LOCATION_RELEASE)
if (NOT Protobuf_INCLUDE_DIR)
get_target_property(Protobuf_INCLUDE_DIR protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
endif()
if (NOT Protobuf_PROTOC_EXECUTABLE)
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc IMPORTED_LOCATION_RELEASE)
set(PROTOBUF_DEPENDS protobuf::protoc)
endif()

if (NOT Protobuf_PROTOC_EXECUTABLE)
message(FATAL_ERROR "Protobuf_PROTOC_EXECUTABLE is empty")
Expand Down Expand Up @@ -78,7 +83,7 @@ function(compile_proto_to_cpp PROTO_LIBRARY_NAME PB_H PB_CC PROTO)
COMMAND ${GEN_COMMAND}
ARGS -I${PROJECT_SOURCE_DIR}/src -I${GEN_ARGS} --cpp_out=${SCHEMA_OUT_DIR} ${PROTO_ABS}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS protobuf::protoc
DEPENDS ${PROTOBUF_DEPENDS}
VERBATIM
)

Expand Down
6 changes: 4 additions & 2 deletions src/common/literals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
#include <libp2p/multi/multihash.hpp>
#include <libp2p/peer/peer_id.hpp>

#include <algorithm>

namespace libp2p::common {
libp2p::common::Hash256 operator""_hash256(const char *c, size_t s) {
libp2p::common::Hash256 hash{};
std::copy_n(c, std::min(s, 32ul), hash.rbegin());
std::copy_n(c, std::min(s, static_cast<size_t>(32u)), hash.rbegin());
return hash;
}

libp2p::common::Hash512 operator""_hash512(const char *c, size_t s) {
libp2p::common::Hash512 hash{};
std::copy_n(c, std::min(s, 64ul), hash.rbegin());
std::copy_n(c, std::min(s, static_cast<size_t>(64u)), hash.rbegin());
return hash;
}

Expand Down
2 changes: 1 addition & 1 deletion src/muxer/yamux/yamux_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace libp2p::connection {
}

boost::optional<YamuxFrame> parseFrame(gsl::span<const uint8_t> frame_bytes) {
if (frame_bytes.size() < YamuxFrame::kHeaderLength) {
if (frame_bytes.size() < static_cast<int>(YamuxFrame::kHeaderLength)) {
return {};
}

Expand Down