Skip to content

Commit abafd8a

Browse files
authored
Vcpkg metaproject support (#37)
* feat: add gitattributes for sane cross-platform line endings * Add transitive dependencies to CMake package config * Generated files now in binary directory. * Change CI script to use VCPKG in its CI * Add explicit commit ID for vcpkg * Only install Boost.Asio with vcpkg
1 parent a0d028f commit abafd8a

4 files changed

Lines changed: 98 additions & 14 deletions

File tree

.gitattributes

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
* text=auto eol=lf
2+
3+
# Source and build files
4+
*.c text eol=lf
5+
*.cc text eol=lf
6+
*.cpp text eol=lf
7+
*.cxx text eol=lf
8+
*.h text eol=lf
9+
*.hh text eol=lf
10+
*.hpp text eol=lf
11+
*.hxx text eol=lf
12+
*.inl text eol=lf
13+
*.ipp text eol=lf
14+
CMakeLists.txt text eol=lf
15+
*.cmake text eol=lf
16+
CMakePresets.json text eol=lf
17+
CTestPresets.json text eol=lf
18+
19+
# Project and config files
20+
*.txt text eol=lf
21+
*.md text eol=lf
22+
*.json text eol=lf
23+
*.yml text eol=lf
24+
*.yaml text eol=lf
25+
*.toml text eol=lf
26+
*.ini text eol=lf
27+
*.cfg text eol=lf
28+
*.conf text eol=lf
29+
*.clang-format text eol=lf
30+
*.clang-tidy text eol=lf
31+
*.clangd text eol=lf
32+
.gitignore text eol=lf
33+
.gitattributes text eol=lf
34+
.gitmodules text eol=lf
35+
.editorconfig text eol=lf
36+
Dockerfile text eol=lf
37+
Doxyfile.in text eol=lf
38+
39+
# Scripts
40+
*.sh text eol=lf
41+
*.bash text eol=lf
42+
*.py text eol=lf
43+
*.bat text eol=crlf
44+
*.cmd text eol=crlf
45+
*.ps1 text eol=crlf
46+
47+
# Binary assets
48+
*.png binary
49+
*.gif binary
50+
*.jpg binary
51+
*.jpeg binary
52+
*.ico binary
53+
*.zip binary
54+
*.gz binary
55+
*.7z binary

.github/workflows/build-system.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ on:
55
push:
66
branches: master
77

8-
env:
9-
EXTERNAL_ROOT: /home/runner/3party
10-
118
jobs:
129
build:
1310
runs-on: ubuntu-latest
@@ -22,25 +19,28 @@ jobs:
2219
BUILD_TYPE: ${{ matrix.build_type }}
2320

2421
steps:
25-
- uses: actions/checkout@v2
22+
- uses: actions/checkout@v4
2623
with:
2724
fetch-depth: 0
2825

29-
- name: Add Boost repository
30-
shell: bash
31-
run: sudo apt-add-repository ppa:mhier/libboost-latest
26+
- name: Setup vcpkg (with binary caching)
27+
uses: lukka/run-vcpkg@v11
28+
with:
29+
runVcpkgInstall: false
30+
vcpkgDirectory: "${{ github.workspace }}/.vcpkg"
31+
vcpkgGitCommitId: "58950f88544e4637524dbd6a01d0317cf4cb77fc"
3232

33-
- name: Install latest Boost
33+
- name: Install dependencies
3434
shell: bash
35-
run: sudo apt install libboost1.74-dev
35+
run: $VCPKG_ROOT/vcpkg install boost-asio
3636

3737
- name: Create Build Environment
3838
run: cmake -E make_directory ${{runner.workspace}}/serverpp/build
3939

4040
- name: Configure CMake
4141
shell: bash
4242
working-directory: ${{runner.workspace}}/serverpp/build
43-
run: cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_PREFIX_PATH=$EXTERNAL_ROOT
43+
run: cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake
4444

4545
- name: Build
4646
shell: bash
@@ -50,4 +50,4 @@ jobs:
5050
- name: Test
5151
working-directory: ${{runner.workspace}}/serverpp/build
5252
shell: bash
53-
run: ctest -C $BUILD_TYPE
53+
run: ctest -C $BUILD_TYPE --output-on-failure

CMakeLists.txt

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,22 @@ endif()
4444
add_library(serverpp)
4545
add_library(KazDragon::serverpp ALIAS serverpp)
4646

47+
set(SERVERPP_GENERATED_INCLUDE_DIR
48+
"${PROJECT_BINARY_DIR}/generated/include")
49+
set(SERVERPP_GENERATED_EXPORT_HEADER
50+
"${SERVERPP_GENERATED_INCLUDE_DIR}/serverpp/detail/export.hpp")
51+
set(SERVERPP_GENERATED_VERSION_HEADER
52+
"${SERVERPP_GENERATED_INCLUDE_DIR}/serverpp/version.hpp")
53+
54+
file(MAKE_DIRECTORY "${SERVERPP_GENERATED_INCLUDE_DIR}/serverpp/detail")
55+
4756
target_sources(serverpp
4857
PRIVATE
4958
src/tcp_server.cpp
5059
src/tcp_socket.cpp
5160
include/serverpp/tcp_server.hpp
5261
include/serverpp/tcp_socket.hpp
53-
include/serverpp/version.hpp
62+
${SERVERPP_GENERATED_VERSION_HEADER}
5463
)
5564

5665
target_link_libraries(serverpp
@@ -61,6 +70,7 @@ target_link_libraries(serverpp
6170

6271
target_include_directories(serverpp
6372
PUBLIC
73+
$<BUILD_INTERFACE:${SERVERPP_GENERATED_INCLUDE_DIR}>
6474
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
6575
$<INSTALL_INTERFACE:include/serverpp-${SERVERPP_VERSION}>
6676
)
@@ -90,12 +100,12 @@ target_compile_options(serverpp
90100
target_compile_features(serverpp PUBLIC cxx_std_20)
91101

92102
generate_export_header(serverpp
93-
EXPORT_FILE_NAME "${PROJECT_SOURCE_DIR}/include/serverpp/detail/export.hpp"
103+
EXPORT_FILE_NAME "${SERVERPP_GENERATED_EXPORT_HEADER}"
94104
)
95105

96106
configure_file(
97107
${PROJECT_SOURCE_DIR}/include/serverpp/version.hpp.in
98-
${PROJECT_SOURCE_DIR}/include/serverpp/version.hpp
108+
${SERVERPP_GENERATED_VERSION_HEADER}
99109
@ONLY)
100110

101111
include(GNUInstallDirs)
@@ -151,6 +161,20 @@ install(
151161
include/serverpp-${SERVERPP_VERSION}
152162
)
153163

164+
install(
165+
FILES
166+
"${SERVERPP_GENERATED_EXPORT_HEADER}"
167+
DESTINATION
168+
include/serverpp-${SERVERPP_VERSION}/serverpp/detail
169+
)
170+
171+
install(
172+
FILES
173+
"${SERVERPP_GENERATED_VERSION_HEADER}"
174+
DESTINATION
175+
include/serverpp-${SERVERPP_VERSION}/serverpp
176+
)
177+
154178
install(
155179
FILES
156180
"${CMAKE_CURRENT_BINARY_DIR}/serverpp-config.cmake"

cmake/serverpp-config.cmake.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
@PACKAGE_INIT@
22

3+
include(CMakeFindDependencyMacro)
4+
5+
find_dependency(Boost 1.69.0)
6+
find_dependency(Threads)
7+
38
include(${CMAKE_CURRENT_LIST_DIR}/serverpp-targets.cmake)
49
check_required_components(serverpp)

0 commit comments

Comments
 (0)