-
Notifications
You must be signed in to change notification settings - Fork 143
/
CMakeLists.txt
executable file
·208 lines (153 loc) · 6.82 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
cmake_minimum_required(VERSION 3.2)
project(framework)
set(CMAKE_VERBOSE_MAKEFILE off)
set(TARS_CPP_COMMON "1")
include("${PROJECT_SOURCE_DIR}/tarscpp/cmake/GenVersion.cmake")
include("${PROJECT_SOURCE_DIR}/tarscpp/cmake/Common.cmake")
include("${PROJECT_SOURCE_DIR}/tarscpp/cmake/BuildTarsCpp.cmake")
include("${PROJECT_SOURCE_DIR}/tarscpp/cmake/Thirdparty.cmake")
include("${PROJECT_SOURCE_DIR}/tarscpp/cmake/ParseAsm.cmake")
add_subdirectory(tarscpp)
if(UNIX OR APPLE)
option(ENABLE_ADDRESSSANITIZER "enable AddressSanitizer" OFF)
if(ENABLE_ADDRESSSANITIZER)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror -fsanitize=address -fno-omit-frame-pointer -g")
endif ()
message("ENABLE_ADDRESSSANITIZER: ${ENABLE_ADDRESSSANITIZER}")
endif()
set(major "3")
set(minor "0")
set(patch "17")
set(FRAMEWORK_VERSION ${major}.${minor}.${patch})
add_definitions(-DFRAMEWORK_VERSION="${FRAMEWORK_VERSION}")
add_definitions(-DTARS_VERSION="${TARS_VERSION}")
message("FRAMEWORK_VERSION: ${FRAMEWORK_VERSION}")
message("----------------------------------------------------")
include_directories(${servant_SOURCE_DIR})
set(BUILD_SERVER servers)
if(WIN32)
set(TARS_INSTALL_PATH c:\\tars-install)
else(WIN32)
set(TARS_INSTALL_PATH /usr/local/app)
endif(WIN32)
macro(complice_module MODULE)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${BUILD_SERVER}/${MODULE}/bin)
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR}/${BUILD_SERVER}/${MODULE}/bin)
endforeach()
include_directories(${PROJECT_SOURCE_DIR}/tarscpp/servant/protocol/framework)
include_directories(${PROJECT_SOURCE_DIR}/tarscpp/util/include)
if(WIN32)
include_directories(${PROJECT_SOURCE_DIR}/tarscpp/util/src/epoll_windows)
endif()
include_directories(${servant_SOURCE_DIR}/servant)
aux_source_directory(. DIR_SRCS)
add_executable(${MODULE} ${DIR_SRCS})
add_dependencies(${MODULE} FRAMEWORK-PROTOCOL)
add_dependencies(${MODULE} tars2cpp)
target_link_libraries(${MODULE} tarsservant tarsutil)
if(TARS_SSL)
target_link_libraries(${MODULE} ${LIB_SSL} ${LIB_CRYPTO})
endif()
if(TARS_HTTP2)
target_link_libraries(${MODULE} ${LIB_HTTP2})
endif()
if(NOT WIN32)
target_link_libraries(${MODULE} ${CMAKE_BINARY_DIR}/src/mysql/lib/libmysqlclient.a)
else ()
target_link_libraries(${MODULE} ${LIB_MYSQL})
endif()
if(NOT WIN32)
link_libraries(pthread z dl)
endif()
endmacro()
add_subdirectory(mysql-tool)
add_subdirectory(ConfigServer)
add_subdirectory(NodeServer)
add_subdirectory(NotifyServer)
add_subdirectory(PatchServer)
add_subdirectory(AdminRegistryServer)
add_subdirectory(RegistryServer)
add_subdirectory(PropertyServer)
add_subdirectory(LogServer)
add_subdirectory(patchclient)
add_subdirectory(StatServer)
add_subdirectory(QueryStatServer)
add_subdirectory(QueryPropertyServer)
############################################################################################
# 打包deploy, 用于部署
set(DEPENDS_LIST)
list(APPEND DEPENDS_LIST tarsnode)
list(APPEND DEPENDS_LIST tarsregistry)
list(APPEND DEPENDS_LIST tarsAdminRegistry)
list(APPEND DEPENDS_LIST tarspatch)
list(APPEND DEPENDS_LIST tarsconfig)
set(FRAMEWORK-TGZ "${CMAKE_BINARY_DIR}/framework.tgz")
#执行命令
add_custom_command(OUTPUT ${FRAMEWORK-TGZ}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/${BUILD_SERVER}
COMMAND ${CMAKE_COMMAND} -E make_directory test
COMMAND ${CMAKE_COMMAND} -E tar czf ${FRAMEWORK-TGZ} ${DEPENDS_LIST}
COMMAND ${CMAKE_COMMAND} -E copy ${FRAMEWORK-TGZ} ${PROJECT_BINARY_DIR}
COMMENT "make framework-tar")
add_custom_target(framework-tar
DEPENDS ${FRAMEWORK-TGZ} ${DEPENDS_LIST})
############################################################################################
# 打包tarsnotify tarsstat tarsproperty tarslog tarsauth tarsquerystat tarsqueryproperty
set(DEPENDS_LIST)
list(APPEND DEPENDS_LIST tarsnotify)
list(APPEND DEPENDS_LIST tarsstat)
list(APPEND DEPENDS_LIST tarsproperty)
list(APPEND DEPENDS_LIST tarslog)
list(APPEND DEPENDS_LIST tarsquerystat)
list(APPEND DEPENDS_LIST tarsqueryproperty)
foreach (MODULE ${DEPENDS_LIST})
set(MODULE-TGZ "${CMAKE_BINARY_DIR}/${MODULE}.tgz")
add_custom_command(OUTPUT ${MODULE-TGZ}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${MODULE}
COMMAND ${CMAKE_COMMAND} -E copy ${BUILD_SERVER}/${MODULE}/bin/${MODULE} ${MODULE}/
COMMAND ${CMAKE_COMMAND} -E tar czf ${MODULE-TGZ} ${MODULE}
COMMAND ${CMAKE_COMMAND} -E remove_directory ${MODULE}
COMMENT "create ${MODULE-TGZ}")
add_custom_target(${MODULE}-tar DEPENDS ${MODULE-TGZ} ${MODULE})
endforeach ()
############################################################################################
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/FRAMEWORK_VERSION.txt CONTENT "${FRAMEWORK_VERSION}")
install(FILES ${CMAKE_BINARY_DIR}/FRAMEWORK_VERSION.txt DESTINATION deploy)
install(DIRECTORY ${PROJECT_BINARY_DIR}/${BUILD_SERVER}/ DESTINATION deploy/framework/${BUILD_SERVER}
PATTERN "tars*"
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE)
IF(WIN32)
install(DIRECTORY deploy DESTINATION ./
PATTERN "*.bat"
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE)
install(FILES ${PROJECT_BINARY_DIR}/src/mysql/lib/libmysql.dll DESTINATION deploy)
else(WIN32)
install(DIRECTORY deploy DESTINATION ./
PATTERN "*.sh"
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE)
install(FILES ${PROJECT_BINARY_DIR}/bin/tars2case DESTINATION deploy)
ENDIF(WIN32)
############################################################################################
#for debug
macro(copy_server server)
add_custom_target(cp-${server}
WORKING_DIRECTORY ${WORKING_DIRECTORY}
DEPENDS ${server}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${BUILD_SERVER}/${server}/bin/ ${TARS_INSTALL_PATH}/tars/${server}/bin/
COMMENT "cp ${server} & restart: copy ${BUILD_SERVER}/${server}/bin/ ${TARS_INSTALL_PATH}/tars/${server}/bin/")
endmacro()
copy_server(tarsAdminRegistry)
copy_server(tarsnotify)
copy_server(tarsstat)
copy_server(tarsnode)
copy_server(tarspatch)
copy_server(tarsquerystat)
copy_server(tarsqueryproperty)
copy_server(tarsregistry)
copy_server(tarslog)
copy_server(tarsproperty)
add_custom_target(cp
DEPENDS cp-tarsAdminRegistry cp-tarsnotify cp-tarsstat cp-tarsnode cp-tarspatch cp-tarsquerystat cp-tarsqueryproperty cp-tarsregistry cp-tarslog cp-tarsproperty)