mirror of
https://github.com/3cky/mbusd
synced 2025-10-19 23:54:47 +08:00
102 lines
2.9 KiB
CMake
102 lines
2.9 KiB
CMake
cmake_minimum_required(VERSION 3.2)
|
|
include(CPack)
|
|
include(CheckFunctionExists)
|
|
include(CheckLibraryExists)
|
|
include(GNUInstallDirs)
|
|
|
|
project(mbusd VERSION 0.2.4)
|
|
|
|
#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()
|
|
option (LOG "enabling logging facility" ON)
|
|
if(LOG)
|
|
add_definitions(-DLOG)
|
|
endif()
|
|
option(DEBUG_LOG "extra debug log info" ON)
|
|
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)
|
|
message("passing HRDATE to compiler space")
|
|
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)
|
|
message("passing HAVE_LIBUTIL to compiler space")
|
|
add_definitions(-DHAVE_LIBUTIL)
|
|
endif()
|
|
|
|
# add the main application
|
|
set(mbusd_SOURCES
|
|
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
|
|
)
|
|
add_executable(mbusd ${mbusd_SOURCES})
|
|
install(TARGETS mbusd DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
|
|
# aggregate the man page template
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/mbusd.8.in mbusd.8)
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mbusd.8 DESTINATION ${CMAKE_INSTALL_MANDIR}/man8)
|
|
|
|
# install example configuration file
|
|
install(
|
|
FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/mbusd.conf.example
|
|
DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/${CMAKE_PROJECT_NAME}
|
|
)
|
|
|
|
# aggregate mbusd@.service from its template
|
|
if(IS_DIRECTORY /usr/lib/systemd/system)
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/systemd-units/mbusd@.service.in mbusd@.service)
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mbusd@.service DESTINATION /usr/lib/systemd/system)
|
|
endif()
|
|
|
|
# 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
|
|
)
|
|
|
|
# unittest target
|
|
option(TESTS "Enable unittests" OFF)
|
|
if(TESTS)
|
|
add_executable(test_basic tests/test_basics.c)
|
|
endif() |