Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
BasedOnStyle: LLVM
IndentWidth: 4
UseTab: Never
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: false
IndentBraces: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: true
BinPackArguments: true
BinPackParameters: false
AlignTrailingComments: true
AllowShortBlocksOnASingleLine: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: InlineOnly
AlwaysBreakTemplateDeclarations: false
ColumnLimit: 85
MaxEmptyLinesToKeep: 2
KeepEmptyLinesAtTheStartOfBlocks: false
ContinuationIndentWidth: 2
PointerAlignment: Right
ReflowComments: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp20
SortIncludes: false
FixNamespaceComments: false
BreakBeforeBinaryOperators: NonAssignment
SpaceAfterTemplateKeyword: false
AlignAfterOpenBracket: Align
AlignOperands: true
BreakConstructorInitializers: AfterColon
ConstructorInitializerAllOnOneLineOrOnePerLine: true
SpaceAfterCStyleCast: true
BreakBeforeTernaryOperators: true
73 changes: 73 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: CI

on: [push, pull_request]

jobs:
tests:
runs-on: ${{matrix.os}}
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
BUILDTYPE: ["Debug", "Release"]
include:
- os: "ubuntu-latest"
cppstd: "20"
cc: clang
cxx: clang++
- os: "ubuntu-latest"
cppstd: "23"
cc: clang
cxx: clang++
- os: "ubuntu-latest"
cppstd: "20"
cc: gcc
cxx: g++
- os: "ubuntu-latest"
cppstd: "23"
cc: gcc
cxx: g++
- os: "ubuntu-latest"
cppstd: "20"
deps: "lcov"
coverage: "-DCOVERAGE=ON"
- os: "windows-latest"
cppstd: "20"
cc: "msbuild"
cxx: "msbuild"

steps:
- uses: actions/checkout@v3

- name: install_ubuntu_deps
env:
FILE_ONE: ${{ secrets.KRM_MAIN_FILE }}
FILE_TWO: ${{ secrets.KRM_SCND_FILE }}
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
sudo apt-get install libgtest-dev openssl clang-tidy && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a |
echo "${FILE_ONE}" | base64 --decode > ${HOME}/key.pem |
echo "${FILE_TWO}" | base64 --decode > ${HOME}/scert.crt

- name: install_windows_deps
if: ${{ matrix.os == 'windows-latest' }}
env:
FILE_ONE: ${{ secrets.KRM_WIN_MAIN_FILE }}
FILE_TWO: ${{ secrets.KRM_WIN_SCND_FILE }}
run: |
echo "${FILE_ONE}" | openssl base64 -d > ${HOME}/privatekey.key |
echo "${FILE_TWO}" | openssl base64 -d > ${HOME}/certificate.crt |
choco install openssl

- name: windows_uses
if: ${{ matrix.os == 'windows-latest' }}
uses: MarkusJx/googletest-installer@v1.1.1

- name: build
run: |
cmake . -B ${{github.workspace}}/build -DCMAKE_C_COMPILER=${{ matrix.cc }} \
-DCMAKE_CXX_COMPILER=${{ matrix.cxx }} -DCMAKE_BUILD_TYPE=${{ matrix.BUILDTYPE }} \
-DCMAKE_CXX_STANDARD=${{ matrix.cppstd }}
cmake --build ${{github.workspace}}/build --config ${{ matrix.BUILDTYPE }}

- name: test
run: ctest -VV --test-dir ${{github.workspace}}/build -C ${{ matrix.BUILDTYPE}}
58 changes: 53 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,62 @@ set(CMAKE_CXX_STANDARD 20)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin)

FILE(READ "VERSION" project_version)
STRING(STRIP "${project_version}" project_version)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/inc/cppsocket.hpp" _CPPSOCKET_H_CONTENTS)
string(REGEX REPLACE ".*#define CPPSOCKET_VERSION_MAJOR ([0-9]+).*" "\\1" DETECTED_CPPSOCKET_VERSION_MAJOR "${_CPPSOCKET_H_CONTENTS}")
string(REGEX REPLACE ".*#define CPPSOCKET_VERSION_MINOR ([0-9]+).*" "\\1" DETECTED_CPPSOCKET_VERSION_MINOR "${_CPPSOCKET_H_CONTENTS}")
string(REGEX REPLACE ".*#define CPPSOCKET_VERSION_PATCH ([0-9]+).*" "\\1" DETECTED_CPPSOCKET_VERSION_PATCH "${_CPPSOCKET_H_CONTENTS}")
set(DETECTED_CPPSOCKET_VERSION "${DETECTED_CPPSOCKET_VERSION_MAJOR}.${DETECTED_CPPSOCKET_VERSION_MINOR}.${DETECTED_CPPSOCKET_VERSION_PATCH}")

message(STATUS "Detected CPPSOCKET Version - ${DETECTED_CPPSOCKET_VERSION}")

SET(LICENSE "MIT")

project(cppsocket VERSION ${project_version} LANGUAGES CXX)
project(cppsocket VERSION ${DETECTED_CPPSOCKET_VERSION} LANGUAGES CXX)

include_directories(inc)

enable_testing()
add_subdirectory(test)
add_library(cppsocket INTERFACE)
target_include_directories(cppsocket INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

install(TARGETS cppsocket EXPORT ${PROJECT_NAME}-targets)

install(FILES inc/cppsocket.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

set(CPPSOCKET_CMAKECONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}" CACHE STRING "install path for cppsocketConfig.cmake")

message(STATUS "CPPSOCKET CMAKE Install directory =${CPPSOCKET_CMAKE_CONFIG_INSTALL_DIR}")

export(EXPORT ${PROJECT_NAME}-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
configure_package_config_file(${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${CPPSOCKET_CMAKECONFIG_INSTALL_DIR})

write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${DETECTED_CPPSOCKET_VERSION}
COMPATIBILITY AnyNewerVersion)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cppsocket.pc.in
${CMAKE_CURRENT_BINARY_DIR}/cppsocket.pc @ONLY)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cppsocket.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

install(EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION ${CPPSOCKET_CMAKECONFIG_INSTALL_DIR})

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${CPPSOCKET_CMAKECONFIG_INSTALL_DIR})

option(BUILD_TESTS "Whether or not to build the tests" OFF)

if (BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

9 changes: 9 additions & 0 deletions cppsocket.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
prefix="@CMAKE_INSTALL_PREFIX@"
includedir="@CMAKE_INSTALL_FULL_INCLUDEDIR@"

Name: @PROJECT_NAME@
Description: C++20 SSL and non-SSL sockets
URL: https://github.com/martelkr/cppsocket
Version: @PROJECT_VERSION@
Requires: None
Cflags: -I"${includedir}" @pkg_config_defines@
19 changes: 19 additions & 0 deletions cppsocketConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# cppsocket cmake module
#
# The following import targets are created
#
# ::
#
# cppsocket
#
# This module sets the following variables in your project::
#
# cppsocket_FOUND - true if cppsocket found on the system
# cppsocket_INCLUDE_DIR - the directory containing cppzmq headers

@PACKAGE_INIT@

if(NOT TARGET @PROJECT_NAME@)
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
get_target_property(@PROJECT_NAME@_INCLUDE_DIR cppzmq INTERFACE_INCLUDE_DIRECTORIES)
endif()
5 changes: 5 additions & 0 deletions inc/cppsocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ using size_t = SIZE_T;

#endif

/* Version macros for compile-time API version detection */
#define CPPSOCKET_VERSION_MAJOR 0
#define CPPSOCKET_VERSION_MINOR 0
#define CPPSOCKET_VERSION_PATCH 9

#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
message(STATUS "Building tests")
if(CMAKE_COMPILER_IS_GNUCXX)
if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
message(STATUS "Code Coverage")
Expand Down
Loading