CMakeLists.txt 13.6 KB
Newer Older
1
################################################################################
2
# CMakeLists.txt
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# Copyright (C) 2017  Belledonne Communications, Grenoble France
#
################################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
################################################################################
22

Ronan's avatar
Ronan committed
23
cmake_minimum_required(VERSION 3.1)
24
project(linphoneqt VERSION 4.0)
25

26 27
set(EXECUTABLE_NAME linphone)
set(TARGET_NAME linphone-qt)
28
set(CMAKE_CXX_STANDARD 11)
29

30 31
set(ASSETS_DIR assets)

32
option(ENABLE_DBUS "Enable single instance handling via DBus." NO)
33 34
option(ENABLE_UPDATE_CHECK "Enable update check." NO)

35
include(GNUInstallDirs)
36
include(CheckCXXCompilerFlag)
37

38 39 40 41
# Use automatically moc from Qt5.
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

42
if (NOT WIN32)
43 44
  check_cxx_compiler_flag("-Wsuggest-override" SUGGEST_OVERRIDE)
  set(CUSTOM_FLAGS "\
Ronan's avatar
Ronan committed
45
-Wall \
46 47
-Wcast-align \
-Wconversion \
48
-Werror=return-type \
49 50 51
-Wextra \
-Wfloat-equal \
-Winit-self \
52
-Wold-style-cast \
53 54 55 56 57
-Woverloaded-virtual \
-Wpointer-arith \
-Wuninitialized \
-Wunused \
")
58
  if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
59
    set(CUSTOM_FLAGS "${CUSTOM_FLAGS} -Wlogical-op")
60 61
  endif ()
  if (SUGGEST_OVERRIDE)
62
    set(CUSTOM_FLAGS "${CUSTOM_FLAGS} -Wsuggest-override -Werror=suggest-override")
63 64
  endif ()
endif ()
65

66
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CUSTOM_FLAGS}")
67
# See: http://stackoverflow.com/a/1372836
68
if (WIN32)
69
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WINSOCKAPI_")
70
endif ()
71

72 73 74
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -DQT_NO_DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG")

Ronan's avatar
Ronan committed
75 76 77
# ------------------------------------------------------------------------------
# Define packages, libs, sources, headers, resources and languages.
# ------------------------------------------------------------------------------
78

79
set(QT5_PACKAGES Core Gui Quick Widgets QuickControls2 Svg LinguistTools Concurrent Network)
80 81 82
if (ENABLE_DBUS)
  list(APPEND QT5_PACKAGES DBus)
endif ()
83
set(QT5_PACKAGES_OPTIONAL TextToSpeech)
84

85
if (LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
86 87
  include("${EP_linphone_CONFIG_DIR}/LinphoneConfig.cmake")
  include("${EP_linphone_CONFIG_DIR}/wrappers/cpp/LinphoneCxxConfig.cmake")
88
  include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
89
  include("${EP_belcard_CONFIG_DIR}/BelcardConfig.cmake")
90
else ()
91 92 93 94
  find_package(Linphone REQUIRED)
  find_package(LinphoneCxx REQUIRED)
  find_package(BcToolbox REQUIRED)
  find_package(Belcard REQUIRED)
95
endif ()
jehan's avatar
jehan committed
96

97
set(SOURCES
98
  src/app/App.cpp
99
  src/app/cli/Cli.cpp
100 101 102
  src/app/logger/Logger.cpp
  src/app/paths/Paths.cpp
  src/app/providers/AvatarProvider.cpp
103
  src/app/providers/ImageProvider.cpp
104 105
  src/app/providers/ThumbnailProvider.cpp
  src/app/translator/DefaultTranslator.cpp
106
  src/components/assistant/AssistantModel.cpp
107
  src/components/authentication/AuthenticationNotifier.cpp
Ronan's avatar
Ronan committed
108 109
  src/components/call/CallModel.cpp
  src/components/calls/CallsListModel.cpp
110
  src/components/calls/CallsListProxyModel.cpp
111
  src/components/camera/Camera.cpp
112
  src/components/camera/CameraPreview.cpp
113
  src/components/camera/MSFunctions.cpp
114
  src/components/chat/ChatModel.cpp
Ronan's avatar
Ronan committed
115
  src/components/chat/ChatProxyModel.cpp
116
  src/components/codecs/AbstractCodecsModel.cpp
117 118
  src/components/codecs/AudioCodecsModel.cpp
  src/components/codecs/VideoCodecsModel.cpp
119
  src/components/conference/ConferenceAddModel.cpp
120
  src/components/conference/ConferenceHelperModel.cpp
121
  src/components/conference/ConferenceModel.cpp
Ronan's avatar
Ronan committed
122 123
  src/components/contact/ContactModel.cpp
  src/components/contact/VcardModel.cpp
124 125
  src/components/contacts/ContactsListModel.cpp
  src/components/contacts/ContactsListProxyModel.cpp
Ronan's avatar
Ronan committed
126
  src/components/core/CoreHandlers.cpp
Ronan's avatar
Ronan committed
127
  src/components/core/CoreManager.cpp
128
  src/components/notifier/Notifier.cpp
129
  src/components/other/colors/Colors.cpp
130 131 132
  src/components/other/clipboard/Clipboard.cpp
  src/components/other/text-to-speech/TextToSpeech.cpp
  src/components/other/units/Units.cpp
133
  src/components/presence/OwnPresenceModel.cpp
Ghislain MARY's avatar
Ghislain MARY committed
134
  src/components/presence/Presence.cpp
135 136
  src/components/settings/AccountSettingsModel.cpp
  src/components/settings/SettingsModel.cpp
137
  src/components/sip-addresses/SipAddressesModel.cpp
138
  src/components/sip-addresses/SipAddressesProxyModel.cpp
139
  src/components/sip-addresses/SipAddressObserver.cpp
140
  src/components/sound-player/SoundPlayer.cpp
141
  src/components/telephone-numbers/TelephoneNumbersModel.cpp
142
  src/components/timeline/TimelineModel.cpp
143
  src/components/url-handlers/UrlHandlers.cpp
144
  src/main.cpp
145 146
  src/utils/LinphoneUtils.cpp
  src/utils/Utils.cpp
147 148 149
)

set(HEADERS
150
  src/app/App.hpp
151
  src/app/cli/Cli.hpp
152 153 154
  src/app/logger/Logger.hpp
  src/app/paths/Paths.hpp
  src/app/providers/AvatarProvider.hpp
155
  src/app/providers/ImageProvider.hpp
156 157
  src/app/providers/ThumbnailProvider.hpp
  src/app/translator/DefaultTranslator.hpp
158
  src/components/assistant/AssistantModel.hpp
159
  src/components/authentication/AuthenticationNotifier.hpp
Ronan's avatar
Ronan committed
160 161
  src/components/call/CallModel.hpp
  src/components/calls/CallsListModel.hpp
162
  src/components/calls/CallsListProxyModel.hpp
163
  src/components/camera/Camera.hpp
164
  src/components/camera/CameraPreview.hpp
165
  src/components/camera/MSFunctions.hpp
166
  src/components/chat/ChatModel.hpp
Ronan's avatar
Ronan committed
167
  src/components/chat/ChatProxyModel.hpp
168 169 170
  src/components/codecs/AbstractCodecsModel.hpp
  src/components/codecs/AudioCodecsModel.hpp
  src/components/codecs/VideoCodecsModel.hpp
171
  src/components/Components.hpp
172
  src/components/conference/ConferenceAddModel.hpp
173
  src/components/conference/ConferenceHelperModel.hpp
174
  src/components/conference/ConferenceModel.hpp
Ronan's avatar
Ronan committed
175 176
  src/components/contact/ContactModel.hpp
  src/components/contact/VcardModel.hpp
177 178
  src/components/contacts/ContactsListModel.hpp
  src/components/contacts/ContactsListProxyModel.hpp
Ronan's avatar
Ronan committed
179
  src/components/core/CoreHandlers.hpp
Ronan's avatar
Ronan committed
180
  src/components/core/CoreManager.hpp
181
  src/components/notifier/Notifier.hpp
182 183
  src/components/other/colors/Colors.hpp
  src/components/other/clipboard/Clipboard.hpp
184 185
  src/components/other/text-to-speech/TextToSpeech.hpp
  src/components/other/units/Units.hpp
186
  src/components/presence/OwnPresenceModel.hpp
187 188 189
  src/components/presence/Presence.hpp
  src/components/settings/AccountSettingsModel.hpp
  src/components/settings/SettingsModel.hpp
190
  src/components/sip-addresses/SipAddressesModel.hpp
191
  src/components/sip-addresses/SipAddressesProxyModel.hpp
192
  src/components/sip-addresses/SipAddressObserver.hpp
193
  src/components/sound-player/SoundPlayer.hpp
194
  src/components/telephone-numbers/TelephoneNumbersModel.hpp
195
  src/components/timeline/TimelineModel.hpp
196
  src/components/url-handlers/UrlHandlers.hpp
197 198
  src/utils/LinphoneUtils.hpp
  src/utils/Utils.hpp
199 200
)

201 202 203 204
if(ENABLE_DBUS)
  list(APPEND SOURCES src/app/single-application/SingleApplicationDBus.cpp)
  list(APPEND HEADERS src/app/single-application/SingleApplicationDBusPrivate.hpp)
else()
205 206
  list(APPEND SOURCES src/app/single-application/SingleApplication.cpp)
  list(APPEND HEADERS src/app/single-application/SingleApplicationPrivate.hpp)
207 208
endif()

Ronan's avatar
Ronan committed
209
set(QRC_RESOURCES resources.qrc)
210

211
set(LANGUAGES_DIRECTORY "${ASSETS_DIR}/languages")
212
set(I18N_FILENAME i18n.qrc)
213 214
set(LANGUAGES en fr)

Ronan's avatar
Ronan committed
215
# ------------------------------------------------------------------------------
216

217 218
function (PREPEND list prefix)
  set(new_list "")
219

220 221 222
  foreach (elem ${${list}})
    list(APPEND new_list "${prefix}${elem}")
  endforeach ()
223

224 225 226 227
  set(${list} ${new_list} PARENT_SCOPE)
endfunction ()

# Force absolute paths.
228 229 230
PREPEND(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/")
PREPEND(HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/")
PREPEND(QRC_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/")
231

Ronan's avatar
Ronan committed
232
# ------------------------------------------------------------------------------
233
# Compute QML files list.
Ronan's avatar
Ronan committed
234
# ------------------------------------------------------------------------------
235 236 237 238 239 240

set(QML_SOURCES)
file(STRINGS ${QRC_RESOURCES} QRC_RESOURCES_CONTENT)
foreach (line ${QRC_RESOURCES_CONTENT})
  set(result)
  string(REGEX REPLACE
Ronan's avatar
Ronan committed
241
    "^[ \t]*<[ \t]*file[ \t]*>[ \t]*(.+\\.[a-z]+)[ \t]*<[ \t]*/[ \t]*file[ \t]*>[ \t]*$"
242 243
    "\\1"
    result
244 245
    "${line}"
  )
246 247
  string(REGEX MATCH "\\.[a-z]+$" is_ui ${result})
  if (NOT ${is_ui} STREQUAL "")
248
    list(APPEND QML_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/${result}")
249 250 251
  endif ()
endforeach ()

252 253 254 255 256
# ------------------------------------------------------------------------------
# Init git hooks.
# ------------------------------------------------------------------------------

if (NOT WIN32)
Ghislain MARY's avatar
Ghislain MARY committed
257 258
  add_custom_target(
    check_qml DEPENDS ${QML_SOURCES}
259
    COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tools/check_qml_syntax"
Ghislain MARY's avatar
Ghislain MARY committed
260
  )
261
endif ()
262 263

execute_process(COMMAND ${CMAKE_COMMAND} -E copy
264
  "${CMAKE_CURRENT_SOURCE_DIR}/tools/private/pre-commit"
265
  "${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit"
266 267
)

268 269 270 271 272 273 274
# ------------------------------------------------------------------------------
# Create config.h file
# ------------------------------------------------------------------------------

set(MSPLUGINS_DIR "${CMAKE_INSTALL_LIBDIR}/mediastreamer/plugins")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/config.h")

Ronan's avatar
Ronan committed
275
# ------------------------------------------------------------------------------
276
# Build.
Ronan's avatar
Ronan committed
277
# ------------------------------------------------------------------------------
278

279
find_package(Qt5 COMPONENTS ${QT5_PACKAGES} REQUIRED)
280
find_package(Qt5 COMPONENTS ${QT5_PACKAGES_OPTIONAL} QUIET)
281

282
if (CMAKE_INSTALL_RPATH)
283 284 285 286
  get_target_property(LUPDATE_PATH Qt5::lupdate LOCATION)
  get_filename_component(LUPDATE_PATH "${LUPDATE_PATH}" DIRECTORY)
  get_filename_component(QT_PATH "${LUPDATE_PATH}/../lib" ABSOLUTE)
  list(APPEND CMAKE_INSTALL_RPATH "${QT_PATH}")
287
endif ()
288

289 290
# Add languages support.
add_subdirectory(${LANGUAGES_DIRECTORY})
291
list(APPEND QRC_RESOURCES "${CMAKE_CURRENT_BINARY_DIR}/${LANGUAGES_DIRECTORY}/${I18N_FILENAME}")
292 293

# Add qrc. (images, qml, translations...)
294
qt5_add_resources(RESOURCES ${QRC_RESOURCES})
295 296

# Build.
297
# Note: `update_translations` is provided by `languages/CMakeLists.txt`.
298
if (WIN32)
299
  add_executable(${TARGET_NAME} WIN32 ${SOURCES} ${HEADERS} ${RESOURCES} linphone.rc)
300
else ()
301
  add_executable(${TARGET_NAME} ${SOURCES} ${HEADERS} ${RESOURCES} ${QML_SOURCES})
302
endif ()
303 304
  bc_git_version(${TARGET_NAME} ${PROJECT_VERSION})
  add_dependencies(${TARGET_NAME} ${TARGET_NAME}-git-version)
305
  add_dependencies(${TARGET_NAME} update_translations)
306
if (NOT WIN32)
Ghislain MARY's avatar
Ghislain MARY committed
307
  add_dependencies(update_translations check_qml)
308
endif ()
309
set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "${EXECUTABLE_NAME}")
jehan's avatar
jehan committed
310
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE "${LINPHONECXX_INCLUDE_DIRS}" "${LINPHONE_INCLUDE_DIRS}" "${BELCARD_INCLUDE_DIRS}" "${BCTOOLBOX_INCLUDE_DIRS}")
311 312

# To start better integration into IDE.
313
source_group(
314
  "Qml" REGULAR_EXPRESSION ".+\.qml$"
315 316
)
source_group(
317
  "Js" REGULAR_EXPRESSION ".+\.js)$"
318 319
)
source_group(
320
  "Svg" REGULAR_EXPRESSION ".+\.svg$"
321
)
322

323
foreach (package ${QT5_PACKAGES})
324
  target_include_directories(${TARGET_NAME} SYSTEM PRIVATE "${Qt5${package}_INCLUDE_DIRS}")
325 326 327
  # `qt5_create_translation` is provided from `LinguistTools` package.
  # But the `Qt5::LinguistTools` lib does not exist. Remove it.
  if (NOT (${package} STREQUAL LinguistTools))
328
    target_link_libraries(${TARGET_NAME} ${Qt5${package}_LIBRARIES})
329 330 331 332 333 334 335 336 337 338
  endif ()
endforeach ()

foreach (package ${QT5_PACKAGES_OPTIONAL})
  if ("${Qt5${package}_FOUND}")
    message("Optional package ${package} found.")
    target_include_directories(${TARGET_NAME} SYSTEM PRIVATE "${Qt5${package}_INCLUDE_DIRS}")
    target_link_libraries(${TARGET_NAME} ${Qt5${package}_LIBRARIES})

    string(TOUPPER "${package}" INCLUDE_NAME)
339
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${INCLUDE_NAME}_ENABLED")
340 341 342
  else ()
    message("Optional package ${package} not found.")
  endif ()
343
endforeach ()
Ronan's avatar
Ronan committed
344

Ghislain MARY's avatar
Ghislain MARY committed
345
target_link_libraries(${TARGET_NAME} ${BCTOOLBOX_CORE_LIBRARIES} ${BELCARD_LIBRARIES} ${LINPHONE_LIBRARIES} ${LINPHONECXX_LIBRARIES})
346

347
install(TARGETS ${TARGET_NAME}
348 349 350 351 352
  RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
353

354 355 356
install(FILES "linphone.desktop"
  DESTINATION "${CMAKE_INSTALL_DATADIR}/applications"
)
357
install(FILES "${ASSETS_DIR}/images/linphone_logo.svg"
358
  DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps/"
359 360
  RENAME "linphone.svg"
)
361

362 363 364 365
# ------------------------------------------------------------------------------
# Install rc files.
# ------------------------------------------------------------------------------

366
install(FILES "${ASSETS_DIR}/linphonerc-factory"
367 368
  DESTINATION "${CMAKE_INSTALL_DATADIR}/linphone"
)
369 370

set(ASSETS_ASSISTANT_DIR "${ASSETS_DIR}/assistant")
371
set(ASSISTANT_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/linphone/assistant")
372 373

install(FILES "${ASSETS_ASSISTANT_DIR}/use-other-sip-account.rc"
374
  DESTINATION "${ASSISTANT_INSTALL_DATADIR}"
375 376
)
install(FILES "${ASSETS_ASSISTANT_DIR}/create-linphone-sip-account.rc"
377
  DESTINATION "${ASSISTANT_INSTALL_DATADIR}"
378 379
)
install(FILES "${ASSETS_ASSISTANT_DIR}/use-linphone-sip-account.rc"
380
  DESTINATION "${ASSISTANT_INSTALL_DATADIR}"
381
)