Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embag: add new recipe #17575

Merged
merged 11 commits into from
Sep 4, 2023
28 changes: 28 additions & 0 deletions recipes/embag/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.15)
valgur marked this conversation as resolved.
Show resolved Hide resolved
project(embag LANGUAGES CXX)

find_package(Boost REQUIRED COMPONENTS iostreams headers)
find_package(lz4 REQUIRED CONFIG)
find_package(BZip2 REQUIRED CONFIG)

file(GLOB_RECURSE embag_SOURCES "lib/*.cc")
add_library(embag ${embag_SOURCES})
set_target_properties(embag PROPERTIES
# embag does not export any symbols otherwise
WINDOWS_EXPORT_ALL_SYMBOLS ON
)
target_compile_features(embag PUBLIC cxx_std_14)
target_link_libraries(embag PUBLIC
Boost::iostreams
Boost::headers
lz4::lz4
BZip2::BZip2
)

install(TARGETS embag)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/embag
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
)
4 changes: 4 additions & 0 deletions recipes/embag/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"0.0.42":
url: "https://github.com/embarktrucks/embag/archive/refs/tags/0.0.42.tar.gz"
sha256: "60b22ba9355528040046b7e2c3ee968798ad5773a9eb7a1d13cf33dc47e2adec"
93 changes: 93 additions & 0 deletions recipes/embag/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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, replace_in_file

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 _patch_sources(self):
# Disable a C++11 workaround that is broken on MSVC
replace_in_file(self, os.path.join(self.source_folder, "lib", "util.h"),
"#if __cplusplus < 201402L", "#if false")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@valgur I think the best way to do that is by adding this as a patch field in the conandata.yml. It would be good to have it there in case of opening a PR upstream to add this patch in the future.


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()
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"]
8 changes: 8 additions & 0 deletions recipes/embag/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(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)
26 changes: 26 additions & 0 deletions recipes/embag/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
18 changes: 18 additions & 0 deletions recipes/embag/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
3 changes: 3 additions & 0 deletions recipes/embag/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.0.42":
folder: all