Skip to content

Commit

Permalink
feat: add libmbus (#1172)
Browse files Browse the repository at this point in the history
* feat: add libmbus

* Apply suggestions from code review

Co-Authored-By: Anonymous Maarten <madebr@users.noreply.github.com>

* chore: bump libmbus

* chore: remove pkgconfig

* Apply suggestions from code review

Co-Authored-By: Anonymous Maarten <madebr@users.noreply.github.com>

Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
  • Loading branch information
gocarlos and madebr committed Apr 30, 2020
1 parent 63f0e8d commit e006ef2
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/libmbus/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8.11)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory(source_subfolder)
4 changes: 4 additions & 0 deletions recipes/libmbus/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"20200424":
sha256: 0357e8795b1685a493399414a676827f4084fcee7806648af65e753ef5734b34
url: https://github.com/rscada/libmbus/archive/baf03e2a47500e088161471829a05a3f42f45a0b.zip
80 changes: 80 additions & 0 deletions recipes/libmbus/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os
from conans import CMake, ConanFile, tools
from conans.errors import ConanInvalidConfiguration


class LibMbusConan(ConanFile):
name = "libmbus"
license = "BSD-3-Clause"
homepage = "https://github.com/rscada/libmbus"
url = "https://github.com/conan-io/conan-center-index"
description = """Meter-bus library and utility programs"""
topics = "conan", "mbus", "metering", "iot", "meter", "bus", "protocol"
exports_sources = "CMakeLists.txt"
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False]
}
default_options = {
"shared": False,
"fPIC": True
}
generators = "cmake", "cmake_find_package"

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
if self.settings.os not in ["Linux"]:
raise ConanInvalidConfiguration("Only Linux supported")
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + \
os.path.basename(
self.conan_data["sources"][self.version]["url"]).split(".")[0]
os.rename(extracted_dir, self._source_subfolder)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions['LIBMBUS_ENABLE_COVERAGE'] = False
self._cmake.definitions['LIBMBUS_BUILD_TESTS'] = False
self._cmake.definitions['LIBMBUS_BUILD_EXAMPLES'] = False
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def build(self):
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "share"))
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder,
"lib", "libmbus", "cmake"))

def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
if self.settings.os == "Linux":
self.cpp_info.system_libs = ["pthread", "m"]
8 changes: 8 additions & 0 deletions recipes/libmbus/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 2.8.11)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
18 changes: 18 additions & 0 deletions recipes/libmbus/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os

from conans import ConanFile, CMake, tools


class TestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
bin_path = self.run(bin_path, run_environment=True)
19 changes: 19 additions & 0 deletions recipes/libmbus/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <mbus/mbus.h>
#include <stdio.h>
#include <string.h>

int main() {
mbus_handle *handle;
char *host = "localhost";
long port = 8000;

if ((handle = mbus_context_tcp(host, port)) == NULL) {
fprintf(stderr, "Scan failed: Could not initialize M-Bus context: %s\n",
mbus_error_str());
return 0;
}

mbus_context_free(handle);

return 0;
}
4 changes: 4 additions & 0 deletions recipes/libmbus/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
versions:
"20200424":
folder: "all"

0 comments on commit e006ef2

Please sign in to comment.