This repository has been archived by the owner on Sep 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
313 lines (273 loc) · 12.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
project(charlie)
cmake_minimum_required(VERSION 3.1)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
set(CHARLIE_MODULE_PATH "${CMAKE_SOURCE_DIR}/src/modules/")
set(CHARLIE_SERVER_MODULE_PATH "${CMAKE_SOURCE_DIR}/src/server_modules/")
# Standard files included in every module
set(CHARLIE_MODULE_SRC
"${CMAKE_SOURCE_DIR}/src/networking/emsgsizes.cpp"
"${CMAKE_SOURCE_DIR}/src/charlie/Crypto.cpp"
"${CMAKE_SOURCE_DIR}/src/charlie/CryptoBuf.cpp"
"${CMAKE_SOURCE_DIR}/src/charlie/xor.cpp"
"${CMAKE_SOURCE_DIR}/src/charlie/base64.cpp"
"charlie.pb.redacted.cc"
"charlie_net.pb.redacted.cc"
"client.pb.redacted.cc")
file(GLOB protogen_SRC "src/protogen/*.cc")
# Standard linking
set(CHARLIE_MODULE_LINK)
add_definitions("-Wno-deprecated-declarations")
add_definitions("-Wno-builtin-macro-redefined")
if (WINCC)
#Undo override by the toolchain
MESSAGE( STATUS "Overriding build type ${CMAKE_BUILD_TYPE} with ${ACTUAL_BUILD_TYPE}...")
set(CMAKE_BUILD_TYPE ${ACTUAL_BUILD_TYPE})
add_definitions("-DCHARLIE_IS_WINDOWS")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions("-DDO_CHARLIE_LOG -DDEBUG")
else()
add_definitions("-DIS_CHARLIE_RELEASE")
endif()
find_package(M REQUIRED)
find_package(DL REQUIRED)
#find_package(RT REQUIRED)
find_package(Threads REQUIRED)
set(THREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
set(HAVE_EVENT2 ON)
set(EVENT2_LIBRARIES "${CMAKE_SOURCE_DIR}/deps/final/lib/${CMAKE_STATIC_LIBRARY_PREFIX}event${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(EVENT2_INCLUDES "${CMAKE_SOURCE_DIR}/deps/final/include")
set(CURL_LIBRARIES_DEPS curl)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX} "so")
set(STATIC_LIBC_ARGS "-static-libgcc -static-libstdc++")
if(NOT WINCC)
message( STATUS "Not using Boost system paths." )
set(Boost_NO_SYSTEM_PATHS ON)
set(BOOST_ROOT "${PROJECT_SOURCE_DIR}/deps/boost/final/")
endif()
find_package(Boost REQUIRED COMPONENTS filesystem system program_options regex thread chrono)
if(WINCC)
find_package(Protobuf REQUIRED)
else()
set(Protobuf_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/deps/protobuf/final/include/")
set(PROTOBUF_LITE_LIBRARIES "${PROJECT_SOURCE_DIR}/deps/protobuf/final/lib/libprotobuf-lite.a")
set(PROTOBUF_LIBRARIES "${PROJECT_SOURCE_DIR}/deps/protobuf/final/lib/libprotobuf.a")
endif()
find_package(GLIB REQUIRED COMPONENTS gmodule)
if(WINCC)
find_package(OpenSSL REQUIRED)
else()
set(OPENSSL_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/deps/openssl/final/include/")
set(OPENSSL_LIBRARIES "${PROJECT_SOURCE_DIR}/deps/openssl/final/lib/libssl.a" "${PROJECT_SOURCE_DIR}/deps/openssl/final/lib/libcrypto.a")
set(OPENSSL_FOUND ON)
endif()
set(PROCESS_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/deps/process/")
if (BUILDING_CUTILS_ONLY OR WINCC)
find_package(ZLIB REQUIRED)
else()
# windows and unix
set(ZLIB_STATIC_LIBRARY_PREFIX lib)
if (WINCC)
set(ZLIB_STATIC_LIBRARY_SUFFIX lib.dll.a)
else()
set(ZLIB_STATIC_LIBRARY_SUFFIX .a)
endif()
add_library(zlibstatic STATIC IMPORTED)
# Might not be necessary
set_target_properties(zlibstatic PROPERTIES IMPORTED_LOCATION "${PROJECT_SOURCE_DIR}/deps/build/zlib/${ZLIB_STATIC_LIBRARY_PREFIX}z${ZLIB_STATIC_LIBRARY_SUFFIX}")
set(ZLIB_LIBRARIES zlibstatic)
set(ZLIB_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/deps/final/include)
endif()
add_library(curl STATIC IMPORTED)
set_target_properties(curl PROPERTIES IMPORTED_LOCATION "${PROJECT_SOURCE_DIR}/deps/final/lib/${CMAKE_STATIC_LIBRARY_PREFIX}curl${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(CURL_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/deps/final/include)
if (NOT WINCC)
add_library(mongo STATIC IMPORTED)
set_target_properties(mongo PROPERTIES IMPORTED_LOCATION "${PROJECT_SOURCE_DIR}/deps/final/lib/${CMAKE_STATIC_LIBRARY_PREFIX}mongoclient${CMAKE_STATIC_LIBRARY_SUFFIX}")
include_directories("${PROJECT_SOURCE_DIR}/deps/final/include/mongo")
endif()
#Remove pthread from the boost libraries
list(REMOVE_AT Boost_LIBRARIES -1)
set(include_t1 ${CURL_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${PROCESS_INCLUDE_DIRS} ${GLIB_INCLUDE_DIRS} ${Protobuf_INCLUDE_DIRS} ${THREADS_PTHREADS_INCLUDE_DIR})
include_directories(${include_t1})
include_directories("include")
include_directories("${PROJECT_SOURCE_DIR}/deps/rapidjson/include")
include_directories("${PROJECT_SOURCE_DIR}/deps/mongoose")
include_directories("${PROJECT_SOURCE_DIR}/deps/tor/include")
MESSAGE( STATUS "GModule: ${GLIB_GMODULE_LIBRARIES}")
MESSAGE( STATUS "GLIB: ${GLIB_LIBRARIES}")
MESSAGE( STATUS "BOOST inc: ${Boost_INCLUDE_DIRS}")
MESSAGE( STATUS "Other inc: ${include_t1}" )
set(LIBS -Wl,-Bstatic ${PROTOBUF_LITE_LIBRARIES} ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${GLIB_GMODULE_LIBRARIES} ${GLIB_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} -Wl,-Bdynamic ${CMAKE_THREAD_LIBS_INIT} ${DL_LIBRARIES})
set(MANAGER_LIBS -Wl,-Bstatic ${CURL_LIBRARIES_DEPS} ${PROTOBUF_LITE_LIBRARIES} ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_REGEX_LIBRARY} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} -Wl,-Bdynamic ${CMAKE_THREAD_LIBS_INIT} ${DL_LIBRARIES})
if(WINCC)
find_package(Libiconv REQUIRED)
find_library(WINSOCK_LIBRARY NAMES ws2_32
PATHS /lib
/usr/lib
/usr/local/lib)
find_library(IPHLPAP_LIBRARY NAMES iphlpapi
PATHS /lib
/usr/lib
/usr/local/lib)
find_package(Intl REQUIRED)
add_definitions("-DPTW32_STATIC_LIB -DWIN32_LEAN_AND_MEAN")
list(APPEND LIBS -Wl,-Bstatic ${WINSOCK_LIBRARY} ${Intl_LIBRARIES} winmm ${IPHLPAP_LIBRARY} ${LIBICONV_LIBRARY})
list(APPEND MANAGER_LIBS -Wl,-Bstatic ${WINSOCK_LIBRARY} ${Intl_LIBRARIES} winmm ${IPHLPAP_LIBRARY} ${LIBICONV_LIBRARY})
endif()
set(STEALTH_FLAGS "-D__FILE__='\"\"' -D__DIR__='\"\"' -Wno-builtin-macro-redefined -fno-rtti -DBOOST_NO_RTTI -DGOOGLE_PROTOBUF_NO_RTTI -D_WIN32_WINNT=0x0501 -fvisibility=hidden")
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(STEALTH_FLAGS "${STEALTH_FLAGS}")
set(MODULE_FLAGS "${STEALTH_FLAGS} -DCHARLIE_MODULE")
else()
set(STEALTH_FLAGS "${STEALTH_FLAGS} -Os -s")
set(MODULE_FLAGS "${STEALTH_FLAGS} -DCHARLIE_MODULE")
endif()
if (NOT WINCC)
set(MODULE_FLAGS "${MODULE_FLAGS} -fPIC")
endif()
if (NO_TOOLS)
MESSAGE( STATUS "Skipping cutils compilation." )
add_custom_target(cutils COMMENT "Not compiling tools.")
else()
# Build compile tool
add_executable(cutils
"src/cutils/main.cpp"
"src/charlie/xor.cpp"
"src/charlie/Crypto.cpp"
"src/charlie/CryptoBuf.cpp"
"src/charlie/hash.cpp"
"src/cserver/ModuleTable.cpp"
${protogen_SRC}
)
target_link_libraries(cutils ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_REGEX_LIBRARY} ${LIBS})
endif()
# Redact files
set(redact_proto)
file(GLOB proto_files "src/proto/*.proto")
foreach(file ${proto_files})
get_filename_component (file_without_extension ${file} NAME_WE)
list(APPEND redact_proto ${file_without_extension})
endforeach()
MESSAGE( STATUS "Will redact charlie proto files." )
foreach(to_redact IN LISTS redact_proto)
MESSAGE( STATUS "Planning to redact ${to_redact} proto files..." )
file(COPY "${CMAKE_SOURCE_DIR}/src/protogen/${to_redact}.pb.h" DESTINATION ${CMAKE_BINARY_DIR})
add_custom_command(
OUTPUT ${to_redact}.pb.redacted.cc
COMMAND "${CMAKE_BINARY_DIR}/cutils"
ARGS protoclean --input "${CMAKE_SOURCE_DIR}/src/protogen/${to_redact}.pb.cc" --output ${to_redact}.pb.redacted.cc
DEPENDS cutils
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endforeach()
file(GLOB module_incs "${CHARLIE_MODULE_PATH}/**/module.cmake")
foreach(file ${module_incs})
MESSAGE( STATUS "Including module ${file}...")
include(${file})
endforeach()
file(GLOB server_module_incs "${CHARLIE_SERVER_MODULE_PATH}/**/module.cmake")
foreach(file ${server_module_incs})
MESSAGE( STATUS "Including server module ${file}...")
include(${file})
endforeach()
# Set the list of libraries to compile embed code
set(embed_libraries manager)
# Copy server identity file
if(EXISTS "${PROJECT_SOURCE_DIR}/resources/identity/server_identity")
file(COPY "${PROJECT_SOURCE_DIR}/resources/identity/server_identity" DESTINATION ${CMAKE_BINARY_DIR})
endif()
if(EXISTS "${CMAKE_BINARY_DIR}/server_identity")
MESSAGE( STATUS "Server identity exists, encoding it into server_pubkey" )
add_custom_target(server_identity COMMENT "Using existing server identity.")
else()
MESSAGE( STATUS "Server identity doesn't exist, one will be re-generated..." )
add_custom_command(
OUTPUT server_identity
COMMAND "${CMAKE_BINARY_DIR}/cutils"
ARGS genident --output server_identity --xorkey serveridentity
DEPENDS cutils
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()
MESSAGE( STATUS "The server identity will be encoded into a pubkey..." )
add_custom_command(
OUTPUT server_pubkey
COMMAND "${CMAKE_BINARY_DIR}/cutils"
ARGS genpubkey --identity server_identity --output server_pubkey --xorkey serveridentity
DEPENDS cutils server_identity
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
MESSAGE( STATUS "Planning to generate the initial module table..." )
add_custom_command(
OUTPUT init_mtable
COMMAND "${CMAKE_BINARY_DIR}/cutils"
ARGS genmodtable --xorkey 70016b8d0c80f1393f8155f897f7e63b7fc2ef0b45c42763325019ef8983ace0 --output init_mtable --sign --identity server_identity --identxor serveridentity --json ../src/config/initmtable.json
DEPENDS cutils server_identity manager
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
# Compile the data into c files (use with plugin_data.c dependency)
foreach(to_embed_lib IN LISTS embed_libraries)
add_custom_command(
OUTPUT ${to_embed_lib}_data.c
COMMAND "${CMAKE_BINARY_DIR}/cutils"
ARGS embed --compress --output ${to_embed_lib}_data.c --input "${CMAKE_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${to_embed_lib}${CMAKE_SHARED_LIBRARY_SUFFIX}" --xorkey GpVDIRK4KfsYC9WGbyXZ
DEPENDS ${to_embed_lib} cutils
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endforeach()
# Compile server pubkey into c file
add_custom_command(
OUTPUT server_pubkey_data.c
COMMAND "${CMAKE_BINARY_DIR}/cutils"
ARGS embed --output server_pubkey_data.c --input "${CMAKE_BINARY_DIR}/server_pubkey"
DEPENDS server_pubkey cutils
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
# Compile initial module table into c file
add_custom_command(
OUTPUT init_modtable_data.c
COMMAND "${CMAKE_BINARY_DIR}/cutils"
ARGS embed --output init_modtable_data.c --input "${CMAKE_BINARY_DIR}/init_mtable"
DEPENDS init_mtable cutils
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
if (WINCC AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
# Makes the compiler set a flag for a GUI program
# But we make no windows :) this is to prevent the console from appearing.
set(CHARLIE_EXTRA_FLAGS "-mwindows -DCHARLIE_ENABLE_GUI")
endif()
# Build charlie
file(GLOB charlie_SRC "src/charlie/*.cpp")
add_executable(charlie manager_data.c server_pubkey_data.c init_modtable_data.c ${charlie_SRC} "charlie.pb.redacted.cc")
set_target_properties(charlie PROPERTIES COMPILE_FLAGS "${STEALTH_FLAGS} ${CHARLIE_EXTRA_FLAGS}")
set_target_properties(charlie PROPERTIES LINK_FLAGS ${STATIC_LIBC_ARGS})
target_link_libraries(charlie ${LIBS})
# Now let's compile the server
if(NOT WINCC)
# Compile mongoose
add_library(mongoose STATIC "${PROJECT_SOURCE_DIR}/deps/mongoose/mongoose.c")
set_target_properties(mongoose PROPERTIES COMPILE_FLAGS "${STEALTH_FLAGS}")
set(SERVER_LIBS -Wl,-Bstatic mongoose ${CURL_LIBRARIES_DEPS} ${OPENSSL_LIBRARIES} ${PROTOBUF_LIBRARIES} ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_CHRONO_LIBRARY} ${GLIB_GMODULE_LIBRARIES} ${GLIB_LIBRARIES} -Wl,-Bdynamic ${CMAKE_THREAD_LIBS_INIT} ${DL_LIBRARIES})
file(GLOB cserver_SRC "src/cserver/*.cpp")
file(GLOB http_SRC "src/http/*.cpp")
file(GLOB networking_SRC "src/networking/*.cpp")
MESSAGE( STATUS "Protogen files: ${protogen_SRC}")
add_executable(cserver ${cserver_SRC} ${protogen_SRC} ${http_SRC}
${networking_SRC}
"src/charlie/random.cpp"
"src/charlie/Crypto.cpp"
"src/charlie/CryptoBuf.cpp"
"src/charlie/base64.cpp"
"src/charlie/hash.cpp"
"src/charlie/xor.cpp"
)
target_link_libraries(cserver mongo ${SERVER_LIBS} ${Boost_REGEX_LIBRARY})
set_target_properties(cserver PROPERTIES COMPILE_FLAGS "${STEALTH_FLAGS} -DDO_CHARLIE_LOG -DIS_CSERVER")
set_target_properties(cserver PROPERTIES LINK_FLAGS ${STATIC_LIBC_ARGS})
endif()