Skip to content

Commit

Permalink
feat, ci, build: library no longer header-only. Windows CIs now added…
Browse files Browse the repository at this point in the history
…, Project is now packagable. (#8)
  • Loading branch information
Jaskowicz1 committed Dec 28, 2023
1 parent c020fb9 commit d888ea8
Show file tree
Hide file tree
Showing 16 changed files with 742 additions and 491 deletions.
111 changes: 83 additions & 28 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ jobs:
fail-fast: false # Don't fail everything if one fails. We want to test each OS/Compiler individually
matrix:
cfg:
- { arch: 'amd64', concurrency: 2, os: ubuntu-20.04, package: clang-10, cpp-version: clang++-10, ctest: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-11, cpp-version: clang++-11, ctest: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-12, cpp-version: clang++-12, ctest: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-13, cpp-version: clang++-13, ctest: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-14, cpp-version: clang++-14, ctest: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-15, cpp-version: clang++-15, ctest: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-20.04, package: g++-9, cpp-version: g++-9, ctest: 'yes', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: g++-10, cpp-version: g++-10, ctest: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: g++-11, cpp-version: g++-11, ctest: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: g++-12, cpp-version: g++-12, ctest: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: g++-13, cpp-version: g++-13, ctest: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-20.04, package: clang-10, cpp-version: clang++-10, ctest: 'no', cpack: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-11, cpp-version: clang++-11, ctest: 'no', cpack: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-12, cpp-version: clang++-12, ctest: 'no', cpack: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-13, cpp-version: clang++-13, ctest: 'no', cpack: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-14, cpp-version: clang++-14, ctest: 'no', cpack: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-15, cpp-version: clang++-15, ctest: 'no', cpack: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-20.04, package: g++-9, cpp-version: g++-9, ctest: 'yes', cpack: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: g++-10, cpp-version: g++-10, ctest: 'no', cpack: 'yes', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: g++-11, cpp-version: g++-11, ctest: 'no', cpack: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: g++-12, cpp-version: g++-12, ctest: 'no', cpack: 'no', downloadcpp: 'yes'}
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: g++-13, cpp-version: g++-13, ctest: 'no', cpack: 'no', downloadcpp: 'yes'}
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
Expand Down Expand Up @@ -69,20 +69,75 @@ jobs:
RCON_TESTING_PORT: ${{secrets.RCON_TESTING_PORT}}
RCON_TESTING_PASSWORD: ${{secrets.RCON_TESTING_PASSWORD}}

#- name: Package distributable
# if: ${{ matrix.cfg.cpack == 'yes' }}
# run: cd build && cpack --verbose

#- name: Upload Binary (DEB)
# if: ${{ matrix.cfg.cpack == 'yes' }}
# uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
# with:
# name: "librconpp - Debian Package ${{matrix.cfg.arch}}"
# path: '${{github.workspace}}/build/*.deb'

#- name: Upload Binary (RPM)
# if: ${{ matrix.cfg.cpack == 'yes' }}
# uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
# with:
# name: "librconpp - RPM Package ${{matrix.cfg.arch}}"
# path: '${{github.workspace}}/build/*.rpm'
- name: Package distributable
if: ${{ matrix.cfg.cpack == 'yes' }}
run: cd build && cpack --verbose

- name: Upload Binary (DEB)
if: ${{ matrix.cfg.cpack == 'yes' }}
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: "librconpp - Debian Package ${{matrix.cfg.arch}}"
path: '${{github.workspace}}/build/*.deb'

windows: # Windows x64 and x86 build matrix
permissions:
contents: write
strategy:
fail-fast: false # Don't cancel other matrix jobs if one fails
matrix:
cfg:
- { name: 'x64', arch: x64, config: Release, vs: '2019', os: 'windows-2019', vsv: '16', upload: true, options: '' }
- { name: 'x64', arch: x64, config: Debug, vs: '2019', os: 'windows-2019', vsv: '16', upload: true, options: '' }
- { name: 'x86', arch: x86, config: Release, vs: '2019', os: 'windows-2019', vsv: '16', upload: true, options: '-T host=x86 ' }
- { name: 'x86', arch: x86, config: Debug, vs: '2019', os: 'windows-2019', vsv: '16', upload: true, options: '-T host=x86 ' }
- { name: 'x64', arch: x64, config: Release, vs: '2022', os: 'windows-2022', vsv: '17', upload: true, options: '' }
- { name: 'x64', arch: x64, config: Debug, vs: '2022', os: 'windows-2022', vsv: '17', upload: true, options: '' }
- { name: 'x86', arch: x86, config: Release, vs: '2022', os: 'windows-2022', vsv: '17', upload: true, options: '-T host=x86' }
- { name: 'x86', arch: x86, config: Debug, vs: '2022', os: 'windows-2022', vsv: '17', upload: true, options: '-T host=x86' }
- { name: 'x64-Clang', arch: x64, config: Release, vs: '2022', os: 'windows-2022', vsv: '17', upload: false, options: '-T ClangCL' }
- { name: 'x64-Clang', arch: x64, config: Debug, vs: '2022', os: 'windows-2022', vsv: '17', upload: false, options: '-T ClangCL' }

name: "Windows ${{matrix.cfg.name}}-${{matrix.cfg.config}}-vs${{matrix.cfg.vs}}"
runs-on: ${{matrix.cfg.os}}
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit

- name: Checkout rconpp
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
path: main

- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@1ff57057b5cfdc39105cd07a01d78e9b0ea0c14c # v1.3.1

- name: Install chocolatey packages ${{ matrix.cfg.arch}}
uses: seanmiddleditch/gha-setup-ninja@8b297075da4cd2a5f1fd21fe011b499edf06e9d2 # master

- name: Generate CMake (x64)
if: ${{ matrix.cfg.arch == 'x64' }}
run: mkdir main/build && cd main/build && cmake -G "Visual Studio ${{matrix.cfg.vsv}} ${{matrix.cfg.vs}}" ${{matrix.cfg.options}} ..

- name: Generate CMake (x86)
if: ${{ matrix.cfg.arch == 'x86' }}
run: mkdir main/build && cd main/build && cmake -DCMAKE_TOOLCHAIN_FILE="cmake\Win32Toolchain.cmake" -G "Visual Studio ${{matrix.cfg.vsv}} ${{matrix.cfg.vs}}" -A Win32 ${{matrix.cfg.options}} ..

- name: Build Project
run: cmake --build main/build --target rconpp --config ${{matrix.cfg.config}} --parallel 2

- name: Move debug files for packaging
if: ${{ matrix.cfg.config == 'Debug' }}
run: xcopy main\build\Debug\* main\build\Release\ /s /q

- name: Package distributable
run: cd main/build && cpack --verbose

- name: Upload Binary
if: ${{ matrix.cfg.upload }}
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: "librconpp - Windows ${{matrix.cfg.name}}-${{matrix.cfg.config}}-vs${{matrix.cfg.vs}}"
path: '${{github.workspace}}/main/build/*.zip'
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
_build
build
cmake-build-debug
out

# Xcode stuff
*.xcworkspace
Expand All @@ -14,6 +15,3 @@ cmake-build-debug

# Apple stuff.
.DS_Store

# Extras
config.cfg
56 changes: 47 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,76 @@
cmake_minimum_required(VERSION 3.10)

option(BUILD_TESTS "Build the test program" ON)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_compile_definitions(RCONPP_BUILD)

set(RCONPP_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})

project(rconpp
VERSION 0.1.0
VERSION 0.5.0
LANGUAGES CXX
HOMEPAGE_URL "https://github.com/Jaskowicz1/rconpp"
DESCRIPTION "A modern Source-RCON library for C++"
)

include(GNUInstallDirs)
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()

add_library(rconpp INTERFACE)
if(UNIX OR MSYS)
find_program(LDCONFIG_EXECUTABLE "ldconfig")
endif()

file(GLOB rconpp_src "src/rconpp/*.cpp" "src/rconpp/*.rc")

if(BUILD_SHARED_LIBS)
add_library(rconpp SHARED ${rconpp_src})
else()
add_library(rconpp STATIC ${rconpp_src})
endif()

target_include_directories(rconpp INTERFACE include/rconpp/rcon.h)
target_include_directories(rconpp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/rconpp>
)

set_target_properties(rconpp PROPERTIES
VERSION ${CMAKE_PROJECT_VERSION}
SOVERSION ${CMAKE_PROJECT_VERSION}
POSITION_INDEPENDENT_CODE true
LINKER_LANGUAGE CXX
)

if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
target_compile_features(rconpp PRIVATE cxx_std_17)
target_compile_features(rconpp PRIVATE cxx_constexpr)
target_compile_features(rconpp PRIVATE cxx_lambdas)

if(BUILD_TESTS)
add_executable(unittest "unittest/test.cpp")
target_compile_features(unittest PRIVATE cxx_std_17)
target_link_directories(unittest PRIVATE rconpp)
target_link_libraries(unittest PUBLIC rconpp)
enable_testing()
add_test(
NAME unittest
COMMAND unittest
)
endif()

if(NOT WIN32)
include(GNUInstallDirs)
install(TARGETS rconpp LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
message("Library install directory at ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
message("Include files install directory at ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -DRUN_LDCONFIG=${RUN_LDCONFIG} -DLDCONFIG_EXECUTABLE=${LDCONFIG_EXECUTABLE} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/PostInstall.cmake)")

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/rconpp.pc.in" "${CMAKE_BINARY_DIR}/rconpp.pc" @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/rconpp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()

# Setup information for packaging and distribution
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPackSetup.cmake")

# CPack initialization for distribution
include(CPack)
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ Rcon++ is a modern Source RCON library for C++, allowing people to easily use RC
#### Library Features

- Support for Valve and non-Valve games.
- Non-blocking and blocking calls.
- Header-Only (all in one file)!
- Callbacks, allowing non-blocking calls.

#### To-do

Expand All @@ -32,17 +31,19 @@ We do not test support for MinGW, nor do we want to actively try and support it.

# Getting Started

For now, rcon++ can only be used by adding the header file into your source code.
rcon++ can be installed from the .deb file in the recent actions (soon to be released!).

From there you can easily start an RCON connection, and do a command, like the following:
We're aiming to start rolling out to package managers soon!

# Quick Example

```c++
#include <iostream>
#include "rcon.h"
#include <rconpp/rcon.h>

int main() {
rcon::rcon_client client("127.0.0.1", 27015, "changeme");
client.send_data("Hello!", 3, data_type::SERVERDATA_EXECCOMMAND, [](const rcon_response& response) {
rconpp::rcon_client client("127.0.0.1", 27015, "changeme");
client.send_data("Hello!", 3, rconpp::data_type::SERVERDATA_EXECCOMMAND, [](const rconpp::response& response) {
std::cout << "response: " << response.data << "\n";
});
Expand Down
55 changes: 55 additions & 0 deletions cmake/CPackSetup.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
include(GNUInstallDirs)
set(RCONPP_EXPORT_NAME rconpp)
set(RCONPP_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${RCONPP_EXPORT_NAME})
set(RCONPP_VERSION_FILE ${PROJECT_BINARY_DIR}/${RCONPP_EXPORT_NAME}-config-version.cmake)

# The three lines below are only used for windows builds
set(RCONPP_VERSIONED ${RCONPP_EXPORT_NAME}-1.0)
set(RCONPP_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${RCONPP_VERSIONED})
set(RCONPP_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}/${RCONPP_VERSIONED})


## Pack the binary output
if (WIN32)
install(TARGETS rconpp
EXPORT ${RCONPP_EXPORT_NAME}
LIBRARY DESTINATION ${RCONPP_INSTALL_LIBRARY_DIR}
ARCHIVE DESTINATION ${RCONPP_INSTALL_LIBRARY_DIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${RCONPP_INSTALL_INCLUDE_DIR})
install(DIRECTORY "${RCONPP_ROOT_PATH}/include/" DESTINATION "${RCONPP_INSTALL_INCLUDE_DIR}")
else()
install(TARGETS rconpp
EXPORT ${RCONPP_EXPORT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBRARY_DIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBRARY_DIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDE_DIR})
endif()

# Prepare information for packaging into .zip, .deb, .rpm
## Project installation metadata
set(CPACK_PACKAGE_NAME librconpp)
set(CPACK_PACKAGE_VENDOR "Archie Jaskowicz") # Maker of the application
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A modern Source RCON library for C++")
set(CPACK_PACKAGE_DESCRIPTION "A modern Source RCON library for C++")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/Jaskowicz1/rconpp")
set(CPACK_FREEBSD_PACKAGE_MAINTAINER "archiejaskowicz@gmail.com")
set(CPACK_FREEBSD_PACKAGE_ORIGIN "misc/librconpp")
set(CPACK_RPM_PACKAGE_LICENSE "Apache 2.0")
set(CPACK_PACKAGE_CONTACT "https://jaskowicz.xyz/contact")
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "A modern Source RCON library for C++")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
set(CPACK_PACKAGE_VERSION_MAJOR 1)
set(CPACK_PACKAGE_VERSION_MINOR 0)
set(CPACK_PACKAGE_VERSION_PATCH 0)

## Select generated based on what operating system
if(WIN32)
set(CPACK_GENERATOR ZIP)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(CPACK_GENERATOR "DEB")
else()
set(CPACK_GENERATOR "TBZ2")
endif()
9 changes: 9 additions & 0 deletions cmake/PostInstall.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if(LDCONFIG_EXECUTABLE)
message(STATUS "Running ldconfig")

execute_process(COMMAND ${LDCONFIG_EXECUTABLE} RESULT_VARIABLE ldconfig_result)

if (NOT ldconfig_result EQUAL 0)
message(WARNING "ldconfig failed")
endif()
endif()
8 changes: 8 additions & 0 deletions cmake/Win32Toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
message("-- Building for windows (x86) with precompiled packaged dependencies")

ADD_DEFINITIONS(/bigobj)

SET(WINDOWS_32_BIT 1)

# BIG FAT STINKY KLUDGE
SET(CMAKE_CXX_COMPILER_WORKS 1)

0 comments on commit d888ea8

Please sign in to comment.