From d96dcfad09e885a6e440eb00bbb016afd75bb105 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Tue, 17 Mar 2020 21:25:08 +0100 Subject: [PATCH 01/23] 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 085383d..1136a1a 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 0000000..d3dafe4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,150 @@ +cmake_minimum_required(VERSION 3.5) + +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 27d393c..133c243 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 0000000..73e1500 --- /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 34c2799..d4ce3c7 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 . diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 0000000..9c15f36 --- /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 0000000..369c7c8 --- /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 0000000..0303d23 --- /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 89db118821b39943a38dd24a8b3e4b675782d7cf Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Fri, 20 Mar 2020 15:38:29 +0100 Subject: [PATCH 02/23] build: add coverage information --- CMakeLists.txt | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3dafe4..4e9ce4f 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 e864d27fbf175607cb972e979043d378dfa31cbd Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 23 Mar 2020 09:22:41 +0100 Subject: [PATCH 03/23] 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 4e9ce4f..477ddf8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,23 @@ cmake_minimum_required(VERSION 3.5) -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 0000000..60329ed --- /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 433b3c4219a2cff611c4cfe5967697e89872c034 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 23 Mar 2020 09:38:47 +0100 Subject: [PATCH 04/23] 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 0000000..fcf122b --- /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 d4ce3c7..2179070 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 . + +# build deb + +# rm -rf _build +# mkdir _build +# cd _build +# cmake .. -DLIBMBUS_PACKAGE_DEB=ON +# cpack .. +# dpkg -i *.deb From 576da85302951406d1c470bf9f4420f6f0301db4 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 23 Mar 2020 11:11:43 +0100 Subject: [PATCH 05/23] 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 0000000..caa4fdd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +/_build +/build diff --git a/Dockerfile.deb b/Dockerfile.deb new file mode 100644 index 0000000..1db6923 --- /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 0000000..2f70df9 --- /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 5a3d13e7add6aefc733f59ca9bf3d1aa38003237 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 23 Mar 2020 13:41:26 +0100 Subject: [PATCH 06/23] build: add documentation --- .github/workflows/ccpp.yml | 8 +++++++ CMakeLists.txt | 43 ++++++++++++++++++++++++++++++++++++-- doxygen.cfg => Doxyfile.in | 9 +++++--- build.sh | 7 +++++++ 4 files changed, 62 insertions(+), 5 deletions(-) rename doxygen.cfg => Doxyfile.in (99%) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index fcf122b..a2e0629 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 477ddf8..000d633 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 3.5) -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 ea1b569..b8393df 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 2179070..e815272 100755 --- a/build.sh +++ b/build.sh @@ -15,3 +15,10 @@ cmake --build . # cmake .. -DLIBMBUS_PACKAGE_DEB=ON # cpack .. # dpkg -i *.deb + +# build doc + +# mkdir build +# cd build +# cmake .. -DLIBMBUS_BUILD_DOCS=ON +# cmake --build . --target doc From 6fb724698f1d525caaa723a01311707e058cb872 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 23 Mar 2020 13:54:57 +0100 Subject: [PATCH 07/23] 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 a2e0629..9b9b4d7 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 bd2fa5759b06cabf324ed37644a4153e79a54e0d Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 23 Mar 2020 14:07:59 +0100 Subject: [PATCH 08/23] 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 93da751..0000000 --- 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 fd519e1..0000000 --- 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 2b04b49..0000000 --- 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 7c9ce41..0000000 --- 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 77f3a6b..0000000 --- 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 d14d0e2..0000000 --- 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 6c1b7d8..0000000 --- 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 06160f7..0000000 --- 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 b074987..0000000 --- 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 c373fa4..0000000 --- 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 ff2e50a38a76827fcf0cab6fd440274b17f036a6 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Wed, 25 Mar 2020 09:23:09 +0100 Subject: [PATCH 09/23] 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 000d633..9599870 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 155e245b613bb8eef01fba9fd31ebc49525905a8 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Wed, 25 Mar 2020 10:27:12 +0100 Subject: [PATCH 10/23] build: add also android --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9599870..d82796c 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 724822b3abc6cceb6d4ab108508c8266e1483c01 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Wed, 25 Mar 2020 11:27:34 +0100 Subject: [PATCH 11/23] 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 d82796c..d89d82a 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 0000000..1baf5a3 --- /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 b0f413037a1121bc477ac8ea216f40c1d6e47e45 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Tue, 31 Mar 2020 21:38:51 +0200 Subject: [PATCH 12/23] test: update generate-xml script --- .github/workflows/ccpp.yml | 9 ++++++++- CMakeLists.txt | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 9b9b4d7..f7922e1 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -9,7 +9,13 @@ 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 && cd .. + + - name: generate test frames + run: ./test/generate-xml.sh test/test-frames build/bin/mbus_parse_hex + + - name: install and run gcovr + run: sudo pip install gcovr && gcovr build/. debian: runs-on: ubuntu-latest @@ -21,6 +27,7 @@ jobs: doc: runs-on: ubuntu-latest + steps: - uses: actions/checkout@v2 - name: build doxygen documentation diff --git a/CMakeLists.txt b/CMakeLists.txt index d89d82a..29d0fba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ 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_ENABLE_COVERAGE "build with coverage support" OFF) 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) From fffdca0504ec374e50bebe9152591b11b1092c6f Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Tue, 31 Mar 2020 21:07:19 +0200 Subject: [PATCH 13/23] build: apply suggestions from code review Co-Authored-By: Anonymous Maarten --- CMakeLists.txt | 12 ++++++------ mbus/config.h.in | 9 +++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29d0fba..b5533f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,7 @@ if(LIBMBUS_RUN_CLANG_TIDY) endif(LIBMBUS_RUN_CLANG_TIDY) if(LIBMBUS_ENABLE_COVERAGE) - if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + if(NOT CMAKE_BUILD_TYPE MATCHES "(Debug)|(RelWithDebInfo)") message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading") endif() @@ -94,7 +94,7 @@ 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 @ONLY) add_library( ${PROJECT_NAME} @@ -111,7 +111,7 @@ add_library( target_include_directories( ${PROJECT_NAME} PUBLIC $ $ $) -if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL Android) +if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") target_link_libraries(${PROJECT_NAME} PRIVATE m) endif() if(NOT MSVC) @@ -151,13 +151,13 @@ include(GNUInstallDirs) include(CMakePackageConfigHelpers) set(INSTALL_PKGCONFIG_DIR - "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" + "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") set(INSTALL_INC_DIR - "${CMAKE_INSTALL_PREFIX}/mbus" + "${CMAKE_INSTALL_INCLUDEDIR}/mbus" CACHE PATH "Installation directory for headers") set(INSTALL_LIB_DIR - "${CMAKE_INSTALL_PREFIX}/lib" + "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation directory for libraries") configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libmbus.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libmbus.pc @ONLY) diff --git a/mbus/config.h.in b/mbus/config.h.in index 369c7c8..9b818f6 100644 --- a/mbus/config.h.in +++ b/mbus/config.h.in @@ -1,6 +1,3 @@ -/* 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@" @@ -35,19 +32,19 @@ #define LT_OBJDIR ".libs/" /* Name of package */ -#define PACKAGE "libmbus" +#define PACKAGE "@PROJECT_NAME@" /* 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 PACKAGE_NAME "@PROJECT_NAME@" /* 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 PACKAGE_TARNAME "@PROJECT_NAME@" /* Define to the home page for this package. */ #define PACKAGE_URL "http://www.rscada.se/libmbus/" From 505c25aa9b08914cddf1a46652003f919de5d7a2 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Tue, 31 Mar 2020 23:45:53 +0200 Subject: [PATCH 14/23] chore: apply suggestions from code review Co-Authored-By: Anonymous Maarten --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5533f7..1d92f0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,7 +168,7 @@ install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib + ARCHIVE DESTINATION ${INSTALL_LIB_DIR} COMPONENT dev RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT lib) install( EXPORT ${PROJECT_NAME}Targets @@ -187,7 +187,7 @@ install( install( DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/mbus/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mbus/ + DESTINATION ${INSTALL_INC_DIR} COMPONENT dev FILES_MATCHING PATTERN "*.h") From b58aca44323650c4c75943bc201f4c21f9bfaa75 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Wed, 1 Apr 2020 15:52:21 +0200 Subject: [PATCH 15/23] build: symplify clang tidy --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d92f0d..d07524a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,6 @@ if(LIBMBUS_RUN_CLANG_TIDY) 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) @@ -119,7 +118,7 @@ if(NOT MSVC) endif() 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 "${CLANG_TIDY_EXE}") endif() add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) From 989404de8381ec25f6d028fa82fb4fd8b66fdd38 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Wed, 1 Apr 2020 15:53:54 +0200 Subject: [PATCH 16/23] chore: simplify cmake --- CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d07524a..41cb669 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,8 +29,7 @@ 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}) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_BINARY_DIR}") # Set the output of the libraries and executables. set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) @@ -166,7 +165,7 @@ 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 + LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib ARCHIVE DESTINATION ${INSTALL_LIB_DIR} COMPONENT dev RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT lib) install( From f3a62d560b26bc23399415d7e2651f792f4dfa25 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Wed, 1 Apr 2020 22:38:53 +0200 Subject: [PATCH 17/23] chore: apply suggestions from code review Co-Authored-By: Anonymous Maarten --- CMakeLists.txt | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 41cb669..a581d60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,19 +96,19 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/mbus/config.h.in ${CMAKE_CURRENT_LIST_D 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) + "${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 $ $ - $) + ${PROJECT_NAME} PUBLIC "$" "$" + "$") if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") target_link_libraries(${PROJECT_NAME} PRIVATE m) endif() @@ -165,27 +165,27 @@ set(LIBMBUS_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets - LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib - ARCHIVE DESTINATION ${INSTALL_LIB_DIR} COMPONENT dev - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT lib) + LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib + ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" COMPONENT dev + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT lib) install( EXPORT ${PROJECT_NAME}Targets - DESTINATION ${LIBMBUS_CONFIG_INSTALL_DIR} + 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}) + "${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} + DESTINATION "${LIBMBUS_CONFIG_INSTALL_DIR}" COMPONENT dev) install( - DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/mbus/ - DESTINATION ${INSTALL_INC_DIR} + DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/mbus/" + DESTINATION "${INSTALL_INC_DIR}" COMPONENT dev FILES_MATCHING PATTERN "*.h") From f31fbea81701f5c33c523ee3ebcdf8fb4bbf21bb Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Tue, 14 Apr 2020 10:29:22 +0200 Subject: [PATCH 18/23] build: add devel package --- CMakeLists.txt | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a581d60..dd43808 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ 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) +option(BUILD_SHARED_LIBS "build shared lib" ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -107,8 +108,9 @@ 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 "$" "$" + "$") if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") target_link_libraries(${PROJECT_NAME} PRIVATE m) endif() @@ -159,7 +161,10 @@ set(INSTALL_LIB_DIR 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}") +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/libmbus.pc + DESTINATION "${INSTALL_PKGCONFIG_DIR}" + COMPONENT dev) set(LIBMBUS_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) install( @@ -211,17 +216,33 @@ 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_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/LICENSE) 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_DEB_COMPONENT_INSTALL ON) +set(CPACK_DEBIAN_PACKAGE_DEBUG ON) set(CPACK_PACKAGE_RELEASE 1) -set(CPACK_COMPONENTS_ALL devel libs) -set(CPACK_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/LICENSE) + +# create 2 components, libmbus, libmbus-dev +set(CPACK_COMPONENTS_ALL lib dev) +set(CPACK_COMPONENT_LIB_DESCRIPTION + "FreeSCADA M-Bus Library. + A free and open-source library for M-Bus (Meter Bus) from the rSCADA project. + ") +set(CPACK_DEBIAN_LIB_PACKAGE_SECTION libs) + +set(CPACK_COMPONENT_DEVEL_DESCRIPTION + "FreeSCADA M-Bus Library Development files. +A free and open-source library for M-Bus (Meter Bus) from the rSCADA project, +including development files.") +set(CPACK_DEBIAN_DEVEL_PACKAGE_SECTION libdevel) + +set(CPACK_COMPONENT_DEVEL_DEPENDS lib) 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") From 9f9c7a5dbfdf6d5a849e9f76b60e8c400a7e1222 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Tue, 14 Apr 2020 11:01:07 +0200 Subject: [PATCH 19/23] fix: unit tests --- test/generate-xml.sh | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/generate-xml.sh b/test/generate-xml.sh index d03aa1f..02e2d88 100755 --- a/test/generate-xml.sh +++ b/test/generate-xml.sh @@ -12,23 +12,25 @@ # #------------------------------------------------------------------------------ -# 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 +# 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" + echo "$directory not found" exit 3 fi @@ -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 @@ -74,4 +76,3 @@ for hexfile in "$directory"/*.hex; do esac done - From ee3a69e5dfc8f8a89c6d75c92b276c44747a7758 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Tue, 14 Apr 2020 11:22:40 +0200 Subject: [PATCH 20/23] docs: add better usage to generate xml script --- test/generate-xml.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/generate-xml.sh b/test/generate-xml.sh index 02e2d88..84e52bd 100755 --- a/test/generate-xml.sh +++ b/test/generate-xml.sh @@ -14,7 +14,7 @@ # Check commandline parameter if [ $# -ne 2 ]; then - echo "usage: $0 directory" + echo "usage: $0 path_to_directory_with_xml_files path_to_mbus_parse_hex_with_filename" exit 3 fi From 716fe0358cbc9149be4574f67af9f59b746952f2 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Tue, 14 Apr 2020 11:36:39 +0200 Subject: [PATCH 21/23] fix: debian package blank line in value of field Description --- CMakeLists.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd43808..c35713f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,10 +226,8 @@ set(CPACK_PACKAGE_RELEASE 1) # create 2 components, libmbus, libmbus-dev set(CPACK_COMPONENTS_ALL lib dev) -set(CPACK_COMPONENT_LIB_DESCRIPTION - "FreeSCADA M-Bus Library. - A free and open-source library for M-Bus (Meter Bus) from the rSCADA project. - ") +set(CPACK_COMPONENT_LIB_DESCRIPTION "FreeSCADA M-Bus Library. + A free and open-source library for M-Bus (Meter Bus) from the rSCADA project.") set(CPACK_DEBIAN_LIB_PACKAGE_SECTION libs) set(CPACK_COMPONENT_DEVEL_DESCRIPTION From f569816788887b2052761d1574d6662b75238172 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Fri, 24 Apr 2020 09:55:01 +0200 Subject: [PATCH 22/23] chore: make path to tests optional --- .github/workflows/ccpp.yml | 2 +- build.sh | 12 ++++++------ test/generate-xml.sh | 27 ++++++++++++++++++--------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index f7922e1..b942801 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -12,7 +12,7 @@ jobs: 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 - run: ./test/generate-xml.sh test/test-frames build/bin/mbus_parse_hex + run: ./test/generate-xml.sh test/test-frames - name: install and run gcovr run: sudo pip install gcovr && gcovr build/. diff --git a/build.sh b/build.sh index e815272..04ea869 100755 --- a/build.sh +++ b/build.sh @@ -1,17 +1,17 @@ #!/bin/sh -rm -rf _build -mkdir _build -cd _build +rm -rf build +mkdir build +cd build cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON cmake --build . # build deb -# rm -rf _build -# mkdir _build -# cd _build +# rm -rf build +# mkdir build +# cd build # cmake .. -DLIBMBUS_PACKAGE_DEB=ON # cpack .. # dpkg -i *.deb diff --git a/test/generate-xml.sh b/test/generate-xml.sh index 84e52bd..6a3231f 100755 --- a/test/generate-xml.sh +++ b/test/generate-xml.sh @@ -13,27 +13,36 @@ #------------------------------------------------------------------------------ # Check commandline parameter -if [ $# -ne 2 ]; then +if [ $# -ne 1 ]; then + echo "usage: $0 path_to_directory_with_xml_files" + echo "or" echo "usage: $0 path_to_directory_with_xml_files path_to_mbus_parse_hex_with_filename" exit 3 fi directory="$1" -# 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 "$directory not found" exit 3 fi +# Default location is this one +mbus_parse_hex="build/bin/mbus_parse_hex" + +# though can be overriten +if [ $# -eq 2 ]; then + mbus_parse_hex="$2" +fi + +# Check if mbus_parse_hex exists +if [ ! -x $mbus_parse_hex ]; then + echo "mbus_parse_hex not found" + echo "path to mbus_parse_hex: $mbus_parse_hex" + exit 3 +fi + for hexfile in "$directory"/*.hex; do if [ ! -f "$hexfile" ]; then continue From ba18321e115787a6c3d1cfdf9035c80091fa528c Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Fri, 24 Apr 2020 15:14:15 +0200 Subject: [PATCH 23/23] chore: run tests also with pull requests --- .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 b942801..1478bc3 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -1,6 +1,6 @@ name: CMake -on: [push] +on: [push, pull_request] jobs: build: