forked from d99kris/nchat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
327 lines (287 loc) · 10.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
# Project
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
project(nchat LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
include(CheckCXXSourceCompiles)
# Paths
if (NOT DEFINED CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR "lib")
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# Build type
set(DEFAULT_BUILD_TYPE "Release")
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Using build type '${DEFAULT_BUILD_TYPE}' (default).")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}")
else()
message(STATUS "Using build type '${CMAKE_BUILD_TYPE}'.")
endif()
# Platform specifics
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_definitions(-D_XOPEN_SOURCE_EXTENDED)
execute_process(COMMAND sh "-c"
"command -v brew &> /dev/null && brew --prefix ncurses 2> /dev/null | tr -d '\n'"
OUTPUT_VARIABLE CMAKE_PREFIX_PATH)
if (EXISTS "${CMAKE_PREFIX_PATH}")
message(STATUS "Ncurses cmake prefix '${CMAKE_PREFIX_PATH}' (detected).")
else()
set(CMAKE_PREFIX_PATH /opt/local)
message(STATUS "Ncurses cmake prefix '${CMAKE_PREFIX_PATH}' (default).")
endif()
endif()
# Optional component - Dummy Protocol
option(HAS_DUMMY "Dummy" ON)
message(STATUS "Dummy: ${HAS_DUMMY}")
# Optional component - Telegram
option(HAS_TELEGRAM "Telegram" ON)
message(STATUS "Telegram: ${HAS_TELEGRAM}")
# Optional component - WhatsApp
option(HAS_WHATSAPP "WhatsApp" ON)
message(STATUS "WhatsApp: ${HAS_WHATSAPP}")
# Feature - Dynamic library load
option(HAS_DYNAMICLOAD "Dynamic Load" ON)
message(STATUS "Dynamic Load: ${HAS_DYNAMICLOAD}")
# Feature - Multi protocol
option(HAS_MULTIPROTOCOL "Multi Protocol" ON)
message(STATUS "Multi Protocol: ${HAS_MULTIPROTOCOL}")
# Feature - Core dump
option(HAS_COREDUMP "Core Dump" ON)
message(STATUS "Core Dump: ${HAS_COREDUMP}")
# Check Go version
if(HAS_WHATSAPP)
# Check Golang version - whatsmeow requires >= v1.18
execute_process(COMMAND bash "-c" "go version | cut -c14- | cut -d' ' -f1 | tr -d '\n'" OUTPUT_VARIABLE GO_VERSION)
if(NOT GO_VERSION VERSION_GREATER_EQUAL 1.18.0)
message(WARNING "Go version ${GO_VERSION} (need v1.18 to build WhatsApp).")
SET(HAS_WHATSAPP OFF)
endif()
endif()
# Application
add_executable(nchat
ext/apathy/path.hpp
src/main.cpp
src/ui.cpp
src/ui.h
src/uicolorconfig.cpp
src/uicolorconfig.h
src/uiconfig.cpp
src/uiconfig.h
src/uicontactlistdialog.cpp
src/uicontactlistdialog.h
src/uicontroller.cpp
src/uicontroller.h
src/uidialog.cpp
src/uidialog.h
src/uiemojilistdialog.cpp
src/uiemojilistdialog.h
src/uientryview.cpp
src/uientryview.h
src/uifilelistdialog.cpp
src/uifilelistdialog.h
src/uihelpview.cpp
src/uihelpview.h
src/uihistoryview.cpp
src/uihistoryview.h
src/uikeyconfig.cpp
src/uikeyconfig.h
src/uikeydump.cpp
src/uikeydump.h
src/uikeyinput.cpp
src/uikeyinput.h
src/uilistborderview.cpp
src/uilistborderview.h
src/uilistdialog.cpp
src/uilistdialog.h
src/uilistview.cpp
src/uilistview.h
src/uimessagedialog.cpp
src/uimessagedialog.h
src/uimodel.cpp
src/uimodel.h
src/uiscreen.cpp
src/uiscreen.h
src/uistatusview.cpp
src/uistatusview.h
src/uitopview.cpp
src/uitopview.h
src/uiview.cpp
src/uiview.h
src/uiviewbase.cpp
src/uiviewbase.h
)
install(TARGETS nchat DESTINATION bin)
# Headers
target_include_directories(nchat PRIVATE "ext/apathy")
target_include_directories(nchat PRIVATE "lib/common/src")
target_include_directories(nchat PRIVATE "lib/ncutil/src")
# Compiler flags
set_target_properties(nchat PROPERTIES COMPILE_FLAGS
"-Wall -Wextra -Wpedantic -Wshadow -Wpointer-arith \
-Wcast-qual -Wno-missing-braces -Wswitch-default \
-Wunreachable-code -Wundef -Wuninitialized \
-Wcast-align")
# Dependency libraries
add_subdirectory(lib/ncutil)
if(HAS_DUMMY)
add_subdirectory(lib/duchat)
endif()
if(HAS_TELEGRAM)
add_subdirectory(lib/tgchat)
endif()
if(HAS_WHATSAPP)
add_subdirectory(lib/wmchat)
endif()
# Dependency clip
add_subdirectory(ext/clip)
# Dependency ncurses
set(CURSES_NEED_NCURSES TRUE)
set(CURSES_NEED_WIDE TRUE)
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
# Compile options
target_compile_options(nchat PUBLIC ${NCURSES_CFLAGS})
# Linking
target_link_libraries(nchat PUBLIC ncutil pthread ${CURSES_LIBRARIES} dl)
# Optionals
if(HAS_DUMMY)
target_include_directories(nchat PRIVATE "lib/duchat/src")
target_compile_definitions(nchat PRIVATE HAS_DUMMY="${HAS_DUMMY}")
if(NOT HAS_DYNAMICLOAD)
target_link_libraries(nchat PUBLIC duchat)
endif()
endif()
if(HAS_TELEGRAM)
target_include_directories(nchat PRIVATE "lib/tgchat/src")
target_compile_definitions(nchat PRIVATE HAS_TELEGRAM="${HAS_TELEGRAM}")
if(NOT HAS_DYNAMICLOAD)
target_link_libraries(nchat PUBLIC tgchat)
endif()
endif()
if(HAS_WHATSAPP)
target_include_directories(nchat PRIVATE "lib/wmchat/src")
target_compile_definitions(nchat PRIVATE HAS_WHATSAPP="${HAS_WHATSAPP}")
if(NOT HAS_DYNAMICLOAD)
target_link_libraries(nchat PUBLIC wmchat)
endif()
endif()
# Features
if(HAS_MULTIPROTOCOL)
target_compile_definitions(nchat PRIVATE HAS_MULTIPROTOCOL="${HAS_MULTIPROTOCOL}")
endif()
if(HAS_DYNAMICLOAD)
target_compile_definitions(nchat PRIVATE HAS_DYNAMICLOAD="${HAS_DYNAMICLOAD}")
endif()
if(HAS_COREDUMP)
target_compile_definitions(nchat PRIVATE HAS_COREDUMP="${HAS_COREDUMP}")
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# Core dump entitlements
set(SIGNSCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/utils/sign")
set(ENTITLEMENTS "${CMAKE_CURRENT_SOURCE_DIR}/src/nchat.entitlements")
install(CODE "execute_process(COMMAND
\"${SIGNSCRIPT}\" \"${ENTITLEMENTS}\" \"${CMAKE_INSTALL_PREFIX}/bin/nchat\"
)" COMPONENT Runtime)
endif()
endif()
# Common
target_compile_definitions(nchat PRIVATE CMAKE_INSTALL_LIBDIR="${CMAKE_INSTALL_LIBDIR}")
# Manual install dir
if(NOT CMAKE_INSTALL_MANDIR)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_INSTALL_MANDIR "${CMAKE_INSTALL_PREFIX}/share/man")
else()
set(CMAKE_INSTALL_MANDIR "${CMAKE_INSTALL_PREFIX}/man")
endif()
message(STATUS "Using fallback man dir: ${CMAKE_INSTALL_MANDIR}")
else()
message(STATUS "Using default man dir: ${CMAKE_INSTALL_MANDIR}")
endif()
# Manual
install(FILES src/nchat.1 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
# Themes
macro(add_theme themedir)
configure_file(themes/${themedir}/color.conf ${CMAKE_CURRENT_BINARY_DIR}/share/nchat/themes/${themedir}/color.conf COPYONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/share/nchat/themes/${themedir}/color.conf DESTINATION share/nchat/themes/${themedir})
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/themes/${themedir}/usercolor.conf")
configure_file(themes/${themedir}/usercolor.conf ${CMAKE_CURRENT_BINARY_DIR}/share/nchat/themes/${themedir}/usercolor.conf COPYONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/share/nchat/themes/${themedir}/usercolor.conf DESTINATION share/nchat/themes/${themedir})
endif()
endmacro()
add_theme("default")
add_theme("basic-color")
add_theme("dracula")
add_theme("catppuccin-mocha")
add_theme("espresso")
add_theme("gruvbox-dark")
add_theme("solarized-dark-higher-contrast")
add_theme("tokyo-night")
add_theme("tomorrow-night")
add_theme("zenbones-dark")
add_theme("zenburned")
# Uninstall
add_custom_target(uninstall
COMMAND "${CMAKE_COMMAND}" -E remove "${CMAKE_INSTALL_PREFIX}/bin/nchat"
COMMAND "${CMAKE_COMMAND}" -E remove "${CMAKE_INSTALL_MANDIR}/man1/nchat.1"
COMMAND "${CMAKE_COMMAND}" -E remove "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libncutil${CMAKE_SHARED_LIBRARY_SUFFIX}"
COMMAND "${CMAKE_COMMAND}" -E remove "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libtdclientshared${CMAKE_SHARED_LIBRARY_SUFFIX}"
COMMAND "${CMAKE_COMMAND}" -E remove "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libtgchat${CMAKE_SHARED_LIBRARY_SUFFIX}"
COMMAND "${CMAKE_COMMAND}" -E remove "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libduchat${CMAKE_SHARED_LIBRARY_SUFFIX}"
COMMAND "${CMAKE_COMMAND}" -E remove "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libwmchat${CMAKE_SHARED_LIBRARY_SUFFIX}"
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_INSTALL_PREFIX}/share/nchat"
)
# Dev Application
if(CMAKE_BUILD_TYPE MATCHES "Debug")
message(STATUS "Building dev application.")
add_executable(devnchat
ext/apathy/path.hpp
src/main.cpp
dev/ui.cpp
dev/ui.h
)
# Headers
target_include_directories(devnchat PRIVATE "ext/apathy")
target_include_directories(devnchat PRIVATE "lib/common/src")
target_include_directories(devnchat PRIVATE "lib/ncutil/src")
# Compiler flags
set_target_properties(devnchat PROPERTIES COMPILE_FLAGS
"-Wall -Wextra -Wpedantic -Wshadow -Wpointer-arith \
-Wcast-qual -Wno-missing-braces -Wswitch-default \
-Wunreachable-code -Wundef -Wuninitialized \
-Wcast-align")
# Linking
target_link_libraries(devnchat PUBLIC ncutil pthread ${CURSES_NCURSES_LIBRARY} dl)
# Optionals
if(HAS_DUMMY)
target_include_directories(devnchat PRIVATE "lib/duchat/src")
target_compile_definitions(devnchat PRIVATE HAS_DUMMY="${HAS_DUMMY}")
if(NOT HAS_DYNAMICLOAD)
target_link_libraries(devnchat PUBLIC duchat)
endif()
endif()
if(HAS_TELEGRAM)
target_include_directories(devnchat PRIVATE "lib/tgchat/src")
target_compile_definitions(devnchat PRIVATE HAS_TELEGRAM="${HAS_TELEGRAM}")
if(NOT HAS_DYNAMICLOAD)
target_link_libraries(devnchat PUBLIC tgchat)
endif()
endif()
if(HAS_WHATSAPP)
target_include_directories(devnchat PRIVATE "lib/wmchat/src")
target_compile_definitions(devnchat PRIVATE HAS_WHATSAPP="${HAS_WHATSAPP}")
if(NOT HAS_DYNAMICLOAD)
target_link_libraries(devnchat PUBLIC wmchat)
endif()
endif()
# Features
if(HAS_MULTIPROTOCOL)
target_compile_definitions(devnchat PRIVATE HAS_MULTIPROTOCOL="${HAS_MULTIPROTOCOL}")
endif()
if(HAS_DYNAMICLOAD)
target_compile_definitions(devnchat PRIVATE HAS_DYNAMICLOAD="${HAS_DYNAMICLOAD}")
endif()
# Common
target_compile_definitions(devnchat PRIVATE CMAKE_INSTALL_LIBDIR="${CMAKE_INSTALL_LIBDIR}")
endif()