-
Notifications
You must be signed in to change notification settings - Fork 219
/
CMakeLists.txt
158 lines (140 loc) · 5.34 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
cmake_minimum_required(VERSION 3.2)
project(mbusd VERSION 0.5.3 LANGUAGES C)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/extern_GPL)
include(CheckFunctionExists)
include(CheckLibraryExists)
include(CheckSymbolExists)
include(GNUInstallDirs)
include(FindUnixCommands)
include(FindSystemd)
#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_symbol_exists(TIOCSRS485 sys/ioctl.h HAVE_TIOCRS485)
if(HAVE_TIOCRS485)
add_definitions(-DHAVE_TIOCRS485)
endif()
check_function_exists(time HAVE_TIME)
check_function_exists(localtime HAVE_LOCALTIME)
if(HAVE_TIME AND HAVE_LOCALTIME)
message(STATUS "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(STATUS "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/state.c
src/sig.c
src/sock.c
src/util.c
)
add_executable(mbusd ${mbusd_SOURCES})
install(TARGETS mbusd DESTINATION bin)
# 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_FULL_DATADIR}/man/man8)
# install example configuration file
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/mbusd.conf.example
DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/${CMAKE_PROJECT_NAME}
)
if(SYSTEMD_SERVICES_INSTALL_DIR)
message(STATUS "Systemd service file will be installed to ${SYSTEMD_SERVICES_INSTALL_DIR}")
# aggregate [email protected] from its template
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/systemd-units/[email protected] [email protected])
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/[email protected] DESTINATION ${SYSTEMD_SERVICES_INSTALL_DIR})
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
)
# integration tests target
enable_testing()
add_test(
NAME itests
COMMAND ${BASH} -c "cd ${CMAKE_CURRENT_SOURCE_DIR}/tests && ./run_itests.sh $<TARGET_FILE:mbusd>"
)
## 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
)
## issue the package creation with $make package
# which infrastructure do we want
set(CPACK_GENERATOR "DEB")
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/
set(CPACK_GENERATOR "RPM")
endif()
set(CPACK_PACKAGE_NAME "mbusd")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Victor Antonovich") #required
set(CPACK_PACKAGE_CONTACT "Victor Antonovich <[email protected]>")
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")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Modbus TCP to Modbus RTU gateway")
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
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}")