-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
157 lines (137 loc) · 3.57 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
cmake_minimum_required(VERSION 3.5)
project(chatroom VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 添加 Qt 的 moc 处理
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui Widgets LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widgets LinguistTools)
find_package(OpenSSL REQUIRED)
# Set up translation
set(TS_FILES chatroom_zh_CN.ts)
qt_add_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
# Client include directories
include_directories(
${CMAKE_SOURCE_DIR}/server/include
${CMAKE_SOURCE_DIR}/client/include
${CMAKE_SOURCE_DIR}/common
${OPENSSL_INCLUDE_DIR}
)
# Client source files
set(CLIENT_SOURCES
client/core/main.cpp
client/core/client.cpp
client/core/widget.cpp
client/core/log.cpp
client/core/reg.cpp
client/core/found.cpp
client/core/setnewpasswd.cpp
client/core/settings.cpp
client/core/menu2.cpp
client/core/filemenu.cpp
client/core/creategroupdialog.cpp
client/core/createfrienddialog.cpp
client/core/informations.cpp
)
# Client header files
set(CLIENT_HEADERS
client/include/client.h
client/include/widget.h
client/include/log.h
client/include/reg.h
client/include/found.h
client/include/setnewpasswd.h
client/include/settings.h
client/include/menu2.h
client/include/filemenu.h
client/include/creategroupdialog.h
client/include/createfrienddialog.h
client/include/msgtype.h
client/include/badgetoolbutton.h
client/include/informations.h
)
# Client common files
set(CLIENT_COMMON
common/threadpool.h
common/mysocket.h
common/mysocket.cpp
)
# Client UI files
set(CLIENT_UI
client/ui/filemenu.ui
client/ui/found.ui
client/ui/informations.ui
client/ui/log.ui
client/ui/menu2.ui
client/ui/reg.ui
client/ui/setnewpasswd.ui
client/ui/settings.ui
client/ui/widget.ui
)
# 使用 qt6/qt5_wrap_ui 来生成 UI 头文件
if(${QT_VERSION_MAJOR} EQUAL 5)
qt5_wrap_ui(UI_HEADERS ${CLIENT_UI})
elseif(${QT_VERSION_MAJOR} EQUAL 6)
qt6_wrap_ui(UI_HEADERS ${CLIENT_UI})
endif()
# Resource files
set(RESOURCES
log.qrc
)
# Combine all client files
set(ALL_CLIENT_FILES
${CLIENT_UI}
${CLIENT_SOURCES}
${CLIENT_HEADERS}
${CLIENT_COMMON}
${RESOURCES}
${TS_FILES}
${UI_HEADERS}
)
# Server source files
set(SERVER_SOURCES
server/server.cpp
server/db/redis.cpp
server/smtp/smtpmailer.cpp
common/mysocket.cpp
)
# Server header files
set(SERVER_HEADERS
server/include/server.h
server/include/redis.h
server/include/smtpmailer.h
common/mysocket.h
common/threadpool.h
)
# Combine all server files
set(ALL_SERVER_FILES
${SERVER_SOURCES}
${SERVER_HEADERS}
)
# Create client executable
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(client
MANUAL_FINALIZATION
${ALL_CLIENT_FILES}
)
qt_finalize_executable(client)
else()
if(ANDROID)
add_library(client SHARED ${ALL_CLIENT_FILES})
else()
add_executable(client ${ALL_CLIENT_FILES})
endif()
endif()
target_link_libraries(client PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${OPENSSL_LIBRARIES})
# Create server executable
add_executable(server ${ALL_SERVER_FILES})
target_link_libraries(server PRIVATE ${OPENSSL_LIBRARIES} hiredis curl)
# Install rules
include(GNUInstallDirs)
install(TARGETS client server
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)