From cf3b616c6565ed5e51db42bb28ea3cc63a070a86 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Tue, 17 Mar 2020 21:25:08 +0100 Subject: [PATCH 01/28] build: add cmake support feat: add cmake support chore: remove old code revert: remove mbus_data_record_unit build: do not break existing building system --- .gitignore | 7 +- CMakeLists.txt | 150 ++++++++++++++++++++++++++++++++++++++++++ README.md | 32 ++++++++- bin/CMakeLists.txt | 19 ++++++ build.sh | 24 ++----- cmake/Config.cmake.in | 4 ++ mbus/config.h.in | 59 +++++++++++++++++ test/CMakeLists.txt | 5 ++ 8 files changed, 279 insertions(+), 21 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 bin/CMakeLists.txt create mode 100644 cmake/Config.cmake.in create mode 100644 mbus/config.h.in create mode 100644 test/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 085383d5..1136a1aa 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,6 @@ test/Makefile.in /compile config.guess config.sub -config.h.in configure /depcomp /install-sh @@ -72,3 +71,9 @@ test/test-frames/*.xml.new test/error-frames/*.xml.new test/unsupported-frames/*.xml.new +/build/ +_build/ + +# IDE +/.vscode/ +CMakeLists.txt.user \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..040d1613 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,150 @@ +cmake_minimum_required(VERSION 3.8) + +project(libmbus LANGUAGES CXX C) + +set(PROJECT_VERSION "0.9.0") + +if(CMAKE_BUILD_TYPE STREQUAL "") + message(STATUS "CMAKE_BUILD_TYPE empty setting to Debug") + set(CMAKE_BUILD_TYPE "Debug") +endif() + +option(LIBMBUS_BUILD_EXAMPLES "build examples" OFF) +option(LIBMBUS_BUILD_TESTS "build tests" OFF) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_C_STANDARD 11) + +# Append our module directory to CMake +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}) + +# Set the output of the libraries and executables. +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) +set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) + +# +# static analysis +# + +if(LIBMBUS_RUN_CLANG_TIDY) + find_program( + CLANG_TIDY_EXE + NAMES "clang-tidy" + DOC "/usr/bin/clang-tidy") + if(NOT CLANG_TIDY_EXE) + message(WARNING "clang-tidy not found.") + else() + message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}") + set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}") + endif() +endif(LIBMBUS_RUN_CLANG_TIDY) + +include(CheckIncludeFile) + +check_include_file(dlfcn.h HAVE_DLFCN_H) +check_include_file(inttypes.h HAVE_INTTYPES_H) +check_include_file(memory.h HAVE_MEMORY_H) +check_include_file(stdlib.h HAVE_STDINT_H) +check_include_file(stdint.h HAVE_STDLIB_H) +check_include_file(strings.h HAVE_STRINGS_H) +check_include_file(string.h HAVE_STRING_H) +check_include_file(sys/stat.h HAVE_SYS_STAT_H) +check_include_file(sys/types.h HAVE_SYS_TYPES_H) +check_include_file(unistd.h HAVE_UNISTD_H) + +# +# library +# +set(PACKAGE_STRING "${PROJECT_NAME} ${PROJECT_VERSION}") + +set(PACKAGE_VERSION "${PROJECT_VERSION}") +set(VERSION "${PROJECT_VERSION}") +configure_file(${CMAKE_CURRENT_LIST_DIR}/mbus/config.h.in + ${CMAKE_CURRENT_LIST_DIR}/config.h) + +add_library( + ${PROJECT_NAME} + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-protocol.c + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-protocol.h + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-tcp.c + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-tcp.h + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus.c + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus.h + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-protocol-aux.c + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-protocol-aux.h + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-serial.c + ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-serial.h) +target_include_directories( + ${PROJECT_NAME} + PUBLIC $ + $ + $) +target_link_libraries(${PROJECT_NAME} PRIVATE m) +target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wno-pedantic) + +if(CLANG_TIDY_EXE) + set_target_properties(${PROJECT_NAME} PROPERTIES CXX_CLANG_TIDY + "${DO_CLANG_TIDY}") +endif() + +add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) + +# +# examples +# + +if(LIBMBUS_BUILD_EXAMPLES) + message(STATUS "building examples") + add_subdirectory(bin) +endif() + +# +# tests +# + +if(LIBMBUS_BUILD_TESTS) + message(STATUS "building tests") + enable_testing() + add_subdirectory(test) +endif() + +# +# install +# + +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +set(LIBMBUS_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) +install( + TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}Targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib) + +install( + EXPORT ${PROJECT_NAME}Targets + DESTINATION ${LIBMBUS_CONFIG_INSTALL_DIR} + NAMESPACE ${PROJECT_NAME}:: + COMPONENT dev) + +configure_package_config_file(cmake/Config.cmake.in ${PROJECT_NAME}Config.cmake + INSTALL_DESTINATION ${LIBMBUS_CONFIG_INSTALL_DIR}) +write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake + COMPATIBILITY SameMajorVersion) +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION ${LIBMBUS_CONFIG_INSTALL_DIR} + COMPONENT dev) + +# BUG: installing empty dirs https://gitlab.kitware.com/cmake/cmake/issues/17122 +install( + DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/mbus/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mbus/ + COMPONENT dev + FILES_MATCHING + PATTERN "*.h") diff --git a/README.md b/README.md index 27d393c0..133c243d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# libmbus: M-bus Library from Raditex Control (http://www.rscada.se) ![Build Status](https://travis-ci.org/rscada/libmbus.svg?branch=master) +# libmbus: M-bus Library from Raditex Control (http://www.rscada.se) + +![Build Status](https://travis-ci.org/rscada/libmbus.svg?branch=master) libmbus is an open source library for the M-bus (Meter-Bus) protocol. @@ -8,4 +10,32 @@ signals on the M-Bus, and the protocol and data format used in transmissions on the M-Bus. The role of libmbus is to decode/encode M-bus data, and to handle the communication with M-Bus devices. + +## BUILD + +with cmake + +```bash +rm -rf _build +mkdir _build +cd _build +# configure +# e.g. on linux +cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON +# e.g. for a target device +cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain/foo-bar-baz.cmake +# compile +cmake --build . -j +# install - optional +cmake --build . --target install +``` + +## CONSUME + +```cmake +find_package(libmbus) +add_executable(my_app main.cpp) +target_link_libraries(my_app libmbus::libmbus) +``` + For more information see http://www.rscada.se/libmbus diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt new file mode 100644 index 00000000..73e15002 --- /dev/null +++ b/bin/CMakeLists.txt @@ -0,0 +1,19 @@ +function(add_example SRCS) + add_executable(${SRCS} ${CMAKE_CURRENT_LIST_DIR}/${SRCS}.c) + target_link_libraries(${SRCS} PRIVATE libmbus::libmbus) +endfunction() + +add_example(mbus-serial-request-data) +add_example(mbus-serial-request-data-multi-reply) +add_example(mbus-serial-scan) +add_example(mbus-serial-scan-secondary) +add_example(mbus-serial-select-secondary) +add_example(mbus-serial-set-address) +add_example(mbus-serial-switch-baudrate) +add_example(mbus-tcp-application-reset) +add_example(mbus-tcp-raw-send) +add_example(mbus-tcp-request-data) +add_example(mbus-tcp-request-data-multi-reply) +add_example(mbus-tcp-scan) +add_example(mbus-tcp-scan-secondary) +add_example(mbus-tcp-select-secondary) diff --git a/build.sh b/build.sh index 34c2799b..16653a9f 100755 --- a/build.sh +++ b/build.sh @@ -1,21 +1,7 @@ #!/bin/sh -# -if [ -f Makefile ]; then - # use existing automake files - echo >> /dev/null -else - # regenerate automake files - echo "Running autotools..." - - autoheader \ - && aclocal \ - && case \ - $(uname) in Darwin*) glibtoolize --ltdl --copy --force ;; \ - *) libtoolize --ltdl --copy --force ;; esac \ - && automake --add-missing --copy \ - && autoconf \ - && ./configure -fi - -make +rm -rf _build +mkdir _build +cd _build +cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON +cmake --build . -j diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 00000000..9c15f36a --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/mbus/config.h.in b/mbus/config.h.in new file mode 100644 index 00000000..369c7c80 --- /dev/null +++ b/mbus/config.h.in @@ -0,0 +1,59 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H "@HAVE_DLFCN_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_INTTYPES_H "@HAVE_INTTYPES_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MEMORY_H "@HAVE_MEMORY_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDINT_H "@HAVE_STDINT_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDLIB_H "@HAVE_STDLIB_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRINGS_H "@HAVE_STRINGS_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRING_H "@HAVE_STRING_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H "@HAVE_SYS_STAT_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H "@HAVE_SYS_TYPES_H@" + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H "@HAVE_UNISTD_H@" + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "libmbus" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "info@rscada.se" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "libmbus" + +/* Define to the full name and version of this package. */ +#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "libmbus" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "http://www.rscada.se/libmbus/" + +/* Define to the version of this package. */ +#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" + +/* Version number of package */ +#cmakedefine VERSION "@PACKAGE_VERSION@" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..0303d236 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,5 @@ +add_executable(mbus_parse ${CMAKE_CURRENT_LIST_DIR}/mbus_parse.c) +target_link_libraries(mbus_parse PRIVATE libmbus::libmbus) + +add_executable(mbus_parse_hex ${CMAKE_CURRENT_LIST_DIR}/mbus_parse_hex.c) +target_link_libraries(mbus_parse_hex PRIVATE libmbus::libmbus) From ed61769f0203bf919d0a3b76b9866ee3afc35027 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Fri, 20 Mar 2020 15:38:29 +0100 Subject: [PATCH 02/28] build: add coverage information --- CMakeLists.txt | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 040d1613..e32bb538 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,8 @@ endif() option(LIBMBUS_BUILD_EXAMPLES "build examples" OFF) option(LIBMBUS_BUILD_TESTS "build tests" OFF) +option(LIBMBUS_ENABLE_COVERAGE "Build with coverage support" ON) +option(LIBMBUS_RUN_CLANG_TIDY "Use Clang-Tidy for static analysis" OFF) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -42,6 +44,35 @@ if(LIBMBUS_RUN_CLANG_TIDY) endif() endif(LIBMBUS_RUN_CLANG_TIDY) +if(LIBMBUS_ENABLE_COVERAGE) + if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + message( + WARNING + "Code coverage results with an optimised (non-Debug) build may be misleading" + ) + endif(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + # https://discuss.circleci.com/t/problems-using-lcov-gcov-for-c-code/13898 + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + # using Clang + message(STATUS "Not doing coverage...") + elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + # using GCC + message(STATUS "Building with code coverage...") + set(CMAKE_BUILD_TYPE DEBUG) + set(CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} -fPIC -ggdb3 -O0 --coverage -fprofile-arcs -ftest-coverage" + ) + set(CMAKE_C_FLAGS + "${CMAKE_C_FLAGS} -fPIC -ggdb3 -O0 --coverage -fprofile-arcs -ftest-coverage " + ) + set(CMAKE_EXE_LINKER_FLAGS + "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage ") + set(CMAKE_SHARED_LINKER_FLAGS + "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage ") + link_libraries(-lgcov) + endif() +endif() + include(CheckIncludeFile) check_include_file(dlfcn.h HAVE_DLFCN_H) From 6071391ecd725e68776c94f49982096d8275bed7 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 23 Mar 2020 09:22:41 +0100 Subject: [PATCH 03/28] build: add debian package --- CMakeLists.txt | 128 ++++++++++++++++++++++++++++++---------------- cmake-format.yaml | 15 ++++++ 2 files changed, 99 insertions(+), 44 deletions(-) create mode 100644 cmake-format.yaml diff --git a/CMakeLists.txt b/CMakeLists.txt index e32bb538..5e5cc158 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,23 @@ cmake_minimum_required(VERSION 3.8) -project(libmbus LANGUAGES CXX C) - -set(PROJECT_VERSION "0.9.0") +project(libmbus LANGUAGES CXX C VERSION "0.9.0") if(CMAKE_BUILD_TYPE STREQUAL "") message(STATUS "CMAKE_BUILD_TYPE empty setting to Debug") set(CMAKE_BUILD_TYPE "Debug") endif() +# ############################################################################## +# default options -> changed with e.g. cd build && cmake .. +# -DLIBMBUS_BUILD_TESTS=ON +# ############################################################################## + option(LIBMBUS_BUILD_EXAMPLES "build examples" OFF) option(LIBMBUS_BUILD_TESTS "build tests" OFF) -option(LIBMBUS_ENABLE_COVERAGE "Build with coverage support" ON) -option(LIBMBUS_RUN_CLANG_TIDY "Use Clang-Tidy for static analysis" OFF) +option(LIBMBUS_ENABLE_COVERAGE "build with coverage support" ON) +option(LIBMBUS_RUN_CLANG_TIDY "use Clang-Tidy for static analysis" OFF) +option(LIBMBUS_PACKAGE_DEB "build debian package" OFF) +option(LIBMBUS_PACKAGE_RPM "build rpm package" OFF) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -27,9 +32,9 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) -# +# ############################################################################## # static analysis -# +# ############################################################################## if(LIBMBUS_RUN_CLANG_TIDY) find_program( @@ -46,12 +51,9 @@ endif(LIBMBUS_RUN_CLANG_TIDY) if(LIBMBUS_ENABLE_COVERAGE) if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") - message( - WARNING - "Code coverage results with an optimised (non-Debug) build may be misleading" - ) - endif(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") - # https://discuss.circleci.com/t/problems-using-lcov-gcov-for-c-code/13898 + message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading") + endif() + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # using Clang message(STATUS "Not doing coverage...") @@ -59,16 +61,10 @@ if(LIBMBUS_ENABLE_COVERAGE) # using GCC message(STATUS "Building with code coverage...") set(CMAKE_BUILD_TYPE DEBUG) - set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -fPIC -ggdb3 -O0 --coverage -fprofile-arcs -ftest-coverage" - ) - set(CMAKE_C_FLAGS - "${CMAKE_C_FLAGS} -fPIC -ggdb3 -O0 --coverage -fprofile-arcs -ftest-coverage " - ) - set(CMAKE_EXE_LINKER_FLAGS - "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage ") - set(CMAKE_SHARED_LINKER_FLAGS - "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage ") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -ggdb3 -O0 --coverage -fprofile-arcs -ftest-coverage") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -ggdb3 -O0 --coverage -fprofile-arcs -ftest-coverage ") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage ") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage ") link_libraries(-lgcov) endif() endif() @@ -86,15 +82,15 @@ check_include_file(sys/stat.h HAVE_SYS_STAT_H) check_include_file(sys/types.h HAVE_SYS_TYPES_H) check_include_file(unistd.h HAVE_UNISTD_H) -# +# ############################################################################## # library -# +# ############################################################################## + set(PACKAGE_STRING "${PROJECT_NAME} ${PROJECT_VERSION}") set(PACKAGE_VERSION "${PROJECT_VERSION}") set(VERSION "${PROJECT_VERSION}") -configure_file(${CMAKE_CURRENT_LIST_DIR}/mbus/config.h.in - ${CMAKE_CURRENT_LIST_DIR}/config.h) +configure_file(${CMAKE_CURRENT_LIST_DIR}/mbus/config.h.in ${CMAKE_CURRENT_LIST_DIR}/config.h) add_library( ${PROJECT_NAME} @@ -109,32 +105,29 @@ add_library( ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-serial.c ${CMAKE_CURRENT_LIST_DIR}/mbus/mbus-serial.h) target_include_directories( - ${PROJECT_NAME} - PUBLIC $ - $ - $) + ${PROJECT_NAME} PUBLIC $ $ + $) target_link_libraries(${PROJECT_NAME} PRIVATE m) target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wno-pedantic) if(CLANG_TIDY_EXE) - set_target_properties(${PROJECT_NAME} PROPERTIES CXX_CLANG_TIDY - "${DO_CLANG_TIDY}") + set_target_properties(${PROJECT_NAME} PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}") endif() add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) -# +# ############################################################################## # examples -# +# ############################################################################## if(LIBMBUS_BUILD_EXAMPLES) message(STATUS "building examples") add_subdirectory(bin) endif() -# +# ############################################################################## # tests -# +# ############################################################################## if(LIBMBUS_BUILD_TESTS) message(STATUS "building tests") @@ -142,9 +135,9 @@ if(LIBMBUS_BUILD_TESTS) add_subdirectory(test) endif() -# +# ############################################################################## # install -# +# ############################################################################## include(GNUInstallDirs) include(CMakePackageConfigHelpers) @@ -162,20 +155,67 @@ install( NAMESPACE ${PROJECT_NAME}:: COMPONENT dev) -configure_package_config_file(cmake/Config.cmake.in ${PROJECT_NAME}Config.cmake - INSTALL_DESTINATION ${LIBMBUS_CONFIG_INSTALL_DIR}) -write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake - COMPATIBILITY SameMajorVersion) +configure_package_config_file(cmake/Config.cmake.in ${PROJECT_NAME}Config.cmake INSTALL_DESTINATION + ${LIBMBUS_CONFIG_INSTALL_DIR}) +write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake COMPATIBILITY SameMajorVersion) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake DESTINATION ${LIBMBUS_CONFIG_INSTALL_DIR} COMPONENT dev) -# BUG: installing empty dirs https://gitlab.kitware.com/cmake/cmake/issues/17122 install( DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/mbus/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mbus/ COMPONENT dev FILES_MATCHING PATTERN "*.h") + +# ############################################################################## +# package +# mkdir build ; cd build ; cmake .. -DLIBMBUS_PACKAGE_DEB=ON ; cpack .. +# ############################################################################## + +include(InstallRequiredSystemLibraries) + +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Open source M-bus (Meter-Bus) library.") +set(CPACK_PACKAGE_DESCRIPTION + "libmbus is an open source library for the M-bus (Meter-Bus) protocol. +The Meter-Bus is a standard for reading out meter data from electricity meters, +heat meters, gas meters, etc. The M-bus standard deals with both the electrical +signals on the M-Bus, and the protocol and data format used in transmissions +on the M-Bus. The role of libmbus is to decode/encode M-bus data, and to handle +the communication with M-Bus devices. + +For more information see http://www.rscada.se/libmbus") + +set(CPACK_PACKAGE_VENDOR "Raditex Control AB") +set(CPACK_PACKAGE_CONTACT "Stefan Wahren ") +set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/rscada/libmbus/") +set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") +set(CPACK_PACKAGE_RELEASE 1) +set(CPACK_COMPONENTS_ALL devel libs) +set(CPACK_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/LICENSE) + +set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") +set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") +set(CPACK_COMPONENTS_ALL Libraries ApplicationData) + +if(LIBMBUS_PACKAGE_DEB) + set(CPACK_GENERATOR "DEB") + set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Stefan Wahren ") + set(CPACK_DEBIAN_PACKAGE_SECTION "Development/Languages/C and C++") + set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) + set(CPACK_DEBIAN_PACKAGE_VERSION + "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}-${CPACK_PACKAGE_RELEASE}" + ) +endif() + +if(LIBMBUS_PACKAGE_RPM) + set(CPACK_GENERATOR "RPM") + set(CPACK_RPM_PACKAGE_LICENSE "BSD") +endif() + +include(CPack) diff --git a/cmake-format.yaml b/cmake-format.yaml new file mode 100644 index 00000000..60329ed6 --- /dev/null +++ b/cmake-format.yaml @@ -0,0 +1,15 @@ +# https://github.com/cheshirekow/cmake_format + +# How wide to allow formatted cmake files +line_width: 120 + +# How many spaces to tab for indent +tab_size: 2 + +# Format command names consistently as 'lower' or 'upper' case +command_case: "lower" + +first_comment_is_literal: False + +# enable comment markup parsing and reflow +enable_markup: False From 491562be8b6e94cbfd6716c089e1e23c5313aa0d Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 23 Mar 2020 09:38:47 +0100 Subject: [PATCH 04/28] feat: add github actions * feat: add github actions * Update ccpp.yml * build: build and install deb in container * build: clean up --- .github/workflows/ccpp.yml | 20 ++++++++++++++++++++ build.sh | 10 ++++++++++ 2 files changed, 30 insertions(+) create mode 100644 .github/workflows/ccpp.yml diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml new file mode 100644 index 00000000..fcf122bd --- /dev/null +++ b/.github/workflows/ccpp.yml @@ -0,0 +1,20 @@ +name: CMake + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: build examples and tests + run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON && cmake --build . -j + + debian: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: build debian package + run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_PACKAGE_DEB=ON && cpack .. && sudo dpkg -i *.deb && ls /usr/lib diff --git a/build.sh b/build.sh index 16653a9f..80e8d47d 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,17 @@ #!/bin/sh + rm -rf _build mkdir _build cd _build cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON cmake --build . -j + +# build deb + +# rm -rf _build +# mkdir _build +# cd _build +# cmake .. -DLIBMBUS_PACKAGE_DEB=ON +# cpack .. +# dpkg -i *.deb \ No newline at end of file From e88585974da7606cbc36fd8ddbbf37d373f0e003 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 23 Mar 2020 11:11:43 +0100 Subject: [PATCH 05/28] build: add dockerfiles for deb and rpm --- .dockerignore | 2 ++ Dockerfile.deb | 14 ++++++++++++++ Dockerfile.rpm | 14 ++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile.deb create mode 100644 Dockerfile.rpm diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..caa4fdd8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +/_build +/build diff --git a/Dockerfile.deb b/Dockerfile.deb new file mode 100644 index 00000000..1db6923d --- /dev/null +++ b/Dockerfile.deb @@ -0,0 +1,14 @@ +# docker build . -f Dockerfile.deb -t deb_builder + +FROM ubuntu + +RUN apt update -y && apt install -y cmake gcc g++ make +COPY . /tmp +RUN cd /tmp && \ + mkdir build && \ + cd build && \ + cmake .. -DLIBMBUS_PACKAGE_DEB=ON && \ + cpack .. && \ + ls -al && \ + dpkg -i *.deb + diff --git a/Dockerfile.rpm b/Dockerfile.rpm new file mode 100644 index 00000000..2f70df96 --- /dev/null +++ b/Dockerfile.rpm @@ -0,0 +1,14 @@ +# docker build . -f Dockerfile.rpm -t rpm_builder + +FROM fedora + +RUN dnf install -y cmake gcc g++ make rpm-build +COPY . /tmp +RUN cd /tmp && \ + mkdir build && \ + cd build && \ + cmake .. -DLIBMBUS_PACKAGE_RPM=ON && \ + cpack .. && \ + ls -al && \ + rpm -i *.rpm + From bdabbc698366ded5a55dcbd99cb4f010e41dc314 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 23 Mar 2020 13:41:26 +0100 Subject: [PATCH 06/28] build: add documentation --- .github/workflows/ccpp.yml | 8 +++++++ CMakeLists.txt | 43 ++++++++++++++++++++++++++++++++++++-- doxygen.cfg => Doxyfile.in | 9 +++++--- build.sh | 9 +++++++- 4 files changed, 63 insertions(+), 6 deletions(-) rename doxygen.cfg => Doxyfile.in (99%) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index fcf122bd..a2e06292 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -18,3 +18,11 @@ jobs: - uses: actions/checkout@v2 - name: build debian package run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_PACKAGE_DEB=ON && cpack .. && sudo dpkg -i *.deb && ls /usr/lib + + doc: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: build doxygen documentation + run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_DOCS=ON && cmake --build . --target doc + diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e5cc158..10132e63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 3.8) -project(libmbus LANGUAGES CXX C VERSION "0.9.0") +project( + libmbus + LANGUAGES CXX C + VERSION "0.9.0") if(CMAKE_BUILD_TYPE STREQUAL "") message(STATUS "CMAKE_BUILD_TYPE empty setting to Debug") @@ -18,6 +21,7 @@ option(LIBMBUS_ENABLE_COVERAGE "build with coverage support" ON) option(LIBMBUS_RUN_CLANG_TIDY "use Clang-Tidy for static analysis" OFF) option(LIBMBUS_PACKAGE_DEB "build debian package" OFF) option(LIBMBUS_PACKAGE_RPM "build rpm package" OFF) +option(LIBMBUS_BUILD_DOCS "build documentation" OFF) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -200,7 +204,8 @@ set(CPACK_COMPONENTS_ALL devel libs) set(CPACK_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/LICENSE) set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") -set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") +set(CPACK_PACKAGE_FILE_NAME + "${CMAKE_PROJECT_NAME}_${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") set(CPACK_COMPONENTS_ALL Libraries ApplicationData) if(LIBMBUS_PACKAGE_DEB) @@ -219,3 +224,37 @@ if(LIBMBUS_PACKAGE_RPM) endif() include(CPack) + +# ############################################################################## +# doc +# mkdir build ; cd build ; cmake .. -DLIBMBUS_BUILD_DOCS=ON ; cmake --build . --target doc +# ############################################################################## + +if(LIBMBUS_BUILD_DOCS) + message(STATUS "building with documentation") + # Generate targets for documentation + # check if Doxygen is installed + find_package(Doxygen) + + if(Doxygen_FOUND) + # set input and output files + set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) + set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) + + # request to configure the file + configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) + + # note the option ALL which allows to build the docs together with the application + add_custom_target( + doc ALL + COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Generating API documentation with Doxygen" + VERBATIM) + + message(STATUS "Setup up the Doxygen documention build") + + else(Doxygen_FOUND) + message(WARNING "Doxygen need to be installed to generate the doxygen documentation") + endif(Doxygen_FOUND) +endif() diff --git a/doxygen.cfg b/Doxyfile.in similarity index 99% rename from doxygen.cfg rename to Doxyfile.in index ea1b569d..b8393df7 100644 --- a/doxygen.cfg +++ b/Doxyfile.in @@ -25,13 +25,13 @@ DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. -PROJECT_NAME = libmbus +PROJECT_NAME = "@CMAKE_PROJECT_NAME@" # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = +PROJECT_NUMBER = @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@ # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. @@ -581,7 +581,7 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = mbus +INPUT = @CMAKE_CURRENT_LIST_DIR@/mbus # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is @@ -1628,3 +1628,6 @@ GENERATE_LEGEND = YES # the various graphs. DOT_CLEANUP = YES + + +USE_MDFILE_AS_MAINPAGE = @CMAKE_CURRENT_LIST_DIR@/README.md diff --git a/build.sh b/build.sh index 80e8d47d..2d84a15b 100755 --- a/build.sh +++ b/build.sh @@ -14,4 +14,11 @@ cmake --build . -j # cd _build # cmake .. -DLIBMBUS_PACKAGE_DEB=ON # cpack .. -# dpkg -i *.deb \ No newline at end of file +# dpkg -i *.deb + +# build doc + +# mkdir build +# cd build +# cmake .. -DLIBMBUS_BUILD_DOCS=ON +# cmake --build . --target doc \ No newline at end of file From 126d707b5aac3f9890da0eefd9db59757256b917 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 23 Mar 2020 13:54:57 +0100 Subject: [PATCH 07/28] build: install doxygen in ci --- .github/workflows/ccpp.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index a2e06292..9b9b4d7f 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -23,6 +23,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: build doxygen documentation + run: sudo apt install -y doxygen + - name: build doxygen documentation run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_DOCS=ON && cmake --build . --target doc From a967850d1689e8b439b6501529b584c2696d2b17 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 23 Mar 2020 14:07:59 +0100 Subject: [PATCH 08/28] build: remove old build system --- Makefile-static | 25 ----------- Makefile.am | 20 --------- bin/Makefile-static | 24 ----------- bin/Makefile.am | 102 -------------------------------------------- build-deb.sh | 25 ----------- configure.ac | 44 ------------------- libmbus.pc.in | 12 ------ libmbus.spec | 87 ------------------------------------- mbus/Makefile.am | 20 --------- test/Makefile.am | 25 ----------- 10 files changed, 384 deletions(-) delete mode 100644 Makefile-static delete mode 100644 Makefile.am delete mode 100644 bin/Makefile-static delete mode 100644 bin/Makefile.am delete mode 100755 build-deb.sh delete mode 100644 configure.ac delete mode 100644 libmbus.pc.in delete mode 100644 libmbus.spec delete mode 100644 mbus/Makefile.am delete mode 100644 test/Makefile.am diff --git a/Makefile-static b/Makefile-static deleted file mode 100644 index 93da7516..00000000 --- a/Makefile-static +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (c) 2010 -# Robert Johansson -# Raditex AB. -# All rights reserved. - -LIB = libmbus.so - -CFLAGS = -Wall -W -g -fPIC -I. -HEADERS = mbus.h mbus-protocol.h -OBJS = mbus.o mbus-protocol.o - -$(LIB): $(OBJS) - gcc -shared -o $(LIB) $(OBJS) - -all: $(LIB) - -clean: - rm -rf *.o *core core $(LIB) - -test: - (cd test && make) - -install: all - cp $(LIB) /usr/local/freescada/lib - cp $(HEADERS) /usr/local/freescada/include diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index fd519e14..00000000 --- a/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -# -# -# -PACKAGE = @PACKAGE@ -VERSION = @VERSION@ - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = libmbus.pc - - -docdir = $(datadir)/doc/$(PACKAGE)-$(VERSION) -dist_docdir = $(DESTDIR)$(docdir) -doc_DATA = README.md \ - COPYING \ - hardware/MBus_USB.pdf \ - hardware/MBus_USB.txt - -SUBDIRS = mbus bin -ACLOCAL = aclocal -I . -ACLOCAL_AMFLAGS = -Werror -I m4 diff --git a/bin/Makefile-static b/bin/Makefile-static deleted file mode 100644 index 2b04b493..00000000 --- a/bin/Makefile-static +++ /dev/null @@ -1,24 +0,0 @@ -# -# Copyright (C) 2011, Robert Johansson, Raditex AB -# All rights reserved. -# -# rSCADA -# http://www.rSCADA.se -# info@rscada.se -# -CFLAGS=-Wall -g -I.. -LDFLAGS=-L.. -lm -lmbus - -all: mbus-tcp-scan mbus-tcp-request-data - -%.o: %.c - $(CC) -c $(CFLAGS) $< -o $@ - -mbus-tcp-scan: mbus-tcp-scan.o mbus-tcp.o - gcc -o $@ $^ $(LDFLAGS) - -mbus-tcp-request-data: mbus-tcp-request-data.o mbus-tcp.o - gcc -o $@ $^ $(LDFLAGS) - -clean: - rm -rf mbus-tcp-request-data mbus-tcp-scan *.o *~ diff --git a/bin/Makefile.am b/bin/Makefile.am deleted file mode 100644 index 7c9ce412..00000000 --- a/bin/Makefile.am +++ /dev/null @@ -1,102 +0,0 @@ -# ------------------------------------------------------------------------------ -# Copyright (C) 2010, Raditex AB -# All rights reserved. -# -# rSCADA -# http://www.rSCADA.se -# info@rscada.se -# -# ------------------------------------------------------------------------------ -PACKAGE = @PACKAGE@ -VERSION = @VERSION@ - -AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir) -I$(top_srcdir)/src - -noinst_HEADERS = -bin_PROGRAMS = mbus-tcp-scan mbus-tcp-request-data mbus-tcp-request-data-multi-reply \ - mbus-tcp-select-secondary mbus-tcp-scan-secondary \ - mbus-serial-scan mbus-serial-request-data mbus-serial-request-data-multi-reply \ - mbus-serial-select-secondary mbus-serial-scan-secondary \ - mbus-serial-switch-baudrate mbus-tcp-raw-send mbus-tcp-application-reset \ - mbus-serial-set-address - -# tcp -mbus_tcp_scan_LDFLAGS = -L$(top_builddir)/mbus -mbus_tcp_scan_LDADD = -lmbus -lm -mbus_tcp_scan_SOURCES = mbus-tcp-scan.c - -mbus_tcp_request_data_LDFLAGS = -L$(top_builddir)/mbus -mbus_tcp_request_data_LDADD = -lmbus -lm -mbus_tcp_request_data_SOURCES = mbus-tcp-request-data.c - -mbus_tcp_request_data_multi_reply_LDFLAGS = -L$(top_builddir)/mbus -mbus_tcp_request_data_multi_reply_LDADD = -lmbus -lm -mbus_tcp_request_data_multi_reply_SOURCES = mbus-tcp-request-data-multi-reply.c - -mbus_tcp_select_secondary_LDFLAGS = -L$(top_builddir)/mbus -mbus_tcp_select_secondary_LDADD = -lmbus -lm -mbus_tcp_select_secondary_SOURCES = mbus-tcp-select-secondary.c - -mbus_tcp_scan_secondary_LDFLAGS = -L$(top_builddir)/mbus -mbus_tcp_scan_secondary_LDADD = -lmbus -lm -mbus_tcp_scan_secondary_SOURCES = mbus-tcp-scan-secondary.c - -mbus_tcp_raw_send_LDFLAGS = -L$(top_builddir)/mbus -mbus_tcp_raw_send_LDADD = -lmbus -lm -mbus_tcp_raw_send_SOURCES = mbus-tcp-raw-send.c - -mbus_tcp_application_reset_LDFLAGS = -L$(top_builddir)/mbus -mbus_tcp_application_reset_LDADD = -lmbus -lm -mbus_tcp_application_reset_SOURCES = mbus-tcp-application-reset.c - -# serial -mbus_serial_scan_LDFLAGS = -L$(top_builddir)/mbus -mbus_serial_scan_LDADD = -lmbus -lm -mbus_serial_scan_SOURCES = mbus-serial-scan.c - -mbus_serial_request_data_LDFLAGS = -L$(top_builddir)/mbus -mbus_serial_request_data_LDADD = -lmbus -lm -mbus_serial_request_data_SOURCES = mbus-serial-request-data.c - -mbus_serial_request_data_multi_reply_LDFLAGS = -L$(top_builddir)/mbus -mbus_serial_request_data_multi_reply_LDADD = -lmbus -lm -mbus_serial_request_data_multi_reply_SOURCES = mbus-serial-request-data-multi-reply.c - -mbus_serial_select_secondary_LDFLAGS = -L$(top_builddir)/mbus -mbus_serial_select_secondary_LDADD = -lmbus -lm -mbus_serial_select_secondary_SOURCES = mbus-serial-select-secondary.c - -mbus_serial_scan_secondary_LDFLAGS = -L$(top_builddir)/mbus -mbus_serial_scan_secondary_LDADD = -lmbus -lm -mbus_serial_scan_secondary_SOURCES = mbus-serial-scan-secondary.c - -mbus_serial_switch_baudrate_LDFLAGS = -L$(top_builddir)/mbus -mbus_serial_switch_baudrate_LDADD = -lmbus -lm -mbus_serial_switch_baudrate_SOURCES = mbus-serial-switch-baudrate.c - -mbus_serial_set_address_LDFLAGS = -L$(top_builddir)/mbus -mbus_serial_set_address_LDADD = -lmbus -lm -mbus_serial_set_address_SOURCES = mbus-serial-set-address.c - -# man pages -dist_man_MANS = libmbus.1 \ - mbus-tcp-scan.1 \ - mbus-tcp-request-data.1 \ - mbus-tcp-request-data-multi-reply.1 \ - mbus-tcp-select-secondary.1 \ - mbus-tcp-scan-secondary.1 \ - mbus-tcp-raw-send.1 \ - mbus-serial-scan.1 \ - mbus-serial-request-data.1 \ - mbus-serial-request-data-multi-reply.1 \ - mbus-serial-select-secondary.1 \ - mbus-serial-scan-secondary.1 \ - mbus-serial-switch-baudrate.1 - -.pod.1: - pod2man --release=$(VERSION) --center=$(PACKAGE) $< \ - >.pod2man.tmp.$$$$ 2>/dev/null && mv -f .pod2man.tmp.$$$$ $@ || true - @if grep '\' $@ >/dev/null 2>&1; \ - then \ - echo "$@ has some POD errors!"; false; \ - fi diff --git a/build-deb.sh b/build-deb.sh deleted file mode 100755 index 77f3a6be..00000000 --- a/build-deb.sh +++ /dev/null @@ -1,25 +0,0 @@ -# ------------------------------------------------------------------------------ -# Copyright (C) 2012, Robert Johansson , Raditex Control AB -# All rights reserved. -# -# rSCADA -# http://www.rSCADA.se -# info@raditex.nu -# -# ------------------------------------------------------------------------------ - -if [ ! -f Makefile ]; then - # - # regenerate automake files - # - echo "Running autotools..." - - autoheader \ - && aclocal \ - && libtoolize --ltdl --copy --force \ - && automake --add-missing --copy \ - && autoconf -fi - -debuild -i -us -uc -b -#sudo pbuilder build $(NAME)_$(VERSION)-1.dsc diff --git a/configure.ac b/configure.ac deleted file mode 100644 index d14d0e2c..00000000 --- a/configure.ac +++ /dev/null @@ -1,44 +0,0 @@ -dnl ---------------------------------------------------------------------------- -dnl Copyright (C) 2010, Raditex AB -dnl All rights reserved. -dnl -dnl rSCADA -dnl http://www.rSCADA.se -dnl info@rscada.se -dnl -dnl ---------------------------------------------------------------------------- - -LT_CONFIG_LTDL_DIR([libltdl]) - -AC_INIT([libmbus], [0.9.0], [info@rscada.se], [libmbus], [http://www.rscada.se/libmbus/]) -AC_CONFIG_AUX_DIR([libltdl/config]) -AM_INIT_AUTOMAKE([-Wall -Werror foreign]) - -AM_PROG_LIBTOOL -# fix for automake 1.11 & 1.12 -m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) - -LDFLAGS="$LDFLAGS -version-info 0:9:0" - -dnl ---------------------- -dnl -AC_PROG_CC - -AC_CONFIG_HEADERS([config.h]) -AC_CONFIG_FILES([Makefile mbus/Makefile test/Makefile bin/Makefile libmbus.pc]) -AC_OUTPUT - - -echo \ -"---------------------------------------------------------- -Configuration: - - Source location: ${srcdir} - Compile: ${CC} - Compiler flags: ${CFLAGS} - Linker flags: ${LDFLAGS} - Host system type: ${host} - Install path: ${prefix} - - See config.h for further configuration. -----------------------------------------------------------" diff --git a/libmbus.pc.in b/libmbus.pc.in deleted file mode 100644 index 6c1b7d8b..00000000 --- a/libmbus.pc.in +++ /dev/null @@ -1,12 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: libmbus -Description: Open source M-bus (Meter-Bus) library. -Requires: -Version: @PACKAGE_VERSION@ -URL: http://www.rscada.se/libmbus/ -Libs: -L${libdir} -lmbus -lm -Cflags: -I${includedir} diff --git a/libmbus.spec b/libmbus.spec deleted file mode 100644 index 06160f75..00000000 --- a/libmbus.spec +++ /dev/null @@ -1,87 +0,0 @@ -# -# spec file for package libmbus -# -# Copyright (c) 2010-2013, Raditex Control AB -# All rights reserved. -# -# rSCADA -# http://www.rSCADA.se -# info@rscada.se -# - -Summary: Open source M-bus (Meter-Bus) library -Name: libmbus -Version: 0.9.0 -Release: 1 -Source: https://github.com/rscada/%{name}/archive/%{version}.tar.gz -URL: https://github.com/rscada/libmbus/ -License: BSD -Vendor: Raditex Control AB -Packager: Stefan Wahren -Group: Development/Languages/C and C++ -BuildRoot: {_tmppath}/%{name}-%{version}-build -AutoReqProv: on - -%description -libmbus: M-bus Library from Raditex Control (http://www.rscada.se) - -libmbus is an open source library for the M-bus (Meter-Bus) protocol. -The Meter-Bus is a standard for reading out meter data from electricity meters, -heat meters, gas meters, etc. The M-bus standard deals with both the electrical -signals on the M-Bus, and the protocol and data format used in transmissions -on the M-Bus. The role of libmbus is to decode/encode M-bus data, and to handle -the communication with M-Bus devices. - -For more information see http://www.rscada.se/libmbus - -%package devel -License: BSD -Summary: Development libraries and header files for using the M-bus library -Group: Development/Libraries/C and C++ -AutoReqProv: on -Requires: %{name} = %{version} - -%description devel -This package contains all necessary include files and libraries needed -to compile and link applications which use the M-bus (Meter-Bus) library. - -%prep -q -%setup -q -# workaround to get it's build -autoreconf - -%build -./configure --prefix=/usr -make - -%install -rm -Rf "%buildroot" -mkdir "%buildroot" -make install DESTDIR="%buildroot" - -%clean -rm -rf "%buildroot" - -%files -%defattr (-,root,root) -%doc COPYING README.md -%{_bindir}/mbus-serial-* -%{_bindir}/mbus-tcp-* -%{_libdir}/libmbus.so* -%{_mandir}/man1/libmbus.1 -%{_mandir}/man1/mbus-* - -%files devel -%defattr (-,root,root) -%{_includedir}/mbus -%{_libdir}/libmbus.a -%{_libdir}/libmbus.la -%{_libdir}/pkgconfig/libmbus.pc - -%changelog -* Fri Feb 22 2019 Stefan Wahren - 0.9.0-1 -- switch to github repo -- enable man pages - -* Fri Mar 29 2013 Stefan Wahren - 0.8.0-1 -- Initial package based on the last official release diff --git a/mbus/Makefile.am b/mbus/Makefile.am deleted file mode 100644 index b0749871..00000000 --- a/mbus/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -# ------------------------------------------------------------------------------ -# Copyright (C) 2010, Raditex AB -# All rights reserved. -# -# rSCADA -# http://www.rSCADA.se -# info@rscada.se -# -# ------------------------------------------------------------------------------ -PACKAGE = @PACKAGE@ -VERSION = @VERSION@ - -AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir) - -includedir = $(prefix)/include/mbus -include_HEADERS = mbus.h mbus-protocol.h mbus-tcp.h mbus-serial.h mbus-protocol-aux.h - -lib_LTLIBRARIES = libmbus.la -libmbus_la_SOURCES = mbus.c mbus-protocol.c mbus-tcp.c mbus-serial.c mbus-protocol-aux.c - diff --git a/test/Makefile.am b/test/Makefile.am deleted file mode 100644 index c373fa48..00000000 --- a/test/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -# ------------------------------------------------------------------------------ -# Copyright (C) 2010, Raditex AB -# All rights reserved. -# -# rSCADA -# http://www.rSCADA.se -# info@rscada.se -# -# ------------------------------------------------------------------------------ -PACKAGE = @PACKAGE@ -VERSION = @VERSION@ - -AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir) -I$(top_srcdir)/mbus - -noinst_HEADERS = -noinst_PROGRAMS = mbus_parse mbus_parse_hex - -mbus_parse_LDFLAGS = -L$(top_builddir)/mbus -mbus_parse_LDADD = -lmbus -lm -mbus_parse_SOURCES = mbus_parse.c - -mbus_parse_hex_LDFLAGS = -L$(top_builddir)/mbus -mbus_parse_hex_LDADD = -lmbus -lm -mbus_parse_hex_SOURCES = mbus_parse_hex.c - From 91fbe7660fc175230593dfbd74340d32c76c0b74 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Wed, 25 Mar 2020 09:23:09 +0100 Subject: [PATCH 09/28] build: do not use gnu style warnings for msvc --- CMakeLists.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10132e63..45a0206d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,8 +111,12 @@ add_library( target_include_directories( ${PROJECT_NAME} PUBLIC $ $ $) -target_link_libraries(${PROJECT_NAME} PRIVATE m) -target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wno-pedantic) +if(LINUX) + target_link_libraries(${PROJECT_NAME} PRIVATE m) +endif() +if(NOT MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wno-pedantic) +endif() if(CLANG_TIDY_EXE) set_target_properties(${PROJECT_NAME} PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}") @@ -151,8 +155,8 @@ install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib) - + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT lib) install( EXPORT ${PROJECT_NAME}Targets DESTINATION ${LIBMBUS_CONFIG_INSTALL_DIR} From e4be69f4f5a80722be85cff9cc8eb63a198e76ea Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Wed, 25 Mar 2020 10:27:12 +0100 Subject: [PATCH 10/28] build: add also android --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 45a0206d..a269e33b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,7 +111,7 @@ add_library( target_include_directories( ${PROJECT_NAME} PUBLIC $ $ $) -if(LINUX) +if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL Android) target_link_libraries(${PROJECT_NAME} PRIVATE m) endif() if(NOT MSVC) From eca37f4627b9f6741701dea4f43050ab6dbb1c7a Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Wed, 25 Mar 2020 11:27:34 +0100 Subject: [PATCH 11/28] build: add pkg config file --- CMakeLists.txt | 13 +++++++++++++ libmbus.pc.in | 12 ++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 libmbus.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index a269e33b..0c7432cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,6 +150,19 @@ endif() include(GNUInstallDirs) include(CMakePackageConfigHelpers) +set(INSTALL_PKGCONFIG_DIR + "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" + CACHE PATH "Installation directory for pkgconfig (.pc) files") +set(INSTALL_INC_DIR + "${CMAKE_INSTALL_PREFIX}/mbus" + CACHE PATH "Installation directory for headers") +set(INSTALL_LIB_DIR + "${CMAKE_INSTALL_PREFIX}/lib" + CACHE PATH "Installation directory for libraries") + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libmbus.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libmbus.pc @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libmbus.pc DESTINATION "${INSTALL_PKGCONFIG_DIR}") + set(LIBMBUS_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) install( TARGETS ${PROJECT_NAME} diff --git a/libmbus.pc.in b/libmbus.pc.in new file mode 100644 index 00000000..1baf5a3e --- /dev/null +++ b/libmbus.pc.in @@ -0,0 +1,12 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@INSTALL_LIB_DIR@ +includedir=@INSTALL_INC_DIR@ + +Name: libmbus +Description: Open source M-bus (Meter-Bus) library. +Requires: +Version: @PROJECT_VERSION@ +URL: http://www.rscada.se/libmbus/ +Libs: -L${libdir} -lmbus -lm +Cflags: -I${includedir} \ No newline at end of file From f6b29b817415f54a3115d1f9fc183d14baed39b4 Mon Sep 17 00:00:00 2001 From: Roger Niederhauser Date: Wed, 25 Mar 2020 12:09:29 +0100 Subject: [PATCH 12/28] test: add slave test to ci --- .github/workflows/ccpp.yml | 10 +++++ test/slave-test.py | 76 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 test/slave-test.py diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 9b9b4d7f..d2811c8b 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -11,6 +11,16 @@ jobs: - name: build examples and tests run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON && cmake --build . -j + test: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: package + run: sudo apt install socat + - name: test + run: sudo python3 test/slave-test.py + debian: runs-on: ubuntu-latest diff --git a/test/slave-test.py b/test/slave-test.py new file mode 100644 index 00000000..3829b6e4 --- /dev/null +++ b/test/slave-test.py @@ -0,0 +1,76 @@ +import os +import codecs +from serial import Serial +from time import sleep +import binascii +import sys +import subprocess +from subprocess import Popen, PIPE + +devices = { + "1": "68 5E 5E 68 08 05 72 91 64 00 08 65 32 99 06 DA 00 00 00 0C 13 00 00 00 00 0B 22 86 40 04 04 6D 24 0A 61 1C 32 6C 00 00 0C 78 91 64 00 08 06 FD 0C 0A 00 01 00 FA 01 0D FD 0B 05 31 32 48 46 57 01 FD 0E 00 4C 13 00 00 00 00 42 6C 5F 1C 0F 37 FD 17 00 00 00 00 00 00 00 00 02 7A 25 00 02 78 25 00 82 16", + "2": "68 AE AE 68 28 01 72 95 08 12 11 83 14 02 04 17 00 00 00 84 00 86 3B 23 00 00 00 84 00 86 3C D1 01 00 00 84 40 86 3B 00 00 00 00 84 40 86 3C 00 00 00 00 85 00 5B 2B 4B AC 41 85 00 5F 20 D7 AC 41 85 40 5B 00 00 B8 42 85 40 5F 00 00 B8 42 85 00 3B 84 00 35 3F 85 40 3B 00 00 00 00 95 00 3B 95 CF B2 43 95 40 3B 00 00 00 00 85 00 2B 00 00 00 00 85 40 2B 00 00 00 00 95 00 2B D3 9F 90 46 95 40 2B 00 00 00 00 04 6D 19 0F 8A 17 84 00 7C 01 43 F3 0D 00 00 84 40 7C 01 43 9D 01 00 00 84 00 7C 01 63 01 00 00 00 84 40 7C 01 63 01 00 00 00 0F 2F 16" +} + +class Slave: + def open_serial(self): + self.ser = Serial("/dev/pty101") + + def getDeviceBytes(self, address): + return bytearray([int(x, 16) for x in devices[str(address)].split(" ")]) + + def read(self): + response = [] + + while True: + value = self.ser.read(1) + buffer_length = int.from_bytes(value, "big") + print(buffer_length) + + frame = [] + for e in range(int(buffer_length / 4)): + buffer = self.ser.read(1) + decoded = binascii.hexlify(buffer) + frame.append(decoded) + response.append(frame) + print(response) + + address = int(response[-1][1], 16) + if address < 3 and address > 0: + self.ser.write(self.getDeviceBytes(address)) + return + + def request_data(self): + Popen("./bin/mbus-serial-request-data -d -b 300 /dev/pty100 1", shell=True) + +# entry point +if __name__ == "__main__": + try: + # open socat + Popen("sudo socat -d -d -d -d pty,raw,echo=0,link=/dev/pty100 pty,raw,echo=0,link=/dev/pty101", shell=True) + + seconds = 5 + print(f"Waiting {seconds} seconds for socat to initialize") + sleep(seconds) + + print("Creating Slave") + # create slave + slave = Slave() + print("Opening serial port..") + slave.open_serial() + print("Serial port has been opened") + print("Reading started. Waiting for data request..") + slave.request_data() + slave.read() + + # success + print("Script finished successfully!") + failed = False + except: + # fail if error occurred + print("Script finished with errors!") + failed = True + finally: + # kill socat at the end of the test + os.system("sudo kill $(pidof socat)") + sys.exit(1 if failed else 0) From db14b57285ed22c964cad4f142a3c61b77dff892 Mon Sep 17 00:00:00 2001 From: Roger Niederhauser Date: Wed, 25 Mar 2020 13:27:40 +0100 Subject: [PATCH 13/28] Revert "test: add slave test to ci" This reverts commit f6b29b817415f54a3115d1f9fc183d14baed39b4. --- .github/workflows/ccpp.yml | 10 ----- test/slave-test.py | 76 -------------------------------------- 2 files changed, 86 deletions(-) delete mode 100644 test/slave-test.py diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index d2811c8b..9b9b4d7f 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -11,16 +11,6 @@ jobs: - name: build examples and tests run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON && cmake --build . -j - test: - needs: build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: package - run: sudo apt install socat - - name: test - run: sudo python3 test/slave-test.py - debian: runs-on: ubuntu-latest diff --git a/test/slave-test.py b/test/slave-test.py deleted file mode 100644 index 3829b6e4..00000000 --- a/test/slave-test.py +++ /dev/null @@ -1,76 +0,0 @@ -import os -import codecs -from serial import Serial -from time import sleep -import binascii -import sys -import subprocess -from subprocess import Popen, PIPE - -devices = { - "1": "68 5E 5E 68 08 05 72 91 64 00 08 65 32 99 06 DA 00 00 00 0C 13 00 00 00 00 0B 22 86 40 04 04 6D 24 0A 61 1C 32 6C 00 00 0C 78 91 64 00 08 06 FD 0C 0A 00 01 00 FA 01 0D FD 0B 05 31 32 48 46 57 01 FD 0E 00 4C 13 00 00 00 00 42 6C 5F 1C 0F 37 FD 17 00 00 00 00 00 00 00 00 02 7A 25 00 02 78 25 00 82 16", - "2": "68 AE AE 68 28 01 72 95 08 12 11 83 14 02 04 17 00 00 00 84 00 86 3B 23 00 00 00 84 00 86 3C D1 01 00 00 84 40 86 3B 00 00 00 00 84 40 86 3C 00 00 00 00 85 00 5B 2B 4B AC 41 85 00 5F 20 D7 AC 41 85 40 5B 00 00 B8 42 85 40 5F 00 00 B8 42 85 00 3B 84 00 35 3F 85 40 3B 00 00 00 00 95 00 3B 95 CF B2 43 95 40 3B 00 00 00 00 85 00 2B 00 00 00 00 85 40 2B 00 00 00 00 95 00 2B D3 9F 90 46 95 40 2B 00 00 00 00 04 6D 19 0F 8A 17 84 00 7C 01 43 F3 0D 00 00 84 40 7C 01 43 9D 01 00 00 84 00 7C 01 63 01 00 00 00 84 40 7C 01 63 01 00 00 00 0F 2F 16" -} - -class Slave: - def open_serial(self): - self.ser = Serial("/dev/pty101") - - def getDeviceBytes(self, address): - return bytearray([int(x, 16) for x in devices[str(address)].split(" ")]) - - def read(self): - response = [] - - while True: - value = self.ser.read(1) - buffer_length = int.from_bytes(value, "big") - print(buffer_length) - - frame = [] - for e in range(int(buffer_length / 4)): - buffer = self.ser.read(1) - decoded = binascii.hexlify(buffer) - frame.append(decoded) - response.append(frame) - print(response) - - address = int(response[-1][1], 16) - if address < 3 and address > 0: - self.ser.write(self.getDeviceBytes(address)) - return - - def request_data(self): - Popen("./bin/mbus-serial-request-data -d -b 300 /dev/pty100 1", shell=True) - -# entry point -if __name__ == "__main__": - try: - # open socat - Popen("sudo socat -d -d -d -d pty,raw,echo=0,link=/dev/pty100 pty,raw,echo=0,link=/dev/pty101", shell=True) - - seconds = 5 - print(f"Waiting {seconds} seconds for socat to initialize") - sleep(seconds) - - print("Creating Slave") - # create slave - slave = Slave() - print("Opening serial port..") - slave.open_serial() - print("Serial port has been opened") - print("Reading started. Waiting for data request..") - slave.request_data() - slave.read() - - # success - print("Script finished successfully!") - failed = False - except: - # fail if error occurred - print("Script finished with errors!") - failed = True - finally: - # kill socat at the end of the test - os.system("sudo kill $(pidof socat)") - sys.exit(1 if failed else 0) From e03e68235e98fb715909e6c1ac797328e4db1260 Mon Sep 17 00:00:00 2001 From: Roger Niederhauser Date: Wed, 25 Mar 2020 15:06:48 +0100 Subject: [PATCH 14/28] chore: enable test coverage --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 2d84a15b..ace660e0 100755 --- a/build.sh +++ b/build.sh @@ -4,7 +4,7 @@ rm -rf _build mkdir _build cd _build -cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON +cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_BUILD_TESTS=ON cmake --build . -j # build deb From 5677181033f51986ec23ae55f335734c91333e94 Mon Sep 17 00:00:00 2001 From: Roger Niederhauser Date: Wed, 25 Mar 2020 15:16:00 +0100 Subject: [PATCH 15/28] chore: enable coverage --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index ace660e0..2869e926 100755 --- a/build.sh +++ b/build.sh @@ -4,7 +4,7 @@ rm -rf _build mkdir _build cd _build -cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_BUILD_TESTS=ON +cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON cmake --build . -j # build deb From 558eed90a48371d11f31cc71073e9d24b2b7636f Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Wed, 25 Mar 2020 15:35:07 +0100 Subject: [PATCH 16/28] test: add test coverage --- .github/workflows/ccpp.yml | 13 ++++++++++++- build.sh | 2 +- test/CMakeLists.txt | 3 +++ test/generate-xml.sh | 24 +++++++++++++----------- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 9b9b4d7f..7e02a6df 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -9,7 +9,18 @@ jobs: steps: - uses: actions/checkout@v2 - name: build examples and tests - run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON && cmake --build . -j + run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON && cmake --build . -j + + - name: generate test frames + working-directory: ${{runner.workspace}}/ + run: ./test/generate-xml.sh test/test-frames build/bin/mbus_parse_hex + + - name: install gcovr + run: sudo pip install gcovr + + - name: execute tests and get coverage + working-directory: ${{runner.workspace}}/build + run: gcovr . debian: runs-on: ubuntu-latest diff --git a/build.sh b/build.sh index ace660e0..2869e926 100755 --- a/build.sh +++ b/build.sh @@ -4,7 +4,7 @@ rm -rf _build mkdir _build cd _build -cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_BUILD_TESTS=ON +cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON cmake --build . -j # build deb diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0303d236..cad2f88b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,3 +3,6 @@ target_link_libraries(mbus_parse PRIVATE libmbus::libmbus) add_executable(mbus_parse_hex ${CMAKE_CURRENT_LIST_DIR}/mbus_parse_hex.c) target_link_libraries(mbus_parse_hex PRIVATE libmbus::libmbus) + +add_test(mbus_parse_hex ${CMAKE_BINARY_DIR}/bin/mbus_parse_hex) +add_test(mbus_parse ${CMAKE_BINARY_DIR}/bin/mbus_parse) diff --git a/test/generate-xml.sh b/test/generate-xml.sh index d03aa1fe..8fe43d75 100755 --- a/test/generate-xml.sh +++ b/test/generate-xml.sh @@ -12,26 +12,28 @@ # #------------------------------------------------------------------------------ -# Check if mbus_parse_hex exists -if [ ! -x ./mbus_parse_hex ]; then - echo "mbus_parse_hex not found" - exit 3 -fi - # Check commandline parameter -if [ $# -ne 1 ]; then +if [ $# -ne 2 ]; then echo "usage: $0 directory" exit 3 fi directory="$1" -# Check directory -if [ ! -d "$directory" ]; then - echo "usage: $0 directory" +# Check if mbus_parse_hex exists +if [ ! -x $2 ]; then + echo "mbus_parse_hex not found" exit 3 fi +mbus_parse_hex="$2" + +# # Check directory +# if [ ! -d "$directory" ]; then +# echo "usage: $0 directory" +# exit 3 +# fi + for hexfile in "$directory"/*.hex; do if [ ! -f "$hexfile" ]; then continue @@ -40,7 +42,7 @@ for hexfile in "$directory"/*.hex; do filename=`basename $hexfile .hex` # Parse hex file and write XML in file - ./mbus_parse_hex "$hexfile" > "$directory/$filename.xml.new" + $mbus_parse_hex "$hexfile" > "$directory/$filename.xml.new" result=$? # Check parsing result From a55e257207cce20ee4b89aa462fe55ddd0606d36 Mon Sep 17 00:00:00 2001 From: Roger Niederhauser Date: Wed, 25 Mar 2020 15:54:30 +0100 Subject: [PATCH 17/28] chore: change working directory --- .github/workflows/ccpp.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 7e02a6df..8f581cc5 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -9,10 +9,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: build examples and tests - run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON && cmake --build . -j + run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON && cmake --build . -j && cd .. - name: generate test frames - working-directory: ${{runner.workspace}}/ run: ./test/generate-xml.sh test/test-frames build/bin/mbus_parse_hex - name: install gcovr From dd41128117ac2617904371d89b84fe825bc3f167 Mon Sep 17 00:00:00 2001 From: Roger Niederhauser Date: Wed, 25 Mar 2020 15:59:53 +0100 Subject: [PATCH 18/28] chore: change gcovr job --- .github/workflows/ccpp.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 8f581cc5..241af3ea 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -14,12 +14,9 @@ jobs: - name: generate test frames run: ./test/generate-xml.sh test/test-frames build/bin/mbus_parse_hex - - name: install gcovr + - name: install and run gcovr run: sudo pip install gcovr - - - name: execute tests and get coverage - working-directory: ${{runner.workspace}}/build - run: gcovr . + run: gcovr build/. debian: runs-on: ubuntu-latest From 5a88e95e547c3d4a5e354f9f3e740654e5d39d8a Mon Sep 17 00:00:00 2001 From: Roger Niederhauser Date: Wed, 25 Mar 2020 16:01:14 +0100 Subject: [PATCH 19/28] fix: make only one run --- .github/workflows/ccpp.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 241af3ea..75ae40fd 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -15,8 +15,7 @@ jobs: run: ./test/generate-xml.sh test/test-frames build/bin/mbus_parse_hex - name: install and run gcovr - run: sudo pip install gcovr - run: gcovr build/. + run: sudo pip install gcovr && gcovr build/. debian: runs-on: ubuntu-latest From 8dd306fdadbd023f977d62b7fb07f1c275cccc4d Mon Sep 17 00:00:00 2001 From: Estefania Otero Date: Thu, 26 Mar 2020 11:10:12 +0100 Subject: [PATCH 20/28] feat: enable clang-tidy --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 75ae40fd..56db3bd3 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: build examples and tests - run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON && cmake --build . -j && cd .. + run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. - name: generate test frames run: ./test/generate-xml.sh test/test-frames build/bin/mbus_parse_hex From 5789b831899f1115e91c7cb701dca96e98e154ce Mon Sep 17 00:00:00 2001 From: Estefania Otero Date: Thu, 26 Mar 2020 11:51:15 +0100 Subject: [PATCH 21/28] feat: install clang-tidy --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 56db3bd3..3956d99e 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: build examples and tests - run: rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. + run: sudo apt-get install clang-tidy && rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. - name: generate test frames run: ./test/generate-xml.sh test/test-frames build/bin/mbus_parse_hex From 437952a08c06cc213f5804b749fc8bfb50bc081e Mon Sep 17 00:00:00 2001 From: Estefania Otero Date: Thu, 26 Mar 2020 12:01:52 +0100 Subject: [PATCH 22/28] feat: install clang-tidy --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 3956d99e..94261c8b 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: build examples and tests - run: sudo apt-get install clang-tidy && rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. + run: sudo apt-get install -y clang-tidy && rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. - name: generate test frames run: ./test/generate-xml.sh test/test-frames build/bin/mbus_parse_hex From 29e1e8dbd93623e1065296b0582d13e20010f3e6 Mon Sep 17 00:00:00 2001 From: Estefania Otero Date: Thu, 26 Mar 2020 13:47:35 +0100 Subject: [PATCH 23/28] feat: install clang-tidy 6.0 --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 94261c8b..61d4233f 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: build examples and tests - run: sudo apt-get install -y clang-tidy && rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. + run: sudo apt-get install clang-tidy-6.0 && rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. - name: generate test frames run: ./test/generate-xml.sh test/test-frames build/bin/mbus_parse_hex From 16dc64909da58cdfa6566a7a095ceab8b64c5902 Mon Sep 17 00:00:00 2001 From: Estefania Otero Date: Thu, 26 Mar 2020 13:49:53 +0100 Subject: [PATCH 24/28] Revert "feat: install clang-tidy 6.0" This reverts commit 29e1e8dbd93623e1065296b0582d13e20010f3e6. --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 61d4233f..94261c8b 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: build examples and tests - run: sudo apt-get install clang-tidy-6.0 && rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. + run: sudo apt-get install -y clang-tidy && rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. - name: generate test frames run: ./test/generate-xml.sh test/test-frames build/bin/mbus_parse_hex From 4a135ecbafd9fca9c4f3717138c59c35b5f7172d Mon Sep 17 00:00:00 2001 From: Estefania Otero Date: Thu, 26 Mar 2020 13:53:14 +0100 Subject: [PATCH 25/28] feat: install clang tidy --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 94261c8b..b9aa2d98 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: build examples and tests - run: sudo apt-get install -y clang-tidy && rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. + run: sudo apt-get update && sudo apt-get install -y clang-tidy && rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. - name: generate test frames run: ./test/generate-xml.sh test/test-frames build/bin/mbus_parse_hex From 1c0bb4e53a08275efe6697bbf10b0ac2cf1cb96d Mon Sep 17 00:00:00 2001 From: Estefania Otero Date: Thu, 26 Mar 2020 13:56:37 +0100 Subject: [PATCH 26/28] feat: install clang-tidy --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index b9aa2d98..28530419 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: build examples and tests - run: sudo apt-get update && sudo apt-get install -y clang-tidy && rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. + run: sudo apt-get install -fy clang-tidy && rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. - name: generate test frames run: ./test/generate-xml.sh test/test-frames build/bin/mbus_parse_hex From 442f6cfc2ce9b41c01094f5bb11c3ee4e07dd364 Mon Sep 17 00:00:00 2001 From: Estefania Otero Date: Thu, 26 Mar 2020 13:59:11 +0100 Subject: [PATCH 27/28] feat: install clang tidy --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 28530419..3e040975 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: build examples and tests - run: sudo apt-get install -fy clang-tidy && rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. + run: sudo apt-get install -y clang-tidy-9 && rm -rf build || true && mkdir build && cd build && cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON -DLIBMBUS_ENABLE_COVERAGE=ON -DLIBMBUS_RUN_CLANG_TIDY=ON && cmake --build . -j && cd .. - name: generate test frames run: ./test/generate-xml.sh test/test-frames build/bin/mbus_parse_hex From ea01ee52d3a844f120d264264b0beb4b13af0141 Mon Sep 17 00:00:00 2001 From: Estefania Otero Date: Thu, 26 Mar 2020 14:09:59 +0100 Subject: [PATCH 28/28] fix: rename clang-tidy-9 --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c7432cb..3b09d88c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,8 +43,8 @@ set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) if(LIBMBUS_RUN_CLANG_TIDY) find_program( CLANG_TIDY_EXE - NAMES "clang-tidy" - DOC "/usr/bin/clang-tidy") + NAMES "clang-tidy-9" + DOC "/usr/bin/clang-tidy-9") if(NOT CLANG_TIDY_EXE) message(WARNING "clang-tidy not found.") else()