-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
284 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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_BINARY_DIR}/mbus/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 $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> | ||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) | ||
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,10 @@ | ||
#!/bin/sh | ||
# | ||
#!/bin/bash | ||
|
||
if [ -f Makefile ]; then | ||
# use existing automake files | ||
echo >> /dev/null | ||
else | ||
# regenerate automake files | ||
echo "Running autotools..." | ||
rm -rf _build | ||
mkdir _build | ||
cd _build | ||
cmake .. -DLIBMBUS_BUILD_EXAMPLES=ON -DLIBMBUS_BUILD_TESTS=ON | ||
cmake --build . -j | ||
|
||
autoheader \ | ||
&& aclocal \ | ||
&& case \ | ||
$(uname) in Darwin*) glibtoolize --ltdl --copy --force ;; \ | ||
*) libtoolize --ltdl --copy --force ;; esac \ | ||
&& automake --add-missing --copy \ | ||
&& autoconf \ | ||
&& ./configure | ||
fi | ||
|
||
make | ||
# conan create . gocarlos/testing --build missing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@PACKAGE_INIT@ | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]") | ||
check_required_components("@PROJECT_NAME@") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 <dlfcn.h> header file. */ | ||
#cmakedefine HAVE_DLFCN_H "@HAVE_DLFCN_H@" | ||
|
||
/* Define to 1 if you have the <inttypes.h> header file. */ | ||
#cmakedefine HAVE_INTTYPES_H "@HAVE_INTTYPES_H@" | ||
|
||
/* Define to 1 if you have the <memory.h> header file. */ | ||
#cmakedefine HAVE_MEMORY_H "@HAVE_MEMORY_H@" | ||
|
||
/* Define to 1 if you have the <stdint.h> header file. */ | ||
#cmakedefine HAVE_STDINT_H "@HAVE_STDINT_H@" | ||
|
||
/* Define to 1 if you have the <stdlib.h> header file. */ | ||
#cmakedefine HAVE_STDLIB_H "@HAVE_STDLIB_H@" | ||
|
||
/* Define to 1 if you have the <strings.h> header file. */ | ||
#cmakedefine HAVE_STRINGS_H "@HAVE_STRINGS_H@" | ||
|
||
/* Define to 1 if you have the <string.h> header file. */ | ||
#cmakedefine HAVE_STRING_H "@HAVE_STRING_H@" | ||
|
||
/* Define to 1 if you have the <sys/stat.h> header file. */ | ||
#cmakedefine HAVE_SYS_STAT_H "@HAVE_SYS_STAT_H@" | ||
|
||
/* Define to 1 if you have the <sys/types.h> header file. */ | ||
#cmakedefine HAVE_SYS_TYPES_H "@HAVE_SYS_TYPES_H@" | ||
|
||
/* Define to 1 if you have the <unistd.h> 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 "[email protected]" | ||
|
||
/* 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@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) |