Merge changes from topic 'find-in-source-view'
[trojita.git] / CMakeLists.txt
blobeb4c93f2cea9f0a1672d89745cfb5a8280c4eed6
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     message(SEND_ERROR "Your compiler doesn't support C++11's alignof")
46 endif()
47 if(NOT CXXFeatures_nullptr_FOUND)
48     message(SEND_ERROR "Your compiler doesn't support C++11's nullptr")
49 endif()
50 if(NOT CXXFeatures_lambda_FOUND)
51     message(SEND_ERROR "Your compiler doesn't support C++11's lambda functions")
52 endif()
53 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")
55 include(TrojitaOption)
57 trojita_option(WITH_DESKTOP "Build desktop version" ON)
58 trojita_option(WITH_DBUS "Build with DBus library" AUTO)
59 trojita_option(WITH_RAGEL "Build with Ragel library" AUTO)
60 trojita_option(WITH_ZLIB "Build with zlib library" AUTO)
61 trojita_option(WITH_SHARED_PLUGINS "Enable shared dynamic plugins" ON)
62 trojita_option(WITH_TESTS "Build tests" ON)
63 trojita_option(WITH_MIMETIC "Build with client-side MIME parsing" AUTO)
64 trojita_option(WITH_GPGMEPP "Build with the GpgME++ library for cryptography" AUTO)
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 trojita_find_package(Mimetic "" "http://www.codesink.org/mimetic_mime_library.html" "C++ MIME Library" "Required for client-side MIME parsing" WITH_MIMETIC)
96 trojita_find_package(KF5Gpgmepp "" "https://quickgit.kde.org/?p=gpgmepp.git" "C++ bindings for gpgme" "Needed for encrypted/signed e-mails" WITH_GPGMEPP)
97 trojita_option(WITH_CRYPTO_MESSAGES "Enable support for encrypted messages" AUTO "WITH_MIMETIC;WITH_GPGMEPP")
99 if(WIN32)
100     trojita_find_package(MakeNSIS "" "http://nsis.sourceforge.net" "Nullsoft Scriptable Install System" "Needed for building Windows installer" WITH_NSIS)
101 endif()
103 # Add support for Mingw RC compiler
104 if(WIN32)
105     enable_language(RC)
106     include(CMakeDetermineRCCompiler)
108     if(MINGW)
109         set(CMAKE_RC_COMPILER_INIT windres)
110         set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -I${CMAKE_CURRENT_BINARY_DIR} -i <SOURCE> -o <OBJECT>")
111     endif()
112 endif()
114 trojita_find_package(Qt5Keychain QUIET "https://github.com/frankosterfeld/qtkeychain" "QtKeychain library (Qt5 version)" "Needed for QtKeychain password plugin" WITH_QTKEYCHAIN_PLUGIN)
115 if(Qt5Keychain_FOUND OR QtKeychain_FOUND)
116     message(STATUS "Found QtKeychain library (includes at ${QTKEYCHAIN_INCLUDE_DIRS}, lib at ${QTKEYCHAIN_LIBRARIES})")
117 else()
118     message(STATUS "Could not find QtKeychain library")
119 endif()
121 if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
122     set(CMAKE_INSTALL_LIBDIR "lib${LIB_SUFFIX}")
123 endif()
124 mark_as_advanced(CMAKE_INSTALL_LIBDIR)
126 if(NOT CMAKE_INSTALL_PLUGIN_DIR)
127     set(CMAKE_INSTALL_PLUGIN_DIR "${CMAKE_INSTALL_LIBDIR}/trojita")
128 endif()
129 mark_as_advanced(CMAKE_INSTALL_PLUGIN_DIR)
131 if(NOT PLUGIN_DIR)
132     if(IS_ABSOLUTE ${CMAKE_INSTALL_PLUGIN_DIR})
133         set(PLUGIN_DIR "${CMAKE_INSTALL_PLUGIN_DIR}")
134     else()
135         set(PLUGIN_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_PLUGIN_DIR}")
136     endif()
137 endif()
138 mark_as_advanced(PLUGIN_DIR)
140 include(GNUInstallDirs)
142 # When manipulating CXXFLAGS, we put the user's CXXFLAGS *after* that so that they take priority.
143 if(MSVC)
144     # See below for some reationale for these optimizations
145     set(CMAKE_CXX_FLAGS "/O2 ${CMAKE_CXX_FLAGS}")
147     # We have no information about the warnings and their usefullness. Reports are welcome.
148     # We might enable warnings on MSVC in future.
149 else()
150     # -Werror is not a default for sanity reasons (one cannot know what warnings a future compiler
151     # might bring along), but it's a default in debug mode. The idea is that developers should care
152     # about a warning-free build, and that this is easier than messing with yet another configure option.
153     set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}")
154     # Also see CMP0043...
156     # Optimizations are enabled unconditionally because they make a big difference in the speed of the
157     # resulting binaries, and that it is better to allow an opt-out from them by adjusting CXXFLAGS through
158     # an env var at cmake time if needed.
159     # The reason for not manipulating just CMAKE_CXX_FLAGS_DEBUG is that unrecognized build types ("DebugFull")
160     # should still benefit from these optimizations. Yup, it would be even better if CMake did a sane thing
161     # and warned when users set an unrecognized and unused build type, but that just isn't the case.
162     set(CMAKE_CXX_FLAGS "-O2 ${CMAKE_CXX_FLAGS}")
164     # Build warnings are useful tools (and Trojita should be warning-free anyway), enable them on all
165     # configurations. They are warnings, not errors.
166     set(CMAKE_CXX_FLAGS "-Wall -Wsign-compare ${CMAKE_CXX_FLAGS}")
167 endif()
169 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
170 # The following is required so that the moc_*.cpp and ui_*.h are found
171 include_directories(${CMAKE_CURRENT_BINARY_DIR})
173 add_definitions(-DQT_STRICT_ITERATORS)
174 add_definitions(-DQT_USE_QSTRINGBUILDER)
175 add_definitions(-DQT_USE_FAST_OPERATOR_PLUS)
176 add_definitions(-DQT_USE_FAST_CONCATENATION)
178 if(NOT MSVC)
179   # We're using C++11's threading features (std::async in particular), and that requires "some threading". With GCC and
180   # Clang, this is implemented through the -pthread build flag. Without using these bits, linking fails on Fedora 23,
181   # and this is apparently a slightly different failure than the Kf5::Gpgmepp-pthread one in commit
182   # 12e41101070f7073caec653185c0504763672ee7.
183   #
184   # Apparently, there's been various methods on how to enable this in the most-cmakeish-way throughout the years, with
185   # cmake-3.1+ supporting some magic linking via the Threads::Threads option on a per-library basis. However, I am not
186   # really looking into that wonderful fun of mixing -pthread and non-pthread translation units, so let's use a big
187   # hammer and set it unconditionally on platforms which use it anyway.
188   #
189   # And because we also support MinGW and its `windres` compiler, we have to avoid passing -pthread to *that* thing, so,
190   # well, let's cheat and put it into the CXXFLAGS.
191   set(CMAKE_CXX_FLAGS "-pthread ${CMAKE_CXX_FLAGS}")
192 endif()
194 # Make sure that plugins not export all symbols, only that which are explicitly marked
195 include(GenerateExportHeader)
196 add_compiler_export_flags()
198 set(CMAKE_AUTOMOC True)
200 trojita_find_package(RagelForTrojita "" "" "" "" WITH_RAGEL)
201 trojita_find_package(ZLIB "" "" "" "" WITH_ZLIB)
203 if(WITH_MIMETIC)
204   set(TROJITA_HAVE_MIMETIC True)
205 else()
206   set(TROJITA_HAVE_MIMETIC False)
207 endif()
209 if(WITH_GPGMEPP)
210   set(TROJITA_HAVE_GPGMEPP True)
211 else()
212   set(TROJITA_HAVE_GPGMEPP False)
213 endif()
215 if(WITH_CRYPTO_MESSAGES)
216   set(TROJITA_HAVE_CRYPTO_MESSAGES True)
217 else()
218   set(TROJITA_HAVE_CRYPTO_MESSAGES False)
219 endif()
221 if(WITH_ZLIB)
222     set(TROJITA_HAVE_ZLIB True)
223     message(STATUS "Support for COMPRESS=DEFLATE enabled")
224 else()
225     set(TROJITA_HAVE_ZLIB False)
226     message(STATUS "Disabling COMPRESS=DEFLATE, zlib is not available")
227 endif()
229 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/configure.cmake.in
230     ${CMAKE_CURRENT_BINARY_DIR}/configure.cmake.h)
231 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/configure-plugins.cmake.in
232     ${CMAKE_CURRENT_BINARY_DIR}/configure-plugins.cmake.h)
234 feature_summary(FATAL_ON_MISSING_REQUIRED_PACKAGES INCLUDE_QUIET_PACKAGES DESCRIPTION "\n" WHAT ALL)
236 set(path_Common ${CMAKE_CURRENT_SOURCE_DIR}/src/Common)
237 set(libCommon_SOURCES
238     ${path_Common}/Application.cpp
239     ${path_Common}/ConnectionId.cpp
240     ${path_Common}/DeleteAfter.cpp
241     ${path_Common}/FileLogger.cpp
242     ${path_Common}/MetaTypes.cpp
243     ${path_Common}/Paths.cpp
244     ${path_Common}/SettingsNames.cpp
247 set(path_Plugins ${CMAKE_CURRENT_SOURCE_DIR}/src/Plugins)
248 set(libPlugins_SOURCES
249     ${path_Plugins}/AddressbookPlugin.cpp
250     ${path_Plugins}/PasswordPlugin.cpp
251     ${path_Plugins}/PluginJob.cpp
252     ${path_Plugins}/PluginManager.cpp
255 set(path_UiUtils ${CMAKE_CURRENT_SOURCE_DIR}/src/UiUtils)
256 set(libUiUtils_SOURCES
257     ${path_UiUtils}/Color.cpp
258     ${path_UiUtils}/Formatting.cpp
259     ${path_UiUtils}/IconLoader.cpp
260     ${path_UiUtils}/PasswordWatcher.cpp
261     ${path_UiUtils}/PlainTextFormatter.cpp
264 set(path_IPC ${CMAKE_CURRENT_SOURCE_DIR}/src/IPC)
266 if(WITH_DBUS)
267     set(libIPC_SOURCES
268         ${path_IPC}/DBusInterface.cpp
269         ${path_IPC}/MainWindowBridge.cpp
270     )
271 else()
272     set(libIPC_SOURCES
273         ${path_IPC}/None.cpp
274     )
275 endif()
277 set(path_Composer ${CMAKE_CURRENT_SOURCE_DIR}/src/Composer)
278 set(libComposer_SOURCES
279     ${path_Composer}/ComposerAttachments.cpp
280     ${path_Composer}/Mailto.cpp
281     ${path_Composer}/MessageComposer.cpp
282     ${path_Composer}/QuoteText.cpp
283     ${path_Composer}/Recipients.cpp
284     ${path_Composer}/ReplaceSignature.cpp
285     ${path_Composer}/SenderIdentitiesModel.cpp
286     ${path_Composer}/SubjectMangling.cpp
287     ${path_Composer}/Submission.cpp
290 set(path_MSA ${CMAKE_CURRENT_SOURCE_DIR}/src/MSA)
291 set(libMSA_SOURCES
292     ${path_MSA}/AbstractMSA.cpp
293     ${path_MSA}/Account.cpp
294     ${path_MSA}/FakeMSA.cpp
295     ${path_MSA}/ImapSubmit.cpp
296     ${path_MSA}/SMTP.cpp
297     ${path_MSA}/Sendmail.cpp
300 set(path_Streams ${CMAKE_CURRENT_SOURCE_DIR}/src/Streams)
301 set(libStreams_SOURCES
302     ${path_Streams}/DeletionWatcher.cpp
303     ${path_Streams}/FakeSocket.cpp
304     ${path_Streams}/IODeviceSocket.cpp
305     ${path_Streams}/Socket.cpp
306     ${path_Streams}/SocketFactory.cpp
309 set(path_Cryptography ${CMAKE_CURRENT_SOURCE_DIR}/src/Cryptography)
310 set(libCryptography_SOURCES
311     ${path_Cryptography}/MessageModel.cpp
312     ${path_Cryptography}/MessagePart.cpp
313     ${path_Cryptography}/PartReplacer.cpp
315 if(WITH_MIMETIC)
316     set(libCryptography_SOURCES
317         ${libCryptography_SOURCES}
318         ${path_Cryptography}/LocalMimeParser.cpp
319         ${path_Cryptography}/MimeticUtils.cpp
320     )
321 endif()
322 if(WITH_CRYPTO_MESSAGES)
323   if(WITH_GPGMEPP)
324     set(libCryptography_SOURCES
325         ${libCryptography_SOURCES}
326         ${path_Cryptography}/GpgMe++.cpp
327     )
328   endif()
329 endif()
331 if(WITH_ZLIB)
332     set(libStreams_SOURCES ${libStreams_SOURCES}
333         ${path_Streams}/3rdparty/rfc1951.cpp)
334 endif()
336 set(path_DesktopGui ${CMAKE_CURRENT_SOURCE_DIR}/src/Gui)
337 set(libDesktopGui_SOURCES
338     ${path_DesktopGui}/AddressRowWidget.cpp
339     ${path_DesktopGui}/AttachmentView.cpp
340     ${path_DesktopGui}/CompleteMessageWidget.cpp
341     ${path_DesktopGui}/ComposeWidget.cpp
342     ${path_DesktopGui}/ComposerAttachmentsList.cpp
343     ${path_DesktopGui}/ComposerTextEdit.cpp
344     ${path_DesktopGui}/EmbeddedWebView.cpp
345     ${path_DesktopGui}/EnvelopeView.cpp
346     ${path_DesktopGui}/ExternalElementsWidget.cpp
347     ${path_DesktopGui}/FindBar.cpp
348     ${path_DesktopGui}/FindBarMixin.cpp
349     ${path_DesktopGui}/FlowLayout.cpp
350     ${path_DesktopGui}/FromAddressProxyModel.cpp
351     ${path_DesktopGui}/LineEdit.cpp
352     ${path_DesktopGui}/LoadablePartWidget.cpp
353     ${path_DesktopGui}/MailBoxTreeView.cpp
354     ${path_DesktopGui}/MessageHeadersWidget.cpp
355     ${path_DesktopGui}/MessageListWidget.cpp
356     ${path_DesktopGui}/MessageSourceWidget.cpp
357     ${path_DesktopGui}/MessageView.cpp
358     ${path_DesktopGui}/MsgListView.cpp
359     ${path_DesktopGui}/OnePanelAtTimeWidget.cpp
360     ${path_DesktopGui}/OneEnvelopeAddress.cpp
361     ${path_DesktopGui}/OverlayWidget.cpp
362     ${path_DesktopGui}/PartWalker.cpp
363     ${path_DesktopGui}/PartWidget.cpp
364     ${path_DesktopGui}/PartWidgetFactoryVisitor.cpp
365     ${path_DesktopGui}/PasswordDialog.cpp
366     ${path_DesktopGui}/ProgressPopUp.cpp
367     ${path_DesktopGui}/ProtocolLoggerWidget.cpp
368     ${path_DesktopGui}/ReplaceCharValidator.cpp
369     ${path_DesktopGui}/SettingsDialog.cpp
370     ${path_DesktopGui}/SimplePartWidget.cpp
371     ${path_DesktopGui}/Spinner.cpp
372     ${path_DesktopGui}/TagListWidget.cpp
373     ${path_DesktopGui}/TagWidget.cpp
374     ${path_DesktopGui}/TaskProgressIndicator.cpp
375     ${path_DesktopGui}/UserAgentWebPage.cpp
376     ${path_DesktopGui}/Util.cpp
377     ${path_DesktopGui}/Window.cpp
378     ${path_DesktopGui}/ShortcutHandler/ShortcutConfigDialog.cpp
379     ${path_DesktopGui}/ShortcutHandler/ShortcutConfigWidget.cpp
380     ${path_DesktopGui}/ShortcutHandler/ShortcutHandler.cpp
382 set(libDesktopGui_UI
383     ${path_DesktopGui}/AboutDialog.ui
384     ${path_DesktopGui}/ComposeWidget.ui
385     ${path_DesktopGui}/CreateMailboxDialog.ui
386     ${path_DesktopGui}/EditIdentity.ui
387     ${path_DesktopGui}/PasswordDialog.ui
388     ${path_DesktopGui}/ProgressPopUp.ui
389     ${path_DesktopGui}/SettingsCachePage.ui
390     ${path_DesktopGui}/SettingsGeneralPage.ui
391     ${path_DesktopGui}/SettingsImapPage.ui
392     ${path_DesktopGui}/SettingsOutgoingPage.ui
393     ${path_DesktopGui}/ShortcutHandler/ShortcutConfigWidget.ui
395 set(libDesktopGui_RESOURCES
396     ${CMAKE_CURRENT_SOURCE_DIR}/src/icons.qrc
397     ${CMAKE_CURRENT_SOURCE_DIR}/src/license.qrc
400 set(libqwwsmtpclient_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/qwwsmtpclient/qwwsmtpclient.cpp)
402 set(libAppVersion_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/AppVersion/SetCoreApplication.cpp)
404 set(path_Imap ${CMAKE_CURRENT_SOURCE_DIR}/src/Imap)
405 set(libImap_SOURCES
406     ${path_Imap}/ConnectionState.cpp
407     ${path_Imap}/Encoders.cpp
408     ${path_Imap}/Exceptions.cpp
409     ${path_Imap}/Parser/3rdparty/kcodecs.cpp
410     ${path_Imap}/Parser/3rdparty/rfccodecs.cpp
412     ${path_Imap}/Parser/Command.cpp
413     ${path_Imap}/Parser/Data.cpp
414     ${path_Imap}/Parser/LowLevelParser.cpp
415     ${path_Imap}/Parser/MailAddress.cpp
416     ${path_Imap}/Parser/Message.cpp
417     ${path_Imap}/Parser/Parser.cpp
418     ${path_Imap}/Parser/Response.cpp
419     ${path_Imap}/Parser/Sequence.cpp
420     ${path_Imap}/Parser/ThreadingNode.cpp
422     ${path_Imap}/Network/FileDownloadManager.cpp
423     ${path_Imap}/Network/ForbiddenReply.cpp
424     ${path_Imap}/Network/MsgPartNetAccessManager.cpp
425     ${path_Imap}/Network/MsgPartNetworkReply.cpp
426     ${path_Imap}/Network/QQuickNetworkReplyWrapper.cpp
428     ${path_Imap}/Model/Cache.cpp
429     ${path_Imap}/Model/CombinedCache.cpp
430     ${path_Imap}/Model/DragAndDrop.cpp
431     ${path_Imap}/Model/DiskPartCache.cpp
432     ${path_Imap}/Model/DummyNetworkWatcher.cpp
433     ${path_Imap}/Model/FindInterestingPart.cpp
434     ${path_Imap}/Model/FlagsOperation.cpp
435     ${path_Imap}/Model/FullMessageCombiner.cpp
436     ${path_Imap}/Model/ImapAccess.cpp
437     ${path_Imap}/Model/MailboxFinder.cpp
438     ${path_Imap}/Model/MailboxMetadata.cpp
439     ${path_Imap}/Model/MailboxModel.cpp
440     ${path_Imap}/Model/MailboxTree.cpp
441     ${path_Imap}/Model/MemoryCache.cpp
442     ${path_Imap}/Model/Model.cpp
443     ${path_Imap}/Model/MsgListModel.cpp
444     ${path_Imap}/Model/NetworkWatcher.cpp
445     ${path_Imap}/Model/OneMessageModel.cpp
446     ${path_Imap}/Model/ParserState.cpp
447     ${path_Imap}/Model/PrettyMailboxModel.cpp
448     ${path_Imap}/Model/PrettyMsgListModel.cpp
449     ${path_Imap}/Model/SpecialFlagNames.cpp
450     ${path_Imap}/Model/SQLCache.cpp
451     ${path_Imap}/Model/SubtreeModel.cpp
452     ${path_Imap}/Model/SystemNetworkWatcher.cpp
453     ${path_Imap}/Model/TaskFactory.cpp
454     ${path_Imap}/Model/TaskPresentationModel.cpp
455     ${path_Imap}/Model/ThreadingMsgListModel.cpp
456     ${path_Imap}/Model/Utils.cpp
457     ${path_Imap}/Model/VisibleTasksModel.cpp
459     # The ModelTest is only needed when debugging manually
460     #${path_Imap}/Model/ModelTest/modeltest.cpp
461     # The ModelWatcher is another debugging aid
462     ${path_Imap}/Model/ModelWatcher.cpp
464     ${path_Imap}/Model/kdeui-itemviews/kdescendantsproxymodel.cpp
466     ${path_Imap}/Tasks/AppendTask.cpp
467     ${path_Imap}/Tasks/CopyMoveMessagesTask.cpp
468     ${path_Imap}/Tasks/CreateMailboxTask.cpp
469     ${path_Imap}/Tasks/DeleteMailboxTask.cpp
470     ${path_Imap}/Tasks/EnableTask.cpp
471     ${path_Imap}/Tasks/ExpungeMailboxTask.cpp
472     ${path_Imap}/Tasks/ExpungeMessagesTask.cpp
473     ${path_Imap}/Tasks/Fake_ListChildMailboxesTask.cpp
474     ${path_Imap}/Tasks/Fake_OpenConnectionTask.cpp
475     ${path_Imap}/Tasks/FetchMsgMetadataTask.cpp
476     ${path_Imap}/Tasks/FetchMsgPartTask.cpp
477     ${path_Imap}/Tasks/GenUrlAuthTask.cpp
478     ${path_Imap}/Tasks/GetAnyConnectionTask.cpp
479     ${path_Imap}/Tasks/IdTask.cpp
480     ${path_Imap}/Tasks/IdleLauncher.cpp
481     ${path_Imap}/Tasks/ImapTask.cpp
482     ${path_Imap}/Tasks/KeepMailboxOpenTask.cpp
483     ${path_Imap}/Tasks/ListChildMailboxesTask.cpp
484     ${path_Imap}/Tasks/NoopTask.cpp
485     ${path_Imap}/Tasks/NumberOfMessagesTask.cpp
486     ${path_Imap}/Tasks/ObtainSynchronizedMailboxTask.cpp
487     ${path_Imap}/Tasks/OfflineConnectionTask.cpp
488     ${path_Imap}/Tasks/OpenConnectionTask.cpp
489     ${path_Imap}/Tasks/SortTask.cpp
490     ${path_Imap}/Tasks/SubscribeUnsubscribeTask.cpp
491     ${path_Imap}/Tasks/ThreadTask.cpp
492     ${path_Imap}/Tasks/UidSubmitTask.cpp
493     ${path_Imap}/Tasks/UnSelectTask.cpp
494     ${path_Imap}/Tasks/UpdateFlagsTask.cpp
495     ${path_Imap}/Tasks/UpdateFlagsOfAllMessagesTask.cpp
498 if(WITH_RAGEL)
499     message(STATUS "Using Ragel for the RFC 5322 parser")
500     ragel_parser(${path_Imap}/Parser/Rfc5322HeaderParser.cpp)
501     set(libImap_SOURCES ${libImap_SOURCES}
502         ${CMAKE_CURRENT_BINARY_DIR}/Rfc5322HeaderParser.generated.cpp)
503 else()
504     message(STATUS "Using pregenerated RFC 5322 parser")
505     set(libImap_SOURCES ${libImap_SOURCES}
506         ${path_Imap}/Parser/Rfc5322HeaderParser.generated.cpp)
507 endif()
509 set(trojita_desktop_SOURCES
510     ${path_DesktopGui}/main.cpp
513 if(WIN32)
514     list(APPEND trojita_desktop_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/trojita_win32.rc)
515     set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/trojita_win32.rc APPEND PROPERTY OBJECT_DEPENDS
516         ${CMAKE_CURRENT_SOURCE_DIR}/src/icons/trojita.ico
517         ${CMAKE_CURRENT_BINARY_DIR}/trojita-git-version.h
518         ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.h
519     )
520 endif()
522 if(Qt5LinguistForTrojita_FOUND)
523     file(GLOB_RECURSE lang_PO "${CMAKE_CURRENT_SOURCE_DIR}/po/trojita_common_*.po")
524     qt5_wrap_po(trojita_QM ${lang_PO})
525     set(language_summary "")
526     foreach(po ${lang_PO})
527         string(REGEX REPLACE "^(.*)/trojita_common_(.*).po" "\\2" lang ${po})
528         list(APPEND language_summary ${lang})
529     endforeach()
530     list(SORT language_summary)
531     list(LENGTH language_summary num_languages)
532     if(num_languages)
533         message(STATUS "Available languages: ${language_summary}")
534         if(WITH_DESKTOP)
535             install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/locale/ DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/trojita/locale" REGEX "(x_test)|(.*\\.ts)" EXCLUDE)
536         endif()
537     else()
538         message(STATUS "No .po files found, will not install any languages")
539     endif()
540 else()
541     message(STATUS "Qt Linguist (lupdate/lrelease/lconvert) not found, disabling localization support")
542 endif()
544 set(version_files ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.h ${CMAKE_CURRENT_BINARY_DIR}/trojita-git-version.h)
545 if(WITH_NSIS)
546     set(version_files ${version_files} ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.nsi)
547     set(NSIS TRUE)
548 endif()
550 add_custom_target(version DEPENDS version_fake_file)
551 add_custom_command(OUTPUT version_fake_file ${version_files}
552     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)
553 set_source_files_properties(${version_files}
554     PROPERTIES GENERATED TRUE
555     HEADER_FILE_ONLY TRUE)
557 add_library(Common STATIC ${libCommon_SOURCES})
558 set_property(TARGET Common APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
559 add_dependencies(Common version)
560 qt5_use_modules(Common Core Network)
562 add_library(AppVersion STATIC ${libAppVersion_SOURCES})
563 set_property(TARGET AppVersion APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
564 add_dependencies(AppVersion version)
565 target_link_libraries(AppVersion Common)
566 qt5_use_modules(AppVersion Core)
568 if(WITH_SHARED_PLUGINS)
569     add_library(Plugins SHARED ${libPlugins_SOURCES})
570     set_property(TARGET Plugins APPEND PROPERTY COMPILE_DEFINITIONS BUILDING_LIBTROJITA_PLUGINS)
571 else()
572     add_library(Plugins STATIC ${libPlugins_SOURCES})
573     set_property(TARGET Plugins APPEND PROPERTY COMPILE_DEFINITIONS QT_STATICPLUGIN)
574 endif()
575 set_target_properties(Plugins PROPERTIES OUTPUT_NAME trojita_plugins)
576 set_property(TARGET Plugins APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
577 qt5_use_modules(Plugins Core)
579 add_library(UiUtils STATIC ${libUiUtils_SOURCES})
580 set_property(TARGET UiUtils APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
581 target_link_libraries(UiUtils Plugins Common)
582 qt5_use_modules(UiUtils Core Gui Network)
584 add_library(Streams STATIC ${libStreams_SOURCES})
585 set_property(TARGET Streams APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
586 if(WITH_ZLIB)
587     set_property(TARGET Streams APPEND PROPERTY INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIR})
588     target_link_libraries(Streams ${ZLIB_LIBRARIES})
589 endif()
590 qt5_use_modules(Streams Network)
592 add_library(IPC STATIC ${libIPC_SOURCES})
593 set_property(TARGET IPC APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
594 if(WITH_DBUS)
595     qt5_use_modules(IPC DBus Widgets)
596 else()
597     qt5_use_modules(IPC Core)
598 endif()
600 add_library(qwwsmtpclient STATIC ${libqwwsmtpclient_SOURCES})
601 qt5_use_modules(qwwsmtpclient Network)
603 add_library(MSA STATIC ${libMSA_SOURCES})
604 set_property(TARGET MSA APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
605 target_link_libraries(MSA Imap Streams qwwsmtpclient)
606 qt5_use_modules(MSA Network)
608 add_library(Composer STATIC ${libComposer_SOURCES})
609 set_property(TARGET Composer APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
610 target_link_libraries(Composer Common MSA Streams UiUtils qwwsmtpclient)
611 qt5_use_modules(Composer Gui Network)
613 add_library(Imap STATIC ${libImap_SOURCES})
614 set_property(TARGET Imap APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
615 target_link_libraries(Imap Common Streams UiUtils)
616 qt5_use_modules(Imap Gui Network Sql)
618 add_library(Cryptography STATIC ${libCryptography_SOURCES})
619 qt5_use_modules(Cryptography Core)
620 set_property(TARGET Cryptography APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
621 target_link_libraries(Cryptography Common Imap)
622 if(WITH_MIMETIC)
623     target_link_libraries(Cryptography ${MIMETIC_LIBRARIES})
624     set_property(TARGET Cryptography APPEND PROPERTY INCLUDE_DIRECTORIES ${MIMETIC_INCLUDE_DIRS})
625 endif()
626 if(WITH_CRYPTO_MESSAGES)
627   if(WITH_GPGMEPP)
628     if (WIN32)
629       target_link_libraries(Cryptography KF5::Gpgmepp KF5::QGpgme)
630     else()
631       target_link_libraries(Cryptography KF5::Gpgmepp-pthread KF5::QGpgme)
632     endif()
633   endif()
634 endif()
636 ## ClearText password plugin
637 if(WITH_CLEARTEXT_PLUGIN)
638     trojita_add_plugin(trojita_plugin_ClearTextPasswordPlugin WITH_CLEARTEXT_PLUGIN src/Plugins/ClearTextPassword/ClearTextPassword.cpp)
639 endif()
641 ## QtKeyChain plugin
642 if(WITH_QTKEYCHAIN_PLUGIN)
643     trojita_add_plugin(trojita_plugin_QtKeychainPasswordPlugin WITH_QTKEYCHAIN_PLUGIN src/Plugins/QtKeyChain/QtKeyChainPassword.cpp)
644     qt5_use_modules(trojita_plugin_QtKeychainPasswordPlugin Core DBus)
645     target_link_libraries(trojita_plugin_QtKeychainPasswordPlugin ${QTKEYCHAIN_LIBRARIES})
646     set_property(TARGET trojita_plugin_QtKeychainPasswordPlugin APPEND PROPERTY INCLUDE_DIRECTORIES ${QTKEYCHAIN_INCLUDE_DIRS})
647 endif()
649 ## AbookAddressbook plugin
650 if(WITH_ABOOKADDRESSBOOK_PLUGIN)
651     set(path_AbookAddressbook ${CMAKE_CURRENT_SOURCE_DIR}/src/Plugins/AbookAddressbook)
652     set(libAbookAddressbook_HEADERS
653         ${path_AbookAddressbook}/AbookAddressbook.h
654         ${path_AbookAddressbook}/be-contacts.h
655     )
656     set(libAbookAddressbook_SOURCES
657         ${path_AbookAddressbook}/AbookAddressbook.cpp
658         ${path_AbookAddressbook}/be-contacts.cpp
659     )
660     set(libAbookAddressbook_UI
661         ${path_AbookAddressbook}/be-contacts.ui
662         ${path_AbookAddressbook}/onecontact.ui
663     )
665     qt5_wrap_ui(libAbookAddressbook_UI_OUT ${libAbookAddressbook_UI})
667     trojita_add_plugin(trojita_plugin_AbookAddressbookPlugin WITH_ABOOKADDRESSBOOK_PLUGIN ${libAbookAddressbook_SOURCES} ${libAbookAddressbook_UI_OUT})
668     set_property(TARGET trojita_plugin_AbookAddressbookPlugin APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
670     qt5_use_modules(trojita_plugin_AbookAddressbookPlugin Widgets)
672     set(be_contacts_SOURCES
673         ${path_AbookAddressbook}/main.cpp
674     )
676     add_executable(be.contacts WIN32 ${be_contacts_SOURCES})
677     set_property(TARGET be.contacts APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
678     target_link_libraries(be.contacts Plugins)
679     if("${WITH_ABOOKADDRESSBOOK_PLUGIN}" STREQUAL "STATIC")
680         set_property(TARGET be.contacts APPEND PROPERTY COMPILE_DEFINITIONS QT_STATICPLUGIN)
681         target_link_libraries(be.contacts trojita_plugin_AbookAddressbookPlugin)
682     endif()
683     qt5_use_modules(be.contacts Widgets)
684 endif()
686 # Generate file static_plugins.h.in
687 get_property(STATIC_PLUGINS GLOBAL PROPERTY TROJITA_STATIC_PLUGINS)
688 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h.in "#include <QtPlugin>\n")
689 foreach(PLUGIN ${STATIC_PLUGINS})
690     file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h.in "Q_IMPORT_PLUGIN(${PLUGIN})\n")
691 endforeach()
692 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h.in ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h)
694 if(WITH_DESKTOP)
695     qt5_wrap_ui(libDesktopGui_UI_OUT ${libDesktopGui_UI})
696     qt5_add_resources(libDesktopGui_RESOURCES_OUT ${libDesktopGui_RESOURCES})
698     add_library(DesktopGui STATIC ${libDesktopGui_SOURCES} ${libDesktopGui_UI_OUT} ${libDesktopGui_RESOURCES_OUT})
699     set_property(TARGET DesktopGui APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
700     # The following is needed for the LineEdit widget within the .ui files.
701     # The ${path_DesktopGui} is needed so that the generated ui_*.h file can find the headers of the custom widgets
702     set_property(TARGET DesktopGui APPEND PROPERTY INCLUDE_DIRECTORIES ${path_DesktopGui})
703     target_link_libraries(DesktopGui Common UiUtils Composer Cryptography Imap IPC MSA Plugins Streams qwwsmtpclient)
705     # On Windows build a real Win32 GUI application without console window
706     # On other platforms WIN32 flag is ignored
707     add_executable(trojita WIN32 ${trojita_desktop_SOURCES} ${trojita_QM})
708     set_property(TARGET trojita APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
709     target_link_libraries(trojita AppVersion Common UiUtils DesktopGui ${STATIC_PLUGINS})
710     qt5_use_modules(DesktopGui Network WebKitWidgets)
711     qt5_use_modules(trojita Widgets Network)
712 endif()
715 if(WITH_SHARED_PLUGINS)
716     install(TARGETS Plugins DESTINATION ${CMAKE_INSTALL_LIBDIR})
717 endif()
719 include(SanitizedDesktopFile)
721 if(WITH_ABOOKADDRESSBOOK_PLUGIN)
722     install(TARGETS be.contacts RUNTIME DESTINATION bin)
723 endif()
725 if(WITH_DESKTOP)
726     copy_desktop_file_without_cruft("${CMAKE_CURRENT_SOURCE_DIR}/src/Gui/trojita.desktop" "${CMAKE_CURRENT_BINARY_DIR}/trojita-DesktopGui.desktop")
727     install(TARGETS trojita RUNTIME DESTINATION bin)
728     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/trojita-DesktopGui.desktop DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications/" RENAME trojita.desktop)
729     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/Gui/trojita.appdata.xml DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/appdata/")
730     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/icons/trojita.png DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/32x32/apps/")
731     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/icons/trojita.svg DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps/")
732 endif()
734 if(WITH_NSIS)
735     include(TrojitaNSIS)
736 endif()
739 if(WITH_TESTS)
740     set(test_LibMailboxSync_SOURCES
741         tests/Utils/ModelEvents.cpp
742         tests/Utils/LibMailboxSync.cpp
743     )
744     add_library(test_LibMailboxSync STATIC ${test_LibMailboxSync_SOURCES})
745     qt5_use_modules(test_LibMailboxSync Test Network)
746     set_property(TARGET test_LibMailboxSync APPEND PROPERTY INCLUDE_DIRECTORIES
747         ${CMAKE_CURRENT_SOURCE_DIR}/tests
748         ${CMAKE_CURRENT_SOURCE_DIR}/tests/Utils)
749     target_link_libraries(test_LibMailboxSync Imap MSA Streams Common Composer)
751     macro(trojita_test dir fname)
752         set(test_${fname}_SOURCES tests/${dir}/test_${fname}.cpp)
753         add_executable(test_${fname} ${test_${fname}_SOURCES})
754         target_link_libraries(test_${fname} Imap MSA Streams Common Composer Cryptography test_LibMailboxSync)
755         qt5_use_modules(test_${fname} Network Sql Test Widgets)
756         set_property(TARGET test_${fname} APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/tests)
757         if(NOT CMAKE_CROSSCOMPILING)
758             add_test(test_${fname} test_${fname})
759         endif()
760     endmacro()
762     enable_testing()
763     trojita_test(Composer Composer_Submission)
764     trojita_test(Composer Composer_responses)
765     trojita_test(Composer Html_formatting)
766     qt5_use_modules(test_Composer_responses WebKitWidgets)
767     qt5_use_modules(test_Html_formatting WebKitWidgets)
768     trojita_test(Imap Imap_DisappearingMailboxes)
769     trojita_test(Imap Imap_Idle)
770     trojita_test(Imap Imap_LowLevelParser)
771     trojita_test(Imap Imap_Message)
772     trojita_test(Imap Imap_Model)
773     trojita_test(Imap Imap_MsgPartNetAccessManager)
774     trojita_test(Imap Imap_Parser_parse)
775     trojita_test(Imap Imap_Responses)
776     trojita_test(Imap Imap_SelectedMailboxUpdates)
777     trojita_test(Imap Imap_Tasks_CreateMailbox)
778     trojita_test(Imap Imap_Tasks_DeleteMailbox)
779     trojita_test(Imap Imap_Tasks_ListChildMailboxes)
780     trojita_test(Imap Imap_Tasks_ObtainSynchronizedMailbox)
781     trojita_test(Imap Imap_Tasks_OpenConnection)
782     trojita_test(Imap Imap_Threading)
783     trojita_test(Imap Imap_BodyParts)
784     trojita_test(Imap Imap_Offline)
785     trojita_test(Imap Imap_CopyAndFlagOperations)
786     trojita_test(Cryptography Cryptography_MessageModel)
788     if(WITH_CRYPTO_MESSAGES)
789       find_program(GPGCONF_BINARY NAMES gpgconf)
790       if(GPGCONF_BINARY_NOTFOUND)
791         message(SEND_ERROR "The `gpgconf` binary from GnuPG not found, this is needed for crypto tests.")
792       endif()
794       if(NOT UNIX)
795         message(SEND_ERROR "The Cryptography unit tests really need Unix. Patches welcome.")
796       endif()
798       add_library(fake-dev-random SHARED ${CMAKE_CURRENT_SOURCE_DIR}/tests/Utils/fake-dev-random.c)
799       target_link_libraries(fake-dev-random dl)
801       # FIXME: it would be nice to depend on the contents of keys/, but in my testing it produces Makefiles
802       # which suffer from races (the keygen.sh is run multiple times in parallel within the CI environment).
803       # I wasn't able to track down the root cause behind this; it affected all cmake versions within the CI
804       # as of Feb 2016, which is 3.1.something up to 3.3.something.
805       add_custom_command(OUTPUT crypto_test_data.h
806         COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/tests/Cryptography/keygen.sh ${CMAKE_CURRENT_SOURCE_DIR}
807         DEPENDS fake-dev-random tests/Cryptography/keygen.sh tests/Cryptography/batch-keygen)
808       add_custom_target(crypto_test_data DEPENDS crypto_test_data.h)
810       trojita_test(Cryptography Cryptography_PGP)
811       add_dependencies(test_Cryptography_PGP crypto_test_data)
812     endif()
814     trojita_test(Misc Rfc5322)
815     trojita_test(Misc RingBuffer)
816     trojita_test(Misc SenderIdentitiesModel)
817     trojita_test(Misc SqlCache)
818     trojita_test(Misc algorithms)
819     trojita_test(Misc rfccodecs)
820     trojita_test(Misc prettySize)
821     trojita_test(Misc Formatting)
823 endif()
825 if(WIN32) # Check if we are on Windows
826     if(MSVC10) # Check if we are using the Visual Studio compiler 2010
827         # Because of linker errors (see http://stackoverflow.com/questions/5625884/conversion-of-stdwstring-to-qstring-throws-linker-error)
828         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:wchar_t-")
829     elseif(MINGW)
830     else()
831         message(WARNING "You are using a compiler which we have not tested yet (not MSVC10 or MINGW).")
832         message(WARNING "Please let us know how well it works.")
833     endif()
834 endif()