Skip to content

Commit 24899c0

Browse files
kamilsaxDimon
andauthored
vcpkg example (#298)
* Initial example * update: qtils & scale Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * Add README.md * update: soralog Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * update: bump version Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> --------- Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> Co-authored-by: Dmitriy Khaustov aka xDimon <[email protected]>
1 parent 0116614 commit 24899c0

28 files changed

+557
-8
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ if (PACKAGE_MANAGER STREQUAL "hunter")
4040
include("cmake/Hunter/init.cmake")
4141
endif ()
4242

43-
project(libp2p VERSION 0.1.17 LANGUAGES C CXX)
43+
project(libp2p VERSION 0.1.32 LANGUAGES C CXX)
4444

4545
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
46+
set(CMAKE_CXX_STANDARD 20)
47+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4648

4749
option(TESTING "Build tests" ON)
4850
option(EXAMPLES "Build examples" ON)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CPP-Libp2p
22

3-
> Fully compatible C++17 implementation of libp2p library
3+
> Fully compatible C++20 implementation of libp2p library
44
55
Libp2p is a modular networking stack described in [spec](https://github.com/libp2p/specs)
66

cmake/Hunter/config.cmake

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
hunter_config(
1919
soralog
20-
URL https://github.com/xDimon/soralog/archive/4dfffd3d949b1c16a04db2e5756555a4031732f7.tar.gz
21-
SHA1 60e3dcaab2d8e43f0ed4fd22087677663c618716
22-
# VERSION 0.2.4
20+
VERSION 0.2.5
21+
URL https://github.com/qdrvm/soralog/archive/refs/tags/v0.2.5.tar.gz
22+
SHA1 67da2d17e93954c198b4419daa55911342c924a9
2323
KEEP_PACKAGE_SOURCES
2424
)
2525

@@ -32,8 +32,9 @@ hunter_config(
3232

3333
hunter_config(
3434
qtils
35-
URL https://github.com/qdrvm/qtils/archive/1e492cf09a3640570cae59a951502614320c0797.tar.gz
36-
SHA1 033dd907e2566c95ce2ccf1fa6dd9766bc896894
35+
VERSION 0.1.0
36+
URL https://github.com/qdrvm/qtils/archive/refs/tags/v0.1.0.tar.gz
37+
SHA1 acc28902af7dc5d74ac33d486ad2261906716f5e
3738
CMAKE_ARGS
3839
FORMAT_ERROR_WITH_FULLTYPE=ON
3940
KEEP_PACKAGE_SOURCES
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(libp2p-example CXX)
3+
4+
set(CMAKE_CXX_STANDARD 20)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
find_package(libsecp256k1 CONFIG REQUIRED)
8+
find_package(ZLIB REQUIRED)
9+
10+
find_package(libp2p CONFIG REQUIRED)
11+
12+
add_executable(example main.cpp)
13+
target_link_libraries(example PRIVATE p2p::p2p)

example/00-vcpkg-install/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# LibP2P Example with vcpkg
2+
3+
This example demonstrates how to build and run a simple LibP2P application using vcpkg as the package manager.
4+
5+
## Prerequisites
6+
7+
- CMake 3.15 or higher
8+
- A C++20 compatible compiler
9+
- Git
10+
- vcpkg
11+
12+
## Getting Started
13+
14+
1. Clone vcpkg if you haven't already:
15+
16+
```bash
17+
git clone https://github.com/microsoft/vcpkg.git
18+
19+
./vcpkg/bootstrap-vcpkg.sh # For Linux/macOS
20+
.\vcpkg\bootstrap-vcpkg.bat # For Windows
21+
```
22+
23+
2. Clone this repository:
24+
25+
```bash
26+
git clone https://github.com/libp2p/libp2p.git
27+
cd libp2p/example/00-vcpkg-install
28+
```
29+
30+
3. Install LibP2P dependencies using vcpkg:
31+
32+
```bash
33+
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=<path-to-vcpkg>/scripts/buildsystems/vcpkg.cmake
34+
cmake --build build
35+
```
36+
37+
4. Run the example:
38+
39+
```bash
40+
./build/example
41+
```
42+
43+
## Notes
44+
45+
- This example assumes you have a working vcpkg installation. If you encounter any issues, please refer to the [vcpkg documentation](https://vcpkg.io/en/getting-started.html) for troubleshooting.
46+
- The example demonstrates how to build and run a simple LibP2P application using vcpkg as the package manager.

example/00-vcpkg-install/main.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <iostream>
2+
#include <libp2p/multi/multiaddress.hpp>
3+
#include <libp2p/peer/peer_id.hpp>
4+
5+
int main() {
6+
auto ma_res = libp2p::multi::Multiaddress::create("/ip4/127.0.0.1/tcp/8080");
7+
if (ma_res.has_value()) {
8+
std::cout << "Created multiaddress: "
9+
<< ma_res.value().getStringAddress() << std::endl;
10+
}
11+
return 0;
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"default-registry": {
3+
"kind": "git",
4+
"baseline": "fe1cde61e971d53c9687cf9a46308f8f55da19fa",
5+
"repository": "https://github.com/microsoft/vcpkg"
6+
},
7+
"overlay-ports": [
8+
"vcpkg-overlay"
9+
]
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
2+
vcpkg_from_github(
3+
OUT_SOURCE_PATH SOURCE_PATH
4+
REPO qdrvm/boost-di
5+
REF d5de6c9840c7fc2e44bf37134b4a14b88151ecc4
6+
SHA512 98e924d02bde23940ab59330730de6d4198d1e98cbb303ef713e3ee06f88e90707a952e6aa9a0372213b46d6c9d3478e86ed5cd64d74899861984e786e21c319
7+
)
8+
vcpkg_cmake_configure(
9+
SOURCE_PATH "${SOURCE_PATH}"
10+
OPTIONS
11+
-DBOOST_DI_OPT_BUILD_TESTS=OFF
12+
-DBOOST_DI_OPT_BUILD_EXAMPLES=OFF
13+
)
14+
vcpkg_cmake_install()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "boost-di",
3+
"version": "1.1.0.1",
4+
"dependencies": [
5+
{ "name": "vcpkg-cmake", "host": true },
6+
{ "name": "vcpkg-cmake-config", "host": true }
7+
]
8+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
vcpkg_from_github(
2+
OUT_SOURCE_PATH SOURCE_PATH
3+
REPO fmtlib/fmt
4+
REF 10.1.1
5+
SHA512 288c349baac5f96f527d5b1bed0fa5f031aa509b4526560c684281388e91909a280c3262a2474d963b5d1bf7064b1c9930c6677fe54a0d8f86982d063296a54c
6+
)
7+
8+
vcpkg_cmake_configure(
9+
SOURCE_PATH "${SOURCE_PATH}"
10+
OPTIONS
11+
-DFMT_DOC=OFF
12+
-DFMT_TEST=OFF
13+
-DFMT_INSTALL=ON
14+
-DCMAKE_CXX_STANDARD=20
15+
)
16+
17+
vcpkg_cmake_install()
18+
vcpkg_copy_pdbs()
19+
vcpkg_cmake_config_fixup(PACKAGE_NAME fmt CONFIG_PATH lib/cmake/fmt)
20+
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")

0 commit comments

Comments
 (0)