forked from appneta/tcpreplay
-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
436 lines (379 loc) · 14.4 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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
cmake_minimum_required(VERSION 2.6)
project(TCPREPLAY)
include(CheckFunctionExists)
include(CheckIncludeFile)
include(CheckCCompilerFlag)
include(CheckSymbolExists)
include(CheckTypeSize)
include(FindCygwin)
include(FindGit)
include(CheckCSourceRuns)
include(CMakeFindFrameworks)
# Where to find local cmake scripts
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-modules")
#packaging
set(CPACK_PACKAGE_NAME tcpreplay)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Pcap editing and replay tools for Unix & Windows")
set(CPACK_PACKAGE_VENDOR "tcpreplay")
# set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
# set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/docs/LICENSE")
set(CPACK_PACKAGE_VERSION_MAJOR "4")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0alpha1")
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(VERSION ${CPACK_PACKAGE_VERSION})
set(CPACK_CMAKE_GENERATOR "Unix Makefiles")
set(CPACK_GENERATOR "TGZ")
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_IGNORE_FILES
/CMakeFiles/
/.svn/
/docs/web/
/.deps/
CMakeCache.txt
cmake_install.cmake
.gdb_history
.*.a$
.*.o$
.*~$
.tmproj
Makefile
doxygen.cfg$
/src/tcpreplay$
/src/tcpreplay-edit$
/src/tcprewrite$
/src/tcpprep$
/src/tcpbridge$
/test/Standard.cmake$
.*tar.gz$
/_CPack_Packages/
CPackSourceConfig.cmake$
CPackConfig.cmake$
)
include(CPack)
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "/usr/local")
set(CPACK_GENERATOR "TGZ")
set(CPACK_SOURCE_GENERATOR "TGZ")
find_program(ECHO echo)
find_program(DIFF diff)
find_program(TCPDUMP_BINARY tcpdump)
find_program(CTAGS ctags)
find_program(ETAGS etags)
find_program(GROFF groff)
set(USE_AUTOOPTS YES)
if(WIN32 AND NOT CYGWIN)
set(USE_AUTOOPTS NO)
message(STATUS "Disabling GNU AutoOpts on Win32 platform")
endif(WIN32 AND NOT CYGWIN)
option(ENABLE_DEBUG "Enable debug support" NO)
option(FORCE_INJECT_PF "Force using Linux's PF_PACKET API to send frames" NO)
option(FORCE_INJECT_BPF "Force using *BSD's BPF API to send frames" NO)
option(FORCE_INJECT_LIBDNET "Force using libdnet to send frames" NO)
option(FORCE_INJECT_PCAP_INJECT "Force using libpcap pcap_inject() to send frames" NO)
option(FORCE_INJECT_PCAP_SENDPACKET "Force using winpcap/libpcap's pcap_sendpacket() to send frames" NO)
option(USE_AUTOOPTS "Compile with GNU AutoOpts support (enables CLI tools)" ${USE_AUTOOPTS})
option(ENABLE_64BITS "Enable 64bit packet counters" YES)
option(BUILD_64BIT_BINARY "Build a 64bit binary")
option(BUILD_QT_GUI "Build QT4 GUI version of tcpreplay tools" NO)
mark_as_advanced(FORCE_INJECT_PF FORCE_INJECT_BPF FORCE_INJECT_LIBDNET
FORCE_INJECT_PCAP_INJECT FORCE_INJECT_PCAP_SENDPACKET AUTOCONF AUTOGEN AUTOMAKE
CMAKE_BUILD_TYPE ECHO MAKE TCPDUMP_BINARY ENABLE_64BITS
USE_AUTOOPTS LIBPCAP_DIR LIBDNET_DIR)
if(ENABLE_DEBUG)
set(__GGDB -g)
CHECK_C_COMPILER_FLAG(-ggdb GCC_GDB)
if(GCC_GDB)
set(__GGDB -ggdb)
endif(GCC_GDB)
add_definitions("-DDEBUG ${__GGDB}")
endif(ENABLE_DEBUG)
add_definitions(-D_GNU_SOURCE)
add_definitions(-D__USE_BSD)
set(ENABLE_VERBOSE "")
if(EXISTS ${TCPDUMP_BINARY})
if(NOT WIN32)
message(STATUS "Enabling tcpreplay verbose mode using ${TCPDUMP_BINARY}")
set(ENABLE_VERBOSE 1)
endif(NOT WIN32)
endif(EXISTS ${TCPDUMP_BINARY})
# Required to help decide how to divide 64 bit integers
check_type_size(long LONG_SIZE BUILTIN_TYPES_ONLY)
# Most of the stuff below is stolen from Wireshark which released this under GPLv2 & BSD
set(gcc_extras "")
check_c_compiler_flag(-std=gnu99 GCC_GNU99)
if(GCC_GNU99)
set(gcc_extras -std=gnu99)
else(GCC_GNU99)
check_c_compiler_flag(-std=c99 GCC_C99)
if(GCC_C99)
set(gcc_extras -std=c99)
endif(GCC_C99)
endif(GCC_GNU99)
check_c_compiler_flag(-Wextra GCC_EXTRA)
if(GCC_EXTRA)
set(gcc_extras ${gcc_extras} -Wextra)
else(GCC_EXTRA)
check_c_compiler_flag(-W GCC_EXTRA_OLD)
if(GCC_EXTRA_OLD)
set(gcc_extras ${gcc_extras} -W)
endif(GCC_EXTRA_OLD)
endif(GCC_EXTRA)
check_c_compiler_flag(-Wfatal-errors GCC_FATAL_ERRORS)
if(GCC_FATAL_ERRORS)
set(gcc_extras ${gcc_extras} -Wfatal-errors)
endif(GCC_FATAL_ERRORS)
check_c_compiler_flag(-Wno-variadic-macros GCC_NO_VARIADIC_MACROS)
if(GCC_NO_VARIADIC_MACROS)
set(gcc_extras ${gcc_extras} -Wno-variadic-macros)
endif(GCC_NO_VARIADIC_MACROS)
if(CMAKE_COMPILER_IS_GNUCC)
add_definitions(
-DHAVE_CONFIG_H
\"-D_U_=__attribute__\(\(unused\)\)\"
-Wall -Wpointer-arith -std=gnu99 ${gcc_extras}
)
else(CMAKE_COMPILER_IS_GNUCC)
add_definitions(-DHAVE_CONFIG_H -D_U_=)
endif(CMAKE_COMPILER_IS_GNUCC)
# Build for x64?.
if(BUILD_64BIT_BINARY)
check_c_compiler_flag(-m64 SUPPORTS_64BIT_FLAG)
if(SUPPORTS_64BIT_FLAG)
# Actually make sure the code runs!
set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -m64)
check_c_source_runs("
#include <stdlib.h>
int
main(int argc, char *argv[])
{
printf(\"Hello world!\\\\n\");
return 0;
}
"
CAN_EXECUTE_M64_FLAG_CODE)
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
if(CAN_EXECUTE_M64_FLAG_CODE EQUAL 1)
message(STATUS "Building 64bit binaries via CFLAGS=-m64")
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -m64)
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -m64)
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} -m64)
set(CMAKE_MODULE_LINKER_FLAGS ${CMAKE_MODULE_LINKER_FLAGS} -m64)
set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} -m64)
endif(CAN_EXECUTE_M64_FLAG_CODE EQUAL 1)
endif(SUPPORTS_64BIT_FLAG)
endif(BUILD_64BIT_BINARY)
# Big or little endian ?
if(WIN32)
# Windows is always little endian
set(WORDS_BIGENDIAN FALSE)
else(WIN32)
include(TestBigEndian)
test_big_endian(WORDS_BIGENDIAN)
endif(WIN32)
include(FindPCAP)
set(ENABLE_TCPBRIDGE NO)
if(NOT HAVE_PCAP_SENDPACKET)
message(STATUS "libpcap does not have pcap_sendpacket(): skipping tcpbridge")
else(NOT HAVE_PCAP_SENDPACKET)
message(STATUS "We will build tcpbridge")
set(ENABLE_TCPBRIDGE YES)
endif(NOT HAVE_PCAP_SENDPACKET)
include(FindEvent)
include(FindDNET)
set(ENABLE_FRAGROUTE NO)
if(HAVE_LIBDNET)
set(ENABLE_FRAGROUTE YES)
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} ${DNET_CFLAGS})
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${DNET_CFLAGS})
endif(HAVE_LIBDNET)
include(CheckBPF)
include(CheckPFPacket)
include(CheckTxRing)
if(NOT HAVE_LIBPCAP AND NOT HAVE_BPF AND NOT HAVE_LIBDNET AND NOT HAVE_PF_PACKET)
message(FATAL_ERROR "You must have libpcap, libdnet, /dev/bpf or PF_PACKET socket support")
endif(NOT HAVE_LIBPCAP AND NOT HAVE_BPF AND NOT HAVE_LIBDNET AND NOT HAVE_PF_PACKET)
#check system for includes
check_include_file("arpa/inet.h" HAVE_ARPA_INET_H)
check_include_file("arpa/nameser.h" HAVE_ARPA_NAMESER_H)
check_include_file("bool.h" HAVE_BOOL_H)
check_include_file("direct.h" HAVE_DIRECT_H)
check_include_file("dirent.h" HAVE_DIRENT_H)
check_include_file("dlfcn.h" HAVE_DLFCN_H)
check_include_file("fcntl.h" HAVE_FCNTL_H)
check_include_file("getopt.h" NEED_GETOPT_H)
check_include_file("g_ascii_strtoull.h" NEED_G_ASCII_STRTOULL_H)
check_include_file("inet/aton.h" NEED_INET_ATON_H)
check_include_file("inttypes.h" HAVE_INTTYPES_H)
check_include_file("lauxlib.h" HAVE_LAUXLIB_H)
check_include_file("memory.h" HAVE_MEMORY_H)
check_include_file("netinet/in.h" HAVE_NETINET_IN_H)
check_include_file("netdb.h" HAVE_NETDB_H)
check_include_file("portaudio.h" HAVE_PORTAUDIO_H)
check_include_file("poll.h" HAVE_POLL_H)
check_include_file("signal.h" HAVE_SIGNAL_H)
check_include_file("stdarg.h" HAVE_STDARG_H)
check_include_file("stdbool.h" HAVE_STDBOOL_H)
check_include_file("stddef.h" HAVE_STDDEF_H)
check_include_file("stdint.h" HAVE_STDINT_H)
check_include_file("stdlib.h" HAVE_STDLIB_H)
check_include_file("strerror.h" NEED_STRERROR_H)
check_include_file("strings.h" HAVE_STRINGS_H)
check_include_file("string.h" HAVE_STRING_H)
check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H)
check_include_file("sys/param.h" HAVE_SYS_PARAM_H)
check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H)
check_include_file("sys/sockio.h" HAVE_SYS_SOCKIO_H)
check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
check_include_file("sys/time.h" HAVE_SYS_TIME_H)
check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
check_include_file("sys/utsname.h" HAVE_SYS_UTSNAME_H)
check_include_file("sys/wait.h" HAVE_SYS_WAIT_H)
check_include_file("unistd.h" HAVE_UNISTD_H)
check_include_file("inttypes.h" HAVE_INTTYPES_H)
check_include_file("time.h" HAVE_TIME_H)
check_include_file("netinet/in_systm.h" HAVE_NETINET_IN_SYSTM_H)
# look for types
check_type_size(uint8_t UINT8_T)
check_type_size(uint16_t UINT16_T)
check_type_size(uint32_t UINT32_T)
check_type_size(uint64_t UINT64_T)
# Functions
check_function_exists("chown" HAVE_CHOWN)
check_function_exists("gethostbyname2" HAVE_GETHOSTBYNAME2)
check_function_exists("getprotobynumber" HAVE_GETPROTOBYNUMBER)
check_function_exists("inet_ntop" HAVE_INET_NTOP)
check_function_exists("inet_aton" HAVE_INET_ATON)
check_function_exists("inet_pton" HAVE_INET_PTON)
check_function_exists("inet_addr" HAVE_INET_ADDR)
check_function_exists("issetugid" HAVE_ISSETUGID)
check_function_exists("mmap" HAVE_MMAP)
check_function_exists("mprotect" HAVE_MPROTECT)
check_function_exists("sysconf" HAVE_SYSCONF)
check_function_exists("poll" HAVE_POLL)
check_function_exists("strlcat" HAVE_STRLCAT)
check_function_exists("strlcpy" HAVE_SYSTEM_STRLCPY)
if(NOT HAVE_SYSTEM_STRLCPY)
add_subdirectory(lib)
include_directories(${CMAKE_SOURCE_DIR}/lib)
endif(NOT HAVE_SYSTEM_STRLCPY)
# is system strictly aligned?
include(CheckStrictAlign)
#64 Bit format
include(Check64BitFormat)
check_64bit_format(ll FORMAT_64BIT)
check_64bit_format(L FORMAT_64BIT)
check_64bit_format(q FORMAT_64BIT)
check_64bit_format(I64 FORMAT_64BIT)
if(NOT FORMAT_64BIT)
message(FATAL " 64 bit format missing")
endif(NOT FORMAT_64BIT)
set(PRIX64 "${FORMAT_64BIT}X")
set(PRIx64 "${FORMAT_64BIT}x")
set(PRId64 "${FORMAT_64BIT}d")
set(PRIo64 "${FORMAT_64BIT}o")
set(PRIu64 "${FORMAT_64BIT}u")
# OS X has absolute time
#CMAKE_FIND_FRAMEWORKS(Carbon)
#CMAKE_FIND_FRAMEWORKS(CoreServices)
#if(CoreServices_FRAMEWORKS AND Carbon_FRAMEWORKS)
# set(HAVE_ABSOLUTE_TIME 1)
# message(STATUS "Enabling OS X's absolute_time()")
#endif(CoreServices_FRAMEWORKS AND Carbon_FRAMEWORKS)
include(FindDoxygen)
include(FindUnixCommands)
include(CheckAutogen)
if(USE_AUTOOPTS)
message(STATUS "Configuring libopts tearoff...")
include(CheckLibopts)
CHECK_LIBOPTS_TEAROFF(${CMAKE_SOURCE_DIR}/libopts 5.9.7)
else(USE_AUTOOPTS)
message(STATUS "Skipping libopts tearoff")
endif(USE_AUTOOPTS)
configure_file(src/config.h.cmake src/config.h @ONLY)
configure_file(src/defines.h.in src/defines.h @ONLY)
configure_file(doxygen.cfg.in doxygen.cfg @ONLY)
include_directories(${CMAKE_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_SOURCE_DIR}/src/tcpedit)
include_directories(${PCAP_INCLUDE_DIRS})
# Recurse into the subdirectories. This does not actually
# cause another cmake executable to run. The same process will walk through
# the project's entire directory structure
add_subdirectory(src)
add_subdirectory(docs)
add_subdirectory(test)
configure_file(${CMAKE_SOURCE_DIR}/cmake/BuildDistTgz.cmake.in ${CMAKE_BINARY_DIR}/cmake/BuildDistTgz.cmake)
add_custom_target(dist-gzip
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/BuildDistTgz.cmake
)
# Create ctags for vim, etc
add_custom_target(ctags
COMMAND ${CTAGS} -R src lib libopts
)
# Create etags for emacs
add_custom_target(etags
COMMAND ${ETAGS} -R src lib libopts
)
if(USE_AUTOOPTS)
add_custom_target(clean_autogen
COMMAND cmake -P ${CMAKE_SOURCE_DIR}/cmake/CleanAutogen.cmake
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src
DEPENDS cmake/CleanAutogen.cmake
VERBATIM)
endif(USE_AUTOOPTS)
# make doxygen
include("${CMAKE_MODULE_PATH}/TargetDoc.cmake" OPTIONAL)
# Clean up to be yes/no not 1/0
if(HAVE_PCAP_INJECT)
set(HAVE_PCAP_INJECT YES)
else(HAVE_PCAP_INJECT)
set(HAVE_PCAP_INJECT NO)
endif(HAVE_PCAP_INJECT)
if(HAVE_PCAP_SENDPACKET)
set(HAVE_PCAP_SENDPACKET YES)
else(HAVE_PCAP_SENDPACKET)
set(HAVE_PCAP_SENDPACKET NO)
endif(HAVE_PCAP_SENDPACKET)
if(HAVE_BPF)
set(HAVE_BPF YES)
else(HAVE_BPF)
set(HAVE_BPF NO)
endif(HAVE_BPF)
if(ENABLE_64BITS)
set(ENABLE_64BITS YES)
else(ENABLE_64BITS)
set(ENABLE_64BITS NO)
endif(ENABLE_64BITS)
string(COMPARE EQUAL AUTOGEN_VERSION LIBOPTS_VERSION AUTOGEN_VER_MATCH)
if(AUTOGEN_VER_MATCH)
set(AUTOGEN_VER_MATCH "matches libopts tearoff")
else(AUTOGEN_VER_MATCH)
set(AUTOGEN_VER_MATCH "warning! libopts tearoff is version ${LIBOPTS_VERSION}")
endif(AUTOGEN_VER_MATCH)
message(STATUS
"
##########################################################################
TCPREPLAY Suite Configuration Results ${VERSION} ${REPO_VERSION}
##########################################################################
install location: ${CPACK_PACKAGE_INSTALL_DIRECTORY}
libpcap: ${HAVE_LIBPCAP} ${PCAP_LIBRARIES}
libdnet: ${HAVE_LIBDNET} ${DNET_LIBS} (${LIBDNET_VERSION})
libevent: ${HAVE_LIBEVENT} ${EVENT_LIBRARIES}
autogen: ${AUTOGEN} (${AUTOGEN_VERSION}) ${AUTOGEN_VER_MATCH}
64bit counter support: ${ENABLE_64BITS}
tcpdump binary path: ${TCPDUMP_BINARY}
fragroute support: ${ENABLE_FRAGROUTE}
tcpbridge support: ${ENABLE_TCPBRIDGE}
Supported Packet Injection Methods (*):
Linux TX_RING: ${HAVE_TX_RING}
Linux PF_PACKET: ${HAVE_PF_PACKET}
BSD BPF: ${HAVE_BPF}
libdnet: ${HAVE_LIBDNET}
pcap_inject: ${HAVE_PCAP_INJECT}
pcap_sendpacket: ${HAVE_PCAP_SENDPACKET} **
* In order of preference; see configure --help to override
** Required for tcpbridge"
)