Skip to content

Commit

Permalink
build: rconpp now properly exports on platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 committed Dec 28, 2023
1 parent 705c861 commit 2ea6b55
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 20 deletions.
22 changes: 11 additions & 11 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
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ 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.5.0
LANGUAGES CXX
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,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
27 changes: 27 additions & 0 deletions cmake/CPackSetup.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
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
Expand Down
2 changes: 1 addition & 1 deletion include/rconpp/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct queued_request {
std::function<void(const response& response)> callback;
};

class rcon_client {
class RCONPP_EXPORT rcon_client {
const std::string address{};
const int port{0};
const std::string password{};
Expand Down
15 changes: 15 additions & 0 deletions include/rconpp/export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#ifdef RCONPP_BUILD
#ifdef _WIN32
#define RCONPP_EXPORT __declspec(dllexport)
#else
#define RCONPP_EXPORT
#endif
#else
#ifdef _WIN32
#define RCONPP_EXPORT __declspec(dllimport)
#else
#define RCONPP_EXPORT
#endif
#endif
5 changes: 5 additions & 0 deletions include/rconpp/rcon.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#pragma once

#ifdef _WIN32
#pragma warning( disable : 4251 ); // 4251 warns when we export classes or structures with stl member variables
#endif

#include "export.h"
#include "client.h"
#include "server.h"
#include "utilities.h"
7 changes: 4 additions & 3 deletions include/rconpp/utilities.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "export.h"
#include <string>
#include <string_view>
#include <vector>
Expand Down Expand Up @@ -65,7 +66,7 @@ struct response {
*
* @returns The packet data (as an array of chars) to send to a server.
*/
packet form_packet(const std::string_view data, int32_t id, int32_t type);
RCONPP_EXPORT packet form_packet(const std::string_view data, int32_t id, int32_t type);

/**
* @brief Turn the first 4 bytes of a buffer (which ideally a 32 bit int) into an integer.
Expand All @@ -74,11 +75,11 @@ packet form_packet(const std::string_view data, int32_t id, int32_t type);
*
* @return The value of the 4 bytes.
*/
int bit32_to_int(const std::vector<char>& buffer);
RCONPP_EXPORT int bit32_to_int(const std::vector<char>& buffer);

/**
* @brief Reports the recent socket error.
*/
void report_error();
RCONPP_EXPORT void report_error();

} // namespace rconpp

0 comments on commit 2ea6b55

Please sign in to comment.