-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
328 lines (283 loc) · 9.44 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
cmake_minimum_required(VERSION 3.11.0)
project(recodex-worker)
set(RECODEX_VERSION 1.9.0)
enable_testing()
set(EXEC_NAME ${PROJECT_NAME})
set(gtest_force_shared_crt ON CACHE BOOL "Use shared (DLL) run-time lib even when Google Test is built as static lib.")
# Find installed packages on the system
# -- LibArchive
find_package(LibArchive)
# -- Boost
if(WIN32)
set(Boost_USE_STATIC_LIBS ON)
else()
set(Boost_USE_STATIC_LIBS OFF)
endif()
# -- load Boost
set (Boost_USE_MULTITHREADED ON)
find_package(Boost 1.74.0 REQUIRED COMPONENTS system program_options)
include_directories(${Boost_INCLUDE_DIRS})
# -- cURL
find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIRS})
# -- Yaml-cpp
# find the yaml-cpp include directory
find_path(YAMLCPP_INCLUDE_DIR yaml-cpp/yaml.h
PATH_SUFFIXES include
PATHS
~/Library/Frameworks/yaml-cpp/include/
/Library/Frameworks/yaml-cpp/include/
/usr/local/include/
/usr/include/
/sw/yaml-cpp/ # Fink
/opt/local/yaml-cpp/ # DarwinPorts
/opt/csw/yaml-cpp/ # Blastwave
/opt/yaml-cpp/
${YAMLCPP_DIR}/include/)
# find the yaml-cpp library
find_library(YAMLCPP_LIBRARY
NAMES ${YAMLCPP_STATIC} yaml-cpp
PATH_SUFFIXES lib64 lib
PATHS ~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw
/opt/local
/opt/csw
/opt
${YAMLCPP_DIR}/lib)
if(YAMLCPP_INCLUDE_DIR AND YAMLCPP_LIBRARY)
set(YAMLCPP_FOUND true)
endif()
# -- ZeroMQ on Windows
if(MSVC)
find_path(ZEROMQ_INCLUDE NAMES zmq.h PATHS ${ZMQ_INCLUDE_DIR})
find_library(ZEROMQ_LIB NAMES libzmq PATHS ${ZMQ_LIBRARY_DIR})
if(ZEROMQ_LIB)
include_directories(${ZEROMQ_INCLUDE})
else()
message(FATAL_ERROR "Fail to load ZeroMQ!")
endif()
endif()
# ZeroMQ C++ bindings headers
include_directories(AFTER, vendor/cppzmq)
# Spdlog logging library
include_directories(AFTER, vendor/spdlog/include)
# Yaml-cpp
if(YAMLCPP_FOUND)
include_directories(AFTER, ${YAMLCPP_INCLUDE_DIR})
else()
include_directories(AFTER, vendor/yaml-cpp/include)
endif()
# Libarchive
if(LibArchive_FOUND)
include_directories(AFTER, ${LibArchive_INCLUDE_DIRS})
else()
include_directories(AFTER, vendor/libarchive/libarchive)
endif()
# Use C++17
if(UNIX)
#-Wno-deprecated-declarations hides warning in yaml-cpp (using std::auto_ptr)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Wno-deprecated-declarations")
elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /EHsc /MP /D NOMINMAX")
endif()
# Bit of sets of handy folders
set(SRC_DIR src)
set(LIBS_DIR vendor)
set(FILEMAN_DIR src/fileman)
set(SANDBOX_DIR src/sandbox)
set(TASKS_DIR src/tasks)
set(HELPERS_DIR src/helpers)
set(CONFIG_DIR src/config)
set(JOB_DIR src/job)
set(COMMAND_DIR src/commands)
# The worker executable
set(SOURCE_FILES
${SRC_DIR}/main.cpp
${SRC_DIR}/broker_connection.h
${SRC_DIR}/connection_proxy.h
${SRC_DIR}/worker_core.h
${SRC_DIR}/worker_core.cpp
${SRC_DIR}/eval_request.h
${SRC_DIR}/archives/archivator.h
${SRC_DIR}/archives/archivator.cpp
${SRC_DIR}/eval_response.h
${FILEMAN_DIR}/file_manager_interface.h
${FILEMAN_DIR}/cache_manager.h
${FILEMAN_DIR}/http_manager.h
${FILEMAN_DIR}/fallback_file_manager.h
${FILEMAN_DIR}/cache_manager.cpp
${FILEMAN_DIR}/http_manager.cpp
${FILEMAN_DIR}/fallback_file_manager.cpp
${FILEMAN_DIR}/prefixed_file_manager.cpp
${FILEMAN_DIR}/prefixed_file_manager.h
${SANDBOX_DIR}/sandbox_base.h
${SANDBOX_DIR}/isolate_sandbox.h
${SANDBOX_DIR}/isolate_sandbox.cpp
${TASKS_DIR}/task_factory_interface.h
${TASKS_DIR}/create_params.h
${TASKS_DIR}/task_factory.h
${TASKS_DIR}/task_factory.cpp
${TASKS_DIR}/root_task.h
${TASKS_DIR}/root_task.cpp
${TASKS_DIR}/task_base.h
${TASKS_DIR}/task_base.cpp
${TASKS_DIR}/external_task.h
${TASKS_DIR}/external_task.cpp
${TASKS_DIR}/internal/cp_task.h
${TASKS_DIR}/internal/cp_task.cpp
${TASKS_DIR}/internal/rename_task.h
${TASKS_DIR}/internal/rename_task.cpp
${TASKS_DIR}/internal/mkdir_task.h
${TASKS_DIR}/internal/mkdir_task.cpp
${TASKS_DIR}/internal/rm_task.h
${TASKS_DIR}/internal/rm_task.cpp
${TASKS_DIR}/internal/archivate_task.h
${TASKS_DIR}/internal/archivate_task.cpp
${TASKS_DIR}/internal/extract_task.h
${TASKS_DIR}/internal/extract_task.cpp
${TASKS_DIR}/internal/fetch_task.h
${TASKS_DIR}/internal/fetch_task.cpp
${TASKS_DIR}/internal/dump_dir_task.h
${TASKS_DIR}/internal/dump_dir_task.cpp
${TASKS_DIR}/internal/truncate_task.h
${TASKS_DIR}/internal/truncate_task.cpp
${TASKS_DIR}/internal/exists_task.h
${TASKS_DIR}/internal/exists_task.cpp
${HELPERS_DIR}/filesystem.h
${HELPERS_DIR}/filesystem.cpp
${HELPERS_DIR}/topological_sort.h
${HELPERS_DIR}/topological_sort.cpp
${HELPERS_DIR}/config.h
${HELPERS_DIR}/config.cpp
${HELPERS_DIR}/zmq_socket.h
${HELPERS_DIR}/zmq_socket.cpp
${HELPERS_DIR}/logger.h
${HELPERS_DIR}/logger.cpp
${HELPERS_DIR}/string_utils.h
${HELPERS_DIR}/string_utils.cpp
${HELPERS_DIR}/type_utils.h
${HELPERS_DIR}/format.h
${CONFIG_DIR}/worker_config.cpp
${CONFIG_DIR}/worker_config.h
${CONFIG_DIR}/fileman_config.h
${CONFIG_DIR}/log_config.h
${CONFIG_DIR}/sandbox_limits.h
${CONFIG_DIR}/task_results.h
${CONFIG_DIR}/job_metadata.h
${CONFIG_DIR}/task_metadata.h
${CONFIG_DIR}/sandbox_config.h
${JOB_DIR}/job.h
${JOB_DIR}/job_exception.h
${JOB_DIR}/job.cpp
${JOB_DIR}/job_evaluator_interface.h
${JOB_DIR}/job_evaluator.h
${JOB_DIR}/job_evaluator.cpp
${JOB_DIR}/job_receiver.cpp
${JOB_DIR}/job_receiver.h
${JOB_DIR}/progress_callback_interface.h
${JOB_DIR}/progress_callback.h
${JOB_DIR}/progress_callback.cpp
${COMMAND_DIR}/command_holder.h
${COMMAND_DIR}/broker_commands.h
${COMMAND_DIR}/jobs_server_commands.h
${COMMAND_DIR}/jobs_client_commands.h
)
include_directories(AFTER, ${SRC_DIR})
add_executable(${EXEC_NAME} ${SOURCE_FILES})
if(YAMLCPP_FOUND)
target_link_libraries(${EXEC_NAME} ${YAMLCPP_LIBRARY})
else()
target_link_libraries(${EXEC_NAME} yaml-cpp)
endif()
if(LibArchive_FOUND)
target_link_libraries(${EXEC_NAME} ${LibArchive_LIBRARIES})
elseif(UNIX)
target_link_libraries(${EXEC_NAME} archive)
else()
target_link_libraries(${EXEC_NAME} archive_static)
target_compile_definitions(${EXEC_NAME} PRIVATE LIBARCHIVE_STATIC)
endif()
target_link_libraries(${EXEC_NAME} ${CURL_LIBRARIES})
target_link_libraries(${EXEC_NAME} ${Boost_LIBRARIES})
if(UNIX)
target_link_libraries(${EXEC_NAME} -lzmq)
target_link_libraries(${EXEC_NAME} pthread)
elseif(MSVC)
target_link_libraries(${EXEC_NAME} ${ZEROMQ_LIB})
endif()
if(NOT LibArchive_FOUND)
# Include libarchive
option(ENABLE_CPIO OFF)
option(ENABLE_TAR OFF)
option(ENABLE_TEST OFF)
add_subdirectory(vendor/libarchive)
endif()
if(NOT YAMLCPP_FOUND)
# Include Yaml-cpp
option(YAML_CPP_BUILD_TOOLS OFF)
add_subdirectory(vendor/yaml-cpp)
endif()
if(NOT DISABLE_TESTS)
# Include Google Test libraries and then our very own unit tests
add_subdirectory(vendor/googletest EXCLUDE_FROM_ALL)
add_subdirectory(tests)
endif()
# Include judges
add_subdirectory(judges)
# ========== Install targets - 'sudo make install' ==========
include(InstallRequiredSystemLibraries)
if(UNIX)
install(TARGETS recodex-worker DESTINATION /usr/bin COMPONENT binaries)
install(FILES install/recodex-worker@.service DESTINATION /lib/systemd/system COMPONENT config)
install(FILES examples/config.yml DESTINATION /etc/recodex/worker COMPONENT config RENAME config-1.yml)
elseif(MSVC)
install(TARGETS recodex-worker DESTINATION worker/bin COMPONENT binaries)
install(DIRECTORY build/Release/ DESTINATION worker/bin COMPONENT binaries FILES_MATCHING PATTERN "*.dll")
install(FILES build/curl-ca-bundle.crt DESTINATION worker/bin COMPONENT binaries)
install(FILES examples/config.yml DESTINATION worker/conf COMPONENT config RENAME config-1.yml)
else()
install(TARGETS recodex-worker DESTINATION recodex/worker/bin COMPONENT binaries)
install(FILES examples/config.yml DESTINATION recodex/worker/conf COMPONENT config RENAME config-1.yml)
endif()
# ========== Packaging targets - 'sudo make package' ==========
set(CPACK_PACKAGE_NAME "recodex-worker")
set(CPACK_PACKAGE_VENDOR "ReCodEx Team")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "ReCodEx Worker - Backend part of ReCodEx programmer testing solution")
set(CPACK_COMPONENTS_ALL "binaries" "config")
set(CPACK_PACKAGE_VERSION ${RECODEX_VERSION})
set(CPACK_PACKAGING_INSTALL_PREFIX "/")
set(CPACK_PACKAGE_RELOCATABLE "FALSE")
if(UNIX)
set(CPACK_GENERATOR "RPM" "DEB")
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
set(CPACK_RPM_PACKAGE_ARCHITECTURE "x86_64")
set(CPACK_RPM_PACKAGE_RELEASE "1")
set(CPACK_RPM_PACKAGE_DESCRIPTION "Backend part of ReCodEx programmer testing solution.")
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/install/postinst")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Petr Stefan <ps@stdin.cz>")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/install/postinst;")
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${RECODEX_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE}")
elseif(MSVC)
set(CPACK_GENERATOR "NSIS")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
endif()
include (CPack)
# ========== Formatting ==========
file(GLOB_RECURSE ALL_SOURCE_FILES src/*.cpp src/*.h tests/*.cpp tests/*.h)
if(UNIX)
add_custom_target(format
COMMAND clang-format --style=file -i ${ALL_SOURCE_FILES}
COMMENT "Running clang-format"
VERBATIM
)
endif()
# Count sum of lines in source files (for Martin)
add_custom_target(lines
COMMAND echo -n "Total lines of code: " && cat ${ALL_SOURCE_FILES} | wc -l
COMMENT "Counting lines"
VERBATIM
)