Skip to content

Commit

Permalink
(#22646) [opendis6] new recipe
Browse files Browse the repository at this point in the history
* Initial template for opendis6

* Added conandata, test package dirs

* Fixed syntax error in conanfile

* Syntax fix

* Fixed conan build, now works

* prepare for CCI

Signed-off-by: Uilian Ries <[email protected]>

* Added CMake as a build req

* Fixed linter issue

* Updated SHA256 to new release file

* Bumped min compiler versions

* Update recipes/opendis6/all/conanfile.py

* Update recipes/opendis6/all/conanfile.py

* Update recipes/opendis6/all/conanfile.py

* Update recipes/opendis6/all/test_package/CMakeLists.txt

* Update recipes/opendis6/all/conanfile.py

---------

Signed-off-by: Uilian Ries <[email protected]>
Co-authored-by: Uilian Ries <[email protected]>
Co-authored-by: Rubén Rincón Blanco <[email protected]>
  • Loading branch information
3 people authored Feb 8, 2024
1 parent adc0f73 commit 7ed79e4
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/opendis6/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/opendis6/archive/refs/tags/0.1.0.tar.gz"
sha256: "7acfd6ecdcea03c75f93834c4e8ad532aee03eb0fdd2736c9095e2d548214125"
95 changes: 95 additions & 0 deletions recipes/opendis6/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
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 = ">=1.53.0"

class OpenDis6Conan(ConanFile):
name = "opendis6"
homepage = "https://github.com/crhowell3/opendis6"
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 "17"

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

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

def generate(self):
tc = CMakeToolchain(self)
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 = ["OpenDIS6"]
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")
8 changes: 8 additions & 0 deletions recipes/opendis6/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(OpenDIS CONFIG REQUIRED)

add_executable(test_package_dis test_package.cpp)
target_link_libraries(test_package_dis PRIVATE OpenDIS::OpenDIS6)
set_target_properties(test_package_dis PROPERTIES CXX_STANDARD 17)
26 changes: 26 additions & 0 deletions recipes/opendis6/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/opendis6/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>

#include "dis6/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/opendis6/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.1.0":
folder: all

0 comments on commit 7ed79e4

Please sign in to comment.