forked from Netis/cloud-probe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
345 lines (289 loc) · 12.1 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
cmake_minimum_required(VERSION 2.8)
project(pktminerg)
option(PROJECT_WITH_PROF "Enable profiling and coverage report analysis" OFF)
message("\${PROJECT_WITH_PROF}: ${PROJECT_WITH_PROF}")
# cmake cxx flags
if (${PROJECT_WITH_PROF})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fprofile-arcs -ftest-coverage")
set(LINK_FLAGS "${LINK_FLAGS} -fprofile-arcs")
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
endif ()
# set PKTMINERG_MAJOR_VERSION, PKTMINERG_MINOR_VERSION, etc.
set(PKTMINERG_MAJOR_VERSION "0")
set(PKTMINERG_MINOR_VERSION "3")
set(PKTMINERG_PATCH_VERSION "6")
set(PKTMINERG_VERSION_STRING "${PKTMINERG_MAJOR_VERSION}.${PKTMINERG_MINOR_VERSION}.${PKTMINERG_PATCH_VERSION}")
if(WIN32)
Add_Definitions(-D_XKEYCHECK_H)
endif()
# Get the current working branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
# COMMAND git symbolic-ref --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message("branch: " ${GIT_BRANCH})
# 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
)
message("commit: " ${GIT_COMMIT_HASH})
# Get build time
string(TIMESTAMP BUILD_TIME "%Y-%m-%d %H:%M:%S")
add_definitions("-DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}")
add_definitions("-DGIT_BRANCH=${GIT_BRANCH}")
add_definitions("-DBUILD_TIME=${BUILD_TIME}")
configure_file(
${PROJECT_SOURCE_DIR}/version.h.in
${PROJECT_BINARY_DIR}/version.h
)
if(APPLE)
find_library(LIBPCAP NAMES libpcap.dylib)
find_library(LIBSTDCPP NAMES libstdc++.6.dylib)
find_library(LIBGCCS NAMES libgcc_s.1.dylib)
add_definitions(-DMAC)
elseif(UNIX)
find_library(LIBPCAP NAMES libpcap.so)
find_library(LIBSTDCPP NAMES libstdc++.so.6)
find_library(LIBGCCS NAMES libgcc_s.so.1)
endif()
if(UNIX)
if (NOT LIBPCAP)
message(FATAL_ERROR "lib pcap not found")
endif()
message("LIBPCAP: " ${LIBPCAP})
if (NOT LIBSTDCPP)
message(FATAL_ERROR "lib stdcpp not found")
endif()
message("LIBSTDCPP: " ${LIBSTDCPP})
if (NOT LIBGCCS)
message(FATAL_ERROR "lib gccs not found")
endif()
message("LIBGCCS: " ${LIBGCCS})
INCLUDE(FindBoost)
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost 1.41.0 REQUIRED COMPONENTS program_options system filesystem)
find_package(cppzmq)
message("Boost_INCLUDE_DIRS: " ${Boost_INCLUDE_DIRS})
message("Boost_LIBRARY_DIRS: " ${Boost_LIBRARY_DIRS})
# include dir
include_directories(
${PROJECT_SOURCE_DIR}/include
${PROJECT_BINARY_DIR}
${Boost_INCLUDE_DIRS}
)
endif()
if(WIN32)
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost REQUIRED COMPONENTS program_options system filesystem)
include_directories(
${PROJECT_SOURCE_DIR}/include
${PROJECT_BINARY_DIR}
${BOOST_ROOT}
${PCAP_ROOT}/Include
)
link_directories(
${BOOST_ROOT}/stage/lib
${PCAP_ROOT}/lib/x64)
endif()
if(UNIX AND NOT APPLE)
# link dir
link_directories(${Boost_LIBRARY_DIRS})
# read the real file which libpcap.so links to
execute_process(COMMAND readlink -f ${LIBPCAP}
OUTPUT_VARIABLE PCAP_REAL_FILE OUTPUT_STRIP_TRAILING_WHITESPACE)
message("PCAP REAL FILE: " ${PCAP_REAL_FILE})
# read the real file which libstdc++.so links to
execute_process(COMMAND readlink -f ${LIBSTDCPP}
OUTPUT_VARIABLE STDCPP_REAL_FILE OUTPUT_STRIP_TRAILING_WHITESPACE)
message("STDCPP REAL FILE: " ${STDCPP_REAL_FILE})
# read the real file which libgcc_s.so links to
execute_process(COMMAND readlink -f ${LIBGCCS}
OUTPUT_VARIABLE GCCS_REAL_FILE OUTPUT_STRIP_TRAILING_WHITESPACE)
message("GCCS REAL FILE: " ${GCCS_REAL_FILE})
# read the real file which libboost_*.so links to
execute_process(COMMAND readlink -f ${Boost_FILESYSTEM_LIBRARY}
OUTPUT_VARIABLE BOOST_FILESYSTEM_REAL_FILE OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND readlink -f ${Boost_PROGRAM_OPTIONS_LIBRARY}
OUTPUT_VARIABLE BOOST_PROGRAM_OPTIONS_REAL_FILE OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND readlink -f ${Boost_SYSTEM_LIBRARY}
OUTPUT_VARIABLE BOOST_SYSTEM_REAL_FILE OUTPUT_STRIP_TRAILING_WHITESPACE)
# mkdir tmp dir to store third party lib
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/netis)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/3rdlib)
file(COPY
${BOOST_FILESYSTEM_REAL_FILE}
${BOOST_PROGRAM_OPTIONS_REAL_FILE}
${BOOST_SYSTEM_REAL_FILE}
${PCAP_REAL_FILE}
${STDCPP_REAL_FILE}
${GCCS_REAL_FILE}
DESTINATION ${PROJECT_BINARY_DIR}/3rdlib
)
# make link file
execute_process(COMMAND basename ${LIBPCAP} OUTPUT_VARIABLE BN_PCAP_LINK OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND basename ${PCAP_REAL_FILE} OUTPUT_VARIABLE BN_PCAP_REAL OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ln -s ${BN_PCAP_REAL} ${BN_PCAP_LINK} WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/3rdlib)
execute_process(COMMAND basename ${LIBSTDCPP} OUTPUT_VARIABLE BN_STDCPP_LINK OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND basename ${STDCPP_REAL_FILE} OUTPUT_VARIABLE BN_STDCPP_REAL OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ln -s ${BN_STDCPP_REAL} ${BN_STDCPP_LINK} WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/3rdlib)
execute_process(COMMAND basename ${LIBGCCS} OUTPUT_VARIABLE BN_GCCS_LINK OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND basename ${GCCS_REAL_FILE} OUTPUT_VARIABLE BN_GCCS_REAL OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ln -s ${BN_GCCS_REAL} ${BN_GCCS_LINK} WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/3rdlib)
endif()
# output dir
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
# source
if(WIN32)
set(SOURCE_FILES_SYSHELP
${PROJECT_SOURCE_DIR}/src/syshelp_win32.cpp
)
else()
set(SOURCE_FILES_SYSHELP
${PROJECT_SOURCE_DIR}/src/syshelp.cpp
)
endif()
if(WIN32)
set(SOURCE_FILES_PCAP
${PROJECT_SOURCE_DIR}/src/pcap_win32.cpp
)
endif()
set(SOURCE_FILES_GREDEMO
${PROJECT_SOURCE_DIR}/tools/gredemo.cpp
)
set(SOURCE_FILES_GREDUMP
${PROJECT_SOURCE_DIR}/tools/gredump.cpp
${SOURCE_FILES_PCAP}
)
set(SOURCE_FILES_PCAPCOMPARE
${PROJECT_SOURCE_DIR}/tools/pcapcompare.cpp
)
if(WIN32)
set(SOURCE_FILES_PKTMINERG_BASE
${SOURCE_FILES_SYSHELP}
${SOURCE_FILES_PCAP}
${PROJECT_SOURCE_DIR}/src/socketgre.cpp
${PROJECT_SOURCE_DIR}/src/pcaphandler.cpp
${PROJECT_SOURCE_DIR}/src/statislog.cpp
)
else()
set(SOURCE_FILES_PKTMINERG_BASE
${SOURCE_FILES_SYSHELP}
${SOURCE_FILES_PCAP}
${PROJECT_SOURCE_DIR}/src/socketgre.cpp
${PROJECT_SOURCE_DIR}/src/pcaphandler.cpp
${PROJECT_SOURCE_DIR}/src/statislog.cpp
${PROJECT_SOURCE_DIR}/src/agent_status.cpp
${PROJECT_SOURCE_DIR}/src/agent_control_plane.cpp
)
endif()
set(SOURCE_FILES_PKTMINERG
${SOURCE_FILES_PKTMINERG_BASE}
${PROJECT_SOURCE_DIR}/src/pktminerg.cpp
)
# about install
set(CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR}/netis)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "/opt/netis/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
if(UNIX)
set(PCAP_LIB pcap)
set(BOOST_LIB boost_program_options.a boost_system.a boost_filesystem.a)
set(ZMQ_LIB cppzmq-static)
else()
set(PCAP_LIB wpcap Packet)
set(SOCKET_LIB ws2_32)
set(ZMQ_LIB )
endif()
# bin -- gredemo
add_executable(gredemo ${SOURCE_FILES_GREDEMO})
if(WIN32)
set_target_properties(gredemo PROPERTIES LINK_FLAGS "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\"")
endif()
target_link_libraries(gredemo ${BOOST_LIB} ${SOCKET_LIB})
# bin -- gredump
add_executable(gredump ${SOURCE_FILES_GREDUMP})
if(WIN32)
set_target_properties(gredump PROPERTIES LINK_FLAGS "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\"")
endif()
target_link_libraries(gredump ${BOOST_LIB} ${PCAP_LIB} ${SOCKET_LIB})
# bin -- pcapcompare
add_executable(pcapcompare ${SOURCE_FILES_PCAPCOMPARE})
target_link_libraries(pcapcompare ${BOOST_LIB} ${PCAP_LIB} ${SOCKET_LIB})
# bin -- pktminerg
add_executable(pktminerg ${SOURCE_FILES_PKTMINERG})
if(WIN32)
set_target_properties(pktminerg PROPERTIES LINK_FLAGS "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\"")
endif()
target_link_libraries(pktminerg ${BOOST_LIB} ${PCAP_LIB} ${SOCKET_LIB} ${ZMQ_LIB})
if(UNIX AND NOT APPLE)
# test
include_directories(${PROJECT_SOURCE_DIR}/test)
set(TEST_DIR ${PROJECT_SOURCE_DIR}/test)
# unit test
set(SOURCE_FILES_UNITTEST ${TEST_DIR}/unit_test.cpp
${TEST_DIR}/src/gtest.cc
${TEST_DIR}/src/gtest-death-test.cc
${TEST_DIR}/src/gtest-filepath.cc
${TEST_DIR}/src/gtest_main.cc
${TEST_DIR}/src/gtest-port.cc
${TEST_DIR}/src/gtest-printers.cc
${TEST_DIR}/src/gtest-test-part.cc
${TEST_DIR}/src/gtest-typed-test.cc)
add_executable(unittest ${SOURCE_FILES_UNITTEST} ${SOURCE_FILES_PKTMINERG_BASE})
target_link_libraries(unittest ${BOOST_LIB} pcap pthread ${ZMQ_LIB})
set_target_properties(unittest PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/test/bin")
endif()
# cpack
if(WIN32)
install(FILES
"${PROJECT_SOURCE_DIR}/README.md" "${PROJECT_SOURCE_DIR}/README-zh-Hans.md"
"${PROJECT_SOURCE_DIR}/USAGE.md" "${PROJECT_SOURCE_DIR}/BUILD.md"
"${PROJECT_SOURCE_DIR}/CHANGES.md" "${PROJECT_SOURCE_DIR}/INSTALL.md"
"${PROJECT_SOURCE_DIR}/LICENSE.md"
DESTINATION doc COMPONENT pktminerg)
install(TARGETS pktminerg gredump pcapcompare gredemo DESTINATION bin COMPONENT pktminerg)
set(CPACK_PACKAGE_NAME "netis-packet-agent")
set(CPACK_PACKAGE_VENDOR "netis")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Netis packet agent tools")
set(CPACK_PACKAGE_VERSION ${PKTMINERG_VERSION_STRING})
set(CPACK_GENERATOR "ZIP")
set(CPACK_OUTPUT_FILE_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.Windows.${CMAKE_SYSTEM_PROCESSOR})
else()
install(FILES
DESTINATION lib COMPONENT pktminerg)
install(FILES "${PROJECT_SOURCE_DIR}/scripts/packet-agent.service" DESTINATION /usr/lib/systemd/system COMPONENT pktminerg)
install(FILES "${PROJECT_SOURCE_DIR}/scripts/pktgd.sh" DESTINATION etc COMPONENT pktminerg)
install(TARGETS pktminerg gredump pcapcompare DESTINATION bin COMPONENT pktminerg)
set(CPACK_PACKAGE_CONTACT "netis")
set(CPACK_PACKAGE_NAME "netis-packet-agent")
set(CPACK_PACKAGE_VENDOR "netis")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Netis packet agent tools")
set(CPACK_PACKAGE_VERSION ${PKTMINERG_VERSION_STRING})
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local")
set(CPACK_OUTPUT_FILE_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/installer)
if (DEBIAN)
set(CPACK_GENERATOR "DEB")
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}_amd64)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${PROJECT_SOURCE_DIR}/scripts/postinst")
else ()
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.el6.${CMAKE_SYSTEM_PROCESSOR})
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/scripts/postinst_rpm.sh")
endif()
#set(CPACK_COMPONENTS_ALL pktminerg)
endif()
include(CPack)