Skip to content

Instantly share code, notes, and snippets.

@igor-egorov
Last active August 19, 2021 17:12
Show Gist options
  • Save igor-egorov/0425ca1d0789d37eb682937cc8728ba7 to your computer and use it in GitHub Desktop.
Save igor-egorov/0425ca1d0789d37eb682937cc8728ba7 to your computer and use it in GitHub Desktop.
Build kagome with libp2p as submodule
diff --git a/CMakeLists.txt b/CMakeLists.txt
index abe60e69..b9043a91 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -114,10 +114,26 @@ endif()
include(GNUInstallDirs)
include(cmake/install.cmake)
+include(ExternalProject)
+
+add_subdirectory(libs/libp2p)
+add_library(p2p::p2p_kademlia ALIAS p2p_kademlia)
+add_library(p2p::p2p_multiaddress ALIAS p2p_multiaddress)
+add_library(p2p::p2p_random_generator ALIAS p2p_random_generator)
+add_library(p2p::p2p_multibase_codec ALIAS p2p_multibase_codec)
+add_library(p2p::p2p_uvarint ALIAS p2p_uvarint)
+add_library(p2p::p2p_loopback_stream ALIAS p2p_loopback_stream)
+add_library(p2p::p2p_identify ALIAS p2p_identify)
+add_library(p2p::p2p_peer_id ALIAS p2p_peer_id)
+add_library(p2p::p2p_message_read_writer ALIAS p2p_message_read_writer)
+add_library(p2p::p2p_ping ALIAS p2p_ping)
+add_library(p2p::p2p_logger ALIAS p2p_logger)
+add_library(p2p::p2p ALIAS p2p)
include_directories(
# project includes
${PROJECT_SOURCE_DIR}/core
+ ${PROJECT_SOURCE_DIR}/libs/libp2p/include
)
add_subdirectory(core)
diff --git a/cmake/Hunter/config.cmake b/cmake/Hunter/config.cmake
index 7bc35897..82fe051a 100644
--- a/cmake/Hunter/config.cmake
+++ b/cmake/Hunter/config.cmake
@@ -23,11 +23,11 @@ hunter_config(
KEEP_PACKAGE_SOURCES
)
-hunter_config(
- libp2p
- URL https://github.com/igor-egorov/cpp-libp2p/archive/7c9d83bf0760a5f653d86ddbb00645414c61d4fc.tar.gz
- SHA1 f4408541230f4953678d1871096786cba2f5fcef
- CMAKE_ARGS TESTING=OFF EXAMPLES=OFF EXPOSE_MOCKS=ON
- KEEP_PACKAGE_SOURCES
-)
+# hunter_config(
+# libp2p
+# URL https://github.com/igor-egorov/cpp-libp2p/archive/7c9d83bf0760a5f653d86ddbb00645414c61d4fc.tar.gz
+# SHA1 f4408541230f4953678d1871096786cba2f5fcef
+# CMAKE_ARGS TESTING=OFF EXAMPLES=OFF EXPOSE_MOCKS=ON
+# KEEP_PACKAGE_SOURCES
+# )
diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake
index 73a20434..d9003734 100644
--- a/cmake/dependencies.cmake
+++ b/cmake/dependencies.cmake
@@ -66,8 +66,8 @@ hunter_add_package(prometheus-cpp)
find_package(prometheus-cpp CONFIG REQUIRED)
# https://github.com/soramitsu/libp2p
-hunter_add_package(libp2p)
-find_package(libp2p CONFIG REQUIRED)
+# hunter_add_package(libp2p)
+# find_package(libp2p CONFIG REQUIRED)
# https://github.com/soramitsu/soramitsu-libsecp256k1
hunter_add_package(libsecp256k1)
diff --git a/libs/libp2p b/libs/libp2p
--- a/libs/libp2p
+++ b/libs/libp2p
@@ -1 +1 @@
-Subproject commit 7c9d83bf0760a5f653d86ddbb00645414c61d4fc
+Subproject commit 7c9d83bf0760a5f653d86ddbb00645414c61d4fc-dirty
diff --git a/cmake/clang-format.cmake b/cmake/clang-format.cmake
index be90d44..82f0f89 100644
--- a/cmake/clang-format.cmake
+++ b/cmake/clang-format.cmake
@@ -8,10 +8,10 @@ file(GLOB_RECURSE
# Adding clang-format target if executable is found
if(NOT CLANG_FORMAT_BIN)
- find_program(CLANG_FORMAT_BIN "clang-format")
+ find_program(CLANG_FORMAT_BIN NAMES clang-format clang-format-9 clang-format-8 clang-format-7)
endif()
-if(CLANG_FORMAT_BIN)
+if(CLANG_FORMAT_BIN AND NOT TARGET clang-format)
message(STATUS "Target clang-format enabled")
add_custom_target(
clang-format
diff --git a/cmake/functions.cmake b/cmake/functions.cmake
index b0a40f8..dcc9a35 100644
--- a/cmake/functions.cmake
+++ b/cmake/functions.cmake
@@ -45,7 +45,7 @@ function(add_flag flag)
endif ()
endfunction()
-function(compile_proto_to_cpp PROTO_LIBRARY_NAME PB_H PB_CC PROTO)
+function(compile_proto_to_cpp_libp2p PROTO_LIBRARY_NAME PB_H PB_CC PROTO)
if (NOT Protobuf_INCLUDE_DIR)
get_target_property(Protobuf_INCLUDE_DIR protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
endif()
@@ -63,7 +63,7 @@ function(compile_proto_to_cpp PROTO_LIBRARY_NAME PB_H PB_CC PROTO)
get_filename_component(PROTO_ABS "${PROTO}" REALPATH)
# get relative (to CMAKE_BINARY_DIR) path of current proto file
- file(RELATIVE_PATH SCHEMA_REL "${CMAKE_BINARY_DIR}/src" "${CMAKE_CURRENT_BINARY_DIR}")
+ file(RELATIVE_PATH SCHEMA_REL "${CMAKE_BINARY_DIR}/libs/libp2p/src" "${CMAKE_CURRENT_BINARY_DIR}")
set(SCHEMA_OUT_DIR ${CMAKE_BINARY_DIR}/pb/${PROTO_LIBRARY_NAME}/generated)
file(MAKE_DIRECTORY ${SCHEMA_OUT_DIR})
@@ -92,18 +92,20 @@ function(compile_proto_to_cpp PROTO_LIBRARY_NAME PB_H PB_CC PROTO)
set(${PB_CC} ${SCHEMA_OUT_DIR}/${SCHEMA_REL}/${GEN_PB} PARENT_SCOPE)
endfunction()
-add_custom_target(generated
- COMMENT "Building generated files..."
- )
+if (NOT TARGET generated)
+ add_custom_target(generated
+ COMMENT "Building generated files..."
+ )
+endif()
-function(add_proto_library NAME)
+function(add_proto_library_p2p NAME)
set(SOURCES "")
foreach (PROTO IN ITEMS ${ARGN})
- compile_proto_to_cpp(${NAME} H C ${PROTO})
+ compile_proto_to_cpp_libp2p(${NAME} H C ${PROTO})
list(APPEND SOURCES ${H} ${C})
endforeach ()
- add_library(${NAME}
+ libp2p_add_library(${NAME}
${SOURCES}
)
target_link_libraries(${NAME}
@@ -117,7 +119,7 @@ function(add_proto_library NAME)
)
disable_clang_tidy(${NAME})
- libp2p_install(${NAME})
+ # libp2p_install(${NAME})
add_dependencies(generated ${NAME})
endfunction()
diff --git a/cmake/install.cmake b/cmake/install.cmake
index 4163e67..f8527ad 100644
--- a/cmake/install.cmake
+++ b/cmake/install.cmake
@@ -9,10 +9,11 @@ function(libp2p_install targets)
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
)
+ kagome_install(${targets})
endfunction()
install(
- DIRECTORY ${CMAKE_SOURCE_DIR}/include/libp2p
+ DIRECTORY ${CMAKE_SOURCE_DIR}/libs/libp2p
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
diff --git a/cmake/libp2p_add_library.cmake b/cmake/libp2p_add_library.cmake
index ee360fa..456d14f 100644
--- a/cmake/libp2p_add_library.cmake
+++ b/cmake/libp2p_add_library.cmake
@@ -2,5 +2,10 @@ function(libp2p_add_library target)
add_library(${target}
${ARGN}
)
+ target_include_directories(${target}
+ INTERFACE
+ $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/libs/libp2p/include>
+ $<INSTALL_INTERFACE:libp2p/include>
+ )
libp2p_install(${target})
endfunction()
diff --git a/src/crypto/protobuf/CMakeLists.txt b/src/crypto/protobuf/CMakeLists.txt
index 4a9144c..01894b6 100644
--- a/src/crypto/protobuf/CMakeLists.txt
+++ b/src/crypto/protobuf/CMakeLists.txt
@@ -3,6 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
#
-add_proto_library(p2p_keys_proto
+add_proto_library_p2p(p2p_keys_proto
keys.proto
)
+# libp2p_install(p2p_keys_proto)
diff --git a/src/protocol/gossip/protobuf/CMakeLists.txt b/src/protocol/gossip/protobuf/CMakeLists.txt
index 864e4e6..13cfa11 100644
--- a/src/protocol/gossip/protobuf/CMakeLists.txt
+++ b/src/protocol/gossip/protobuf/CMakeLists.txt
@@ -1,6 +1,6 @@
# Copyright Soramitsu Co., Ltd. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
-add_proto_library(p2p_gossip_proto
+add_proto_library_p2p(p2p_gossip_proto
rpc.proto
)
diff --git a/src/protocol/identify/protobuf/CMakeLists.txt b/src/protocol/identify/protobuf/CMakeLists.txt
index a93a8fe..5f83908 100644
--- a/src/protocol/identify/protobuf/CMakeLists.txt
+++ b/src/protocol/identify/protobuf/CMakeLists.txt
@@ -3,6 +3,6 @@
# SPDX-License-Identifier: Apache-2.0
#
-add_proto_library(p2p_identify_proto
+add_proto_library_p2p(p2p_identify_proto
identify.proto
)
diff --git a/src/protocol/kademlia/protobuf/CMakeLists.txt b/src/protocol/kademlia/protobuf/CMakeLists.txt
index f477c7d..b5a74f7 100644
--- a/src/protocol/kademlia/protobuf/CMakeLists.txt
+++ b/src/protocol/kademlia/protobuf/CMakeLists.txt
@@ -1,6 +1,6 @@
# Copyright Soramitsu Co., Ltd. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
-add_proto_library(p2p_kademlia_proto
+add_proto_library_p2p(p2p_kademlia_proto
kademlia.proto
)
diff --git a/src/security/noise/protobuf/CMakeLists.txt b/src/security/noise/protobuf/CMakeLists.txt
index 593ce69..190aede 100644
--- a/src/security/noise/protobuf/CMakeLists.txt
+++ b/src/security/noise/protobuf/CMakeLists.txt
@@ -3,6 +3,6 @@
# SPDX-License-Identifier: Apache-2.0
#
-add_proto_library(p2p_noise_proto
+add_proto_library_p2p(p2p_noise_proto
noise.proto
)
diff --git a/src/security/plaintext/protobuf/CMakeLists.txt b/src/security/plaintext/protobuf/CMakeLists.txt
index 81e48ce..3e11f0c 100644
--- a/src/security/plaintext/protobuf/CMakeLists.txt
+++ b/src/security/plaintext/protobuf/CMakeLists.txt
@@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
#
-add_proto_library(p2p_plaintext_proto
+add_proto_library_p2p(p2p_plaintext_proto
plaintext.proto
)
target_link_libraries(p2p_plaintext_proto
diff --git a/src/security/secio/protobuf/CMakeLists.txt b/src/security/secio/protobuf/CMakeLists.txt
index 4666569..19d24a5 100644
--- a/src/security/secio/protobuf/CMakeLists.txt
+++ b/src/security/secio/protobuf/CMakeLists.txt
@@ -3,6 +3,6 @@
# SPDX-License-Identifier: Apache-2.0
#
-add_proto_library(p2p_secio_proto
+add_proto_library_p2p(p2p_secio_proto
secio.proto
)
diff --git a/test/deps/CMakeLists.txt b/test/deps/CMakeLists.txt
index 17da20c..f039059 100644
--- a/test/deps/CMakeLists.txt
+++ b/test/deps/CMakeLists.txt
@@ -3,12 +3,12 @@
# SPDX-License-Identifier: Apache-2.0
#
-addtest(outcome_test outcome_test.cpp)
-target_link_libraries(outcome_test
+addtest(p2p_outcome_test outcome_test.cpp)
+target_link_libraries(p2p_outcome_test
Boost::boost
)
-addtest(di_test di_test.cpp)
-target_link_libraries(di_test
+addtest(p2p_di_test di_test.cpp)
+target_link_libraries(p2p_di_test
Boost::Boost.DI
)
diff --git a/test/libp2p/basic/CMakeLists.txt b/test/libp2p/basic/CMakeLists.txt
index 4812e19..aa045a4 100644
--- a/test/libp2p/basic/CMakeLists.txt
+++ b/test/libp2p/basic/CMakeLists.txt
@@ -3,10 +3,10 @@
# SPDX-License-Identifier: Apache-2.0
#
-addtest(message_read_writer_test
+addtest(p2p_message_read_writer_test
message_read_writer_test.cpp
)
-target_link_libraries(message_read_writer_test
+target_link_libraries(p2p_message_read_writer_test
p2p_message_read_writer
p2p_protobuf_message_read_writer
p2p_message_read_writer_error
diff --git a/test/libp2p/common/CMakeLists.txt b/test/libp2p/common/CMakeLists.txt
index 19e1d0e..7c4114e 100644
--- a/test/libp2p/common/CMakeLists.txt
+++ b/test/libp2p/common/CMakeLists.txt
@@ -3,10 +3,10 @@
# SPDX-License-Identifier: Apache-2.0
##
-addtest(hexutil_test
+addtest(p2p_hexutil_test
hexutil_test.cpp
)
-target_link_libraries(hexutil_test
+target_link_libraries(p2p_hexutil_test
p2p_hexutil
p2p_literals
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment