File: CMakeLists.txt

package info (click to toggle)
mbuffer 20200929%2Bds2-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,072 kB
  • sloc: ansic: 4,189; sh: 3,384; makefile: 160
file content (197 lines) | stat: -rw-r--r-- 5,208 bytes parent folder | download | duplicates (4)
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#
#  Copyright (C) 2019, Thomas Maier-Komor
#
#  This is source code of mbuffer.
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

cmake_minimum_required(VERSION 3.1.0)

include(CheckStructHasMember)
include(CheckLibraryExists)
include(CheckSymbolExists)
include(CMakePrintHelpers)

project(mbuffer C)

find_package(Threads)

set(PACKAGE_VERSION "20191016")
set(CMAKE_C_FLAGS_DEBUG "-g")
set(CMAKE_LD_FLAGS_DEBUG "-g")
set(CMAKE_C_FLAGS_RELEASE "-O2")
set(CMAKE_LD_FLAGS_RELEASE "-O2")
set(TESTTREE "..")
add_compile_options("-Wall")
add_definitions(-DDEBUG)

find_program(AWK NAMES gawk awk)
find_program(MT mt)
find_program(OPENSSL openssl)
find_program(NM NAMES gnm nm)
find_program(SH NAMES bash sh)
find_program(DIFF NAMES gdiff diff)
find_program(TAR NAMES gtar tar)


set(TESTFILE "test.tar" CACHE PATH "test input file")
#message(STATUS "testfile is ${TESTFILE}")

check_struct_has_member("struct stat" st_blksize sys/stat.h HAVE_STRUCT_STAT_ST_BLKSIZE LANGUAGE C)
check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
check_library_exists(crypto MD5_Init "openssl/md5.h" HAVE_LIBCRYPTO)

if (HAVE_LIBCRYPTO)
	set(LIBS ${LIBS} crypto)
endif()

check_include_file(alloca.h HAVE_ALLOCA_H)
check_include_file(md5.h HAVE_MD5_H)
check_include_file(sys/sendfile.h HAVE_SENDFILE_H)

check_symbol_exists(alloca stdlib.h;alloca.h HAVE_ALLOCA)
check_symbol_exists(sendfile "sendfile.h;sys/sendfile.h;sys/socket.h" HAVE_SENDFILE)
check_symbol_exists(hstrerror netdb.h HAVE_HSTRERROR)
check_symbol_exists(getaddrinfo "netdb.h;sys/socket.h" HAVE_GETADDRINFO)
check_symbol_exists(mmap sys/mman.h HAVE_MMAP)
check_symbol_exists(seteuid unistd.h HAVE_SETEUID)


find_library(LIBSENDFILE sendfile)
if (LIBSENDFILE)
	set(LIBS ${LIBS} ${LIBSENDFILE})
endif()

find_library(LIBDL dl)
if (LIBDL)
	set(LIBS ${LIBS} ${LIBDL})
endif()

find_library(LIBRT rt)
if (LIBRT)
	set(LIBS ${LIBS} ${LIBRT})
endif()

find_library(LIBRESOLV resolv)
if (LIBRESOLV)
	set(LIBS ${LIBS} ${LIBRESOLV})
endif()

find_library(LIBSOCKET socket)
if (LIBSOCKET)
	set(LIBS ${LIBS} ${LIBSOCKET})
endif()

find_library(LIBNSL nsl)
if (LIBNSL)
	set(LIBS ${LIBS} ${LIBNSL})
endif()

find_library(LIBM m)
if (LIBM)
	set(LIBS ${LIBS} ${LIBM})
endif()

add_executable(mbuffer
	mbuffer.c
	input.c
	network.c
	hashing.c
	common.c
	globals.c
	settings.c
	log.c
)

target_link_libraries(
	mbuffer
	${LIBS}
	${CMAKE_THREAD_LIBS_INIT}
)

target_compile_definitions(
	mbuffer
	PRIVATE PREFIX="${CMAKE_INSTALL_PREFIX}"
)

install(FILES
	mbuffer
	DESTINATION bin
)

# testing section

if (ENABLE_TESTING)
	enable_testing()

	try_compile(LFNAMES ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/lf_names.c COPY_FILE ${PROJECT_BINARY_DIR}/lf_names)
	if (LFNAMES)
		execute_process(
			COMMAND ${NM} -u -P ${PROJECT_BINARY_DIR}/lf_names
			OUTPUT_FILE "${PROJECT_BINARY_DIR}/lf_names.txt"
		)
		execute_process(
			COMMAND ${AWK} "/open/ { sub(\"@.*\",\"\",$1); printf(\"%s\",\$1); }" ${PROJECT_BINARY_DIR}/lf_names.txt
			OUTPUT_VARIABLE LF_OPEN
		)
		execute_process(
			COMMAND ${AWK} "/fstat/ { sub(\"@.*\",\"\",$1); printf(\"%s\",\$1); }" ${PROJECT_BINARY_DIR}/lf_names.txt
			OUTPUT_VARIABLE LF_FSTAT
		)
		execute_process(
			COMMAND ${AWK} "/read/ { sub(\"@.*\",\"\",$1); printf(\"%s\",\$1); }" ${PROJECT_BINARY_DIR}/lf_names.txt
			OUTPUT_VARIABLE LF_READ
		)
		execute_process(
			COMMAND ${AWK} "/write/ { sub(\"@.*\",\"\",$1); printf(\"%s\",\$1); }" ${PROJECT_BINARY_DIR}/lf_names.txt
			OUTPUT_VARIABLE LF_WRITE
		)
		cmake_print_variables(LF_OPEN)
	endif()

	add_executable(have-af have-af.c)

	add_library(idev SHARED idev.c)
	add_library(tapetest SHARED tapetest.c)

	set_target_properties(idev tapetest
		PROPERTIES
		INTERFACE_POSITION_INDEPENDENT_CODE ON
	)
	
	add_test(NAME test0 COMMAND ${SH} -x test0.sh ${TESTFILE})
	add_test(NAME test1 COMMAND ${SH} -x test1.sh ${TESTFILE})
	add_test(NAME test2 COMMAND ${SH} -x test2.sh ${TESTFILE})
	add_test(NAME test3 COMMAND ${SH} -x test3.sh ${TESTFILE})
	add_test(NAME test4 COMMAND ${SH} -x test4.sh ${TESTFILE})
	add_test(NAME test5 COMMAND ${SH} -x test5.sh ${TESTFILE})
	add_test(NAME test6 COMMAND ${SH} -x test6.sh ${TESTFILE})
	add_test(NAME test7 COMMAND ${SH} -x test7.sh ${TESTFILE})
	
	set_tests_properties(test0 test1 test2 test3 test4 test5 test6 test7
		PROPERTIES
		ENVIRONMENT "DIFF=${DIFF};OPENSSL=${OPENSSL}"
		WORKING_DIRECTORY tests
		DEPENDS test.tar
	)
	
	set_tests_properties(test4 PROPERTIES DEPENDS tapetest)
	set_tests_properties(test5 PROPERTIES DEPENDS tapetest)
	#set_tests_properties(test6 PROPERTIES DEPENDS idev)
	
endif()

configure_file(config.h.cm config.h)