Compare commits

...

16 commits

Author SHA1 Message Date
29804dddd0 Support Macos linking c++ stl in CMakeLists.txt
All checks were successful
Run UnitTests / build-and-run-tests (push) Successful in 4m28s
2024-07-14 11:36:44 +09:00
4afec4ddb9 Update conanfile.py linking c++ stl for Macos too
Some checks failed
Run UnitTests / build-and-run-tests (push) Has been cancelled
TODO: Figure out linking for Windows.
2024-07-14 11:33:08 +09:00
442aa1e422 Attempt to fix conan build
All checks were successful
Run UnitTests / build-and-run-tests (push) Successful in 1m20s
2024-07-13 23:02:17 +09:00
f30e911208 Merge branch 'master' into conan
Some checks failed
Run UnitTests / build-and-run-tests (push) Failing after 1m23s
2024-07-13 22:43:09 +09:00
c3182cb127 Fix conanfile.py/CMakeLists.txt for C consumers
The new configuration should make C consumers link to "stdc++" by
default, which should fix building with static libs for C programs.
2024-07-13 22:41:16 +09:00
83aacc3090 Make test work with C compiler not C++ compiler
All checks were successful
Run UnitTests / build-and-run-tests (push) Successful in 2m0s
2024-07-13 16:14:00 +09:00
23e20ca41c Merge branch 'master' into conan
All checks were successful
Run UnitTests / build-and-run-tests (push) Successful in 1m24s
2024-07-13 15:03:52 +09:00
c9397835f2 Make conan example project work with static lib 2024-07-13 14:52:38 +09:00
d545e22815 Update version to udpc/1.1
All checks were successful
Run UnitTests / build-and-run-tests (push) Successful in 2m10s
2024-07-13 13:46:08 +09:00
5c296632b0 Merge branch 'master' into conan 2024-07-13 13:44:55 +09:00
7c1256567b Merge branch 'master' into conan
All checks were successful
Run UnitTests / build-and-run-tests (push) Successful in 1m43s
2024-07-13 13:18:50 +09:00
2bb283e335 Minor tweaks to actions/workflows files (unittest)
All checks were successful
Run UnitTests / build-and-run-tests (push) Successful in 4m48s
2024-07-13 11:43:01 +09:00
125ef0aaf5 Add example CMake project that uses UDPC 2024-07-13 11:43:01 +09:00
2adfb03b12 Update github workflow to use conan 2024-07-13 11:43:01 +09:00
13899404ec Update forgejo workflow to use conan 2024-07-13 11:43:01 +09:00
35db9faeeb Add conan related files and adapt CMakeLists.txt
This is put in a new "conan" branch. Changes to the conan build process
will only occur on this branch.
2024-07-13 11:43:01 +09:00
14 changed files with 221 additions and 52 deletions

View file

@ -0,0 +1,28 @@
name: Run UnitTests
on:
push:
branches:
- 'conan'
jobs:
build-and-run-tests:
runs-on: docker_arch
steps:
- run: pacman-key --init && pacman-key --populate
name: Init pacman keyring
- run: pacman --noconfirm --needed -Sy archlinux-keyring
name: Update pacman keyring
- run: pacman --noconfirm --needed -Su git cmake libsodium python
name: Update and get dependencies
- run: python -m venv conan_venv && source conan_venv/bin/activate && pip install conan
name: Get conan
- run: source conan_venv/bin/activate && conan profile detect --force
name: Set up conan profile
- run: git clone --depth=1 --no-single-branch https://git.seodisparate.com/stephenseo/UDPConnection.git UDPC
name: Get repository
- run: cd UDPC && git checkout $GITHUB_REF_NAME
name: Checkout git repository
- run: source conan_venv/bin/activate && conan build UDPC -of buildConan --settings=build_type=Debug --build=missing
name: Build with conan
- run: find buildConan -name UnitTest -execdir './{}' ';'
name: Test

View file

@ -1,14 +0,0 @@
name: Run UnitTests
on:
push:
branches:
- '*'
jobs:
build-and-run-tests:
runs-on: any_archLinux
steps:
- run: git clone --depth=1 --no-single-branch https://git.seodisparate.com/stephenseo/UDPConnection.git UDPC
- run: cd UDPC && git checkout $GITHUB_REF_NAME
- run: cd UDPC && cmake -S . -B buildDebug -DCMAKE_BUILD_TYPE=Debug
- run: make -C UDPC/buildDebug && ./UDPC/buildDebug/UnitTest

22
.github/workflows/conan_unittests.yml vendored Normal file
View file

@ -0,0 +1,22 @@
name: Run UnitTests
on:
push:
branches:
- 'conan'
jobs:
build-and-run-tests:
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: sudo /usr/bin/env DEBIAN_FRONTEND=noninteractive apt-get install cmake git python3
- name: Get sources
run: git clone --depth=1 --no-single-branch https://github.com/Stephen-Seo/UDPConnection.git UDPC && cd UDPC && git checkout $GITHUB_REF_NAME
- name: Get Conan
run: python -m venv venv_conan && source venv_conan/bin/activate && pip install conan
- name: Set up conan
run: source venv_conan/bin/activate && conan profile detect --force
- name: Build with conan
run: source venv_conan/bin/activate && conan build UDPC -of buildConan --settings=build_type=Debug --build=missing
- name: Run tests
run: find buildConan -name UnitTest -execdir './{}' ';'

View file

@ -1,18 +0,0 @@
name: Run UnitTests
on:
push:
branches:
- '*'
jobs:
build-and-run-tests:
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: sudo /usr/bin/env DEBIAN_FRONTEND=noninteractive apt-get install cmake git libsodium-dev
- name: Get sources
run: git clone --depth=1 --no-single-branch https://github.com/Stephen-Seo/UDPConnection.git UDPC && cd UDPC && git checkout $GITHUB_REF_NAME
- name: Build sources
run: cd UDPC && cmake -S . -B buildDebug -DCMAKE_BUILD_TYPE=Debug && make -C buildDebug
- name: Run tests
run: ./UDPC/buildDebug/UnitTest

2
.gitignore vendored
View file

@ -4,3 +4,5 @@ compile_commands.json
*.o
doxygen_out/
/tags
CMakeUserPresets.json

View file

@ -23,6 +23,18 @@ endif()
add_library(UDPC ${UDPC_SOURCES})
# Enforce linking with libstdc++ even with C targets.
# Doesn't affect conan, so conanfile.py was also modified for this.
if(APPLE)
set_target_properties(UDPC PROPERTIES
INTERFACE_LINK_LIBRARIES "libc++"
)
elseif(UNIX)
set_target_properties(UDPC PROPERTIES
INTERFACE_LINK_LIBRARIES "stdc++"
)
endif()
set_target_properties(UDPC PROPERTIES VERSION ${UDPC_VERSION} SOVERSION ${UDPC_SOVERSION})
target_compile_features(UDPC PUBLIC cxx_std_11)
@ -38,26 +50,10 @@ if(WIN32)
endif()
endif()
if(UDPC_DISABLE_LIBSODIUM)
message(STATUS "libsodium disabled")
elseif(DEFINED M_LIBSODIUM_LIBRARIES AND DEFINED M_LIBSODIUM_INCLUDE_DIRS)
message(STATUS "libsodium manual paths detected, using them")
target_compile_definitions(UDPC PUBLIC UDPC_LIBSODIUM_ENABLED)
target_link_libraries(UDPC PUBLIC ${M_LIBSODIUM_LIBRARIES})
target_include_directories(UDPC PUBLIC ${M_LIBSODIUM_INCLUDE_DIRS})
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBSODIUM QUIET libsodium)
if(LIBSODIUM_FOUND)
target_compile_definitions(UDPC PUBLIC UDPC_LIBSODIUM_ENABLED)
target_link_libraries(UDPC PUBLIC ${LIBSODIUM_LIBRARIES})
target_include_directories(UDPC PUBLIC ${LIBSODIUM_INCLUDE_DIRS})
target_compile_options(UDPC PUBLIC ${LIBSODIUM_CFLAGS_OTHER})
message(STATUS "libsodium enabled")
else()
message(STATUS "libsodium not found, UDPC will be compiled without libsodium support")
endif()
endif()
find_package(libsodium REQUIRED)
target_compile_definitions(UDPC PUBLIC UDPC_LIBSODIUM_ENABLED)
target_link_libraries(UDPC PUBLIC libsodium::libsodium)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
set(UDPC_UnitTest_SOURCES

View file

@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.7)
project(UDPC_NetworkTest C)
set(UDPC_NetworkTest_SOURCES
src/UDPC_NetworkTest.c
)
add_compile_options(
-Wall -Wextra -Wpedantic -Wno-missing-braces
$<$<COMPILE_LANGUAGE:CXX>:-Weffc++>
$<$<CONFIG:DEBUG>:-Og>
)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Debug', none was specified.")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif()
find_package(udpc CONFIG REQUIRED)
add_executable(UDPC_NetworkTest
${UDPC_NetworkTest_SOURCES}
)
target_link_libraries(UDPC_NetworkTest PUBLIC udpc::udpc)

View file

@ -0,0 +1,6 @@
[requires]
udpc/1.2
[generators]
CMakeDeps
CMakeToolchain

View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
cd "$(dirname "$0")"
set -ve
if ! [[ -e "${HOME}/.conan2/profiles/default" ]]; then
conan profile detect
fi
if ! grep stephens_forgejo "${HOME}/.conan2/remotes.json" >&/dev/null; then
conan remote add stephens_forgejo "https://git.seodisparate.com/api/packages/stephenseo/conan"
fi
conan install . -r stephens_forgejo -r conancenter --output-folder=buildConan --build=missing
cmake -S . -B buildConan -DCMAKE_TOOLCHAIN_FILE=buildConan/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build buildConan

View file

@ -0,0 +1 @@
../../src/test/UDPC_NetworkTest.c

61
conanfile.py Normal file
View file

@ -0,0 +1,61 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
import os
class udpcRecipe(ConanFile):
name = "udpc"
version = "1.2"
package_type = "library"
# Optional metadata
license = "MIT"
author = "Stephen Seo stephen@seodisparate.com"
url = "https://git.seodisparate.com/stephenseo/UDPConnection"
description = "Implements a connection over UDP"
topics = ("UDPC", "UDP", "Network", "Network Connection")
# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = "CMakeLists.txt", "src/*"
def config_options(self):
if self.settings.os == "Windows":
self.options.rm_safe("fPIC")
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires("libsodium/cci.20220430")
def generate(self):
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def package(self):
cmake = CMake(self)
cmake.install()
def package_info(self):
self.cpp_info.libs.append("UDPC")
if self.settings.os == "Linux":
self.cpp_info.system_libs.append("stdc++")
elif self.settings.os == "Macos":
self.cpp_info.system_libs.append("libc++")
# TODO figure out linking static library for other OS.

View file

@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(PackageTest CXX)
find_package(udpc CONFIG REQUIRED)
add_executable(example src/test.cpp)
target_link_libraries(example udpc::udpc)

26
test_package/conanfile.py Normal file
View file

@ -0,0 +1,26 @@
import os
from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import can_run
class udpcTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain"
def requirements(self):
self.requires(self.tested_reference_str)
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def layout(self):
cmake_layout(self)
def test(self):
if can_run(self):
cmd = os.path.join(self.cpp.build.bindir, "example")
self.run(cmd, env="conanrun")

10
test_package/src/test.cpp Normal file
View file

@ -0,0 +1,10 @@
#include "UDPC.h"
int main() {
auto ctx = UDPC_init(UDPC_create_id_easy("127.0.0.1", 0), 1, 1);
if (UDPC_is_valid_context(ctx) == 0) {
return 1;
}
UDPC_destroy(ctx);
return 0;
}