-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
229 lines (194 loc) · 9.32 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
# Подключаем версию CMake
cmake_minimum_required(VERSION 3.15)
# TODO: вписать рабочее название проекта
project(alm LANGUAGES CXX)
set(PROJECT_VENDOR_LONG "ANYKS Language Model")
# Опции сборки
# Сборка тестового ПО
option(ENABLE_CONSOLE_APP "Build test app" TRUE)
set(PROJECT_COPYRIGHT "Copyright (c) ${CURRENT_YEAR} ${PROJECT_VENDOR_LONG}")
# Тип сборки
# cmake -DCMAKE_BUILD_TYPE=YES ..
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}\n")
# Получаем архитектуру
EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE )
message( STATUS "Architecture: ${ARCHITECTURE}" )
# Проверка версии OS
string(REGEX MATCH "Linux" PROJECT_OS_LINUX ${CMAKE_SYSTEM_NAME})
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
message(STATUS "Detected OS: Linux")
set(DEBUGGER "-ggdb3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--no-as-needed -ldl")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
message(STATUS "Detected OS: MacOS X")
set(DEBUGGER "-glldb")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
message(STATUS "Detected OS: FreeBSD")
set(DEBUGGER "-ggdb3")
else()
set(DEBUGGER "")
endif()
# Enable C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Устанавливаем опции компилятора
set(CMAKE_CXX_COMPILER_ID "clang++")
message(STATUS "Using C compiler: ${CMAKE_C_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS "Using C++ compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}\n")
# Информация и времени компиляции
string(TIMESTAMP CURRENT_YEAR "%Y")
string(TIMESTAMP CURRENT_TIME "%d.%m.%Y %H:%M:%S")
# Опции компилятора
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(TON_PARAMS "-Wno-cpp -Wno-deprecated")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(TON_PARAMS "-Wno-cpp -Wno-deprecated")
else()
set(TON_PARAMS "-Wno-unknown-attributes")
endif()
if (${ARCHITECTURE} MATCHES "aarch64" OR ${ARCHITECTURE} MATCHES "arm*")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -pipe -DNDEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -fno-permissive -Wno-pedantic -Wno-narrowing -Wno-deprecated-declarations ${TON_PARAMS}")
else()
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -pipe -mrdrnd -march=core2 -DNDEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -fno-permissive -Wno-pedantic -Wno-narrowing -Wno-deprecated-declarations ${TON_PARAMS}")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -DDEBUG_MODE ${DEBUGGER}")
if(CMAKE_BUILD_TYPE MATCHES Debug)
message(STATUS "C Flags: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}")
message(STATUS "C++ Flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}\n")
else()
message(STATUS "C Flags: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}")
message(STATUS "C++ Flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}\n")
endif()
# Добавляем модули cmake
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Выполняем поиск нужных библиотек
find_package(Zlib REQUIRED)
find_package(Python REQUIRED)
find_package(OpenSSL REQUIRED)
# Провекра OpenSSL
if (OpenSSL_FOUND)
message(STATUS "OpenSSL libs found: " ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
message(STATUS "OpenSSL include dir found: " ${OPENSSL_INCLUDE_DIR})
else()
message(FATAL_ERROR "OpenSSL not found")
endif()
# Провекра ZLib
if (Zlib_FOUND)
message(STATUS "ZLib lib found: " ${ZLIB_LIBRARY})
message(STATUS "ZLib include dir found: " ${ZLIB_INCLUDE_DIR})
else()
message(FATAL_ERROR "ZLib not found")
endif()
# Провекра Python
if (Python_FOUND)
message(STATUS "Python lib found: " ${PYTHON_LIBRARY})
message(STATUS "Python include dir found: " ${PYTHON_INCLUDE_DIR})
else()
message(FATAL_ERROR "Python not found")
endif()
# Выполняем подключение хидеров
include_directories(${ZLIB_INCLUDE_DIR})
include_directories(${PYTHON_INCLUDE_DIR})
include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/)
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/contrib/include)
# Выполняем подключение исходников
set(SOURCE_FILES
"${CMAKE_SOURCE_DIR}/src/idw.cpp"
"${CMAKE_SOURCE_DIR}/src/nwt.cpp"
"${CMAKE_SOURCE_DIR}/src/env.cpp"
"${CMAKE_SOURCE_DIR}/src/alm.cpp"
"${CMAKE_SOURCE_DIR}/src/alm1.cpp"
"${CMAKE_SOURCE_DIR}/src/alm2.cpp"
"${CMAKE_SOURCE_DIR}/src/arpa.cpp"
"${CMAKE_SOURCE_DIR}/src/ablm.cpp"
"${CMAKE_SOURCE_DIR}/src/python.cpp"
"${CMAKE_SOURCE_DIR}/src/toolkit.cpp"
"${CMAKE_SOURCE_DIR}/src/alphabet.cpp"
"${CMAKE_SOURCE_DIR}/src/progress.cpp"
"${CMAKE_SOURCE_DIR}/src/tokenizer.cpp"
"${CMAKE_SOURCE_DIR}/src/collector.cpp"
"${CMAKE_SOURCE_DIR}/src/levenshtein.cpp"
"${CMAKE_SOURCE_DIR}/contrib/src/cityhash/city.cc"
"${CMAKE_SOURCE_DIR}/contrib/src/bigint/BigInteger.cc"
"${CMAKE_SOURCE_DIR}/contrib/src/bigint/BigUnsigned.cc"
"${CMAKE_SOURCE_DIR}/contrib/src/bigint/BigIntegerUtils.cc"
"${CMAKE_SOURCE_DIR}/contrib/src/bigint/BigUnsignedInABase.cc"
"${CMAKE_SOURCE_DIR}/contrib/src/bigint/BigIntegerAlgorithms.cc"
)
set(ALM_LIB_NAME ${PROJECT_NAME})
set(ALM_APP_NAME ${PROJECT_NAME}_bin)
# Делаем либу
add_library(${ALM_LIB_NAME} STATIC ${SOURCE_FILES})
# Если установлен флаг ENABLE_CONSOLE_APP собираем консольное приложение
if (ENABLE_CONSOLE_APP)
# Проставляем платформозависимые зависимости
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(OS_FLAGS "-lutil -Xlinker -export-dynamic")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
set(OS_FLAGS "-lutil -Xlinker -export-dynamic")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(OS_FLAGS -lws2_32 -lgdi32 -lcrypt32 -lIphlpapi)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(OS_FLAGS "")
endif()
# Устанавливаем иконку для windows под MinGW.
set(RES_FILES "")
if(MINGW)
set(RES_FILES "alm.rc")
set(CMAKE_RC_COMPILER_INIT windres)
ENABLE_LANGUAGE(RC)
SET(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
endif(MINGW)
add_executable(${ALM_APP_NAME} app/alm.cpp ${RES_FILES})
# Если операционной системой является Windows
if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
target_link_libraries(${ALM_APP_NAME}
${ALM_LIB_NAME}
${PYTHON_LIBRARY}
${OPENSSL_LIBRARIES}
${ZLIB_LIBRARY}
${OS_FLAGS}
)
# Для всех остальных операционных систем
else()
target_link_libraries(${ALM_APP_NAME}
${ALM_LIB_NAME}
${PYTHON_LIBRARY}
${OPENSSL_LIBRARIES}
${ZLIB_LIBRARY}
${OS_FLAGS}
)
endif()
set_target_properties(${ALM_APP_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
endif()
# Устанавливаем адрес установки, запрет установки в /usr/local
if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local" OR "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local/")
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}")
endif()
# Устанавливаем хидеры
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/app" DESTINATION "${CMAKE_INSTALL_PREFIX}/include/${CMAKE_PROJECT_NAME}" FILES_MATCHING PATTERN "*.hpp")
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include" DESTINATION "${CMAKE_INSTALL_PREFIX}/include/${CMAKE_PROJECT_NAME}" FILES_MATCHING PATTERN "*.hpp")
# Устанавливаем библиотеку
install(TARGETS ${ALM_LIB_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
# Устанавливаем исполнительные файлы
install(TARGETS ${ALM_APP_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin/${CMAKE_PROJECT_NAME}")
# Устанавливаем хидеры сторонних библиотек
install(DIRECTORY "${ZLIB_INCLUDE_DIR}" DESTINATION "${CMAKE_INSTALL_PREFIX}/include" FILES_MATCHING PATTERN "*.h")
install(DIRECTORY "${PYTHON_INCLUDE_DIR}" DESTINATION "${CMAKE_INSTALL_PREFIX}/include" FILES_MATCHING PATTERN "*.h")
install(DIRECTORY "${OPENSSL_INCLUDE_DIR}/openssl" DESTINATION "${CMAKE_INSTALL_PREFIX}/include" FILES_MATCHING PATTERN "*.h")
# Устанавливаем заголовочные файлы зависимостей
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/contrib/include" DESTINATION "${CMAKE_INSTALL_PREFIX}" FILES_MATCHING PATTERN "*.h")
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/contrib/include" DESTINATION "${CMAKE_INSTALL_PREFIX}" FILES_MATCHING PATTERN "*.hh")
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/contrib/include" DESTINATION "${CMAKE_INSTALL_PREFIX}" FILES_MATCHING PATTERN "*.hpp")
# Устанавливаем стороние библиотеки
install(FILES ${ZLIB_LIBRARY} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
install(FILES ${PYTHON_LIBRARY} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
install(FILES ${OPENSSL_LIBRARIES} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")