Repository: conan-io/conan-center-index

Issue:
[request] embag
### Package Name/Version

embag/0.0.42

### Webpage

https://github.com/embarktrucks/embag

### Source code

https://github.com/embarktrucks/embag

### Description of the library/tool

Embag reads [ROS](https://wiki.ros.org) [bag files](http://wiki.ros.org/Bags/Format/2.0) quickly without their [message descriptions](http://wiki.ros.org/msg) and without any ROS dependencies.

There are currently no libraries available on ConanCenter and this is a good candidate. Another good option is [starship-technologies/bag_rdr](https://github.com/starship-technologies/bag_rdr), but it requires ROS to deserialize messages.



Discussion:

Resolving patch:
diff --git a/recipes/embag/all/conanfile.py b/recipes/embag/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/embag/all/conanfile.py
@@ -0,0 +1,91 @@
+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 get, copy, rm
+from conan.tools.microsoft import is_msvc
+
+required_conan_version = ">=1.53.0"
+
+
+class EmbagConan(ConanFile):
+    name = "embag"
+    description = "Schema and dependency free ROS bag reader"
+    license = "MIT"
+    url = "https://github.com/conan-io/conan-center-index"
+    homepage = "https://github.com/embarktrucks/embag"
+    topics = ("rosbag", "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):
+        copy(self, "CMakeLists.txt",
+             src=self.recipe_folder,
+             dst=os.path.join(self.export_sources_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 layout(self):
+        cmake_layout(self, src_folder="src")
+
+    def requirements(self):
+        # INFO: embag.h includes boost/variant.hpp
+        self.requires("boost/1.82.0", transitive_headers=True)
+        # INFO: decompression.h includes lz4frame.h
+        self.requires("lz4/1.9.4", transitive_headers=True)
+        # INFO: ros_bag_types.h includes bzlib.h
+        self.requires("bzip2/1.0.8", transitive_headers=True)
+
+    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()
+        deps = CMakeDeps(self)
+        deps.generate()
+
+    def build(self):
+        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()
+        rm(self, "*.pdb", self.package_folder, recursive=True)
+
+    def package_info(self):
+        self.cpp_info.libs = ["embag"]
+
+        if self.settings.os in ["Linux", "FreeBSD"]:
+            self.cpp_info.system_libs = ["m"]
+        if is_msvc(self):
+            # For a #if __cplusplus < 201402L check in lib/util.h, which is a public header
+            self.cpp_info.cxxflags.append("/Zc:__cplusplus")


Test patch:
diff --git a/recipes/embag/all/test_package/CMakeLists.txt b/recipes/embag/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/embag/all/test_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.15)
+project(test_package LANGUAGES CXX)
+
+find_package(embag REQUIRED CONFIG)
+
+add_executable(${PROJECT_NAME} test_package.cpp)
+target_link_libraries(${PROJECT_NAME} PRIVATE embag::embag)
+target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
diff --git a/recipes/embag/all/test_package/conanfile.py b/recipes/embag/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/embag/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/embag/all/test_package/test_package.cpp b/recipes/embag/all/test_package/test_package.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/embag/all/test_package/test_package.cpp
@@ -0,0 +1,18 @@
+#include <cstdlib>
+#include <iostream>
+
+#include <embag/view.h>
+
+int main() {
+    Embag::View view{};
+    // Do not load any bag file for testing
+    // view.addBag("xyz.bag");
+    const auto start_time = view.getStartTime();
+    const auto end_time = view.getEndTime();
+    std::cout << "Start time is " << start_time.secs + start_time.nsecs * 1e-9 << std::endl;
+    std::cout << "End time is " << end_time.secs + end_time.nsecs * 1e-9 << std::endl;
+    for (const auto &message : view.getMessages()) {
+        message->print();
+    }
+    return EXIT_SUCCESS;
+}