-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
158 lines (123 loc) · 4.74 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
cmake_minimum_required(VERSION 3.1.0)
project(XiaoTuNetBox)
set(PACKAGE_VERSION "0.0.8")
add_compile_options(-std=c++17)
set(CMAKE_BUILD_TYPE DEBUG)
message("${PROJECT_NAME}")
message("${PROJECT_SOURCE_DIR}")
message("${PROJECT_BINARY_DIR}")
message("${CMAKE_INSTALL_PREFIX}")
include_directories(
${PROJECT_SOURCE_DIR}/include
)
############################################################################
#
# libXiaoTuNetBox.so
#
############################################################################
file(GLOB PROJECT_SRC_FILES
${PROJECT_SOURCE_DIR}/src/*cpp
${PROJECT_SOURCE_DIR}/src/Event/*cpp
${PROJECT_SOURCE_DIR}/src/Http/*cpp
)
add_library(${PROJECT_NAME} SHARED
${PROJECT_SRC_FILES}
)
target_link_libraries(${PROJECT_NAME})
############################################################################
#
# utils
#
############################################################################
# echo 服务器 - 原始 poll 接口实现
add_executable(u_raw_poll_echo utils/u_raw_poll_echo.cpp)
target_link_libraries(u_raw_poll_echo ${PROJECT_NAME} glog gflags pthread)
# echo 服务器 - 原始 epoll 接口实现
add_executable(u_raw_epoll_echo utils/u_raw_epoll_echo.cpp)
target_link_libraries(u_raw_epoll_echo ${PROJECT_NAME} glog gflags pthread)
# 一个 TCP 客户端
add_executable(u_stdin_ipv4_talk utils/u_stdin_ipv4_talk.cpp)
target_link_libraries(u_stdin_ipv4_talk ${PROJECT_NAME} glog gflags pthread)
# echo 服务器
add_executable(u_echo_server utils/u_echo_server.cpp)
target_link_libraries(u_echo_server ${PROJECT_NAME} glog gflags pthread)
# epoll echo 服务器
add_executable(u_epoll_echo_server utils/u_epoll_echo_server.cpp)
target_link_libraries(u_epoll_echo_server ${PROJECT_NAME} glog gflags pthread)
# HTTP 服务器
add_executable(u_http_server utils/u_http_server.cpp)
target_link_libraries(u_http_server pthread ${PROJECT_NAME} glog gflags pthread)
# epoll http 服务器
add_executable(u_epoll_http_server utils/u_epoll_http_server.cpp)
target_link_libraries(u_epoll_http_server ${PROJECT_NAME} glog gflags pthread)
# WebSocket 服务器
add_executable(u_ws_server utils/u_ws_server.cpp)
target_link_libraries(u_ws_server pthread ${PROJECT_NAME} glog gflags pthread)
#
## epoll WebSocket 服务器
#add_executable(u_epoll_ws_server utils/u_epoll_ws_server.cpp)
#target_link_libraries(u_epoll_ws_server pthread ${PROJECT_NAME})
############################################################################
#
# tests
#
############################################################################
enable_testing()
set(TEST_DEPENDS gtest gtest_main pthread rt)
function(build_test_case NAME EXEC TSRC)
message(STATUS "build_test_case:" ${NAME})
message(STATUS "EXEC = " ${EXEC})
message(STATUS "TSRC = " ${TSRC})
add_executable(${EXEC} ${TSRC})
target_link_libraries(${EXEC} ${TEST_DEPENDS} ${PROJECT_NAME} glog gflags pthread)
add_test(NAME ${NAME} COMMAND ${EXEC})
endfunction()
build_test_case(DataArray t_DataArray test/t_DataArray.cpp)
build_test_case(DataQueue t_DataQueue test/t_DataQueue.cpp)
build_test_case(Address t_Address test/t_Address.cpp)
build_test_case(Socket t_Socket test/t_Socket.cpp)
############################################################################
#
# documentation
#
############################################################################
include(cmake/build_doxygen.cmake)
build_doxygen()
############################################################################
#
# install
#
############################################################################
include(cmake/install_package.cmake)
install_package()
INSTALL(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
)
file(GLOB PROJECT_INC_FILES
${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/*.h
${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/*.hpp
)
INSTALL(FILES ${PROJECT_INC_FILES}
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}
)
function(install_include_subset SUBDIR)
message(STATUS "install_include_subset:" ${SUBDIR})
file(GLOB SUBDIR_INC_FILES
${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/${SUBDIR}/*.h
${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/${SUBDIR}/*.hpp
)
INSTALL(FILES ${SUBDIR_INC_FILES}
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}/${SUBDIR}
)
endfunction()
install_include_subset(Event)
install_include_subset(Http)
add_custom_target("uninstall" COMMENT "Uninstall installed files")
add_custom_command(
TARGET "uninstall"
POST_BUILD
COMMENT "Uninstall files with install_manifest.txt"
COMMAND xargs rm -vf < install_manifest.txt || echo Nothing in
install_manifest.txt to be uninstalled!
)