Merge "Fix warning from QSqlDatabasePrivate::removeDatabase"
[trojita.git] / CMakeLists.txt
blobc2618849cd63a7a90804ad1c3eb214bf2b57d0fa
1 project(trojita)
2 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
4 # Qt5's qt5_use_modules need 2.8.9+
5 # On win32, we need QtMain linking, which means 2.8.11+
6 # EL7 ships 2.8.11, Debian 8 ships 3.0.2, and Ubuntu 14.04 LTS has 2.8.12
7 cmake_minimum_required(VERSION 2.8.11)
8 cmake_policy(SET CMP0020 NEW)
10 if(POLICY CMP0054)
11     # Silence warnings in TrojitaOption.cmake; we are fine with only doing the
12     # expansion by hand
13     cmake_policy(SET CMP0054 NEW)
14 endif()
16 if(POLICY CMP0043)
17     # We make use of CMAKE_CXXFLAGS_DEBUG...
18     cmake_policy(SET CMP0043 OLD)
19 endif()
21 # Set a default build type if none was specified. This was shamelessly stolen
22 # from VTK's cmake setup because these guys produce both CMake and a project that
23 # manipulates this variable, and the web is full of posts where people say that
24 # it is apparently evil to just set the build type in a way an earlier version of
25 # this patch did. Oh, and the location of this check/update matters, apparently.
27 # Yes, this is just plain crazy.
28 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
29     message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
30     set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
31     # Set the possible values of build type for cmake-gui
32     set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
33 endif()
35 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
37 include(FindCXXFeatures)
38 if(NOT CXXFeatures_auto_FOUND)
39     message(SEND_ERROR "Your compiler doesn't support C++11's auto")
40 endif()
41 if(NOT CXXFeatures_static_assert_FOUND)
42     message(SEND_ERROR "Your compiler doesn't support C++11's static_assert")
43 endif()
44 if(NOT CXXFeatures_alignof_FOUND)
45     if(NOT CMAKE_COMPILER_IS_GNUCXX AND NOT MSVC)
46         message(SEND_ERROR "Your compiler doesn't support C++11's alignof and it also isn't gcc or MSVC. Either would work.")
47     endif()
48 endif()
49 if(NOT CXXFeatures_nullptr_FOUND)
50     message(SEND_ERROR "Your compiler doesn't support C++11's nullptr")
51 endif()
52 if(NOT CXXFeatures_lambda_FOUND)
53     message(SEND_ERROR "Your compiler doesn't support C++11's lambda functions")
54 endif()
55 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")
57 include(TrojitaOption)
59 trojita_option(WITH_DESKTOP "Build desktop version" ON)
60 trojita_option(WITH_DBUS "Build with DBus library" AUTO)
61 trojita_option(WITH_RAGEL "Build with Ragel library" AUTO)
62 trojita_option(WITH_ZLIB "Build with zlib library" AUTO)
63 trojita_option(WITH_SHARED_PLUGINS "Enable shared dynamic plugins" ON)
64 trojita_option(WITH_TESTS "Build tests" ON)
66 if(WIN32)
67     trojita_option(WITH_NSIS "Build Windows NSIS installer" AUTO "WITH_DESKTOP")
68 endif()
70 if(UNIX AND NOT APPLE)
71     set(QTKEYCHAIN_DEPENDS ";WITH_DBUS")
72 else()
73     set(QTKEYCHAIN_DEPENDS "")
74 endif()
76 find_package(Qt5Core 5.2 REQUIRED)
77 find_package(Qt5Gui REQUIRED)
78 find_package(Qt5Network REQUIRED)
79 find_package(Qt5Sql REQUIRED)
80 find_package(Qt5WebKitWidgets REQUIRED)
81 find_package(Qt5Widgets REQUIRED)
82 find_package(Qt5LinguistTools)
83 trojita_find_package(Qt5DBus "" "http://qt-project.org" "Qt5 D-Bus support" "Needed for IPC and for some plugins" WITH_DBUS)
84 trojita_find_package(Qt5Test "" "http://qt-project.org" "Qt5 QTest library" "Needed for automated tests" WITH_TESTS)
85 if(Qt5LinguistTools_FOUND)
86     find_package(Qt5LinguistForTrojita)
87 endif()
89 trojita_plugin_option(WITH_ABOOKADDRESSBOOK_PLUGIN "Build AbookAddressbook plugin" STATIC)
90 trojita_plugin_option(WITH_CLEARTEXT_PLUGIN "Build Cleartext password plugin" STATIC)
91 trojita_plugin_option(WITH_QTKEYCHAIN_PLUGIN "Build Qtkeychain password plugin" "${QTKEYCHAIN_DEPENDS}")
93 trojita_find_package(Git "" "" "" "")
95 if(WIN32)
96     trojita_find_package(MakeNSIS "" "http://nsis.sourceforge.net" "Nullsoft Scriptable Install System" "Needed for building Windows installer" WITH_NSIS)
97 endif()
99 # Add support for Mingw RC compiler
100 if(WIN32)
101     enable_language(RC)
102     include(CMakeDetermineRCCompiler)
104     if(MINGW)
105         set(CMAKE_RC_COMPILER_INIT windres)
106         set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
107     endif()
108 endif()
110 trojita_find_package(Qt5Keychain QUIET "https://github.com/frankosterfeld/qtkeychain" "QtKeychain library (Qt5 version)" "Needed for QtKeychain password plugin" WITH_QTKEYCHAIN_PLUGIN)
111 if(Qt5Keychain_FOUND OR QtKeychain_FOUND)
112     message(STATUS "Found QtKeychain library (includes at ${QTKEYCHAIN_INCLUDE_DIRS}, lib at ${QTKEYCHAIN_LIBRARIES})")
113 else()
114     message(STATUS "Could not find QtKeychain library")
115 endif()
117 if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
118     set(CMAKE_INSTALL_LIBDIR "lib${LIB_SUFFIX}")
119 endif()
120 mark_as_advanced(CMAKE_INSTALL_LIBDIR)
122 if(NOT CMAKE_INSTALL_PLUGIN_DIR)
123     set(CMAKE_INSTALL_PLUGIN_DIR "${CMAKE_INSTALL_LIBDIR}/trojita")
124 endif()
125 mark_as_advanced(CMAKE_INSTALL_PLUGIN_DIR)
127 if(NOT PLUGIN_DIR)
128     if(IS_ABSOLUTE ${CMAKE_INSTALL_PLUGIN_DIR})
129         set(PLUGIN_DIR "${CMAKE_INSTALL_PLUGIN_DIR}")
130     else()
131         set(PLUGIN_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_PLUGIN_DIR}")
132     endif()
133 endif()
134 mark_as_advanced(PLUGIN_DIR)
136 include(GNUInstallDirs)
138 # When manipulating CXXFLAGS, we put the user's CXXFLAGS *after* that so that they take priority.
139 if(MSVC)
140     # See below for some reationale for these optimizations
141     set(CMAKE_CXX_FLAGS "/O2 ${CMAKE_CXX_FLAGS}")
143     # We have no information about the warnings and their usefullness. Reports are welcome.
144     # We might enable warnings on MSVC in future.
145 else()
146     # -Werror is not a default for sanity reasons (one cannot know what warnings a future compiler
147     # might bring along), but it's a default in debug mode. The idea is that developers should care
148     # about a warning-free build, and that this is easier than messing with yet another configure option.
149     set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}")
150     # Also see CMP0043...
152     # Optimizations are enabled unconditionally because they make a big difference in the speed of the
153     # resulting binaries, and that it is better to allow an opt-out from them by adjusting CXXFLAGS through
154     # an env var at cmake time if needed.
155     # The reason for not manipulating just CMAKE_CXX_FLAGS_DEBUG is that unrecognized build types ("DebugFull")
156     # should still benefit from these optimizations. Yup, it would be even better if CMake did a sane thing
157     # and warned when users set an unrecognized and unused build type, but that just isn't the case.
158     set(CMAKE_CXX_FLAGS "-O2 ${CMAKE_CXX_FLAGS}")
160     # Build warnings are useful tools (and Trojita should be warning-free anyway), enable them on all
161     # configurations. They are warnings, not errors.
162     set(CMAKE_CXX_FLAGS "-Wall -Wsign-compare ${CMAKE_CXX_FLAGS}")
163 endif()
165 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
166 # The following is required so that the moc_*.cpp and ui_*.h are found
167 include_directories(${CMAKE_CURRENT_BINARY_DIR})
169 add_definitions(-DQT_STRICT_ITERATORS)
170 add_definitions(-DQT_USE_QSTRINGBUILDER)
171 add_definitions(-DQT_USE_FAST_OPERATOR_PLUS)
172 add_definitions(-DQT_USE_FAST_CONCATENATION)
174 # Make sure that plugins not export all symbols, only that which are explicitly marked
175 include(GenerateExportHeader)
176 add_compiler_export_flags()
178 set(CMAKE_AUTOMOC True)
180 trojita_find_package(RagelForTrojita "" "" "" "" WITH_RAGEL)
181 trojita_find_package(ZLIB "" "" "" "" WITH_ZLIB)
183 if(WITH_ZLIB)
184     set(TROJITA_HAVE_ZLIB True)
185     message(STATUS "Support for COMPRESS=DEFLATE enabled")
186 else()
187     set(TROJITA_HAVE_ZLIB False)
188     message(STATUS "Disabling COMPRESS=DEFLATE, zlib is not available")
189 endif()
191 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/configure.cmake.in
192     ${CMAKE_CURRENT_BINARY_DIR}/configure.cmake.h)
194 feature_summary(FATAL_ON_MISSING_REQUIRED_PACKAGES INCLUDE_QUIET_PACKAGES DESCRIPTION "\n" WHAT ALL)
196 set(path_Common ${CMAKE_CURRENT_SOURCE_DIR}/src/Common)
197 set(libCommon_SOURCES
198     ${path_Common}/Application.cpp
199     ${path_Common}/ConnectionId.cpp
200     ${path_Common}/DeleteAfter.cpp
201     ${path_Common}/FileLogger.cpp
202     ${path_Common}/MetaTypes.cpp
203     ${path_Common}/Paths.cpp
204     ${path_Common}/SettingsNames.cpp
207 set(path_Plugins ${CMAKE_CURRENT_SOURCE_DIR}/src/Plugins)
208 set(libPlugins_SOURCES
209     ${path_Plugins}/AddressbookPlugin.cpp
210     ${path_Plugins}/PasswordPlugin.cpp
211     ${path_Plugins}/PluginJob.cpp
212     ${path_Plugins}/PluginManager.cpp
215 set(path_UiUtils ${CMAKE_CURRENT_SOURCE_DIR}/src/UiUtils)
216 set(libUiUtils_SOURCES
217     ${path_UiUtils}/Color.cpp
218     ${path_UiUtils}/Formatting.cpp
219     ${path_UiUtils}/IconLoader.cpp
220     ${path_UiUtils}/PasswordWatcher.cpp
221     ${path_UiUtils}/PlainTextFormatter.cpp
224 set(path_IPC ${CMAKE_CURRENT_SOURCE_DIR}/src/IPC)
226 if(WITH_DBUS)
227     set(libIPC_SOURCES
228         ${path_IPC}/DBusInterface.cpp
229         ${path_IPC}/MainWindowBridge.cpp
230     )
231 else()
232     set(libIPC_SOURCES
233         ${path_IPC}/None.cpp
234     )
235 endif()
237 set(path_Composer ${CMAKE_CURRENT_SOURCE_DIR}/src/Composer)
238 set(libComposer_SOURCES
239     ${path_Composer}/ComposerAttachments.cpp
240     ${path_Composer}/Mailto.cpp
241     ${path_Composer}/MessageComposer.cpp
242     ${path_Composer}/QuoteText.cpp
243     ${path_Composer}/Recipients.cpp
244     ${path_Composer}/ReplaceSignature.cpp
245     ${path_Composer}/SenderIdentitiesModel.cpp
246     ${path_Composer}/SubjectMangling.cpp
247     ${path_Composer}/Submission.cpp
250 set(path_MSA ${CMAKE_CURRENT_SOURCE_DIR}/src/MSA)
251 set(libMSA_SOURCES
252     ${path_MSA}/AbstractMSA.cpp
253     ${path_MSA}/Account.cpp
254     ${path_MSA}/FakeMSA.cpp
255     ${path_MSA}/ImapSubmit.cpp
256     ${path_MSA}/SMTP.cpp
257     ${path_MSA}/Sendmail.cpp
260 set(path_Streams ${CMAKE_CURRENT_SOURCE_DIR}/src/Streams)
261 set(libStreams_SOURCES
262     ${path_Streams}/DeletionWatcher.cpp
263     ${path_Streams}/FakeSocket.cpp
264     ${path_Streams}/IODeviceSocket.cpp
265     ${path_Streams}/Socket.cpp
266     ${path_Streams}/SocketFactory.cpp
269 if(WITH_ZLIB)
270     set(libStreams_SOURCES ${libStreams_SOURCES}
271         ${path_Streams}/3rdparty/rfc1951.cpp)
272 endif()
274 set(path_DesktopGui ${CMAKE_CURRENT_SOURCE_DIR}/src/Gui)
275 set(libDesktopGui_SOURCES
276     ${path_DesktopGui}/AddressRowWidget.cpp
277     ${path_DesktopGui}/AttachmentView.cpp
278     ${path_DesktopGui}/CompleteMessageWidget.cpp
279     ${path_DesktopGui}/ComposeWidget.cpp
280     ${path_DesktopGui}/ComposerAttachmentsList.cpp
281     ${path_DesktopGui}/ComposerTextEdit.cpp
282     ${path_DesktopGui}/EmbeddedWebView.cpp
283     ${path_DesktopGui}/EnvelopeView.cpp
284     ${path_DesktopGui}/ExternalElementsWidget.cpp
285     ${path_DesktopGui}/FindBar.cpp
286     ${path_DesktopGui}/FlowLayout.cpp
287     ${path_DesktopGui}/FromAddressProxyModel.cpp
288     ${path_DesktopGui}/LineEdit.cpp
289     ${path_DesktopGui}/LoadablePartWidget.cpp
290     ${path_DesktopGui}/MailBoxTreeView.cpp
291     ${path_DesktopGui}/MessageListWidget.cpp
292     ${path_DesktopGui}/MessageSourceWidget.cpp
293     ${path_DesktopGui}/MessageView.cpp
294     ${path_DesktopGui}/MsgListView.cpp
295     ${path_DesktopGui}/OnePanelAtTimeWidget.cpp
296     ${path_DesktopGui}/OneEnvelopeAddress.cpp
297     ${path_DesktopGui}/OverlayWidget.cpp
298     ${path_DesktopGui}/PartWalker.cpp
299     ${path_DesktopGui}/PartWidget.cpp
300     ${path_DesktopGui}/PartWidgetFactoryVisitor.cpp
301     ${path_DesktopGui}/PasswordDialog.cpp
302     ${path_DesktopGui}/ProgressPopUp.cpp
303     ${path_DesktopGui}/ProtocolLoggerWidget.cpp
304     ${path_DesktopGui}/ReplaceCharValidator.cpp
305     ${path_DesktopGui}/SettingsDialog.cpp
306     ${path_DesktopGui}/SimplePartWidget.cpp
307     ${path_DesktopGui}/Spinner.cpp
308     ${path_DesktopGui}/TagListWidget.cpp
309     ${path_DesktopGui}/TagWidget.cpp
310     ${path_DesktopGui}/TaskProgressIndicator.cpp
311     ${path_DesktopGui}/UserAgentWebPage.cpp
312     ${path_DesktopGui}/Util.cpp
313     ${path_DesktopGui}/Window.cpp
314     ${path_DesktopGui}/ShortcutHandler/ShortcutConfigDialog.cpp
315     ${path_DesktopGui}/ShortcutHandler/ShortcutConfigWidget.cpp
316     ${path_DesktopGui}/ShortcutHandler/ShortcutHandler.cpp
318 set(libDesktopGui_UI
319     ${path_DesktopGui}/AboutDialog.ui
320     ${path_DesktopGui}/ComposeWidget.ui
321     ${path_DesktopGui}/CreateMailboxDialog.ui
322     ${path_DesktopGui}/EditIdentity.ui
323     ${path_DesktopGui}/PasswordDialog.ui
324     ${path_DesktopGui}/ProgressPopUp.ui
325     ${path_DesktopGui}/SettingsCachePage.ui
326     ${path_DesktopGui}/SettingsGeneralPage.ui
327     ${path_DesktopGui}/SettingsImapPage.ui
328     ${path_DesktopGui}/SettingsOutgoingPage.ui
329     ${path_DesktopGui}/ShortcutHandler/ShortcutConfigWidget.ui
331 set(libDesktopGui_RESOURCES
332     ${CMAKE_CURRENT_SOURCE_DIR}/src/icons.qrc
333     ${CMAKE_CURRENT_SOURCE_DIR}/src/license.qrc
336 set(libqwwsmtpclient_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/qwwsmtpclient/qwwsmtpclient.cpp)
338 set(libAppVersion_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/AppVersion/SetCoreApplication.cpp)
340 set(path_Imap ${CMAKE_CURRENT_SOURCE_DIR}/src/Imap)
341 set(libImap_SOURCES
342     ${path_Imap}/ConnectionState.cpp
343     ${path_Imap}/Encoders.cpp
344     ${path_Imap}/Exceptions.cpp
345     ${path_Imap}/Parser/3rdparty/kcodecs.cpp
346     ${path_Imap}/Parser/3rdparty/rfccodecs.cpp
348     ${path_Imap}/Parser/Command.cpp
349     ${path_Imap}/Parser/Data.cpp
350     ${path_Imap}/Parser/LowLevelParser.cpp
351     ${path_Imap}/Parser/MailAddress.cpp
352     ${path_Imap}/Parser/Message.cpp
353     ${path_Imap}/Parser/Parser.cpp
354     ${path_Imap}/Parser/Response.cpp
355     ${path_Imap}/Parser/Sequence.cpp
356     ${path_Imap}/Parser/ThreadingNode.cpp
358     ${path_Imap}/Network/FileDownloadManager.cpp
359     ${path_Imap}/Network/ForbiddenReply.cpp
360     ${path_Imap}/Network/MsgPartNetAccessManager.cpp
361     ${path_Imap}/Network/MsgPartNetworkReply.cpp
362     ${path_Imap}/Network/QQuickNetworkReplyWrapper.cpp
364     ${path_Imap}/Model/Cache.cpp
365     ${path_Imap}/Model/CombinedCache.cpp
366     ${path_Imap}/Model/DragAndDrop.cpp
367     ${path_Imap}/Model/DiskPartCache.cpp
368     ${path_Imap}/Model/DummyNetworkWatcher.cpp
369     ${path_Imap}/Model/FindInterestingPart.cpp
370     ${path_Imap}/Model/FlagsOperation.cpp
371     ${path_Imap}/Model/FullMessageCombiner.cpp
372     ${path_Imap}/Model/ImapAccess.cpp
373     ${path_Imap}/Model/MailboxFinder.cpp
374     ${path_Imap}/Model/MailboxMetadata.cpp
375     ${path_Imap}/Model/MailboxModel.cpp
376     ${path_Imap}/Model/MailboxTree.cpp
377     ${path_Imap}/Model/MemoryCache.cpp
378     ${path_Imap}/Model/Model.cpp
379     ${path_Imap}/Model/MsgListModel.cpp
380     ${path_Imap}/Model/NetworkWatcher.cpp
381     ${path_Imap}/Model/OneMessageModel.cpp
382     ${path_Imap}/Model/ParserState.cpp
383     ${path_Imap}/Model/PrettyMailboxModel.cpp
384     ${path_Imap}/Model/PrettyMsgListModel.cpp
385     ${path_Imap}/Model/SpecialFlagNames.cpp
386     ${path_Imap}/Model/SQLCache.cpp
387     ${path_Imap}/Model/SubtreeModel.cpp
388     ${path_Imap}/Model/SystemNetworkWatcher.cpp
389     ${path_Imap}/Model/TaskFactory.cpp
390     ${path_Imap}/Model/TaskPresentationModel.cpp
391     ${path_Imap}/Model/ThreadingMsgListModel.cpp
392     ${path_Imap}/Model/Utils.cpp
393     ${path_Imap}/Model/VisibleTasksModel.cpp
395     # The ModelTest is only needed when debugging manually
396     #${path_Imap}/Model/ModelTest/modeltest.cpp
397     # The ModelWatcher is another debugging aid
398     ${path_Imap}/Model/ModelWatcher.cpp
400     ${path_Imap}/Model/kdeui-itemviews/kdescendantsproxymodel.cpp
402     ${path_Imap}/Tasks/AppendTask.cpp
403     ${path_Imap}/Tasks/CopyMoveMessagesTask.cpp
404     ${path_Imap}/Tasks/CreateMailboxTask.cpp
405     ${path_Imap}/Tasks/DeleteMailboxTask.cpp
406     ${path_Imap}/Tasks/EnableTask.cpp
407     ${path_Imap}/Tasks/ExpungeMailboxTask.cpp
408     ${path_Imap}/Tasks/ExpungeMessagesTask.cpp
409     ${path_Imap}/Tasks/Fake_ListChildMailboxesTask.cpp
410     ${path_Imap}/Tasks/Fake_OpenConnectionTask.cpp
411     ${path_Imap}/Tasks/FetchMsgMetadataTask.cpp
412     ${path_Imap}/Tasks/FetchMsgPartTask.cpp
413     ${path_Imap}/Tasks/GenUrlAuthTask.cpp
414     ${path_Imap}/Tasks/GetAnyConnectionTask.cpp
415     ${path_Imap}/Tasks/IdTask.cpp
416     ${path_Imap}/Tasks/IdleLauncher.cpp
417     ${path_Imap}/Tasks/ImapTask.cpp
418     ${path_Imap}/Tasks/KeepMailboxOpenTask.cpp
419     ${path_Imap}/Tasks/ListChildMailboxesTask.cpp
420     ${path_Imap}/Tasks/NoopTask.cpp
421     ${path_Imap}/Tasks/NumberOfMessagesTask.cpp
422     ${path_Imap}/Tasks/ObtainSynchronizedMailboxTask.cpp
423     ${path_Imap}/Tasks/OfflineConnectionTask.cpp
424     ${path_Imap}/Tasks/OpenConnectionTask.cpp
425     ${path_Imap}/Tasks/SortTask.cpp
426     ${path_Imap}/Tasks/SubscribeUnsubscribeTask.cpp
427     ${path_Imap}/Tasks/ThreadTask.cpp
428     ${path_Imap}/Tasks/UidSubmitTask.cpp
429     ${path_Imap}/Tasks/UnSelectTask.cpp
430     ${path_Imap}/Tasks/UpdateFlagsTask.cpp
431     ${path_Imap}/Tasks/UpdateFlagsOfAllMessagesTask.cpp
434 if(WITH_RAGEL)
435     message(STATUS "Using Ragel for the RFC 5322 parser")
436     ragel_parser(${path_Imap}/Parser/Rfc5322HeaderParser.cpp)
437     set(libImap_SOURCES ${libImap_SOURCES}
438         ${CMAKE_CURRENT_BINARY_DIR}/Rfc5322HeaderParser.generated.cpp)
439 else()
440     message(STATUS "Using pregenerated RFC 5322 parser")
441     set(libImap_SOURCES ${libImap_SOURCES}
442         ${path_Imap}/Parser/Rfc5322HeaderParser.generated.cpp)
443 endif()
445 set(trojita_desktop_SOURCES
446     ${path_DesktopGui}/main.cpp
449 if(WIN32)
450     list(APPEND trojita_desktop_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/trojita_win32.rc)
451     set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/trojita_win32.rc APPEND PROPERTY OBJECT_DEPENDS
452         ${CMAKE_CURRENT_SOURCE_DIR}/src/icons/trojita.ico
453         ${CMAKE_CURRENT_BINARY_DIR}/trojita-git-version.h
454         ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.h
455     )
456 endif()
458 if(LinguistForTrojita_FOUND OR Qt5LinguistForTrojita_FOUND)
459     file(GLOB_RECURSE lang_PO "${CMAKE_CURRENT_SOURCE_DIR}/po/trojita_common_*.po")
460     qt5_wrap_po(trojita_QM ${lang_PO})
461     set(language_summary "")
462     foreach(po ${lang_PO})
463         string(REGEX REPLACE "^(.*)/trojita_common_(.*).po" "\\2" lang ${po})
464         list(APPEND language_summary ${lang})
465     endforeach()
466     list(SORT language_summary)
467     list(LENGTH language_summary num_languages)
468     if(num_languages)
469         message(STATUS "Available languages: ${language_summary}")
470         if(WITH_DESKTOP)
471             install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/locale/ DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/trojita/locale" REGEX "(x_test)|(.*\\.ts)" EXCLUDE)
472         endif()
473     else()
474         message(STATUS "No .po files found, will not install any languages")
475     endif()
476 else()
477     message(STATUS "Qt Linguist (lupdate/lrelease/lconvert) not found, disabling localization support")
478 endif()
480 set(version_files ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.h ${CMAKE_CURRENT_BINARY_DIR}/trojita-git-version.h)
481 if(WITH_NSIS)
482     set(version_files ${version_files} ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.nsi)
483     set(NSIS TRUE)
484 endif()
486 add_custom_target(version DEPENDS version_fake_file)
487 add_custom_command(OUTPUT version_fake_file ${version_files}
488     COMMAND ${CMAKE_COMMAND} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DNSIS=${NSIS} -DHOST_ARCH=${HOST_ARCH} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TrojitaVersion.cmake)
489 set_source_files_properties(${version_files}
490     PROPERTIES GENERATED TRUE
491     HEADER_FILE_ONLY TRUE)
493 add_library(Common STATIC ${libCommon_SOURCES})
494 set_property(TARGET Common APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
495 add_dependencies(Common version)
496 qt5_use_modules(Common Core Network)
498 add_library(AppVersion STATIC ${libAppVersion_SOURCES})
499 set_property(TARGET AppVersion APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
500 add_dependencies(AppVersion version)
501 target_link_libraries(AppVersion Common)
502 qt5_use_modules(AppVersion Core)
504 if(WITH_SHARED_PLUGINS)
505     add_library(Plugins SHARED ${libPlugins_SOURCES})
506 else()
507     add_library(Plugins STATIC ${libPlugins_SOURCES})
508     set_property(TARGET Plugins APPEND PROPERTY COMPILE_DEFINITIONS QT_STATICPLUGIN)
509 endif()
510 set_target_properties(Plugins PROPERTIES OUTPUT_NAME trojita_plugins)
511 set_property(TARGET Plugins APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
512 qt5_use_modules(Plugins Core)
514 add_library(UiUtils STATIC ${libUiUtils_SOURCES})
515 set_property(TARGET UiUtils APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
516 target_link_libraries(UiUtils Plugins Common)
517 qt5_use_modules(UiUtils Core Gui Network)
519 add_library(Streams STATIC ${libStreams_SOURCES})
520 set_property(TARGET Streams APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
521 if(WITH_ZLIB)
522     set_property(TARGET Streams APPEND PROPERTY INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIR})
523     target_link_libraries(Streams ${ZLIB_LIBRARIES})
524 endif()
525 qt5_use_modules(Streams Network)
527 add_library(IPC STATIC ${libIPC_SOURCES})
528 set_property(TARGET IPC APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
529 if(WITH_DBUS)
530     qt5_use_modules(IPC DBus Widgets)
531 else()
532     qt5_use_modules(IPC Core)
533 endif()
535 add_library(qwwsmtpclient STATIC ${libqwwsmtpclient_SOURCES})
536 qt5_use_modules(qwwsmtpclient Network)
538 add_library(MSA STATIC ${libMSA_SOURCES})
539 set_property(TARGET MSA APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
540 target_link_libraries(MSA Imap Streams qwwsmtpclient)
541 qt5_use_modules(MSA Network)
543 add_library(Composer STATIC ${libComposer_SOURCES})
544 set_property(TARGET Composer APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
545 target_link_libraries(Composer Common MSA Streams UiUtils qwwsmtpclient)
546 qt5_use_modules(Composer Gui Network)
548 add_library(Imap STATIC ${libImap_SOURCES})
549 set_property(TARGET Imap APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
550 target_link_libraries(Imap Common Streams UiUtils)
551 qt5_use_modules(Imap Gui Network Sql)
553 ## ClearText password plugin
554 if(WITH_CLEARTEXT_PLUGIN)
555     trojita_add_plugin(trojita_plugin_ClearTextPasswordPlugin WITH_CLEARTEXT_PLUGIN src/Plugins/ClearTextPassword/ClearTextPassword.cpp)
556 endif()
558 ## QtKeyChain plugin
559 if(WITH_QTKEYCHAIN_PLUGIN)
560     trojita_add_plugin(trojita_plugin_QtKeychainPasswordPlugin WITH_QTKEYCHAIN_PLUGIN src/Plugins/QtKeyChain/QtKeyChainPassword.cpp)
561     qt5_use_modules(trojita_plugin_QtKeychainPasswordPlugin Core DBus)
562     target_link_libraries(trojita_plugin_QtKeychainPasswordPlugin ${QTKEYCHAIN_LIBRARIES})
563     set_property(TARGET trojita_plugin_QtKeychainPasswordPlugin APPEND PROPERTY INCLUDE_DIRECTORIES ${QTKEYCHAIN_INCLUDE_DIRS})
564 endif()
566 ## AbookAddressbook plugin
567 if(WITH_ABOOKADDRESSBOOK_PLUGIN)
568     set(path_AbookAddressbook ${CMAKE_CURRENT_SOURCE_DIR}/src/Plugins/AbookAddressbook)
569     set(libAbookAddressbook_HEADERS
570         ${path_AbookAddressbook}/AbookAddressbook.h
571         ${path_AbookAddressbook}/be-contacts.h
572     )
573     set(libAbookAddressbook_SOURCES
574         ${path_AbookAddressbook}/AbookAddressbook.cpp
575         ${path_AbookAddressbook}/be-contacts.cpp
576     )
577     set(libAbookAddressbook_UI
578         ${path_AbookAddressbook}/be-contacts.ui
579         ${path_AbookAddressbook}/onecontact.ui
580     )
582     qt5_wrap_ui(libAbookAddressbook_UI_OUT ${libAbookAddressbook_UI})
584     trojita_add_plugin(trojita_plugin_AbookAddressbookPlugin WITH_ABOOKADDRESSBOOK_PLUGIN ${libAbookAddressbook_SOURCES} ${libAbookAddressbook_UI_OUT})
585     set_property(TARGET trojita_plugin_AbookAddressbookPlugin APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
587     qt5_use_modules(trojita_plugin_AbookAddressbookPlugin Widgets)
589     set(be_contacts_SOURCES
590         ${path_AbookAddressbook}/main.cpp
591     )
593     add_executable(be.contacts WIN32 ${be_contacts_SOURCES})
594     set_property(TARGET be.contacts APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
595     target_link_libraries(be.contacts Plugins)
596     if("${WITH_ABOOKADDRESSBOOK_PLUGIN}" STREQUAL "STATIC")
597         set_property(TARGET be.contacts APPEND PROPERTY COMPILE_DEFINITIONS QT_STATICPLUGIN)
598         target_link_libraries(be.contacts trojita_plugin_AbookAddressbookPlugin)
599     endif()
600     qt5_use_modules(be.contacts Widgets)
601 endif()
603 # Generate file static_plugins.h.in
604 get_property(STATIC_PLUGINS GLOBAL PROPERTY TROJITA_STATIC_PLUGINS)
605 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h.in "#include <QtPlugin>\n")
606 foreach(PLUGIN ${STATIC_PLUGINS})
607     file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h.in "Q_IMPORT_PLUGIN(${PLUGIN})\n")
608 endforeach()
609 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h.in ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h)
611 if(WITH_DESKTOP)
612     qt5_wrap_ui(libDesktopGui_UI_OUT ${libDesktopGui_UI})
613     qt5_add_resources(libDesktopGui_RESOURCES_OUT ${libDesktopGui_RESOURCES})
615     add_library(DesktopGui STATIC ${libDesktopGui_SOURCES} ${libDesktopGui_UI_OUT} ${libDesktopGui_RESOURCES_OUT})
616     set_property(TARGET DesktopGui APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
617     # The following is needed for the LineEdit widget within the .ui files.
618     # The ${path_DesktopGui} is needed so that the generated ui_*.h file can find the headers of the custom widgets
619     set_property(TARGET DesktopGui APPEND PROPERTY INCLUDE_DIRECTORIES ${path_DesktopGui})
620     target_link_libraries(DesktopGui Common UiUtils Composer Imap IPC MSA Plugins Streams qwwsmtpclient)
622     # On Windows build a real Win32 GUI application without console window
623     # On other platforms WIN32 flag is ignored
624     add_executable(trojita WIN32 ${trojita_desktop_SOURCES} ${trojita_QM})
625     set_property(TARGET trojita APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
626     target_link_libraries(trojita AppVersion Common UiUtils DesktopGui ${STATIC_PLUGINS})
627     qt5_use_modules(DesktopGui Network WebKitWidgets)
628     qt5_use_modules(trojita Widgets Network)
629 endif()
632 if(WITH_SHARED_PLUGINS)
633     install(TARGETS Plugins DESTINATION ${CMAKE_INSTALL_LIBDIR})
634 endif()
636 include(SanitizedDesktopFile)
638 if(WITH_ABOOKADDRESSBOOK_PLUGIN)
639     install(TARGETS be.contacts RUNTIME DESTINATION bin)
640 endif()
642 if(WITH_DESKTOP)
643     copy_desktop_file_without_cruft("${CMAKE_CURRENT_SOURCE_DIR}/src/Gui/trojita.desktop" "${CMAKE_CURRENT_BINARY_DIR}/trojita-DesktopGui.desktop")
644     install(TARGETS trojita RUNTIME DESTINATION bin)
645     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/trojita-DesktopGui.desktop DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications/" RENAME trojita.desktop)
646     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/Gui/trojita.appdata.xml DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/appdata/")
647     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/icons/trojita.png DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/32x32/apps/")
648     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/icons/trojita.svg DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps/")
649 endif()
651 if(WITH_NSIS)
652     include(TrojitaNSIS)
653 endif()
656 if(WITH_TESTS)
657     set(test_LibMailboxSync_SOURCES
658         tests/Utils/ModelEvents.cpp
659         tests/Utils/LibMailboxSync.cpp
660     )
661     add_library(test_LibMailboxSync STATIC ${test_LibMailboxSync_SOURCES})
662     qt5_use_modules(test_LibMailboxSync Test Network)
663     set_property(TARGET test_LibMailboxSync APPEND PROPERTY INCLUDE_DIRECTORIES
664         ${CMAKE_CURRENT_SOURCE_DIR}/tests
665         ${CMAKE_CURRENT_SOURCE_DIR}/tests/Utils)
666     target_link_libraries(test_LibMailboxSync Imap MSA Streams Common Composer)
668     macro(trojita_test dir fname)
669         set(test_${fname}_SOURCES tests/${dir}/test_${fname}.cpp)
670         add_executable(test_${fname} ${test_${fname}_SOURCES})
671         target_link_libraries(test_${fname} Imap MSA Streams Common Composer test_LibMailboxSync)
672         qt5_use_modules(test_${fname} Network Sql Test Widgets)
673         set_property(TARGET test_${fname} APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/tests)
674         if(NOT CMAKE_CROSSCOMPILING)
675             add_test(test_${fname} test_${fname})
676         endif()
677     endmacro()
679     enable_testing()
680     trojita_test(Composer Composer_Submission)
681     trojita_test(Composer Composer_responses)
682     trojita_test(Composer Html_formatting)
683     qt5_use_modules(test_Composer_responses WebKitWidgets)
684     qt5_use_modules(test_Html_formatting WebKitWidgets)
685     trojita_test(Imap Imap_DisappearingMailboxes)
686     trojita_test(Imap Imap_Idle)
687     trojita_test(Imap Imap_LowLevelParser)
688     trojita_test(Imap Imap_Message)
689     trojita_test(Imap Imap_Model)
690     trojita_test(Imap Imap_MsgPartNetAccessManager)
691     trojita_test(Imap Imap_Parser_parse)
692     trojita_test(Imap Imap_Responses)
693     trojita_test(Imap Imap_SelectedMailboxUpdates)
694     trojita_test(Imap Imap_Tasks_CreateMailbox)
695     trojita_test(Imap Imap_Tasks_DeleteMailbox)
696     trojita_test(Imap Imap_Tasks_ListChildMailboxes)
697     trojita_test(Imap Imap_Tasks_ObtainSynchronizedMailbox)
698     trojita_test(Imap Imap_Tasks_OpenConnection)
699     trojita_test(Imap Imap_Threading)
700     trojita_test(Imap Imap_BodyParts)
701     trojita_test(Imap Imap_Offline)
702     trojita_test(Imap Imap_CopyAndFlagOperations)
703     trojita_test(Misc Rfc5322)
704     trojita_test(Misc RingBuffer)
705     trojita_test(Misc SenderIdentitiesModel)
706     trojita_test(Misc SqlCache)
707     trojita_test(Misc algorithms)
708     trojita_test(Misc rfccodecs)
710 endif()
712 if(WIN32) # Check if we are on Windows
713     if(MSVC10) # Check if we are using the Visual Studio compiler 2010
714         # Because of linker errors (see http://stackoverflow.com/questions/5625884/conversion-of-stdwstring-to-qstring-throws-linker-error)
715         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:wchar_t-")
716     elseif(MINGW)
717     else()
718         message(WARNING "You are using a compiler which we have not tested yet (not MSVC10 or MINGW).")
719         message(WARNING "Please let us know how well it works.")
720     endif()
721 endif()