Skip to content
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

Embedded Filecoin: Enable cross-compiling #114

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
42 changes: 24 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,11 @@ endif ()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include(CheckCXXCompilerFlag)
include(cmake/toolchain-util.cmake)
include(cmake/dependencies.cmake)
include(cmake/functions.cmake)
include(cmake/san.cmake)

# export compile commands for clang-tidy to analyse only changed files
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

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

option(TESTING "Build tests" ON)
option(BUILD_INTERNAL_DEPS "Build internal dependencies from git submodules" ON)
option(CLANG_FORMAT "Enable clang-format target" ON)
option(CLANG_TIDY "Enable clang-tidy checks during compilation" OFF)
option(COVERAGE "Enable generation of coverage info" OFF)
Expand All @@ -59,6 +50,17 @@ option(MSAN "Enable memory sanitizer" OFF)
option(TSAN "Enable thread sanitizer" OFF)
option(UBSAN "Enable UB sanitizer" OFF)

include(CheckCXXCompilerFlag)
include(cmake/install.cmake)
include(cmake/filecoin_functions.cmake)
include(cmake/toolchain-util.cmake)
include(cmake/dependencies.cmake)
include(cmake/functions.cmake)
include(cmake/san.cmake)

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

## setup compilation flags
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(AppleClang|Clang|GNU)$")
Expand Down Expand Up @@ -102,19 +104,23 @@ if (CLANG_FORMAT)
include(cmake/clang-format.cmake)
endif ()

add_subdirectory(deps)
if (BUILD_INTERNAL_DEPS)
add_subdirectory(deps)
endif()

include_directories(
# project includes
${PROJECT_SOURCE_DIR}/core
${PROJECT_SOURCE_DIR}/include
)

include_directories(
SYSTEM
# system includes
deps/outcome
deps/tinycbor/src
)
if (BUILD_INTERNAL_DEPS)
include_directories(
SYSTEM
# system includes
deps/outcome
${TINY_CBOR_INCLUDE_DIRS}
)
endif()

add_subdirectory(core)

Expand Down
22 changes: 14 additions & 8 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
# hunter dependencies
# https://docs.hunter.sh/en/latest/packages/

# https://docs.hunter.sh/en/latest/packages/pkg/GTest.html
hunter_add_package(GTest)
find_package(GTest CONFIG REQUIRED)
find_package(GMock CONFIG REQUIRED)
# Append local modules path if Hunter is not enabled
if (NOT HUNTER_ENABLED)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
endif()

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 date_time filesystem random system)
find_package(Boost CONFIG REQUIRED date_time filesystem random system)

# https://docs.hunter.sh/en/latest/packages/pkg/Microsoft.GSL.html
hunter_add_package(Microsoft.GSL)
find_package(Microsoft.GSL CONFIG REQUIRED)

# https://www.openssl.org/
hunter_add_package(OpenSSL)
find_package(OpenSSL REQUIRED)

# https://developers.google.com/protocol-buffers/
hunter_add_package(Protobuf)
find_package(Protobuf CONFIG REQUIRED)
find_package(Protobuf REQUIRED)

# https://docs.hunter.sh/en/latest/packages/pkg/spdlog.html
hunter_add_package(spdlog)
Expand All @@ -36,12 +42,12 @@ find_package(Boost.DI CONFIG REQUIRED)

# https://docs.hunter.sh/en/latest/packages/pkg/leveldb.html
hunter_add_package(leveldb)
find_package(leveldb CONFIG REQUIRED)
find_package(leveldb REQUIRED)

# https://github.com/soramitsu/libp2p
hunter_add_package(libp2p)
find_package(libp2p CONFIG REQUIRED)

# https://docs.hunter.sh/en/latest/packages/pkg/cppcodec.html
hunter_add_package(cppcodec)
find_package(cppcodec CONFIG REQUIRED)
find_package(cppcodec REQUIRED)
13 changes: 13 additions & 0 deletions cmake/filecoin_functions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# Copyright Soramitsu Co., Ltd. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#

include(GNUInstallDirs)

function(filecoin_add_library target)
add_library(${target}
${ARGN}
)
filecoin_install(${target})
endfunction()
28 changes: 28 additions & 0 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright Soramitsu Co., Ltd. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#

include(GNUInstallDirs)

function (filecoin_install targets)
install(TARGETS ${targets} EXPORT filecoinConfig
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
)
endfunction()

install(
DIRECTORY ${CMAKE_SOURCE_DIR}/include/filecoin
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(
EXPORT filecoinConfig
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/filecoin
NAMESPACE filecoin::
)
9 changes: 9 additions & 0 deletions cmake/modules/Findcppcodec.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Try to find cppcodec
# Once done, this will define
#
# CPPCODEC_FOUND - system has cppcodec

find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(CPPCODEC cppcodec)
endif()
47 changes: 47 additions & 0 deletions cmake/modules/Findleveldb.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#.rst:
# Findleveldb
# -----------
# Finds the leveldb library
#
# This will define the following variables:
#
# LEVELDB_FOUND - system has leveldb
# LEVELDB_INCLUDE_DIRS - leveldb include directories
# LEVELDB_LIBRARIES - libraries needed to use leveldb
#
# and the following imported targets:
#
# leveldb::leveldb - The leveldb library
#

include(FindPackageHandleStandardArgs)

find_path(
LEVELDB_INCLUDE_DIR
NAMES leveldb/db.h
HINTS ${LEVELDB_ROOT_DIR} $ENV{LEVELDB_ROOT_DIR}
PATH_SUFFIXES include)

find_library(
LEVELDB_LIBRARY
NAMES leveldb
HINTS ${LEVELDB_ROOT_DIR} $ENV{LEVELDB_ROOT_DIR}
PATH_SUFFIXES ${LIBRARY_PATH_PREFIX})

find_package_handle_standard_args(
leveldb
DEFAULT_MSG LEVELDB_LIBRARY LEVELDB_INCLUDE_DIR)

if (LEVELDB_FOUND)
set(LEVELDB_INCLUDE_DIRS ${LEVELDB_INCLUDE_DIR})
set(LEVELDB_LIBRARIES ${LEVELDB_LIBRARY})

if (NOT TARGET leveldb::leveldb)
add_library(leveldb::leveldb UNKNOWN IMPORTED)
set_target_properties(leveldb::leveldb PROPERTIES
IMPORTED_LOCATION "${LEVELDB_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${LEVELDB_INCLUDE_DIR}")
endif()
endif()

mark_as_advanced(LEVELDB_LIBRARY LEVELDB_INCLUDE_DIR)
28 changes: 14 additions & 14 deletions core/adt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
# SPDX-License-Identifier: Apache-2.0
#

add_custom_target(adt
add_custom_target(filecoin_adt
DEPENDS
array
multimap
filecoin_array
filecoin_multimap
)

add_library(array
filecoin_add_library(filecoin_array
impl/array.cpp
)
target_link_libraries(array
amt
target_link_libraries(filecoin_array
filecoin_amt
)

add_library(balance_table_hamt
filecoin_add_library(filecoin_balance_table_hamt
impl/balance_table_hamt.cpp
)
target_link_libraries(balance_table_hamt
address
hamt
target_link_libraries(filecoin_balance_table_hamt
filecoin_address
filecoin_hamt
)

add_library(multimap
filecoin_add_library(filecoin_multimap
impl/multimap.cpp
)
target_link_libraries(multimap
array
hamt
target_link_libraries(filecoin_multimap
filecoin_array
filecoin_hamt
)
2 changes: 1 addition & 1 deletion core/adt/impl/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "adt/array.hpp"
#include "filecoin/adt/array.hpp"

namespace fc::adt {

Expand Down
4 changes: 2 additions & 2 deletions core/adt/impl/balance_table_hamt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "adt/balance_table_hamt.hpp"
#include "primitives/address/address_codec.hpp"
#include "filecoin/adt/balance_table_hamt.hpp"
#include "filecoin/primitives/address/address_codec.hpp"

using fc::adt::BalanceTableHamt;
using fc::adt::TokenAmount;
Expand Down
4 changes: 2 additions & 2 deletions core/adt/impl/multimap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "adt/multimap.hpp"
#include "filecoin/adt/multimap.hpp"

#include "adt/array.hpp"
#include "filecoin/adt/array.hpp"

namespace fc::adt {

Expand Down
12 changes: 6 additions & 6 deletions core/blockchain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
add_subdirectory(message_pool)
add_subdirectory(production)

add_library(block_validator
filecoin_add_library(filecoin_block_validator
impl/block_validator_impl.cpp
)
target_link_libraries(block_validator
block
target_link_libraries(filecoin_block_validator
filecoin_block
)

add_library(weight_calculator
filecoin_add_library(filecoin_weight_calculator
impl/weight_calculator_impl.cpp
)
target_link_libraries(weight_calculator
tipset
target_link_libraries(filecoin_weight_calculator
filecoin_tipset
)
2 changes: 1 addition & 1 deletion core/blockchain/impl/block_validator_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "blockchain/impl/block_validator_impl.hpp"
#include "filecoin/blockchain/impl/block_validator_impl.hpp"

namespace fc::blockchain::block_validator {
// TODO (yuraz): FIL-87 implement proper validation
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain/impl/weight_calculator_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "blockchain/impl/weight_calculator_impl.hpp"
#include "filecoin/blockchain/impl/weight_calculator_impl.hpp"

namespace fc::blockchain::weight {
using primitives::BigInt;
Expand Down
8 changes: 4 additions & 4 deletions core/blockchain/message_pool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# SPDX-License-Identifier: Apache-2.0
#

add_library(message_pool
filecoin_add_library(filecoin_message_pool
impl/gas_price_scored_message_storage.cpp
impl/message_pool_error.cpp)
target_link_libraries(message_pool
outcome
message
target_link_libraries(filecoin_message_pool
filecoin_outcome
filecoin_message
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "blockchain/message_pool/impl/gas_price_scored_message_storage.hpp"
#include "filecoin/blockchain/message_pool/impl/gas_price_scored_message_storage.hpp"

#include "blockchain/message_pool/message_pool_error.hpp"
#include "filecoin/blockchain/message_pool/message_pool_error.hpp"

using fc::blockchain::message_pool::GasPriceScoredMessageStorage;
using fc::blockchain::message_pool::MessagePoolError;
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain/message_pool/impl/message_pool_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "blockchain/message_pool/message_pool_error.hpp"
#include "filecoin/blockchain/message_pool/message_pool_error.hpp"

OUTCOME_CPP_DEFINE_CATEGORY(fc::blockchain::message_pool, MessagePoolError, e) {
using fc::blockchain::message_pool::MessagePoolError;
Expand Down
Loading