forked from psi-im/psi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
364 lines (324 loc) · 14.5 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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
cmake_minimum_required(VERSION 3.1.0)
if(POLICY CMP0071)
cmake_policy(SET CMP0071 OLD)
endif ()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
endif()
#Psi or Psi+ detection
set( IS_PSIPLUS ON CACHE BOOL "Build Psi+ client")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/widgets/psiwindowheader.cpp")
message(STATUS "Psi+ features - FOUND")
set(IS_PSIPLUS ON)
project(psi-plus)
else()
message(STATUS "Psi+ features - NOT FOUND")
set(IS_PSIPLUS OFF)
project(psi)
endif()
#Common options
option( BUNDLED_IRIS "Build iris library bundled" ON )
option( ONLY_PLUGINS "Build psi-plus plugins only" OFF )
option( USE_HUNSPELL "Build psi-plus with hunspell spellcheck" ON )
option( USE_ENCHANT "Build psi-plus with enchant spellcheck" OFF )
option( ENABLE_PLUGINS "Enable plugins" OFF )
option( ENABLE_WEBKIT "Enable webkit/webengine support" ON )
option( USE_WEBKIT "Use Webkit support instead of WebEngine" OFF )
option( USE_WEBENGINE "Use WebEngine support instead of Webkit" OFF )
option( USE_CCACHE "Use ccache utility if found" ON )
option( VERBOSE_PROGRAM_NAME "Verbose output binary name" OFF ) #Experimental
option( USE_CRASH "Enable builtin sigsegv handling" OFF )
option( USE_KEYCHAIN "Enable Qt5Keychain support" ON )
option( ONLY_BINARY "Build and install only binary file" OFF )
option( INSTALL_EXTRA_FILES "Install sounds, iconsets, certs, client_icons.txt, themes" ON )
#Iris options
option( USE_QJDNS "Use qjdns/jdns library. Disabled by default for Qt5" OFF )
option( SEPARATE_QJDNS "Build qjdns as separate lib" OFF )
if( IS_PSIPLUS )
option( PRODUCTION "Build production version" OFF )
else()
option( PRODUCTION "Build production version" ON )
endif()
#Windows or MXE only
option( USE_MXE "Use MXE cross-compilation" OFF )
option( ENABLE_PORTABLE "Create portable version of Psi+ in win32" OFF )
option( DEV_MODE "Enable prepare-bin-libs target for Windows OS" OFF )
if( USE_HUNSPELL AND USE_ENCHANT )
message(FATAL_ERROR "Both flags USE_HUNSPELL and USE_ENCHANT cannot be enabled at the same time. Please disable one of them")
endif()
if( ONLY_BINARY AND INSTALL_EXTRA_FILES )
message(FATAL_ERROR "Both flags ONLY_BINARY and INSTALL_EXTRA_FILES cannot be enabled at the same time. Please disable one of them")
endif()
set( QT4_BUILD OFF )
set( GLOBAL_DEPENDS_DEBUG_MODE ON )
set( CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" )
set( ENABLE_SQL OFF CACHE BOOL "Enable SQL history support")
if(ENABLE_WEBKIT)
add_definitions(
-DWEBKIT
)
find_package( Qt5Core REQUIRED )
find_package( Qt5 COMPONENTS WebEngine QUIET )
if(${Qt5Core_VERSION} VERSION_GREATER 5.6.0)
if( Qt5WebEngine_FOUND AND (NOT USE_WEBKIT) )
set( USE_WEBENGINE ON )
add_definitions(
-DWEBENGINE=1
)
message(STATUS "QtWebEngine - enabled")
else()
set( USE_WEBENGINE OFF )
endif()
endif()
message(STATUS "Webkit - enabled")
endif()
if(USE_WEBENGINE AND USE_WEBKIT)
message(FATAL_ERROR "Both flags USE_WEBENGINE and USE_WEBKIT cannot be enabled at the same time. Please disable one of them")
endif()
if(USE_WEBENGINE AND (NOT ENABLE_WEBKIT))
message(FATAL_ERROR "USE_WEBENGINE flag is enabled but ENABLE_WEBKIT flag is disabled. Please disable USE_WEBENGINE or enable ENABLE_WEBKIT")
endif()
if(USE_WEBKIT AND (NOT ENABLE_WEBKIT))
message(FATAL_ERROR "USE_WEBKIT flag is enabled but ENABLE_WEBKIT flag is disabled. Please disable USE_WEBKIT or enable ENABLE_WEBKIT")
endif()
if(EXISTS "${PROJECT_SOURCE_DIR}/src/historyimp.cpp")
message(STATUS "SQL history - enabled")
set(ENABLE_SQL ON)
else()
set(ENABLE_SQL OFF)
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo"))
set(ISDEBUG ON)
endif()
if(ONLY_PLUGINS)
set(ENABLE_PLUGINS ON)
endif()
if(USE_CRASH)
add_definitions(-DUSE_CRASH)
endif()
#Detect MXE cross-compilation
if( (CMAKE_CROSSCOMPILING) AND (DEFINED MSYS) )
message(STATUS "MXE environment detected")
set(USE_MXE ON)
message(STATUS "MXE root path: ${CMAKE_PREFIX_PATH}")
# TODO: Check why this breaks build with GCC >= 6.0:
#set(Qt5Keychain_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5Keychain" CACHE STRING "Path to Qt5Keychain cmake files")
endif()
if(WIN32)
if(MSVC)
set(BUILD_ARCH "win64" CACHE STRING "CPU architecture win32/win64")
set(SDK_PATH "e:/build/msvc2015-root" CACHE STRING "Path to SDK")
else()
set(BUILD_ARCH "i386" CACHE STRING "CPU architecture i386/x86_64")
set(SDK_PATH "e:/build/psisdk" CACHE STRING "Path to SDK")
endif()
#autodetect 64bit architecture
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
if(MSVC)
set(BUILD_ARCH "win64")
else()
set(BUILD_ARCH "x86_64")
endif()
if(DEV_MODE)
set(GST_SDK $ENV{GSTREAMER_1_0_ROOT_x86_64})
endif()
else()
if(MSVC)
set(BUILD_ARCH "win32")
else()
set(BUILD_ARCH "i386")
endif()
if(DEV_MODE)
set(GST_SDK $ENV{GSTREAMER_1_0_ROOT_x86})
endif()
endif()
message(STATUS "Detecting build architecture: ${BUILD_ARCH} detected")
if(EXISTS "${SDK_PATH}")
if(MSVC)
set(QCA_DIR "${SDK_PATH}/" CACHE STRING "Path to QCA")
set(IDN_ROOT "${SDK_PATH}/" CACHE STRING "Path to IDN library")
set(HUNSPELL_ROOT "${SDK_PATH}/" CACHE STRING "Path to hunspell library")
if(ENABLE_PLUGINS)
set(LIBGCRYPT_ROOT "${SDK_PATH}/" CACHE STRING "Path to libgcrypt library")
set(LIBGPGERROR_ROOT "${SDK_PATH}/" CACHE STRING "Path to libgpg-error library")
set(LIBOTR_ROOT "${SDK_PATH}/" CACHE STRING "Path to libotr library")
set(LIBTIDY_ROOT "${SDK_PATH}/" CACHE STRING "Path to libtidy library")
set(SIGNAL_PROTOCOL_C_ROOT "${SDK_PATH}/" CACHE STRING "Path to libsignal-protocol-c library")
endif()
set(ZLIB_ROOT "${SDK_PATH}/" CACHE STRING "Path to zlib")
set(OPENSSL_ROOT_DIR "${SDK_PATH}/" CACHE STRING "Path to openssl library")
set(Qt5Keychain_DIR "${SDK_PATH}/lib/cmake/Qt5Keychain" CACHE STRING "Path to Qt5Keychain cmake files")
#set(QJDNS_DIR "${SDK_PATH}/" CACHE STRING "Path to qjdns")
else()
set(QCA_DIR "${SDK_PATH}/qca/" CACHE STRING "Path to QCA")
set(IDN_ROOT "${SDK_PATH}/libidn/" CACHE STRING "Path to IDN library")
set(HUNSPELL_ROOT "${SDK_PATH}/hunspell/" CACHE STRING "Path to hunspell library")
if(ENABLE_PLUGINS)
set(LIBGCRYPT_ROOT "${SDK_PATH}/libgcrypt/" CACHE STRING "Path to libgcrypt library")
set(LIBGPGERROR_ROOT "${SDK_PATH}/libgpg-error/" CACHE STRING "Path to libgpg-error library")
set(LIBOTR_ROOT "${SDK_PATH}/libotr/" CACHE STRING "Path to libotr library")
set(LIBTIDY_ROOT "${SDK_PATH}/libtidy/" CACHE STRING "Path to libtidy library")
set(SIGNAL_PROTOCOL_C_ROOT "${SDK_PATH}/singal-protocol-c" CACHE STRING "Path to libsignal-protocol-c library")
endif()
set(ZLIB_ROOT "${SDK_PATH}/zlib/" CACHE STRING "Path to zlib")
set(OPENSSL_ROOT_DIR "${SDK_PATH}/openssl" CACHE STRING "Path to openssl library")
set(Qt5Keychain_DIR "${SDK_PATH}/qt5keychain/lib/cmake/Qt5Keychain" CACHE STRING "Path to Qt5Keychain cmake files")
#set(QJDNS_DIR "${SDK_PATH}/qjdns/${SDK_SUFFIX}/" CACHE STRING "Path to qjdns")
if(DEV_MODE)
if(NOT GST_SDK)
set(GST_SDK "${SDK_PATH}/gstbundle/" CACHE STRING "Path to gstreamer SDK")
endif()
set(PSIMEDIA_DIR "${SDK_PATH}/psimedia/" CACHE STRING "Path to psimedia plugin")
endif()
endif()
else()
if(NOT USE_MXE)
message(WARNING "Psi SDK not found at ${SDK_PATH}. Please set SDK_PATH variable or add Psi dependencies to PATH system environmet variable")
endif()
endif()
set(PLUGINS_PATH "/plugins" CACHE STRING "Install suffix for plugins")
endif()
# Define LINUX on Linux like as WIN32 on Windows and APPLE on Mac OS X
if(UNIX AND NOT APPLE)
set(LINUX ON)
add_definitions(
-DHAVE_X11
-DHAVE_FREEDESKTOP
-DAPP_PREFIX=${CMAKE_INSTALL_PREFIX}
-DAPP_BIN_NAME=${PROJECT_NAME}
)
endif()
# Qt dependencies make building very slow
# Track only .h files
include_regular_expression("^.*\\.h$")
# Put executable in build root dir
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/psi" )
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-overloaded-virtual")
else()
# Enable all warnings
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(DEFAULT_DEBUG_FLAG "/ENTRY:mainCRTStartup /DEBUG /INCREMENTAL /SAFESEH:NO /MANIFEST:NO")
set(DEFAULT_LINKER_FLAG "/ENTRY:mainCRTStartup /INCREMENTAL:NO /LTCG")
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${DEFAULT_DEBUG_FLAG}" CACHE STRING "" FORCE)
set (CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${DEFAULT_LINKER_FLAG}" CACHE STRING "" FORCE)
set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${DEFAULT_LINKER_FLAG}" CACHE STRING "" FORCE)
set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${DEFAULT_DEBUG_FLAG}" CACHE STRING "" FORCE)
set (CMAKE_MODULE_LINKER_FLAGS_DEBUG "/DEBUG /INCREMENTAL /SAFESEH:NO /MANIFEST:NO" CACHE STRING "" FORCE)
set (CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL "/INCREMENTAL:NO /LTCG" CACHE STRING "" FORCE)
set (CMAKE_MODULE_LINKER_FLAGS_RELEASE "/INCREMENTAL:NO /LTCG" CACHE STRING "" FORCE)
set (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /INCREMENTAL:NO /MANIFEST:NO" CACHE STRING "" FORCE)
set (CMAKE_SHARED_LINKER_FLAGS_DEBUG "${DEFAULT_DEBUG_FLAG}" CACHE STRING "" FORCE)
set (CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${DEFAULT_LINKER_FLAG}" CACHE STRING "" FORCE)
set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${DEFAULT_LINKER_FLAG}" CACHE STRING "" FORCE)
set (CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${DEFAULT_DEBUG_FLAG}" CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /ZI")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /ZI /MTd")
add_definitions(-DNOMINMAX)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
add_definitions(-D_CRT_NON_CONFORMING_SWPRINTFS)
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
add_definitions(-D_UNICODE)
endif()
endif()
if(ISDEBUG)
message(STATUS "CXX debug flags: ${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "C debug flags: ${CMAKE_C_FLAGS_DEBUG}")
else()
message(STATUS "CXX flags: ${CMAKE_CXX_FLAGS}")
message(STATUS "C flags: ${CMAKE_C_FLAGS}")
endif()
if(NOT WIN32 AND ENABLE_PORTABLE)
message(WARNING "Portable version creation possible only for Windows OS")
set(ENABLE_PORTABLE OFF)
elseif(WIN32 AND ENABLE_PORTABLE)
message(STATUS "Portable version - ENABLED")
endif()
if( PRODUCTION )
message(STATUS "Production version - ENABLED")
endif()
if( DEV_MODE OR ENABLE_PORTABLE )
message(STATUS "prepare-bin-libs target - ENABLED")
endif()
# Copy a list of files from one directory to another. Only full paths.
function(copy SOURCE DEST TARGET)
if(EXISTS ${SOURCE})
set(OUT_TARGET_FILE "${CMAKE_BINARY_DIR}/${TARGET}.cmake")
string(REGEX REPLACE "\\\\+" "/" DEST "${DEST}")
string(REGEX REPLACE "\\\\+" "/" SOURCE "${SOURCE}")
if(NOT TARGET ${TARGET})
file(REMOVE "${OUT_TARGET_FILE}")
add_custom_target(${TARGET} COMMAND ${CMAKE_COMMAND} -P "${OUT_TARGET_FILE}")
endif()
if(IS_DIRECTORY ${SOURCE})
# copy directory
file(GLOB_RECURSE FILES "${SOURCE}/*")
get_filename_component(SOURCE_DIR_NAME ${SOURCE} NAME)
foreach(FILE ${FILES})
file(RELATIVE_PATH REL_PATH ${SOURCE} ${FILE})
set(REL_PATH "${SOURCE_DIR_NAME}/${REL_PATH}")
get_filename_component(REL_PATH ${REL_PATH} DIRECTORY)
set(DESTIN "${DEST}/${REL_PATH}")
string(REGEX REPLACE "/+" "/" DESTIN ${DESTIN})
string(REGEX REPLACE "/+" "/" FILE ${FILE})
file(APPEND
"${OUT_TARGET_FILE}"
"file(INSTALL \"${FILE}\" DESTINATION \"${DESTIN}\" USE_SOURCE_PERMISSIONS)\n")
endforeach()
else()
string(REPLACE "//" "/" DEST ${DEST})
if(DEST MATCHES "/$")
set(DIR "${DEST}")
string(REGEX REPLACE "^(.+)/$" "\\1" DIR ${DIR})
else()
# need to copy and rename
get_filename_component(DIR ${DEST} DIRECTORY)
get_filename_component(FILENAME ${DEST} NAME)
get_filename_component(SOURCE_FILENAME ${SOURCE} NAME)
endif()
file(APPEND
"${OUT_TARGET_FILE}"
"file(INSTALL \"${SOURCE}\" DESTINATION \"${DIR}\" USE_SOURCE_PERMISSIONS)\n")
if(DEFINED FILENAME)
file(APPEND
"${OUT_TARGET_FILE}"
"file(RENAME \"${DIR}/${SOURCE_FILENAME}\" \"${DIR}/${FILENAME}\")\n")
endif()
endif()
endif()
endfunction()
if(USE_MXE)
set(USE_CCACHE OFF)
endif()
if(USE_CCACHE)
# Configure CCache if available
find_program(CCACHE_PATH ccache DOC "Path to ccache")
if(CCACHE_PATH)
message(STATUS "Found ccache at ${CCACHE_PATH}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PATH})
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_PATH})
endif()
endif()
if(NOT ONLY_PLUGINS)
if( USE_WEBENGINE )
add_subdirectory( 3rdparty )
endif()
if( ${BUNDLED_IRIS} )
add_subdirectory( iris )
else( ${BUNDLED_IRIS} )
find_package( Iris REQUIRED )
include_directories(${Iris_INCLUDE_DIR})
endif( ${BUNDLED_IRIS} )
set( iris_LIB iris )
add_subdirectory(src)
else()
add_subdirectory(src/plugins)
endif()