-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
383 lines (317 loc) · 11.9 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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# This file is part of 'Nostr_client_relay'
# Copyright (c) 2023, Space Research Software LLC, Pedro Vicente. All rights reserved.
# See file LICENSE for full license details.
if (MSVC)
cmake_minimum_required(VERSION 3.26)
else()
cmake_minimum_required(VERSION 3.15)
endif()
set(CMAKE_BUILD_TYPE Debug)
project (nostr_client_relay LANGUAGES CXX C)
option(BUILD_RELEASE "BUILD_RELEASE" ON)
if(BUILD_RELEASE)
set(CMAKE_BUILD_TYPE Release)
endif()
option(BUILD_STATIC "BUILD_STATIC" OFF)
option(BUILD_GUI "BUILD_STATIC" OFF)
option(BUILD_WEB "BUILD_WEB" OFF)
option(USE_OPENSSL "set OFF to build without OpenSSL" ON)
option(DEV_MODE "DEV_MODE" OFF)
option(OPENSSL_BREW "OPENSSL_BREW" ON)
if(MSVC)
if(BUILD_STATIC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endif()
message("-- nostr_client_relay static build: " ${BUILD_STATIC})
message(STATUS "Source directory is " ${CMAKE_SOURCE_DIR})
message(STATUS "Build directory is " ${CMAKE_CURRENT_BINARY_DIR})
#//////////////////////////
# external dependencies
#//////////////////////////
include_directories(${CMAKE_SOURCE_DIR}/ext/asio-1.18.1/include)
include_directories(${CMAKE_SOURCE_DIR}/ext/json-3.11.2/single_include)
include_directories(${CMAKE_SOURCE_DIR}/ext/secp256k1-0.3.2/include)
add_subdirectory(${CMAKE_SOURCE_DIR}/ext/secp256k1-0.3.2)
if(BUILD_WEB)
if(MSVC)
if(DEV_MODE)
set(BOOST_PREFIX ${CMAKE_SOURCE_DIR}/ext/boost_1_82_0)
add_subdirectory(${CMAKE_SOURCE_DIR}/ext/wt-4.10.0)
add_definitions(-DDEV_MODE)
endif()
endif()
endif()
#//////////////////////////
# nostril
#//////////////////////////
add_subdirectory(${CMAKE_SOURCE_DIR}/src/nostril)
include_directories(${CMAKE_SOURCE_DIR}/src/nostril)
include_directories(src)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
#//////////////////////////
# Asio definitions
#//////////////////////////
set(CMAKE_CXX_STANDARD 17)
add_definitions(-DASIO_STANDALONE)
add_definitions(-DASIO_HAS_STD_ADDRESSOF)
add_definitions(-DASIO_HAS_STD_ARRAY)
add_definitions(-DASIO_HAS_CSTDINT)
add_definitions(-DASIO_HAS_STD_SHARED_PTR)
add_definitions(-DASIO_HAS_STD_TYPE_TRAITS)
add_definitions(-DASIO_HAS_VARIADIC_TEMPLATES)
add_definitions(-DASIO_HAS_STD_FUNCTION)
add_definitions(-DASIO_HAS_STD_CHRONO)
add_definitions(-DBOOST_ALL_NO_LIB)
if (MSVC)
add_definitions(-D_WIN32_WINNT=0x0501)
add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
endif()
#//////////////////////////
# Linux/Mac
#//////////////////////////
if(UNIX AND NOT APPLE)
set(LINUX TRUE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wno-deprecated-declarations -Wno-nonnull -Wno-psabi")
message(STATUS "Compiler flags: ${CMAKE_CXX_FLAGS}")
endif()
if(UNIX AND APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wno-deprecated-declarations -Wno-nonnull")
message(STATUS "Compiler flags: ${CMAKE_CXX_FLAGS}")
endif()
#//////////////////////////
# Nostr library
#//////////////////////////
set(src ${src})
set(src ${src} src/log.hh)
set(src ${src} src/log.cc)
set(src ${src} src/nostr.hh)
set(src ${src} src/nostr.cc)
set(src ${src} src/relay.hh)
set(src ${src} src/relay.cc)
set(src ${src} src/uuid.cc)
set(src ${src} src/uuid.hh)
set(src ${src} src/database.hh)
set(src ${src} src/database.cc)
add_library(nostr ${src})
add_dependencies(nostr configurator)
##TODO:rename to gnostr-get-relays
## once tools are stable
add_executable(gnostr-getrelays src/gnostr-get-relays.c)
add_executable(gnostr-set-relays src/gnostr-set-relays.c)
add_executable(gnostr-pi src/gnostr-pi.c)
install(PROGRAMS template/gnostr-add DESTINATION bin)
install(PROGRAMS template/gnostr-add.sh DESTINATION bin)
install(PROGRAMS template/gnostr-blockheight DESTINATION bin)
install(PROGRAMS template/gnostr-e DESTINATION bin)
install(PROGRAMS template/gnostr-fs DESTINATION bin)
install(PROGRAMS template/gnostr-functions DESTINATION bin)
install(PROGRAMS template/gnostr-git-log DESTINATION bin)
install(PROGRAMS template/gnostr-git-reflog DESTINATION bin)
install(PROGRAMS template/gnostr-git-send DESTINATION bin)
install(PROGRAMS template/gnostr-git-show DESTINATION bin)
install(PROGRAMS template/gnostr-hexidrome DESTINATION bin)
install(PROGRAMS template/gnostr-iftop DESTINATION bin)
install(PROGRAMS template/gnostr-init DESTINATION bin)
install(PROGRAMS template/gnostr-jsmin.c DESTINATION bin)
install(PROGRAMS template/gnostr-keyconv DESTINATION bin)
install(PROGRAMS template/gnostr-nip DESTINATION bin)
install(PROGRAMS template/gnostr-nonce DESTINATION bin)
install(PROGRAMS template/gnostr-nvm DESTINATION bin)
install(PROGRAMS template/gnostr-org DESTINATION bin)
install(PROGRAMS template/gnostr-post DESTINATION bin)
install(PROGRAMS template/gnostr-proxy DESTINATION bin)
install(PROGRAMS template/gnostr-proxy-test DESTINATION bin)
install(PROGRAMS template/gnostr-query DESTINATION bin)
install(PROGRAMS template/gnostr-relays DESTINATION bin)
install(PROGRAMS template/gnostr-send DESTINATION bin)
install(PROGRAMS template/gnostr-snapshot DESTINATION bin)
install(PROGRAMS template/gnostr-syndication DESTINATION bin)
install(PROGRAMS template/gnostr-syndication-test DESTINATION bin)
if(BUILD_WEB)
install(PROGRAMS web/gnostr-web DESTINATION bin)
endif()
install(PROGRAMS web/gnostr-web-deploy DESTINATION bin)
install(PROGRAMS template/gnostr-weeble DESTINATION bin)
install(PROGRAMS template/gnostr-wobble DESTINATION bin)
install(PROGRAMS template/gnostr-xor DESTINATION bin)
#//////////////////////////
# link with libraries
# lib_dep contains a cascade definition of all the libraries needed to link
#//////////////////////////
set(lib_dep ${lib_dep})
set(lib_dep ${lib_dep} nostr)
set(lib_dep ${lib_dep} secp256k1)
set(lib_dep ${lib_dep} nostri)
if (MSVC)
set(lib_dep ${lib_dep} Ws2_32.lib)
set(lib_dep ${lib_dep} Bcrypt.lib)
endif()
#//////////////////////////
# LINUX
# order of the link libraries matters; pthread dl
#//////////////////////////
if(LINUX)
set(lib_dep ${lib_dep} pthread dl)
set(lib_dep ${lib_dep} stdc++fs)
find_program(LSB_RELEASE_EXEC lsb_release)
execute_process(COMMAND ${LSB_RELEASE_EXEC} -is OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Building in " ${LSB_RELEASE_ID_SHORT})
endif()
#//////////////////////////
#OpenSSL
#//////////////////////////
if(USE_OPENSSL)
include_directories(${CMAKE_SOURCE_DIR}/ext/Simple-WebSocket-Server-v2.0.2)
add_definitions(-DUSE_STANDALONE_ASIO)
set (ASIO_PATH ${CMAKE_SOURCE_DIR}/ext/asio-1.18.1)
endif()
if(USE_OPENSSL)
set(OPENSSL_ROOT_DIR "${CMAKE_SOURCE_DIR}/ext/openssl-3.0.5")
find_package(OpenSSL REQUIRED)
message(STATUS "OpenSSL include: ${OPENSSL_INCLUDE_DIR}")
message(STATUS "OpenSSL libraries: ${OPENSSL_LIBRARIES}")
include_directories(${OPENSSL_INCLUDE_DIR})
set(lib_dep ${lib_dep} ${OPENSSL_LIBRARIES})
if (MSVC)
set(OPENSSL_ROOT_DIR "${CMAKE_SOURCE_DIR}/ext/openssl-3.0.5")
message(STATUS "OpenSSL include: ${OPENSSL_INCLUDE_DIR}")
endif()
find_package(OpenSSL REQUIRED)
message(STATUS "OpenSSL include: ${OPENSSL_INCLUDE_DIR}")
message(STATUS "OpenSSL libraries: ${OPENSSL_LIBRARIES}")
include_directories(${OPENSSL_INCLUDE_DIR})
set(lib_dep ${lib_dep} ${OPENSSL_LIBRARIES})
if (MSVC)
set(lib_dep ${lib_dep} crypt32.lib)
endif()
endif()
#//////////////////////////
# HTTP demo
#//////////////////////////
add_executable(http_client src/http/http.hh src/http/http.cc src/http/http_client.cc)
add_executable(http_relay src/http/http.hh src/http/http.cc src/http/http_relay.cc)
target_link_libraries (http_client ${lib_dep})
target_link_libraries (http_relay ${lib_dep})
#//////////////////////////
# executables
#//////////////////////////
add_executable(gnostr-client src/wss_client.cc)
add_executable(gnostr-req src/wss_req.cc)
add_executable(gnostr-gnode src/wss_relay.cc)
target_link_libraries (gnostr-client ${lib_dep})
target_link_libraries (gnostr-req ${lib_dep})
target_link_libraries (gnostr-gnode ${lib_dep})
#//////////////////////////
# tests
#//////////////////////////
add_executable(gnostr-tests test/tests.cc)
target_link_libraries (gnostr-tests ${lib_dep})
add_executable(gnostr-test test/gnostr_test.cc)
target_link_libraries (gnostr-test ${lib_dep})
add_executable(gnostr-get-relays-test test/gnostr_get_relays_test.cc)
target_link_libraries (gnostr-get-relays-test ${lib_dep})
add_executable(gnostr-sha256-tests test/gnostr_sha256_test.cc)
target_link_libraries (gnostr-sha256-tests ${lib_dep})
#//////////////////////////
# examples
#//////////////////////////
if(UNIX AND NOT APPLE AND NOT LINUX)
add_executable(examples examples/examples.cc)
target_link_libraries (examples ${lib_dep})
endif()
#//////////////////////////
# IDE project virtual folders
#//////////////////////////
set_target_properties(http_client PROPERTIES FOLDER "http")
set_target_properties(http_relay PROPERTIES FOLDER "http")
set_target_properties(nostri PROPERTIES FOLDER "nostril")
set_target_properties(nostril PROPERTIES FOLDER "nostril")
set_target_properties(configurator PROPERTIES FOLDER "nostril")
set_target_properties(secp256k1 PROPERTIES FOLDER "nostril")
set_target_properties(secp256k1_precomputed PROPERTIES FOLDER "nostril")
if(BUILD_WEB)
if(MSVC)
if(DEV_MODE)
set_target_properties(wt PROPERTIES FOLDER "wt")
set_target_properties(wthttp PROPERTIES FOLDER "wt")
set_target_properties(wtisapi PROPERTIES FOLDER "wt")
endif()
endif()
endif()
message(STATUS "Copying data files to: ${CMAKE_BINARY_DIR}")
file(COPY "${CMAKE_SOURCE_DIR}/test/list_01.txt" DESTINATION ${CMAKE_BINARY_DIR})
file(COPY "${CMAKE_SOURCE_DIR}/test/list_02.txt" DESTINATION ${CMAKE_BINARY_DIR})
file(COPY "${CMAKE_SOURCE_DIR}/resources/server.key" DESTINATION ${CMAKE_BINARY_DIR})
file(COPY "${CMAKE_SOURCE_DIR}/resources/server.crt" DESTINATION ${CMAKE_BINARY_DIR})
file(COPY "${CMAKE_SOURCE_DIR}/database/database.json" DESTINATION ${CMAKE_BINARY_DIR})
file(COPY "${CMAKE_SOURCE_DIR}/resources/wt_config.xml" DESTINATION ${CMAKE_BINARY_DIR}/web)
#//////////////////////////
# Wt desktop
#//////////////////////////
if (BUILD_GUI)
add_subdirectory(desktop)
endif()
#//////////////////////////
# Wt web
#//////////////////////////
if (BUILD_WEB)
add_subdirectory(web)
endif()
#//////////////////////////
# Install
#//////////////////////////
install(TARGETS gnostr-gnode
CONFIGURATIONS Debug
RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
install(TARGETS gnostr-gnode
CONFIGURATIONS Release
RUNTIME DESTINATION /usr/local/bin)
install(TARGETS gnostr-getrelays
CONFIGURATIONS Debug
RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
install(TARGETS gnostr-getrelays
CONFIGURATIONS Release
RUNTIME DESTINATION /usr/local/bin)
install(TARGETS gnostr-set-relays
CONFIGURATIONS Debug
RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
install(TARGETS gnostr-set-relays
CONFIGURATIONS Release
RUNTIME DESTINATION /usr/local/bin)
install(TARGETS gnostr-client
CONFIGURATIONS Debug
RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
install(TARGETS gnostr-client
CONFIGURATIONS Release
RUNTIME DESTINATION /usr/local/bin)
install(TARGETS gnostr-pi
CONFIGURATIONS Debug
RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
install(TARGETS gnostr-pi
CONFIGURATIONS Release
RUNTIME DESTINATION /usr/local/bin)
install(TARGETS gnostr-req
CONFIGURATIONS Debug
RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
install(TARGETS gnostr-req
CONFIGURATIONS Release
RUNTIME DESTINATION /usr/local/bin)
install(TARGETS gnostr-tests
CONFIGURATIONS Debug
RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
install(TARGETS gnostr-tests
CONFIGURATIONS Release
RUNTIME DESTINATION /usr/local/bin)
if(BUILD_WEB)
#install(TARGETS gnostr-web
# CONFIGURATIONS Debug
# RUNTIME DESTINATION ${CMAKE_SOURCE_DIR}/bin)
#install(TARGETS gnostr-web
# CONFIGURATIONS Release
# RUNTIME DESTINATION /usr/local/bin)
endif()
if (BUILD_GUI)
endif()