-
Notifications
You must be signed in to change notification settings - Fork 19
/
CMakeLists.txt
212 lines (167 loc) · 6.57 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
project(ccommet)
cmake_minimum_required(VERSION 2.6)
message(STATUS "System: " ${CMAKE_SYSTEM_NAME} " " ${CMAKE_SYSTEM_VERSION})
message(STATUS "Processor: " ${CMAKE_HOST_SYSTEM_PROCESSOR})
# Проверить версию gcc так как на меньше чем 4.9 не собирается
# Установка версии gcc 4.9 в убунту https://askubuntu.com/questions/428198/getting-installing-gcc-g-4-9-on-ubuntu/507068#507068
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# require at least gcc 4.9
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
message(FATAL_ERROR "GCC version must be at least 4.9! Now ${CMAKE_CXX_COMPILER_VERSION}")
message(FATAL_ERROR "GCC version must be at least 4.9!")
endif()
endif()
SET(CMAKE_CXX_FLAGS "-std=c++11 -g3")
#add_definitions(-DMY_PROJECT)
add_definitions(-DCMAKE_BUILD_TYPE=debug)
# Поиск библиотеки pthreads
find_package(Threads REQUIRED)
if(NOT Threads_FOUND)
message(SEND_ERROR "Не найден Threads.")
return()
else()
include_directories(${Threads_INCLUDE_DIRS})
endif()
###########################################
#
# Необходимо уставновить пакет libmysqlclient-dev для работы с mysql
# sudo apt-get install libmysqlclient-dev
#
###########################################
###########################################
#
# - Find mysqlclient
# Find the native MySQL includes and library
#
# MYSQL_INCLUDE_DIR - where to find mysql.h, etc.
# MYSQL_LIBRARIES - List of libraries when using MySQL.
# MYSQL_FOUND - True if MySQL found.
IF (MYSQL_INCLUDE_DIR)
# Already in cache, be silent
SET(MYSQL_FIND_QUIETLY TRUE)
ENDIF (MYSQL_INCLUDE_DIR)
FIND_PATH(MYSQL_INCLUDE_DIR mysql.h
/usr/local/include/mysql
/usr/include/mysql
/usr/include/mariadb
)
SET(MYSQL_NAMES mysqlclient mysqlclient_r)
FIND_LIBRARY(MYSQL_LIBRARY
NAMES ${MYSQL_NAMES}
PATHS /usr/lib /usr/local/lib
PATH_SUFFIXES mysql
)
IF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
SET(MYSQL_FOUND TRUE)
SET( MYSQL_LIBRARIES ${MYSQL_LIBRARY} )
ELSE (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
SET(MYSQL_FOUND FALSE)
SET( MYSQL_LIBRARIES )
ENDIF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
IF (MYSQL_FOUND)
IF (NOT MYSQL_FIND_QUIETLY)
MESSAGE(STATUS "Found MySQL: ${MYSQL_LIBRARY}")
ENDIF (NOT MYSQL_FIND_QUIETLY)
ELSE (MYSQL_FOUND)
IF (MYSQL_FIND_REQUIRED)
MESSAGE(STATUS "Looked for MySQL libraries named ${MYSQL_NAMES}.")
MESSAGE(FATAL_ERROR "Could NOT find MySQL library")
ENDIF (MYSQL_FIND_REQUIRED)
ENDIF (MYSQL_FOUND)
MARK_AS_ADVANCED(
MYSQL_LIBRARY
MYSQL_INCLUDE_DIR
)
###########################################
find_package(OpenSSL REQUIRED)
if(NOT Threads_FOUND)
message(FATAL_ERROR "OpenSSL Not found.")
return()
else()
include_directories(${OpenSSL_INCLUDE_DIRS})
endif()
include_directories(${MYSQL_INCLUDE_DIR} dependencies dependencies/freeswitch-esl/include dependencies/jwt-cpp/src/include)
# Расположение заголовочных файлов
#include_directories(foo)
execute_process( COMMAND flex -i src/CometQL.l)
execute_process( COMMAND bison -d src/CometQL.y)
execute_process( COMMAND yacc -d src/CometQL.y)
execute_process( COMMAND bison -d --verbose --debug src/CometQL.y -o src/CometQL.cc)
execute_process( COMMAND yacc -d --verbose --debug src/CometQL.y -o src/CometQL.cc)
execute_process( COMMAND cc -c src/lex.yy.c -o src/lex.yy.o)
execute_process( COMMAND mv CometQL.tab.c src/CometQL.tab.c)
execute_process( COMMAND mv CometQL.tab.h src/CometQL.tab.h)
execute_process( COMMAND mv lex.yy.c src/lex.yy.c)
execute_process( COMMAND mv y.tab.c src/y.tab.c)
execute_process( COMMAND mv y.tab.h src/y.tab.h)
MESSAGE(STATUS "Build dependencies")
execute_process( COMMAND sh dependencies/build.sh)
set(ESL_EXE
dependencies/freeswitch-esl/cJSON.c
dependencies/freeswitch-esl/cJSON_Utils.c
dependencies/freeswitch-esl/esl.c
dependencies/freeswitch-esl/esl_buffer.c
dependencies/freeswitch-esl/esl_config.c
dependencies/freeswitch-esl/esl_event.c
dependencies/freeswitch-esl/esl_json.c
dependencies/freeswitch-esl/esl_threadmutex.c)
set(TINYXML2_EXE
dependencies/tinyxml2/tinyxml2.cpp)
set(HASHLIB2PLUS_EXE
dependencies/hashlib2plus/src/hl_md5.cpp
dependencies/hashlib2plus/src/hl_md5wrapper.cpp)
# Установка переменной со списком исходников для исполняемого файла
set(SOURCE_EXE
src/TagLoger.cpp
src/TagTimer.cpp
src/main.cpp
src/appConf.cpp
src/dbLink.cpp
src/intervalLoop.cpp
src/tcpServer_benchmark.cpp
src/base64.cpp
src/sha1.cpp
src/CometQL.cpp
src/devManager.cpp
src/internalApi.cpp
src/Client_connection.cpp
src/Freeswitch_connection.cpp
src/MySqlProtocol.cpp
src/connection.cpp
src/mystring.cpp
src/MySql_connection.cpp
src/CometQLProxy_connection.cpp
src/tcpServer.cpp
src/user_index.cpp
src/backtrace.cpp
src/thread_data.cpp
src/thread_data.h
src/lex.yy.o
src/CometQL.cc)
add_library(libjwta STATIC IMPORTED)
set_property(TARGET libjwta PROPERTY
IMPORTED_LOCATION dependencies/jwt-cpp/src/libjwt.a)
# Создает исполняемый файл с именем cpp_comet из исходников
add_executable(cppcomet ${HASHLIB2PLUS_EXE} ${SOURCE_EXE} ${TINYXML2_EXE} ${ESL_EXE} )
# Подключение библиотеки pthreads
target_link_libraries (cppcomet ${CMAKE_THREAD_LIBS_INIT} ${MYSQL_LIBRARIES} ${OPENSSL_LIBRARIES} crypt uuid libjwta)
#cmake ./ && make
#INSTALL( DIRECTORY <directory> DESTINATION usr/myproject )
#mkdir /etc/comet-server
#cp ./comet-service.sh /etc/comet-server/comet-service.sh
#cp ./comet.ini /etc/comet-server/comet.ini
#cp ./cpp_comet /etc/comet-server/cpp_comet
# https://mirkokiefer.com/cmake-by-example-f95eb47d45b1
set(INSTALL_CONF_DIR
/etc/comet-server)
set(INSTALL_BIN_DIR
/usr/bin)
set(INSTALL_SYSTEMD_DIR
/etc/systemd/system)
install(FILES comet.service DESTINATION ${INSTALL_SYSTEMD_DIR} PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
install(FILES comet.ini DESTINATION ${INSTALL_CONF_DIR} PERMISSIONS OWNER_READ GROUP_READ )
install(PROGRAMS comet-service.sh DESTINATION ${INSTALL_CONF_DIR} PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
install(TARGETS cppcomet DESTINATION ${INSTALL_BIN_DIR} PERMISSIONS OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
INSTALL( SCRIPT postinstall.cmake )
# https://cmake.org/pipermail/cmake/2009-September/031887.html
# INSTALL(SCRIPT CopyIfNotExists.cmake)