2017-11-22 09:46:28 +01:00
|
|
|
cmake_minimum_required(VERSION 3.2)
|
2018-02-20 21:42:19 +01:00
|
|
|
|
|
|
|
project(mbusd VERSION 0.3.1)
|
|
|
|
|
2017-12-04 21:37:14 +01:00
|
|
|
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/extern_GPL)
|
2017-11-22 09:46:28 +01:00
|
|
|
include(CheckFunctionExists)
|
2017-11-23 17:06:55 +01:00
|
|
|
include(CheckLibraryExists)
|
|
|
|
include(GNUInstallDirs)
|
2018-04-11 15:42:50 +02:00
|
|
|
include(FindUnixCommands)
|
2017-12-04 21:37:14 +01:00
|
|
|
include(FindSystemd)
|
2017-11-22 09:46:28 +01:00
|
|
|
|
|
|
|
#TODO ISC_Posix, prog_libtool
|
|
|
|
# single-configuration generator setup
|
|
|
|
SET(BASIC_C_FLAGS "-W -pedantic -fno-builtin-log -Wall")
|
|
|
|
SET(CMAKE_C_FLAGS_RELEASE "${BASIC_C_FLAGS} -O2")
|
|
|
|
SET(CMAKE_C_FLAGS_DEBUG "${BASIC_C_FLAGS} -g")
|
|
|
|
|
|
|
|
add_definitions(-DPACKAGE="${PROJECT_NAME}" -DVERSION="${PROJECT_VERSION}")
|
|
|
|
|
|
|
|
# user options
|
|
|
|
option (TRXCTL "Support RS-232 to RS-485 converter data direction control" ON)
|
|
|
|
if(TRXCTL)
|
|
|
|
add_definitions(-DTRXCTL)
|
|
|
|
endif()
|
2017-11-23 17:06:26 +01:00
|
|
|
option (LOG "enabling logging facility" ON)
|
|
|
|
if(LOG)
|
2017-11-22 09:46:28 +01:00
|
|
|
add_definitions(-DLOG)
|
|
|
|
endif()
|
2017-11-23 17:06:26 +01:00
|
|
|
option(DEBUG_LOG "extra debug log info" ON)
|
2017-11-22 09:46:28 +01:00
|
|
|
if(DEBUG_LOG)
|
|
|
|
add_definitions(-DDEBUG)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
## check for and pass preprocessor flags
|
|
|
|
check_function_exists(cfmakeraw HAVE_CFMAKERAW)
|
|
|
|
if(HAVE_CFMAKERAW)
|
|
|
|
add_definitions(-DHAVE_CFMAKERAW)
|
|
|
|
endif()
|
|
|
|
check_function_exists(cfsetspeed HAVE_CFSETSPEED)
|
|
|
|
check_function_exists(cfsetispeed HAVE_CFSETISPEED)
|
|
|
|
if(HAVE_CFSETSPEED AND HAVE_CFSETISPEED)
|
|
|
|
add_definitions(-DHAVE_CFSETSPEED)
|
|
|
|
endif()
|
|
|
|
check_function_exists(time HAVE_TIME)
|
|
|
|
check_function_exists(localtime HAVE_LOCALTIME)
|
|
|
|
if(HAVE_TIME AND HAVE_LOCALTIME)
|
2017-12-05 16:10:46 +01:00
|
|
|
message(STATUS "Passing HRDATE to compiler space")
|
2017-11-22 09:46:28 +01:00
|
|
|
add_definitions(-DHRDATE)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_library(LIB_UTIL NAMES libutil util)
|
|
|
|
check_library_exists(util tty_get_name LIB_UTIL HAVE_TTY_GET_NAME)
|
|
|
|
check_library_exists(util uu_lock LIB_UTIL HAVE_UU_LOCK)
|
|
|
|
if(LIB_UTIL AND HAVE_TTY_GET_NAME AND HAVE_UU_LOCK)
|
2017-12-05 16:10:46 +01:00
|
|
|
message(STATUS "Passing HAVE_LIBUTIL to compiler space")
|
2017-11-22 09:46:28 +01:00
|
|
|
add_definitions(-DHAVE_LIBUTIL)
|
|
|
|
endif()
|
|
|
|
|
2017-11-29 22:34:32 +01:00
|
|
|
# add the main application
|
2017-11-22 09:46:28 +01:00
|
|
|
set(mbusd_SOURCES
|
2017-12-04 16:43:10 +01:00
|
|
|
src/main.c
|
|
|
|
src/tty.c
|
|
|
|
src/log.c
|
|
|
|
src/cfg.c
|
|
|
|
src/conn.c
|
|
|
|
src/queue.c
|
|
|
|
src/modbus.c
|
|
|
|
src/crc16.c
|
|
|
|
src/state.c
|
|
|
|
src/sig.c
|
|
|
|
src/sock.c
|
|
|
|
)
|
2017-11-23 17:06:55 +01:00
|
|
|
add_executable(mbusd ${mbusd_SOURCES})
|
2017-12-04 16:43:10 +01:00
|
|
|
install(TARGETS mbusd DESTINATION bin)
|
2017-11-29 12:02:36 +01:00
|
|
|
|
2017-11-29 22:34:32 +01:00
|
|
|
# aggregate the man page template
|
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/mbusd.8.in mbusd.8)
|
2018-02-20 21:42:19 +01:00
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mbusd.8 DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/man/man8)
|
2017-11-29 22:34:32 +01:00
|
|
|
|
2017-11-30 14:36:19 +01:00
|
|
|
# install example configuration file
|
|
|
|
install(
|
2017-12-04 16:43:10 +01:00
|
|
|
FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/mbusd.conf.example
|
|
|
|
DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/${CMAKE_PROJECT_NAME}
|
2017-11-30 14:36:19 +01:00
|
|
|
)
|
2017-11-29 22:34:32 +01:00
|
|
|
|
2018-03-05 15:19:52 +01:00
|
|
|
if(SYSTEMD_SERVICES_INSTALL_DIR)
|
2017-12-05 16:10:46 +01:00
|
|
|
message(STATUS "Systemd service file will be installed to ${SYSTEMD_SERVICES_INSTALL_DIR}")
|
2017-12-04 16:43:10 +01:00
|
|
|
# aggregate mbusd@.service from its template
|
2017-11-30 14:36:19 +01:00
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/systemd-units/mbusd@.service.in mbusd@.service)
|
2018-02-20 21:42:19 +01:00
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mbusd@.service DESTINATION ${SYSTEMD_SERVICES_INSTALL_DIR})
|
2017-11-29 22:34:32 +01:00
|
|
|
endif()
|
|
|
|
|
2017-11-30 14:36:19 +01:00
|
|
|
# uninstall target
|
|
|
|
configure_file(
|
|
|
|
${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
|
|
|
|
@ONLY)
|
|
|
|
add_custom_target(uninstall
|
|
|
|
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
|
|
|
|
)
|
2017-12-05 16:10:46 +01:00
|
|
|
|
2018-04-11 15:42:50 +02:00
|
|
|
# integration tests target
|
|
|
|
enable_testing()
|
|
|
|
add_test(
|
|
|
|
NAME itests
|
|
|
|
COMMAND ${BASH} -c "cd ${CMAKE_CURRENT_SOURCE_DIR}/tests && ./run_itests.sh $<TARGET_FILE:mbusd>"
|
|
|
|
)
|
2017-12-04 16:43:10 +01:00
|
|
|
|
|
|
|
## Please find Packaging stuff following
|
|
|
|
#@source http://xit0.org/2013/04/cmake-use-git-branch-and-commit-details-in-project/
|
|
|
|
# Get the current working branch
|
|
|
|
execute_process(
|
|
|
|
COMMAND git rev-parse --abbrev-ref HEAD
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE GIT_BRANCH
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
# Get the latest abbreviated commit hash of the working branch
|
|
|
|
execute_process(
|
|
|
|
COMMAND git log -1 --format=%h
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE GIT_COMMIT_HASH
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
|
2017-12-04 22:40:12 +01:00
|
|
|
## issue the package creation with $make package
|
2017-12-04 16:43:10 +01:00
|
|
|
# which infrastructure do we want
|
|
|
|
set(CPACK_GENERATOR "DEB")
|
2018-03-05 15:19:52 +01:00
|
|
|
find_program(rpmBuilder rpmbuild)
|
|
|
|
if(rpmBuilder)
|
|
|
|
# @see https://schneide.wordpress.com/2013/02/11/build-a-rpm-package-using-cmake/
|
|
|
|
# @see http://www.g-loaded.eu/2006/04/05/how-to-build-rpm-packages-on-fedora/
|
2017-12-04 16:43:10 +01:00
|
|
|
set(CPACK_GENERATOR "RPM")
|
|
|
|
endif()
|
|
|
|
|
2017-12-05 16:10:46 +01:00
|
|
|
set(CPACK_PACKAGE_NAME "mbusd")
|
2017-12-04 16:43:10 +01:00
|
|
|
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Victor Antonovich") #required
|
|
|
|
set(CPACK_PACKAGE_CONTACT "Victor Antonovich <v.antonovich@gmail.com>")
|
|
|
|
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}-${GIT_BRANCH}-g${GIT_COMMIT_HASH})
|
|
|
|
set(CPACK_PACKAGE_FILE_NAME ${PROJECT_NAME}-${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR}-v${PROJECT_VERSION})
|
|
|
|
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
|
2017-12-05 16:10:46 +01:00
|
|
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Modbus TCP to Modbus RTU gateway")
|
2017-12-04 16:43:10 +01:00
|
|
|
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
|
|
|
|
|
|
|
|
set(CPACK_SOURCE_STRIP_FILES TRUE)
|
|
|
|
set(CPACK_STRIP_FILES TRUE)
|
|
|
|
#the include must be after all the cpack concerning set's
|
2018-02-20 21:42:19 +01:00
|
|
|
include(CPack)
|
|
|
|
|
|
|
|
message(STATUS "Install prefix ${CMAKE_INSTALL_PREFIX}")
|
|
|
|
message(STATUS "Install bindir: ${CMAKE_INSTALL_FULL_BINDIR}")
|
|
|
|
message(STATUS "Install sysconfdir: ${CMAKE_INSTALL_FULL_SYSCONFDIR}")
|
|
|
|
message(STATUS "Install datadir: ${CMAKE_INSTALL_FULL_DATADIR}")
|