-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
7 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
versions: | ||
"20200424": | ||
folder: "all" |