Skip to content

Commit e8242b9

Browse files
committed
Modernize CMake project
1 parent 4e5e3a9 commit e8242b9

116 files changed

Lines changed: 1685 additions & 974 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/linux.yaml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ jobs:
1313
- name: Checkoout
1414
uses: actions/checkout@v4
1515

16-
- name: Create VCPKG cache
16+
- name: Setup VCPKG
17+
run: echo "VCPKG_ROOT=$VCPKG_INSTALLATION_ROOT" >> "${{ github.env }}"
18+
19+
- name: Setup VCPKG cache
1720
run: |
1821
mkdir "$HOME/vcpkg-cache"
1922
echo "VCPKG_DEFAULT_BINARY_CACHE=$HOME/vcpkg-cache" >> "${{ github.env }}"
@@ -24,21 +27,8 @@ jobs:
2427
path: ${{ env.VCPKG_DEFAULT_BINARY_CACHE }}
2528
key: ${{ runner.os }}
2629

27-
- name: Install dependencies
28-
run: vcpkg install boost-asio boost-filesystem boost-test boost-system
29-
30-
- name: Configure
31-
run: cmake
32-
-B build -G Ninja
33-
-DCMAKE_BUILD_TYPE=Debug
34-
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
35-
-DCMAKE_TOOLCHAIN_FILE=${VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake
36-
3730
- name: Build
38-
run: cmake --build build
39-
40-
- name: Tests
41-
run: ctest --test-dir build --output-on-failure
31+
run: cmake --workflow default
4232

4333
- name: Install gcovr
4434
run: |

.github/workflows/osx.yaml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ on: push
33
jobs:
44
BuildAndTest:
55
runs-on: macos-15
6-
env:
7-
VCPKG_DEFAULT_BINARY_CACHE: /vcpkg-cache
8-
VCPKG_ROOT: /vcpkg
96
steps:
107
- name: Checkoout
118
uses: actions/checkout@v4
129

13-
- name: Install VCPKG
10+
- name: Setup VCPKG
1411
run: |
1512
git clone https://github.com/microsoft/vcpkg $HOME/vcpkg
1613
$HOME/vcpkg/bootstrap-vcpkg.sh -disableMetrics
1714
echo "VCPKG_ROOT=$HOME/vcpkg" >> ${{ github.env }}
18-
19-
- name: Create VCPKG cache
15+
16+
- name: Setup VCPKG cache
2017
run: |
2118
mkdir "$HOME/vcpkg-cache"
2219
echo "VCPKG_DEFAULT_BINARY_CACHE=$HOME/vcpkg-cache" >> "${{ github.env }}"
@@ -27,17 +24,5 @@ jobs:
2724
path: ${{ env.VCPKG_DEFAULT_BINARY_CACHE }}
2825
key: ${{ runner.os }}
2926

30-
- name: Install dependencies
31-
run: ${{ env.VCPKG_ROOT }}/vcpkg install boost-asio boost-filesystem boost-test boost-system
32-
33-
- name: Configure
34-
run: cmake
35-
-B build -G Ninja
36-
-DCMAKE_BUILD_TYPE=Debug
37-
-DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake
38-
3927
- name: Build
40-
run: cmake --build build
41-
42-
- name: Tests
43-
run: ctest --test-dir build --output-on-failure
28+
run: cmake --workflow default

.github/workflows/windows.yaml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,30 @@ name: Windows
22
on: push
33
jobs:
44
BuildAndTest:
5-
runs-on: windows-latest
5+
runs-on: windows-2025
66
env:
7-
VCPKG_DEFAULT_BINARY_CACHE: C:\vcpkg-cache
7+
VCPKG_DEFAULT_TRIPLET: x64-windows
88
steps:
99
- name: Checkoout
1010
uses: actions/checkout@v4
1111

12-
- name: Create VCPKG cache
13-
run: New-Item -ItemType Directory -Path ${{ env.VCPKG_DEFAULT_BINARY_CACHE }}
12+
- name: Setup VCPKG
13+
run: |
14+
Add-Content -Path "${{ github.env }}" -Value VCPKG_ROOT=$Env:VCPKG_INSTALLATION_ROOT
15+
16+
- name: Setup VCPKG cache
17+
run: |
18+
New-Item -ItemType Directory -Path C:\vcpkg-cache
19+
Add-Content -Path "${{ github.env }}" -Value VCPKG_DEFAULT_BINARY_CACHE=C:\vcpkg-cache
1420
1521
- name: Register VCPKG cache
1622
uses: actions/cache@v4
1723
with:
1824
path: ${{ env.VCPKG_DEFAULT_BINARY_CACHE }}
1925
key: ${{ runner.os }}
2026

21-
- name: Install dependencies
22-
run: vcpkg install boost-asio boost-filesystem boost-test boost-system
23-
24-
- name: Configure
25-
run: cmake
26-
-B build -G "Visual Studio 17 2022" -A x64
27-
-DCMAKE_TOOLCHAIN_FILE=$Env:VCPKG_INSTALLATION_ROOT\scripts\buildsystems\vcpkg.cmake
28-
2927
- name: Build
30-
run: cmake --build build --config Debug
31-
32-
- name: Tests
33-
run: ctest --test-dir build --build-config Debug --output-on-failure
28+
shell: cmd
29+
run: |
30+
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
31+
cmake --workflow windows

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Ignore vim stuff
22
*.swp
3-
build/*
3+
out/
4+
build/
45
.DS_Store

CMakeLists.txt

Lines changed: 10 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,19 @@
1-
# Copyright (c) 2021, David Keller
2-
# All rights reserved.
3-
# Redistribution and use in source and binary forms, with or without
4-
# modification, are permitted provided that the following conditions are met:
5-
#
6-
# * Redistributions of source code must retain the above copyright
7-
# notice, this list of conditions and the following disclaimer.
8-
# * Redistributions in binary form must reproduce the above copyright
9-
# notice, this list of conditions and the following disclaimer in the
10-
# documentation and/or other materials provided with the distribution.
11-
# * Neither the name of the University of California, Berkeley nor the
12-
# names of its contributors may be used to endorse or promote products
13-
# derived from this software without specific prior written permission.
14-
#
15-
# THIS SOFTWARE IS PROVIDED BY DAVID KELLER AND CONTRIBUTORS ``AS IS AND ANY
16-
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17-
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18-
# DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
19-
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20-
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21-
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22-
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23-
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24-
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25-
cmake_minimum_required(VERSION 3.10)
1+
# SPDX-License-Identifier: MIT
262

27-
project(kademlia)
28-
include(CTest)
3+
cmake_minimum_required(VERSION 3.27)
294

30-
list(INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake")
5+
project(kademlia LANGUAGES CXX VERSION 0.0.2)
316

32-
# C++11.
33-
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
34-
if (MSVC_VERSION LESS 1910) # 1910 -> VS 15.0
35-
message(FATAL_ERROR "Current compiler does'nt support c++11 yet")
36-
endif()
37-
add_definitions(
38-
-D_WIN32_WINNT=_WIN32_WINNT_WIN7
39-
-D_WINSOCK_DEPRECATED_NO_WARNINGS
40-
)
41-
else()
42-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
43-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
44-
endif()
7+
include(cmake/options.cmake)
8+
include(cmake/dependencies.cmake)
9+
include(cmake/project_setup.cmake)
4510

46-
include(CheckCXXCompilerFlag)
47-
check_cxx_compiler_flag(-std=c++11 IS_CXX11_SUPPORTED)
48-
if(NOT IS_CXX11_SUPPORTED)
49-
message(FATAL_ERROR "Current compiler does'nt support c++11 yet")
50-
endif()
51-
set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -fvisibility=hidden ${CMAKE_CXX_FLAGS}")
52-
endif()
53-
54-
# Coverage
55-
option(ENABLE_COVERAGE "Enable coverage target")
56-
if(ENABLE_COVERAGE)
57-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
58-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
59-
set(CMAKE_EXEC_LINKER_FLAGS "${CMAKE_EXEC_LINKER_FLAGS} --coverage")
60-
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
61-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
62-
set(CMAKE_EXEC_LINKER_FLAGS "${CMAKE_EXEC_LINKER_FLAGS} --coverage")
63-
else()
64-
message(FATAL_ERROR "Can't generate coverage target on ${CMAKE_CXX_COMPILER_ID}")
65-
endif()
66-
endif()
67-
68-
# Documentation
69-
option(ENABLE_DOCUMENTATION "Enable documentation" OFF)
70-
71-
# Threads
72-
find_package(Threads REQUIRED)
73-
74-
# Boost
75-
if(WIN32)
76-
set(Boost_USE_STATIC_LIBS ON)
77-
endif()
78-
find_package(Boost 1.70 CONFIG REQUIRED COMPONENTS
79-
system
80-
filesystem
81-
unit_test_framework)
82-
83-
# Crypto
84-
find_package(OpenSSL REQUIRED)
85-
86-
# Setup C++ definitions.
87-
add_definitions(-DPACKAGE_VERSION="0.0.0")
88-
add_definitions(-DPACKAGE_BUGREPORT="david.keller@litchis.fr")
89-
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
90-
add_definitions(-DKADEMLIA_ENABLE_DEBUG)
91-
endif()
92-
93-
# Setup includes directories.
94-
include_directories(BEFORE include src test)
95-
include_directories(${Boost_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR})
96-
97-
# Build everything.
98-
add_subdirectory(include)
9911
add_subdirectory(src)
100-
if(BUILD_TESTING)
101-
enable_testing()
102-
add_subdirectory(test)
103-
endif()
12+
add_subdirectory(include)
13+
add_subdirectory(test)
10414
add_subdirectory(examples)
105-
106-
if(ENABLE_DOCUMENTATION)
15+
if(KADEMLIA_ENABLE_DOCUMENTATION)
10716
add_subdirectory(docs)
10817
endif()
10918

19+
include(cmake/install.cmake)

CMakePresets.json

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"version": 6,
3+
"configurePresets": [
4+
{
5+
"name": "default",
6+
"binaryDir": "${sourceDir}/out/",
7+
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
8+
"generator": "Ninja Multi-Config"
9+
},
10+
{
11+
"name": "windows",
12+
"inherits": "default",
13+
"cacheVariables": {
14+
"VCPKG_TARGET_TRIPLET": "x64-windows-static-md"
15+
}
16+
}
17+
],
18+
"buildPresets": [
19+
{
20+
"name": "default",
21+
"configurePreset": "default",
22+
"configuration": "Debug"
23+
},
24+
{
25+
"name": "windows",
26+
"inherits": "default",
27+
"configurePreset": "windows"
28+
}
29+
],
30+
"testPresets": [
31+
{
32+
"name": "default",
33+
"output": {
34+
"outputOnFailure": true
35+
},
36+
"configurePreset": "default",
37+
"configuration": "Debug"
38+
},
39+
{
40+
"name": "windows",
41+
"inherits": "default",
42+
"configurePreset": "windows"
43+
}
44+
],
45+
"workflowPresets": [
46+
{
47+
"name": "default",
48+
"steps": [
49+
{
50+
"type": "configure",
51+
"name": "default"
52+
},
53+
{
54+
"type": "build",
55+
"name": "default"
56+
},
57+
{
58+
"type": "test",
59+
"name": "default"
60+
}
61+
]
62+
},
63+
{
64+
"name": "windows",
65+
"steps": [
66+
{
67+
"type": "configure",
68+
"name": "windows"
69+
},
70+
{
71+
"type": "build",
72+
"name": "windows"
73+
},
74+
{
75+
"type": "test",
76+
"name": "windows"
77+
}
78+
]
79+
}
80+
]
81+
}

INSTALL.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,4 @@
66
* c++11 compiler
77

88
## Compilation
9-
1. `$ mkdir build && cd build`
10-
2. `$ cmake ..`
11-
2. `$ make`
12-
13-
## Installation
14-
1. `$ sudo make install`
15-
9+
1. `$ cmake --workflow default`

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
[![Documentation Status](https://readthedocs.org/projects/kademlia-cpp/badge/?version=master)](https://kademlia-cpp.readthedocs.io/en/latest/?badge=master)
2-
[![Build Status Linux](https://app.travis-ci.com/DavidKeller/kademlia.svg?branch=master)](https://app.travis-ci.com/DavidKeller/kademlia)
3-
[![Build status Windows](https://ci.appveyor.com/api/projects/status/vf43m6qq8fk6kri1?svg=true)](https://ci.appveyor.com/project/DavidKeller/kademlia)
2+
[![Build status Linux](https://github.com/DavidKeller/kademlia/actions/workflows/linux.yaml/badge.svg)](https://github.com/DavidKeller/kademlia/actions/workflows/linux.yaml)
3+
[![Build status OSX](https://github.com/DavidKeller/kademlia/actions/workflows/osx.yaml/badge.svg)](https://github.com/DavidKeller/kademlia/actions/workflows/osx.yaml)
4+
[![Build status Windows](https://github.com/DavidKeller/kademlia/actions/workflows/windows.yaml/badge.svg)](https://github.com/DavidKeller/kademlia/actions/workflows/windows.yaml)
45
[![Coverage Status](https://coveralls.io/repos/github/DavidKeller/kademlia/badge.svg?branch=master)](https://coveralls.io/github/DavidKeller/kademlia?branch=master)
56

67
# Description
78
C++11 distributed hash table library
89

9-
**This software is experimental and under active development**.
10+
**This software is experimental and under development**.
1011

1112
# Development
1213

13-
## Bug and feature requests
14-
* [Tracker](http://redmine.litchis.fr/projects/kademlia)
15-
1614
## Supported targets
1715
<table>
1816
<tr><th>OS</th><th>Compiler</th></tr>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: MIT
2+
3+
include(CMakeFindDependencyMacro)
4+
find_dependency(Boost COMPONENTS system filesystem)
5+
find_dependency(OpenSSL)
6+
find_dependency(Threads)
7+
8+
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")

0 commit comments

Comments
 (0)