Repository: conan-io/conan-center-index

Issue:
[request] console_bridge
### Package Name/Version

console_bridge/1.0.2

### Webpage

https://github.com/ros/console_bridge

### Source code

https://github.com/ros/console_bridge

### Description of the library/tool

A ROS-independent library for logging that seamlessly pipes into rosconsole/rosout for ROS-dependent packages.

Useful for libraries that are expected to be used both with ROS and independently from it, such as [`urdfdom`](https://github.com/ros/urdfdom).

[![Packaging status](https://repology.org/badge/tiny-repos/console-bridge.svg)](https://repology.org/project/console-bridge/versions)


Discussion:

Resolving patch:
diff --git a/recipes/console_bridge/all/conanfile.py b/recipes/console_bridge/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/console_bridge/all/conanfile.py
@@ -0,0 +1,79 @@
+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 copy, get, rm, rmdir
+
+required_conan_version = ">=1.53.0"
+
+
+class PackageConan(ConanFile):
+    name = "console_bridge"
+    description = "A ROS-independent library for logging that seamlessly pipes into rosconsole/rosout for ROS-dependent packages"
+    license = "BSD-3-Clause"
+    url = "https://github.com/conan-io/conan-center-index"
+    homepage = "https://github.com/ros/console_bridge"
+    topics = ("logging", "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 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):
+        pass
+
+    def validate(self):
+        if self.settings.compiler.cppstd:
+            check_min_cppstd(self, self._min_cppstd)
+
+    def source(self):
+        get(self, **self.conan_data["sources"][self.version], strip_root=True)
+
+    def generate(self):
+        tc = CMakeToolchain(self)
+        tc.generate()
+        CMakeDeps(self).generate()
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def package(self):
+        copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
+        cmake = CMake(self)
+        cmake.install()
+
+        rm(self, "*.pdb", os.path.join(self.package_folder))
+        rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
+        rmdir(self, os.path.join(self.package_folder, "lib", "console_bridge"))
+        rmdir(self, os.path.join(self.package_folder, "CMake"))
+
+    def package_info(self):
+        self.cpp_info.libs = ["console_bridge"]
+
+
+        if self.settings.os in ["Linux", "FreeBSD"]:
+            self.cpp_info.system_libs = ["m"]


Test patch:
diff --git a/recipes/console_bridge/all/test_package/CMakeLists.txt b/recipes/console_bridge/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/console_bridge/all/test_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.15)
+project(test_package CXX)
+
+find_package(console_bridge REQUIRED CONFIG)
+
+add_executable(${PROJECT_NAME} test_package.cpp)
+target_link_libraries(${PROJECT_NAME} PRIVATE console_bridge::console_bridge)
+target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
diff --git a/recipes/console_bridge/all/test_package/conanfile.py b/recipes/console_bridge/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/console_bridge/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/console_bridge/all/test_package/test_package.cpp b/recipes/console_bridge/all/test_package/test_package.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/console_bridge/all/test_package/test_package.cpp
@@ -0,0 +1,9 @@
+#include <cstdlib>
+
+#include <console_bridge/console.h>
+
+int main() {
+    console_bridge::setLogLevel(console_bridge::CONSOLE_BRIDGE_LOG_DEBUG);
+    CONSOLE_BRIDGE_logInform("CONSOLE_BRIDGE_logInform() ran successfully");
+    return EXIT_SUCCESS;
+}