Compare commits
16 commits
Author | SHA1 | Date | |
---|---|---|---|
29804dddd0 | |||
4afec4ddb9 | |||
442aa1e422 | |||
f30e911208 | |||
c3182cb127 | |||
83aacc3090 | |||
23e20ca41c | |||
c9397835f2 | |||
d545e22815 | |||
5c296632b0 | |||
7c1256567b | |||
2bb283e335 | |||
125ef0aaf5 | |||
2adfb03b12 | |||
13899404ec | |||
35db9faeeb |
14 changed files with 221 additions and 52 deletions
28
.forgejo/workflows/conan_unittests.yml
Normal file
28
.forgejo/workflows/conan_unittests.yml
Normal 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
|
|
@ -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
22
.github/workflows/conan_unittests.yml
vendored
Normal 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 './{}' ';'
|
18
.github/workflows/unittests.yml
vendored
18
.github/workflows/unittests.yml
vendored
|
@ -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
2
.gitignore
vendored
|
@ -4,3 +4,5 @@ compile_commands.json
|
|||
*.o
|
||||
doxygen_out/
|
||||
/tags
|
||||
|
||||
CMakeUserPresets.json
|
||||
|
|
|
@ -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
|
||||
|
|
25
conan_usage_example/CMakeLists.txt
Normal file
25
conan_usage_example/CMakeLists.txt
Normal 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)
|
6
conan_usage_example/conanfile.txt
Normal file
6
conan_usage_example/conanfile.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
[requires]
|
||||
udpc/1.2
|
||||
|
||||
[generators]
|
||||
CMakeDeps
|
||||
CMakeToolchain
|
17
conan_usage_example/setup_build_with_conan.sh
Executable file
17
conan_usage_example/setup_build_with_conan.sh
Executable 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
|
1
conan_usage_example/src/UDPC_NetworkTest.c
Symbolic link
1
conan_usage_example/src/UDPC_NetworkTest.c
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../src/test/UDPC_NetworkTest.c
|
61
conanfile.py
Normal file
61
conanfile.py
Normal 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.
|
7
test_package/CMakeLists.txt
Normal file
7
test_package/CMakeLists.txt
Normal 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
26
test_package/conanfile.py
Normal 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
10
test_package/src/test.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in a new issue