Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

set (MODBUSPP_WITH_STATIC 0 CACHE BOOL "Enable building static libraries.")
set (MODBUSPP_UNIT_TESTS 1 CACHE BOOL "Enable building unit tests.")
set (MODBUSPP_WITH_STATIC 1 CACHE BOOL "Enable building static libraries.")
set (MODBUSPP_UNIT_TESTS 0 CACHE BOOL "Enable building unit tests.")

# Offer the user the choice of overriding the installation directories
set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
set(INSTALL_INCLUDE_DIR include CACHE PATH
"Installation directory for header files")
set(INSTALL_CODELITE_DIR /usr/share/codelite CACHE PATH "Installation directory for codelite templates")
option(MODBUSPP_USE_EXTERNAL_JSON "Use an external JSON library" OFF)
option(MODBUSPP_USE_EXTERNAL_JSON "Use an external JSON library" ON)



set(DEF_INSTALL_CMAKE_DIR lib)
set(DEF_INSTALL_DOC_DIR share/doc)
Expand Down Expand Up @@ -91,11 +93,11 @@ find_package(Gzip)
pkg_check_modules (UNITTESTPP UnitTest++>=2.0.0)

if(MODBUSPP_USE_EXTERNAL_JSON)
find_package(nlohmann_json 3.2.0 REQUIRED)
find_package(nlohmann_json CONFIG)
else()
set(JSON_BuildTests OFF CACHE INTERNAL "")
set(JSON_Install OFF CACHE INTERNAL "")
add_subdirectory(3rdparty/json)
#set(JSON_BuildTests OFF CACHE INTERNAL "")
#set(JSON_Install OFF CACHE INTERNAL "")
#add_subdirectory(3rdparty/json)
endif()

set (MODBUSPP_CFLAGS_OTHER ${CMAKE_THREAD_LIBS_INIT} ${LIBMODBUS_CFLAGS})
Expand All @@ -108,10 +110,7 @@ include (GitVersion)
GetGitVersion(MODBUSPP_VERSION)
set(MODBUSPP_VERSION
${MODBUSPP_VERSION_MAJOR}.${MODBUSPP_VERSION_MINOR}.${MODBUSPP_VERSION_PATCH})
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY)
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/version.h.in
${CMAKE_CURRENT_BINARY_DIR}/version.h @ONLY)


include(CheckTypeSize)
check_type_size(bool SIZEOF_BOOL BUILTIN_TYPES_ONLY LANGUAGE CXX)
Expand All @@ -127,6 +126,13 @@ check_symbol_exists(TIOCM_RTS sys/ioctl.h MODBUSPP_HAVE_TIOCM_RTS)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBMODBUS_NAME})
check_symbol_exists(modbus_rtu_set_recv_filter ${LIBMODBUS_NAME}/modbus-rtu.h MODBUSPP_HAVE_RTU_MULTI_SLAVES)


message (STATUS "MODBUSPP_HAVE_RTU_MULTI_SLAVES: ${MODBUSPP_HAVE_RTU_MULTI_SLAVES}.")
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY)
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/version.h.in
${CMAKE_CURRENT_BINARY_DIR}/version.h @ONLY)

# Make relative paths absolute (needed later on)
foreach(p LIB BIN INCLUDE CMAKE DATA DOC CODELITE)
set(var INSTALL_${p}_DIR)
Expand Down Expand Up @@ -273,7 +279,7 @@ set(CPACK_PACKAGE_CONTACT "Pascal JEAN <[email protected]>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_NAME} - ${PROJECT_DESCRIPTION}")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING.LESSER")

set(CPACK_GENERATOR "DEB")
#set(CPACK_GENERATOR "DEB")

if (CPACK_GENERATOR STREQUAL "DEB")

Expand Down Expand Up @@ -319,4 +325,4 @@ if (CPACK_GENERATOR STREQUAL "DEB")

endif (CPACK_GENERATOR STREQUAL "DEB")

include(CPack)
include(CPack)
11 changes: 7 additions & 4 deletions dev/cmake/GitVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ function(GetGitVersion _prefix)
set(str v1.0-0)
set(ret 0)
endif()

#message("GetGitVersion:str=${str}")
#message("GetGitVersion:ret=${ret}")

set(str v1.1)
set(ret 0)

message("GetGitVersion:str=${str}")
message("GetGitVersion:ret=${ret}")

if (ret EQUAL 0 AND str)

string(REGEX MATCH "^[vV][0-9]\\.[0-9].*" str ${str})
#message("GetGitVersion:version=${version}")
message("GetGitVersion:version=${str}")

if (str)

Expand Down
2 changes: 1 addition & 1 deletion src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ namespace Modbus {
}
while (d->recoveryLink && rc == -1 && !msg->isResponse());

if (rc > 0 && rc != msg->size()) {
if (rc > 0 && rc != msg->aduSize()) {

errno = EMBBADDATA;
return -1;
Expand Down
12 changes: 7 additions & 5 deletions src/rtulayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,13 @@ namespace Modbus {
// ---------------------------------------------------------------------------
// static
int RtuLayer::stop (const std::string & settings) {

if (parity (settings) == 'N') {

return 2;
}
size_t s = settings.length();
if (s >= 2)
{
char c = settings[s - 1];
if (c == '1') { return 1; }
else if (c == '2') { return 2; }
}
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ namespace Modbus {

// ---------------------------------------------------------------------------
// static
void * Server::Private::loop (std::future<void> run, Private * d) {
void Server::Private::loop(std::future<void>&& run, Private* d) {
int rc;

while (run.wait_for (std::chrono::milliseconds (100)) == std::future_status::timeout) {
Expand Down
2 changes: 1 addition & 1 deletion src/server_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Modbus {

BufferedSlave * addSlave (int slaveAddr, Device * master);

static void * loop (std::future<void> run, Private * d);
static void loop (std::future<void>&& run, Private * d);
static int receive (Private * d);

int sock;
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cmake_minimum_required(VERSION 2.8.11)
include(SubDirList)
SUBDIRLIST(TESTS ${CMAKE_CURRENT_SOURCE_DIR})

find_package(modbuspp CONFIG)
find_package(MODBUSPP CONFIG)

add_custom_target(build_and_test ${CMAKE_CTEST_COMMAND} -V)
link_directories(${MODBUSPP_LIBRARY_DIRS})
Expand Down