Skip to content

Commit

Permalink
libsersi: Deprecate opendis6 in favour of libsersi (#26367)
Browse files Browse the repository at this point in the history
* Deprecate opendis6 in favour of libsersi

* Update recipes/libsersi/all/conandata.yml

* Cleanup

* fix windows build

* bring back old URL

---------

Co-authored-by: Luis Caro Campos <[email protected]>
  • Loading branch information
AbrilRBS and jcar87 authored Jan 15, 2025
1 parent 4f8adc1 commit fb856b4
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 2 deletions.
4 changes: 4 additions & 0 deletions recipes/libsersi/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"0.1.0":
url: "https://github.com/crhowell3/libsersi/archive/refs/tags/v0.1.0.tar.gz"
sha256: "b3ce8c73a5b69b963e3c5090e2e237fe142f9aff69a1b6b477b52e2a6a55abb4"
97 changes: 97 additions & 0 deletions recipes/libsersi/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import os

from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rmdir
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.errors import ConanInvalidConfiguration

required_conan_version = ">=2"

class LibsersiConan(ConanFile):
name = "libsersi"
homepage = "https://github.com/crhowell3/libsersi"
description = "Modern C++ implementation of IEEE 1278.1a-1998"
topics = ("library", "protocol", "dis")
url = "https://github.com/conan-io/conan-center-index"
license = "BSD-2-Clause"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False]
}
default_options = {
"shared": False,
"fPIC": True
}

@property
def _min_cppstd(self):
return "14"

@property
def _compilers_minimum_version(self):
return {
"Visual Studio": "15",
"msvc": "191",
"gcc": "7",
"clang": "7",
"apple-clang": "10",
}

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def generate(self):
tc = CMakeToolchain(self)

# build scripts assume CMAKE_BUILD_TYPE is a cache variable,
# but CMakeToolchain sets it as a regular variable otherwise
tc.cache_variables["CMAKE_BUILD_TYPE"] = str(self.settings.build_type)
tc.cache_variables["BUILD_EXAMPLES"] = False
tc.cache_variables["BUILD_TESTS"] = False
tc.generate()

def layout(self):
cmake_layout(self, src_folder="src")

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def build_requirements(self):
self.tool_requires("cmake/[>=3.22 <4]")

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support.")

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, pattern="LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "res"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.libs = ["sersi"]
self.cpp_info.set_property("cmake_target_name", "libsersi::sersi")

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")
8 changes: 8 additions & 0 deletions recipes/libsersi/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(libsersi CONFIG REQUIRED)

add_executable(test_package_dis test_package.cpp)
target_link_libraries(test_package_dis PRIVATE libsersi::sersi)
set_target_properties(test_package_dis PROPERTIES CXX_STANDARD 14)
26 changes: 26 additions & 0 deletions recipes/libsersi/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
self.run(os.path.join(self.cpp.build.bindirs[0],
"test_package_dis"), env="conanrun")
14 changes: 14 additions & 0 deletions recipes/libsersi/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>

#include "libsersi/entity_information/EntityStatePdu.h"

int main() {
dis::EntityStatePdu pdu1, pdu2;

dis::DataStream ds(dis::kBig);
pdu1.Marshal(ds);
pdu2.Unmarshal(ds);

std::cout << "Success\n";
return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/libsersi/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.1.0":
folder: all
7 changes: 5 additions & 2 deletions recipes/opendis6/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class OpenDis6Conan(ConanFile):
"fPIC": True
}

provides = "libsersi"
deprecated = "libsersi"

@property
def _min_cppstd(self):
return "14"
Expand Down Expand Up @@ -63,7 +66,7 @@ def source(self):

def build_requirements(self):
self.tool_requires("cmake/[>=3.22 <4]")

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
Expand All @@ -90,6 +93,6 @@ def package_info(self):
self.cpp_info.set_property("cmake_file_name", "OpenDIS")
self.cpp_info.set_property("cmake_target_name", "OpenDIS::OpenDIS6")
self.cpp_info.set_property("cmake_target_aliases", ["OpenDIS::DIS6","OpenDIS6"])

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")

0 comments on commit fb856b4

Please sign in to comment.