added initial support for cmake

Note: make install is currently not supported
This commit is contained in:
Nick 2017-11-22 09:46:28 +01:00
parent fa5a950171
commit d26f68ee05
5 changed files with 84 additions and 11 deletions

71
CMakeLists.txt Normal file
View File

@ -0,0 +1,71 @@
cmake_minimum_required(VERSION 3.2)
include(CMakeDependentOption)
include(CPack)
include(CheckFunctionExists)
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 via logw" ON)
check_function_exists(logw HAVE_LOGW)
if(HAVE_LOGW AND LOG)
add_definitions(-DLOG)
endif()
CMAKE_DEPENDENT_OPTION(DEBUG_LOG "extra debug log info" OFF "LOGW" OFF)
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()
include(CheckLibraryExists)
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()
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})

View File

@ -39,6 +39,15 @@ $ make
$ make clean
</pre>
Compilation using cmake
<pre>
$ git clone https://github.com/3cky/mbusd.git mbusd.git
$ cd mbusd.git
$ mkdir -p output.dir && cd output.dir
$ cmake ../
$ make
</pre>
Usage:
------

View File

@ -63,15 +63,6 @@
# include <libutil.h>
#endif
/*
* Uncomment this for enabling logging facility
*/
#define LOG
#ifdef LOG
/* uncomment this line for extra debug log info */
# define DEBUG
#endif
/*
* Useful min/max macroses
*/

View File

@ -46,6 +46,8 @@ extern int isdaemon;
int log_init(char *logname);
int log_app(char *logname, char *string);
void logw(int level, char *fmt, ...);
#else
#define logw(fmt, ...) {}
#endif
#endif /* _LOG_H */

View File

@ -85,12 +85,12 @@ daemon(nochdir, noclose)
if (!nochdir)
(void)chdir("/");
if (!noclose && (fd = _open("/dev/null", O_RDWR, 0)) != -1) {
if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) {
(void)dup2(fd, STDIN_FILENO);
(void)dup2(fd, STDOUT_FILENO);
(void)dup2(fd, STDERR_FILENO);
if (fd > 2)
(void)_close(fd);
(void)close(fd);
}
return (0);
}