Repository: conan-io/conan-center-index

Issue:
[request] open-dis-cpp/ 1.0.1
### Package Name/Version

open-dis-cpp/1.0.1

### Webpage

https://www.open-dis.org

### Source code

https://github.com/open-dis/open-dis-cpp

### Description of the library/tool

open-dis-cpp is a C++ implementation of the IEEE 1278.1 standard for Distributed Interactive Simulation (DIS).


Discussion:

Resolving patch:
diff --git a/recipes/open-dis-cpp/all/conanfile.py b/recipes/open-dis-cpp/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/open-dis-cpp/all/conanfile.py
@@ -0,0 +1,94 @@
+import os
+
+from conan import ConanFile
+from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
+from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
+from conan.tools.layout import basic_layout
+from conan.tools.build import check_min_cppstd
+from conan.tools.scm import Version
+
+required_conan_version = ">=1.53.0"
+
+
+class OpenDisConan(ConanFile):
+    name = "open-dis-cpp"
+    homepage = "https://open-dis.org"
+    description = "C++ implementation of the IEEE-1278.1 Distributed Interactive Simulation (DIS) application protocol v6 and v7"
+    topics = ("library","protocol","simulation-framework","dis")
+    url = "https://github.com/conan-io/conan-center-index"
+    license = "BSD-2-Clause"
+    settings = "os", "arch", "compiler", "build_type"
+    options = {
+        "shared": [True, False],
+        "fPIC": [True, False]
+    }
+    default_options = {
+        "shared": False,
+        "fPIC": True
+    }
+
+    def export_sources(self):
+        export_conandata_patches(self)
+
+    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 config_options(self):
+        if self.settings.os == "Windows":
+            del self.options.fPIC
+
+    def configure(self):
+        if self.options.shared:
+            self.options.rm_safe("fPIC")
+
+    def validate(self):
+        if self.info.settings.get_safe("compiler.cppstd"):
+            check_min_cppstd(self, 11)
+
+    def source(self):
+        get(self, **self.conan_data["sources"][self.version],
+            destination=self.source_folder, strip_root=True)
+
+    def build(self):
+        apply_conandata_patches(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.set_property("cmake_find_mode", "both")
+        self.cpp_info.set_property("cmake_module_file_name", "OpenDIS")
+        self.cpp_info.set_property("cmake_file_name", "OpenDIS")
+
+        # TODO: back to global scope in conan v2 once cmake_find_package* generators removed
+        self.cpp_info.components["OpenDIS6"].libs = ["OpenDIS6"]
+        self.cpp_info.components["OpenDIS7"].libs = ["OpenDIS7"]
+
+        # TODO: to remove in conan v2 once cmake_find_package* generators removed
+        self.cpp_info.filenames["cmake_find_package"] = "OpenDIS"
+        self.cpp_info.filenames["cmake_find_package_multi"] = "OpenDIS"
+        self.cpp_info.names["cmake_find_package"] = "OpenDIS"
+        self.cpp_info.names["cmake_find_package_multi"] = "OpenDIS"
+        self.cpp_info.components["OpenDIS6"].names["cmake_find_package"] = "OpenDIS6"
+        self.cpp_info.components["OpenDIS6"].names["cmake_find_package_multi"] = "OpenDIS6"
+        self.cpp_info.components["OpenDIS6"].set_property("cmake_target_name", "OpenDIS::OpenDIS6")
+        self.cpp_info.components["OpenDIS6"].set_property("cmake_target_aliases", ["OpenDIS::DIS6","OpenDIS6"])
+        self.cpp_info.components["OpenDIS7"].names["cmake_find_package"] = "OpenDIS7"
+        self.cpp_info.components["OpenDIS7"].names["cmake_find_package_multi"] = "OpenDIS7"
+        self.cpp_info.components["OpenDIS7"].set_property("cmake_target_name", "OpenDIS::OpenDIS7")
+        self.cpp_info.components["OpenDIS7"].set_property("cmake_target_aliases", ["OpenDIS::DIS7","OpenDIS7"])


Test patch:
diff --git a/recipes/open-dis-cpp/all/test_package/CMakeLists.txt b/recipes/open-dis-cpp/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/open-dis-cpp/all/test_package/CMakeLists.txt
@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 3.15)
+project(test_package LANGUAGES CXX)
+
+find_package(OpenDIS REQUIRED)
+
+add_executable(test_package_dis6 test_package.cpp)
+target_link_libraries(test_package_dis6 PRIVATE OpenDIS::OpenDIS6)
+
+
+add_executable(test_package_dis7 test_package.cpp)
+target_compile_definitions(test_package_dis7 PRIVATE TEST_DIS7)
+target_link_libraries(test_package_dis7 PRIVATE OpenDIS::OpenDIS7)
diff --git a/recipes/open-dis-cpp/all/test_package/conanfile.py b/recipes/open-dis-cpp/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/open-dis-cpp/all/test_package/conanfile.py
@@ -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_dis6"), env="conanrun")
+            self.run(os.path.join(self.cpp.build.bindirs[0], "test_package_dis7"), env="conanrun")
diff --git a/recipes/open-dis-cpp/all/test_package/test_package.cpp b/recipes/open-dis-cpp/all/test_package/test_package.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/open-dis-cpp/all/test_package/test_package.cpp
@@ -0,0 +1,18 @@
+#ifdef TEST_DIS7
+#include <dis7/EntityStatePdu.h>
+#else
+#include <dis6/EntityStatePdu.h>
+#endif
+
+#include <iostream>
+
+int main() {
+  DIS::EntityStatePdu pdu1, pdu2;
+
+  DIS::DataStream ds(DIS::BIG);
+  pdu1.marshal(ds);
+  pdu2.unmarshal(ds);
+
+  std::cout << "Success\n";
+  return EXIT_SUCCESS;
+}
diff --git a/recipes/open-dis-cpp/all/test_v1_package/CMakeLists.txt b/recipes/open-dis-cpp/all/test_v1_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/open-dis-cpp/all/test_v1_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.1)
+project(test_package)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup(TARGETS)
+
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
+                 ${CMAKE_CURRENT_BINARY_DIR}/test_package/)
diff --git a/recipes/open-dis-cpp/all/test_v1_package/conanfile.py b/recipes/open-dis-cpp/all/test_v1_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/open-dis-cpp/all/test_v1_package/conanfile.py
@@ -0,0 +1,17 @@
+from conans import ConanFile, CMake, tools
+import os
+
+
+class TestPackageConan(ConanFile):
+    settings = "os", "arch", "compiler", "build_type"
+    generators = "cmake", "cmake_find_package_multi"
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def test(self):
+        if not tools.cross_building(self):
+            self.run(os.path.join("bin", "test_package_dis6"), run_environment=True)
+            self.run(os.path.join("bin", "test_package_dis7"), run_environment=True)