Repository: conan-io/conan-center-index

Issue:
[request] urdfdom
### Package Name/Version

urdfdom

### Webpage

https://github.com/ros/urdfdom

### Source code

https://github.com/ros/urdfdom

### Description of the library/tool

The urdfdom library provides core data structures and a simple XML parsers for populating the class data structures from an [URDF (U-Robot Description Format) file](https://www.mathworks.com/help/sm/ug/urdf-model-import.html).

A core ROS (Robot Operating System) library for dealing with URDF files.

[![Packaging status](https://repology.org/badge/tiny-repos/urdfdom.svg)](https://repology.org/project/urdfdom/versions)


Discussion:

Resolving patch:
diff --git a/recipes/urdfdom/all/conanfile.py b/recipes/urdfdom/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/urdfdom/all/conanfile.py
@@ -0,0 +1,107 @@
+import os
+
+from conan import ConanFile
+from conan.tools.build import check_min_cppstd
+from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
+from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rm, rmdir
+
+required_conan_version = ">=1.53.0"
+
+
+class PackageConan(ConanFile):
+    name = "urdfdom"
+    description = "Data structures and parsers to access URDF files using the DOM model"
+    license = "BSD-3-Clause"
+    url = "https://github.com/conan-io/conan-center-index"
+    homepage = "https://github.com/ros/urdfdom"
+    topics = ("urdf", "ros", "robotics")
+    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
+
+    def export_sources(self):
+        export_conandata_patches(self)
+
+    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 layout(self):
+        cmake_layout(self, src_folder="src")
+
+    def requirements(self):
+        self.requires("tinyxml/2.6.2", transitive_headers=True)
+        self.requires("console_bridge/1.0.2")
+
+    def validate(self):
+        if self.settings.compiler.cppstd:
+            check_min_cppstd(self, self._min_cppstd)
+
+    def source(self):
+        # urdfdom packages its headers separately as urdfdom_headers.
+        # There is no obvious benefit of doing the same for the Conan package,
+        # so we simply merge the headers into the main source tree.
+        sources = self.conan_data["sources"][self.version]
+        get(self, **sources["urdfdom_headers"], strip_root=True,
+            destination=os.path.join(self.source_folder, "urdf_parser"))
+        get(self, **sources["urdfdom"], strip_root=True, destination=self.source_folder)
+
+    def generate(self):
+        tc = CMakeToolchain(self)
+        tc.variables["APPEND_PROJECT_NAME_TO_INCLUDEDIR"] = False
+        tc.variables["BUILD_TESTING"] = False
+        tc.variables["BUILD_APPS"] = False
+        if not self.options.shared:
+            tc.preprocessor_definitions["URDFDOM_STATIC"] = "1"
+        tc.generate()
+        CMakeDeps(self).generate()
+
+    def _patch_sources(self):
+        apply_conandata_patches(self)
+        # Do not hard-code libraries to SHARED
+        parser_cmakelists = os.path.join(self.source_folder, "urdf_parser", "CMakeLists.txt")
+        replace_in_file(self, parser_cmakelists, " SHARED", "")
+
+    def build(self):
+        self._patch_sources()
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def package(self):
+        copy(self, "LICENSE",
+            dst=os.path.join(self.package_folder, "licenses"),
+            src=self.source_folder)
+        cmake = CMake(self)
+        cmake.install()
+        rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
+        rmdir(self, os.path.join(self.package_folder, "lib", "urdfdom"))
+        rmdir(self, os.path.join(self.package_folder, "CMake"))
+        rmdir(self, os.path.join(self.package_folder, "share"))
+        rm(self, "*.pdb", self.package_folder, recursive=True)
+
+    def package_info(self):
+        self.cpp_info.libs = [
+            "urdfdom_model",
+            "urdfdom_model_state",
+            "urdfdom_sensor",
+            "urdfdom_world",
+        ]
+
+        if not self.options.shared:
+            self.cpp_info.defines.append("URDFDOM_STATIC=1")


Test patch:
diff --git a/recipes/urdfdom/all/test_package/CMakeLists.txt b/recipes/urdfdom/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/urdfdom/all/test_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.15)
+project(test_package CXX)
+
+find_package(urdfdom REQUIRED CONFIG)
+
+add_executable(${PROJECT_NAME} test_package.cpp)
+target_link_libraries(${PROJECT_NAME} PRIVATE urdfdom::urdfdom)
+target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
diff --git a/recipes/urdfdom/all/test_package/conanfile.py b/recipes/urdfdom/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/urdfdom/all/test_package/conanfile.py
@@ -0,0 +1,26 @@
+from conan import ConanFile
+from conan.tools.build import can_run
+from conan.tools.cmake import cmake_layout, CMake
+import os
+
+
+class TestPackageConan(ConanFile):
+    settings = "os", "arch", "compiler", "build_type"
+    generators = "CMakeDeps", "CMakeToolchain", "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):
+            bin_path = os.path.join(self.cpp.build.bindir, "test_package")
+            self.run(bin_path, env="conanrun")
diff --git a/recipes/urdfdom/all/test_package/test_package.cpp b/recipes/urdfdom/all/test_package/test_package.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/urdfdom/all/test_package/test_package.cpp
@@ -0,0 +1,15 @@
+#include <cstdlib>
+#include <iostream>
+#include <string>
+
+#include <urdf_parser/urdf_parser.h>
+
+int main() {
+    std::string test_str =
+        "<robot name=\"test\" version=\"1.0\">"
+        "  <link name=\"l1\"/>"
+        "</robot>";
+    urdf::ModelInterfaceSharedPtr urdf = urdf::parseURDF(test_str);
+    std::cout << "urdf::parseURDF() ran successfully" << std::endl;
+    return EXIT_SUCCESS;
+}