generated from ucu-cs/template_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
executable file
·154 lines (126 loc) · 4.8 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
cmake_minimum_required(VERSION 3.15)
set(PROJECT_NAME echo-server)
project(${PROJECT_NAME} CXX)
set(CMAKE_CXX_STANDARD 20)
##########################################################
# User configurable options of the template
##########################################################
# Note: symbols like WARNINGS_AS_ERRORS in configuration are intentionally variables
# and not CMake options --using options creates too much problem for students.
#! It is a good practice to set "WARNINGS_AS_ERRORS" ON,
# but sometimes it creates too much trouble, so default is OFF.
set(WARNINGS_AS_ERRORS OFF)
#! Always use PVS Studio while developing.
set(ENABLE_PVS_STUDIO OFF)
#! Select appropriate sanitizers.
# Definitely enable sanitizers while developing.
# Disable it for the production builds and before submitting for grading.
# Only one of Memory (MSAN), Address (ASAN), or Thread (TSan)
# sanitizers is applicable at the time -- the first defined.
#! UndefinedBehaviorSanitizer (UBSan)
# Info: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
set(ENABLE_UBSan OFF)
#! AddressSanitizer -- detects use after free or after scope exit,
# memory overflows and leaks.
# Info: https://github.com/google/sanitizers/wiki/AddressSanitizer
set(ENABLE_ASAN OFF)
#! ThreadSanitizer -- detects data races.
set(ENABLE_TSan OFF)
#! MemorySanitizer detects uninitialized memory reads
# Info: https://github.com/google/sanitizers/wiki/MemorySanitizer
set(ENABLE_MSAN OFF)
#! Be default -- build release version if not specified otherwise.
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif ()
# Warnings as errors should be imported here -- do not move this line
include(cmake/CompilerWarnings.cmake)
##########################################################
# Project files, packages, libraries and so on
##########################################################
#! Prepare libraries
# Boost
find_package(Boost 1.71.0 COMPONENTS system REQUIRED)
set(BOOST_KEY_WORD boost_lib)
# Standard Threads
find_package(Threads REQUIRED)
set(THREADS_KEY_WORD thread_lib)
# Google Log
find_package(PkgConfig REQUIRED)
pkg_check_modules(glog REQUIRED libglog)
set(GLOG_KEY_WORD glog_lib)
# Google Flags for glog configurations
find_package(gflags REQUIRED)
set(GFLAGS_KEY_WORD gflags_lib)
#! Common Sources
set(COMMON_SRC
src/common/io.cpp include/common/io.h include/common/defines.h
src/common/socket.cpp include/common/socket.h
src/common/logging.cpp include/common/logging.h
include/common/thread_safe_queue.h
include/common/thread_safe_radio_queue.h
)
#! Specify targets
set(SERVER_TARGETS
echo_server_simple
echo_server_simple_threaded
echo_server_custom_thread_pool
echo_server_boost_asio
echo_server_boost_asio_threaded
)
#! Specify libs to link
set(LINK_LIBS_echo_server_simple
)
set(LINK_LIBS_echo_server_simple_threaded
${THREADS_KEY_WORD}
)
set(LINK_LIBS_echo_server_custom_thread_pool
${THREADS_KEY_WORD}
)
set(LINK_LIBS_echo_server_boost_asio
${BOOST_KEY_WORD}
)
set(LINK_LIBS_echo_server_boost_asio_threaded
${BOOST_KEY_WORD}
${THREADS_KEY_WORD}
)
#! Compile Common Lib
add_library(common STATIC ${COMMON_SRC})
target_include_directories(common PUBLIC include)
# link Google Logs
target_include_directories(common PRIVATE ${glog_INCLUDE_DIRS})
target_link_libraries(common ${glog_LIBRARIES})
# Google Flags
target_include_directories(common PRIVATE ${gflags_INCLUDE_DIRS})
target_link_libraries(common ${gflags_LIBRARIES})
#! Project executables source compilation
foreach (TARGET ${SERVER_TARGETS})
MESSAGE("Compiling target: ${TARGET}")
add_executable(${TARGET} main.cpp
src/${TARGET}.cpp include/${TARGET}.h
)
string(TOUPPER ${TARGET} TARGET_SPECIFIER)
target_compile_definitions(${TARGET} PUBLIC ${TARGET_SPECIFIER})
# Link common library by default
target_link_libraries(${TARGET} common)
target_include_directories(${TARGET} PRIVATE include)
if ($<IN_LIST:${BOOST_KEY_WORD},LINK_LIBS_${TARGET}>)
# Boost
target_include_directories(${TARGET} PRIVATE ${Boost_INCLUDE_DIR})
target_link_libraries(${TARGET} ${Boost_LIBRARIES})
elseif ($<IN_LIST:${THREAD_KEY_WORD},LINK_LIBS_${TARGET}>)
# Thread
target_link_libraries(${TARGET} ${CMAKE_THREAD_LIBS_INIT})
endif ()
endforeach ()
##########################################################
# Fixed CMakeLists.txt part
##########################################################
foreach (TARGET ${SERVER_TARGETS})
INSTALL(TARGETS ${TARGET}
DESTINATION bin)
endforeach ()
# Define ALL_TARGETS variable to use in PVS and Sanitizers
set(ALL_TARGETS ${SERVER_TARGETS})
# Include CMake setup
include(cmake/main-config.cmake)