diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..7c01f47 --- /dev/null +++ b/.clang-format @@ -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 \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..eeea9ea --- /dev/null +++ b/.github/workflows/ci.yml @@ -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}} diff --git a/CMakeLists.txt b/CMakeLists.txt index e618181..81d51c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) \ No newline at end of file +add_library(cppsocket INTERFACE) +target_include_directories(cppsocket INTERFACE $ + $) + +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() diff --git a/VERSION b/VERSION deleted file mode 100644 index d169b2f..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.0.8 diff --git a/cppsocket.pc.in b/cppsocket.pc.in new file mode 100644 index 0000000..e277689 --- /dev/null +++ b/cppsocket.pc.in @@ -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@ \ No newline at end of file diff --git a/cppsocketConfig.cmake.in b/cppsocketConfig.cmake.in new file mode 100644 index 0000000..935c6c2 --- /dev/null +++ b/cppsocketConfig.cmake.in @@ -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() diff --git a/inc/cppsocket.hpp b/inc/cppsocket.hpp index 3719cbb..6d130f5 100644 --- a/inc/cppsocket.hpp +++ b/inc/cppsocket.hpp @@ -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 #include #include diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5199e19..0d40df2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,4 @@ +message(STATUS "Building tests") if(CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_BUILD_TYPE STREQUAL "Coverage") message(STATUS "Code Coverage")