Merge changes I3ec8a1e1,I0a2562a4,If7a8f745,I509b785a
[trojita.git] / CMakeLists.txt
bloba7d5f3f6108b0efbc607dffc49efe999b1891507
1 if(WITH_QT5)
2     # The Qt5's qt5_use_modules is only available on 2.8.9 or later -- sweet, isn't it?
3     cmake_minimum_required(VERSION 2.8.9)
4 else()
5     cmake_minimum_required(VERSION 2.8.7)
6 endif()
7 project(trojita)
8 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
10 # POSITION_INDEPENDENT_CODE is only available on cmake 2.8.9 or later
11 # Add needed flags for supported compilers which simulate POSITION_INDEPENDENT_CODE property
12 if(CMAKE_VERSION VERSION_LESS "2.8.9")
13     if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
14         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
15     else()
16         message(FATAL_ERROR "Needs GNU or Clang C++ compiler or CMake 2.8.9 (or later)")
17     endif()
18 else()
19     set(CMAKE_POSITION_INDEPENDENT_CODE ON)
20 endif()
22 include(FindCXXFeatures)
23 if(NOT CXXFeatures_auto_FOUND)
24     message(SEND_ERROR "Your compiler doesn't support C++11's auto")
25 endif()
26 if(NOT CXXFeatures_static_assert_FOUND)
27     message(SEND_ERROR "Your compiler doesn't support C++11's static_assert")
28 endif()
29 if(NOT CXXFeatures_alignof_FOUND)
30     if(NOT CMAKE_COMPILER_IS_GNUCXX AND NOT MSVC)
31         message(SEND_ERROR "Your compiler doesn't support C++11's alignof and it also isn't gcc or MSVC. Either would work.")
32     endif()
33 endif()
34 if(NOT CXXFeatures_nullptr_FOUND)
35     # Yes, this is extremely fragile; it will break on any code which wants to
36     # distinguish between an int and nullptr_t. So far, we don't have anything
37     # like that in Trojita. Let's just pretend that it won't ever happen, and
38     # if it happens, then let's hope that an "ambiguous overload" would come up.
39     add_definitions(-Dnullptr=0)
40     message(WARNING "Your C++ compiler doesn't support C++11's nullptr. Activating a very hackish workaround "
41             "which can break existing code because nullptr is not plain 0.")
42 endif()
43 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")
45 include(TrojitaOption)
47 trojita_option(WITH_DESKTOP "Build desktop version" ON)
48 trojita_option(WITH_HARMATTAN "Build MeeGo Harmattan version" OFF "NOT WITH_DESKTOP")
49 trojita_option(WITH_QT5 "Build with Qt5 library" OFF)
50 trojita_option(WITH_DBUS "Build with DBus library" AUTO)
51 trojita_option(WITH_RAGEL "Build with Ragel library" AUTO)
52 trojita_option(WITH_ZLIB "Build with zlib library" AUTO)
53 trojita_option(WITH_SHARED_PLUGINS "Enable shared dynamic plugins" ON)
54 trojita_option(WITH_TESTS "Build tests" ON "NOT WITH_HARMATTAN")
55 trojita_option(DEV_FATAL_WARNINGS "Turn build warnings into errors (developers only)" OFF)
57 if(WIN32)
58     trojita_option(WITH_NSIS "Build Windows NSIS installer" AUTO)
59 endif()
61 if(UNIX AND NOT APPLE)
62     set(QTKEYCHAIN_DEPENDS ";WITH_DBUS")
63 else()
64     set(QTKEYCHAIN_DEPENDS "")
65 endif()
67 trojita_plugin_option(WITH_CLEARTEXT_PLUGIN "Build Cleartext password plugin" STATIC)
68 trojita_plugin_option(WITH_QTKEYCHAIN_PLUGIN "Build Qtkeychain password plugin" "NOT WITH_HARMATTAN${QTKEYCHAIN_DEPENDS}")
70 if(WITH_QT5)
71     message(STATUS "Building the Qt5 version")
72     find_package(Qt5Core 5.2 REQUIRED)
73     find_package(Qt5Gui REQUIRED)
74     find_package(Qt5Network REQUIRED)
75     find_package(Qt5Sql REQUIRED)
76     find_package(Qt5WebKitWidgets REQUIRED)
77     find_package(Qt5Widgets REQUIRED)
78     find_package(Qt5LinguistTools)
79     if(WITH_DBUS)
80         find_package(Qt5DBus REQUIRED)
81     endif()
82     if(WITH_TESTS)
83         find_package(Qt5Test REQUIRED)
84     endif()
85     if(Qt5LinguistTools_FOUND)
86         find_package(Qt5LinguistForTrojita)
87     endif()
88 else()
89     message(STATUS "Building the Qt4 version")
90     set(QT_USE_QTNETWORK 1)
91     set(QT_USE_QTSQL 1)
92     set(QT_USE_QTWEBKIT 1)
93     if(WITH_DBUS)
94         set(QT_USE_QTDBUS 1)
95     endif()
96     if(WITH_TESTS)
97         set(QT_USE_QTTEST 1)
98     endif()
99     if(WITH_HARMATTAN)
100         set(QT_USE_QTDECLARATIVE 1)
101     endif()
102     trojita_find_package(Qt4 4.6 "http://qt-project.org" "Qt4" "Needed for building" REQUIRED)
103     include(${QT_USE_FILE})
104     trojita_check_qt4_module(QTCORE REQUIRED)
105     trojita_check_qt4_module(QTGUI REQUIRED)
106     trojita_check_qt4_module(QTNETWORK REQUIRED)
107     trojita_check_qt4_module(QTSQL REQUIRED)
108     trojita_check_qt4_module(QTWEBKIT REQUIRED)
109     trojita_check_qt4_module(QTDBUS WITH_DBUS)
110     trojita_check_qt4_module(QTTEST WITH_TESTS)
111     trojita_check_qt4_module(QTDECLARATIVE WITH_HARMATTAN)
112     trojita_find_package(LinguistForTrojita "" "" "" "")
113     if(NOT QT_QCONFIG MATCHES "openssl" OR QT_QCONFIG MATCHES "no-openssl")
114         message(FATAL_ERROR "Your copy of Qt was build without SSL support. Please get openssl and rebuild Qt or a Qt binary with SSL support compiled in")
115     endif()
116 endif()
118 trojita_find_package(Git "" "" "" "")
120 if(WIN32)
121     trojita_find_package(MakeNSIS "" "http://nsis.sourceforge.net" "Nullsoft Scriptable Install System" "Needed for building Windows installer" WITH_NSIS)
122 endif()
124 # Add support for Mingw RC compiler
125 if(WIN32)
126     enable_language(RC)
127     include(CMakeDetermineRCCompiler)
129     if(MINGW)
130         set(CMAKE_RC_COMPILER_INIT windres)
131         set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
132     endif()
133 endif()
135 if (WITH_QT5)
136     trojita_find_package(Qt5Keychain "" "https://github.com/frankosterfeld/qtkeychain" "QtKeychain library (Qt5 version)" "Needed for QtKeychain password plugin" WITH_QTKEYCHAIN_PLUGIN)
137 else()
138     trojita_find_package(QtKeychain "" "https://github.com/frankosterfeld/qtkeychain" "QtKeychain library" "Needed for QtKeychain password plugin" WITH_QTKEYCHAIN_PLUGIN)
139 endif()
140 if(Qt5Keychain_FOUND OR QtKeychain_FOUND)
141     message(STATUS "Found QtKeychain library (includes at ${QTKEYCHAIN_INCLUDE_DIRS}, lib at ${QTKEYCHAIN_LIBRARIES})")
142 endif()
144 if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
145     set(CMAKE_INSTALL_LIBDIR "lib${LIB_SUFFIX}")
146 endif()
147 mark_as_advanced(CMAKE_INSTALL_LIBDIR)
149 if(NOT CMAKE_INSTALL_PLUGIN_DIR)
150     set(CMAKE_INSTALL_PLUGIN_DIR "${CMAKE_INSTALL_LIBDIR}/trojita")
151 endif()
152 mark_as_advanced(CMAKE_INSTALL_PLUGIN_DIR)
154 if(NOT PLUGIN_DIR)
155     if(IS_ABSOLUTE ${CMAKE_INSTALL_PLUGIN_DIR})
156         set(PLUGIN_DIR "${CMAKE_INSTALL_PLUGIN_DIR}")
157     else()
158         set(PLUGIN_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_PLUGIN_DIR}")
159     endif()
160 endif()
161 mark_as_advanced(PLUGIN_DIR)
163 if(NOT WIN32 AND NOT MSVC)
164     # Check if we are NOT on Windows and don't use MSVC since -g is not supported by VC
165     # and Wall makes the build very noisy.
166     # At first, enable optimizations. In my testing, these do *not* make debugging any harder than no optimization and
167     # they (of course) optimize away stuff like QByteArray::operator[] etc.
168     # We put the user's CXXFLAGS *after* that so that they take priority.
169     set(CMAKE_CXX_FLAGS "-O2 -g ${CMAKE_CXX_FLAGS}")
170     # Now enable build warnings; these are useful tools (and Trojita should be warning-free anyway). We do not set
171     # -Werror for sanity reasons, though (one cannot know what warnings a future compiler might bring along).
172     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wsign-compare")
173 endif(NOT WIN32 AND NOT MSVC)
174 if(DEV_FATAL_WARNINGS)
175     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
176 endif()
178 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
179 # The following is required so that the moc_*.cpp and ui_*.h are found
180 include_directories(${CMAKE_CURRENT_BINARY_DIR})
181 add_definitions(-DQT_STRICT_ITERATORS)
183 # Make sure that plugins not export all symbols, only that which are explicitly marked
184 include(GenerateExportHeader)
185 add_compiler_export_flags()
187 if(NOT WITH_QT5 AND CMAKE_VERSION VERSION_LESS 2.8.10)
188     set(SUPPORTS_TARGET_INCLUDES 0)
189     include_directories(
190         ${QT_MKSPECS_DIR}/default
191         ${CMAKE_CURRENT_SOURCE_DIR}/src/Gui/
192         ${CMAKE_CURRENT_SOURCE_DIR}/src/mimetypes-qt4/io/
193         ${CMAKE_CURRENT_SOURCE_DIR}/src/Harmattan/qmlapplicationviewer
194         ${CMAKE_CURRENT_SOURCE_DIR}/tests
195         ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_LibMailboxSync)
196 else()
197     set(SUPPORTS_TARGET_INCLUDES 1)
198 endif()
200 set(CMAKE_AUTOMOC True)
202 trojita_find_package(RagelForTrojita "" "" "" "" WITH_RAGEL)
204 if(WIN32) # Check if we are on Windows
205     # On win32, qt can statically link to zlib and export their symbols.
206     # We check if we can find the string " zlib " in the QT_CONFIG list in
207     # ${QT_MKSPECS_DIR}/qconfig.pri and include on success ${QT_QTCORE_LIBRARY}
208     # and ${QTDIR}/src/3rdparty/zlib as lib and include folder
209     if(QT_QTCORE_FOUND)
210         message(STATUS "We are on Windows with Qt. Checking if zlib is built into Qt")
212         if(EXISTS "${QT_MKSPECS_DIR}/qconfig.pri")
213             file(READ ${QT_MKSPECS_DIR}/qconfig.pri _qconfig_FILE_contents_ZLIB_CHECK)
214             string(REGEX MATCH "QT_CONFIG[^\n]+" QT_CONFIG_ZLIB_CHECK ${_qconfig_FILE_contents_ZLIB_CHECK})
216             set(ENV_QTDIR $ENV{QTDIR})
217             if(NOT DEFINED ENV_QTDIR)
218                 message(STATUS "QTDIR not specified in environment, will not use zlib")
219             elseif(QT_CONFIG_ZLIB_CHECK)
220                 if(QT_CONFIG_ZLIB_CHECK MATCHES " zlib ")
221                     message(STATUS "Found zlib in QT_QCONFIG. zlib seems to be built into Qt")
222                     set(ZLIB_LIBRARY_RELEASE ${QT_QTCORE_LIBRARY_RELEASE})
223                     set(ZLIB_LIBRARY_DEBUG ${QT_QTCORE_LIBRARY_DEBUG})
224                     set(ZLIB_LIBRARY ${QT_QTCORE_LIBRARY})
226                     string(REGEX REPLACE "\\\\" "/" QTDIR ${ENV_QTDIR})
227                     set(ZLIB_INCLUDE_DIR "${QTDIR}/src/3rdparty/zlib")
229                     set(ZLIB_FOUND TRUE)
230                     set(ZLIB_LIBRARIES ${ZLIB_LIBRARY} )
231                     mark_as_advanced(ZLIB_LIBRARY ZLIB_INCLUDE_DIR ZLIB_FOUND)
232                 else(QT_CONFIG_ZLIB_CHECK MATCHES " zlib ")
233                     message(STATUS "Could not determine if Qt was built with zlib support.")
234                 endif(QT_CONFIG_ZLIB_CHECK MATCHES " zlib ")
236             endif()
237         endif(EXISTS "${QT_MKSPECS_DIR}/qconfig.pri")
238     endif(QT_QTCORE_FOUND)
239 endif()
241 if(NOT ZLIB_FOUND)
242     trojita_find_package(ZLIB "" "" "" "" WITH_ZLIB)
243 endif()
245 if(WITH_ZLIB)
246     set(TROJITA_HAVE_ZLIB True)
247     message(STATUS "Support for COMPRESS=DEFLATE enabled")
248 else()
249     set(TROJITA_HAVE_ZLIB False)
250     message(STATUS "Disabling COMPRESS=DEFLATE, zlib is not available")
251 endif()
253 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/configure.cmake.in
254     ${CMAKE_CURRENT_BINARY_DIR}/configure.cmake.h)
256 feature_summary(FATAL_ON_MISSING_REQUIRED_PACKAGES DESCRIPTION "\n" WHAT ALL)
258 set(path_Common ${CMAKE_CURRENT_SOURCE_DIR}/src/Common)
259 set(libCommon_SOURCES
260     ${path_Common}/Application.cpp
261     ${path_Common}/ConnectionId.cpp
262     ${path_Common}/DeleteAfter.cpp
263     ${path_Common}/FileLogger.cpp
264     ${path_Common}/MetaTypes.cpp
265     ${path_Common}/Paths.cpp
266     ${path_Common}/SettingsNames.cpp
269 set(path_Plugins ${CMAKE_CURRENT_SOURCE_DIR}/src/Plugins)
270 set(libPlugins_SOURCES
271     ${path_Plugins}/AddressbookPlugin.cpp
272     ${path_Plugins}/PasswordPlugin.cpp
273     ${path_Plugins}/PluginJob.cpp
274     ${path_Plugins}/PluginManager.cpp
277 set(path_UiUtils ${CMAKE_CURRENT_SOURCE_DIR}/src/UiUtils)
278 set(libUiUtils_SOURCES
279     ${path_UiUtils}/Color.cpp
280     ${path_UiUtils}/Formatting.cpp
281     ${path_UiUtils}/PasswordWatcher.cpp
282     ${path_UiUtils}/PlainTextFormatter.cpp
285 set(path_Composer ${CMAKE_CURRENT_SOURCE_DIR}/src/Composer)
286 set(libComposer_SOURCES
287     ${path_Composer}/ComposerAttachments.cpp
288     ${path_Composer}/Mailto.cpp
289     ${path_Composer}/MessageComposer.cpp
290     ${path_Composer}/QuoteText.cpp
291     ${path_Composer}/Recipients.cpp
292     ${path_Composer}/ReplaceSignature.cpp
293     ${path_Composer}/SenderIdentitiesModel.cpp
294     ${path_Composer}/SubjectMangling.cpp
295     ${path_Composer}/Submission.cpp
298 set(path_MSA ${CMAKE_CURRENT_SOURCE_DIR}/src/MSA)
299 set(libMSA_SOURCES
300     ${path_MSA}/AbstractMSA.cpp
301     ${path_MSA}/Account.cpp
302     ${path_MSA}/FakeMSA.cpp
303     ${path_MSA}/ImapSubmit.cpp
304     ${path_MSA}/SMTP.cpp
305     ${path_MSA}/Sendmail.cpp
308 set(path_Streams ${CMAKE_CURRENT_SOURCE_DIR}/src/Streams)
309 set(libStreams_SOURCES
310     ${path_Streams}/DeletionWatcher.cpp
311     ${path_Streams}/FakeSocket.cpp
312     ${path_Streams}/IODeviceSocket.cpp
313     ${path_Streams}/Socket.cpp
314     ${path_Streams}/SocketFactory.cpp
317 if(WITH_ZLIB)
318     set(libStreams_SOURCES ${libStreams_SOURCES}
319         ${path_Streams}/3rdparty/rfc1951.cpp)
320     include_directories(${ZLIB_INCLUDE_DIR})
321 endif()
323 if(NOT WITH_QT5)
324     set(path_mimetypesqt4 ${CMAKE_CURRENT_SOURCE_DIR}/src/mimetypes-qt4)
325     set(libMimetypesQt4_SOURCES
326         ${path_mimetypesqt4}/io/qstandardpaths.cpp
327         ${path_mimetypesqt4}/mimetypes/qmimedatabase.cpp
328         ${path_mimetypesqt4}/mimetypes/qmimeglobpattern.cpp
329         ${path_mimetypesqt4}/mimetypes/qmimemagicrule.cpp
330         ${path_mimetypesqt4}/mimetypes/qmimemagicrulematcher.cpp
331         ${path_mimetypesqt4}/mimetypes/qmimetype.cpp
332         ${path_mimetypesqt4}/mimetypes/qmimetypeparser.cpp
333         ${path_mimetypesqt4}/mimetypes/qmimeprovider.cpp
334     )
335     if(WIN32)
336         set(libMimetypesQt4_SOURCES ${libMimetypesQt4_SOURCES}
337             ${path_mimetypesqt4}/io/qstandardpaths_win.cpp)
338     elseif(APPLE)
339         set(libMimetypesQt4_SOURCES ${libMimetypesQt4_SOURCES}
340             ${path_mimetypesqt4}/io/qstandardpaths_mac.cpp)
341     elseif (OS2)
342         set(libMimetypesQt4_SOURCES ${libMimetypesQt4_SOURCES}
343             ${path_mimetypesqt4}/io/qstandardpaths_os2.cpp)
344     elseif (UNIX)
345         set(libMimetypesQt4_SOURCES ${libMimetypesQt4_SOURCES}
346             ${path_mimetypesqt4}/io/qstandardpaths_unix.cpp)
347     else()
348         message(FATAL_ERROR "Unsupported platform -- mimetypes-Qt4 support only Unix, MacOSX, Windows and OS/2")
349     endif()
350 endif()
352 set(path_DesktopGui ${CMAKE_CURRENT_SOURCE_DIR}/src/Gui)
353 set(libDesktopGui_SOURCES
354     ${path_DesktopGui}/AttachmentView.cpp
355     ${path_DesktopGui}/AutoCompletion.cpp
356     ${path_DesktopGui}/CompleteMessageWidget.cpp
357     ${path_DesktopGui}/ComposeWidget.cpp
358     ${path_DesktopGui}/ComposerAttachmentsList.cpp
359     ${path_DesktopGui}/ComposerTextEdit.cpp
360     ${path_DesktopGui}/EmbeddedWebView.cpp
361     ${path_DesktopGui}/EnvelopeView.cpp
362     ${path_DesktopGui}/ExternalElementsWidget.cpp
363     ${path_DesktopGui}/FindBar.cpp
364     ${path_DesktopGui}/FlowLayout.cpp
365     ${path_DesktopGui}/FromAddressProxyModel.cpp
366     ${path_DesktopGui}/LineEdit.cpp
367     ${path_DesktopGui}/LoadablePartWidget.cpp
368     ${path_DesktopGui}/MailBoxTreeView.cpp
369     ${path_DesktopGui}/MessageListWidget.cpp
370     ${path_DesktopGui}/MessageSourceWidget.cpp
371     ${path_DesktopGui}/MessageView.cpp
372     ${path_DesktopGui}/MsgListView.cpp
373     ${path_DesktopGui}/OnePanelAtTimeWidget.cpp
374     ${path_DesktopGui}/OverlayWidget.cpp
375     ${path_DesktopGui}/PartWalker.cpp
376     ${path_DesktopGui}/PartWidget.cpp
377     ${path_DesktopGui}/PartWidgetFactoryVisitor.cpp
378     ${path_DesktopGui}/PasswordDialog.cpp
379     ${path_DesktopGui}/ProgressPopUp.cpp
380     ${path_DesktopGui}/ProtocolLoggerWidget.cpp
381     ${path_DesktopGui}/ReplaceCharValidator.cpp
382     ${path_DesktopGui}/SettingsDialog.cpp
383     ${path_DesktopGui}/SimplePartWidget.cpp
384     ${path_DesktopGui}/Spinner.cpp
385     ${path_DesktopGui}/TagListWidget.cpp
386     ${path_DesktopGui}/TagWidget.cpp
387     ${path_DesktopGui}/TaskProgressIndicator.cpp
388     ${path_DesktopGui}/UserAgentWebPage.cpp
389     ${path_DesktopGui}/Util.cpp
390     ${path_DesktopGui}/Window.cpp
391     ${path_DesktopGui}/ShortcutHandler/ShortcutConfigDialog.cpp
392     ${path_DesktopGui}/ShortcutHandler/ShortcutConfigWidget.cpp
393     ${path_DesktopGui}/ShortcutHandler/ShortcutHandler.cpp
395 set(libDesktopGui_UI
396     ${path_DesktopGui}/AboutDialog.ui
397     ${path_DesktopGui}/ComposeWidget.ui
398     ${path_DesktopGui}/CreateMailboxDialog.ui
399     ${path_DesktopGui}/EditIdentity.ui
400     ${path_DesktopGui}/PasswordDialog.ui
401     ${path_DesktopGui}/ProgressPopUp.ui
402     ${path_DesktopGui}/SettingsCachePage.ui
403     ${path_DesktopGui}/SettingsGeneralPage.ui
404     ${path_DesktopGui}/SettingsImapPage.ui
405     ${path_DesktopGui}/SettingsOutgoingPage.ui
406     ${path_DesktopGui}/ShortcutHandler/ShortcutConfigWidget.ui
408 set(libDesktopGui_RESOURCES
409     ${CMAKE_CURRENT_SOURCE_DIR}/src/icons.qrc
410     ${CMAKE_CURRENT_SOURCE_DIR}/src/license.qrc
413 set(libqwwsmtpclient_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/qwwsmtpclient/qwwsmtpclient.cpp)
415 set(libAppVersion_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/AppVersion/SetCoreApplication.cpp)
417 set(path_Imap ${CMAKE_CURRENT_SOURCE_DIR}/src/Imap)
418 set(libImap_SOURCES
419     ${path_Imap}/ConnectionState.cpp
420     ${path_Imap}/Encoders.cpp
421     ${path_Imap}/Exceptions.cpp
422     ${path_Imap}/Parser/3rdparty/kcodecs.cpp
423     ${path_Imap}/Parser/3rdparty/rfccodecs.cpp
425     ${path_Imap}/Parser/Command.cpp
426     ${path_Imap}/Parser/Data.cpp
427     ${path_Imap}/Parser/LowLevelParser.cpp
428     ${path_Imap}/Parser/MailAddress.cpp
429     ${path_Imap}/Parser/Message.cpp
430     ${path_Imap}/Parser/Parser.cpp
431     ${path_Imap}/Parser/Response.cpp
432     ${path_Imap}/Parser/Sequence.cpp
433     ${path_Imap}/Parser/ThreadingNode.cpp
435     ${path_Imap}/Network/FileDownloadManager.cpp
436     ${path_Imap}/Network/ForbiddenReply.cpp
437     ${path_Imap}/Network/MsgPartNetAccessManager.cpp
438     ${path_Imap}/Network/MsgPartNetworkReply.cpp
439     ${path_Imap}/Network/QQuickNetworkReplyWrapper.cpp
441     ${path_Imap}/Model/Cache.cpp
442     ${path_Imap}/Model/CombinedCache.cpp
443     ${path_Imap}/Model/DragAndDrop.cpp
444     ${path_Imap}/Model/DiskPartCache.cpp
445     ${path_Imap}/Model/DummyNetworkWatcher.cpp
446     ${path_Imap}/Model/FindInterestingPart.cpp
447     ${path_Imap}/Model/FlagsOperation.cpp
448     ${path_Imap}/Model/FullMessageCombiner.cpp
449     ${path_Imap}/Model/ImapAccess.cpp
450     ${path_Imap}/Model/MailboxFinder.cpp
451     ${path_Imap}/Model/MailboxMetadata.cpp
452     ${path_Imap}/Model/MailboxModel.cpp
453     ${path_Imap}/Model/MailboxTree.cpp
454     ${path_Imap}/Model/MemoryCache.cpp
455     ${path_Imap}/Model/Model.cpp
456     ${path_Imap}/Model/MsgListModel.cpp
457     ${path_Imap}/Model/NetworkWatcher.cpp
458     ${path_Imap}/Model/OneMessageModel.cpp
459     ${path_Imap}/Model/ParserState.cpp
460     ${path_Imap}/Model/PrettyMailboxModel.cpp
461     ${path_Imap}/Model/PrettyMsgListModel.cpp
462     ${path_Imap}/Model/SpecialFlagNames.cpp
463     ${path_Imap}/Model/SQLCache.cpp
464     ${path_Imap}/Model/SubtreeModel.cpp
465     ${path_Imap}/Model/SystemNetworkWatcher.cpp
466     ${path_Imap}/Model/TaskFactory.cpp
467     ${path_Imap}/Model/TaskPresentationModel.cpp
468     ${path_Imap}/Model/ThreadingMsgListModel.cpp
469     ${path_Imap}/Model/Utils.cpp
470     ${path_Imap}/Model/VisibleTasksModel.cpp
472     # The ModelTest is only needed when debugging manually
473     #${path_Imap}/Model/ModelTest/modeltest.cpp
474     # The ModelWatcher is another debugging aid
475     ${path_Imap}/Model/ModelWatcher.cpp
477     ${path_Imap}/Model/kdeui-itemviews/kdescendantsproxymodel.cpp
479     ${path_Imap}/Tasks/AppendTask.cpp
480     ${path_Imap}/Tasks/CopyMoveMessagesTask.cpp
481     ${path_Imap}/Tasks/CreateMailboxTask.cpp
482     ${path_Imap}/Tasks/DeleteMailboxTask.cpp
483     ${path_Imap}/Tasks/EnableTask.cpp
484     ${path_Imap}/Tasks/ExpungeMailboxTask.cpp
485     ${path_Imap}/Tasks/ExpungeMessagesTask.cpp
486     ${path_Imap}/Tasks/Fake_ListChildMailboxesTask.cpp
487     ${path_Imap}/Tasks/Fake_OpenConnectionTask.cpp
488     ${path_Imap}/Tasks/FetchMsgMetadataTask.cpp
489     ${path_Imap}/Tasks/FetchMsgPartTask.cpp
490     ${path_Imap}/Tasks/GenUrlAuthTask.cpp
491     ${path_Imap}/Tasks/GetAnyConnectionTask.cpp
492     ${path_Imap}/Tasks/IdTask.cpp
493     ${path_Imap}/Tasks/IdleLauncher.cpp
494     ${path_Imap}/Tasks/ImapTask.cpp
495     ${path_Imap}/Tasks/KeepMailboxOpenTask.cpp
496     ${path_Imap}/Tasks/ListChildMailboxesTask.cpp
497     ${path_Imap}/Tasks/NoopTask.cpp
498     ${path_Imap}/Tasks/NumberOfMessagesTask.cpp
499     ${path_Imap}/Tasks/ObtainSynchronizedMailboxTask.cpp
500     ${path_Imap}/Tasks/OfflineConnectionTask.cpp
501     ${path_Imap}/Tasks/OpenConnectionTask.cpp
502     ${path_Imap}/Tasks/SortTask.cpp
503     ${path_Imap}/Tasks/SubscribeUnsubscribeTask.cpp
504     ${path_Imap}/Tasks/ThreadTask.cpp
505     ${path_Imap}/Tasks/UidSubmitTask.cpp
506     ${path_Imap}/Tasks/UnSelectTask.cpp
507     ${path_Imap}/Tasks/UpdateFlagsTask.cpp
508     ${path_Imap}/Tasks/UpdateFlagsOfAllMessagesTask.cpp
511 if(WITH_RAGEL)
512     message(STATUS "Using Ragel for the RFC 5322 parser")
513     ragel_parser(${path_Imap}/Parser/Rfc5322HeaderParser.cpp)
514     set(libImap_SOURCES ${libImap_SOURCES}
515         ${CMAKE_CURRENT_BINARY_DIR}/Rfc5322HeaderParser.generated.cpp)
516 else()
517     message(STATUS "Using pregenerated RFC 5322 parser")
518     set(libImap_SOURCES ${libImap_SOURCES}
519         ${path_Imap}/Parser/Rfc5322HeaderParser.generated.cpp)
520 endif()
522 set(path_AbookAddressbook ${CMAKE_CURRENT_SOURCE_DIR}/src/AbookAddressbook)
523 set(libAbookAddressbook_SOURCES
524     ${path_AbookAddressbook}/AbookAddressbook.cpp
525     ${path_AbookAddressbook}/be-contacts.cpp
527 set(libAbookAddressbook_UI
528     ${path_AbookAddressbook}/be-contacts.ui
529     ${path_AbookAddressbook}/onecontact.ui
532 set(trojita_desktop_SOURCES
533     ${path_DesktopGui}/main.cpp
536 if(WIN32)
537     list(APPEND trojita_desktop_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/trojita_win32.rc)
538 endif()
540 set(be_contacts_SOURCES
541     ${CMAKE_CURRENT_SOURCE_DIR}/src/be.contacts/main.cpp
544 set(libQNAMWebView_SOURCES
545     ${CMAKE_CURRENT_SOURCE_DIR}/src/QmlSupport/QNAMWebView/plugin.cpp
546     ${CMAKE_CURRENT_SOURCE_DIR}/src/QmlSupport/QNAMWebView/qdeclarativewebview.cpp
549 set(trojitaHarmattan_SOURCES
550     ${CMAKE_CURRENT_SOURCE_DIR}/src/Harmattan/main.cpp
551     ${CMAKE_CURRENT_SOURCE_DIR}/src/Harmattan/qmlapplicationviewer/qmlapplicationviewer.cpp
554 if(LinguistForTrojita_FOUND OR Qt5LinguistForTrojita_FOUND)
555     file(GLOB_RECURSE lang_PO "${CMAKE_CURRENT_SOURCE_DIR}/po/trojita_common_*.po")
556     if(WITH_QT5)
557         qt5_wrap_po(trojita_QM ${lang_PO})
558     else()
559         qt4_wrap_po(trojita_QM ${lang_PO})
560     endif()
561     set(language_summary "")
562     foreach(po ${lang_PO})
563         string(REGEX REPLACE "^(.*)/trojita_common_(.*).po" "\\2" lang ${po})
564         list(APPEND language_summary ${lang})
565     endforeach()
566     list(SORT language_summary)
567     list(LENGTH language_summary num_languages)
568     if(num_languages)
569         message(STATUS "Available languages: ${language_summary}")
570         if(WITH_DESKTOP)
571             install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/locale/ DESTINATION share/trojita/locale REGEX "(x_test)|(.*\\.ts)" EXCLUDE)
572         endif()
573     else()
574         message(STATUS "No .po files found, will not install any languages")
575     endif()
576 else()
577     message(STATUS "Qt Linguist (lupdate/lrelease/lconvert) not found, disabling localization support")
578 endif()
580 set(version_files ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.h ${CMAKE_CURRENT_BINARY_DIR}/trojita-git-version.h)
581 if(WITH_NSIS)
582     set(version_files ${version_files} ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.nsi)
583     set(NSIS TRUE)
584 endif()
586 add_custom_target(version DEPENDS version_fake_file)
587 add_custom_command(OUTPUT version_fake_file ${version_files}
588     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)
589 set_source_files_properties(${version_files}
590     PROPERTIES GENERATED TRUE
591     HEADER_FILE_ONLY TRUE)
593 add_library(Common STATIC ${libCommon_SOURCES})
594 set_property(TARGET Common APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
595 add_dependencies(Common version)
596 target_link_libraries(Common ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
598 add_library(AppVersion STATIC ${libAppVersion_SOURCES})
599 set_property(TARGET AppVersion APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
600 add_dependencies(AppVersion version)
601 target_link_libraries(AppVersion Common ${QT_QTCORE_LIBRARY})
603 if(WITH_SHARED_PLUGINS)
604     add_library(Plugins SHARED ${libPlugins_SOURCES})
605 else()
606     add_library(Plugins STATIC ${libPlugins_SOURCES})
607     set_property(TARGET Plugins APPEND PROPERTY COMPILE_DEFINITIONS QT_STATICPLUGIN)
608 endif()
609 set_target_properties(Plugins PROPERTIES OUTPUT_NAME trojita_plugins)
610 set_property(TARGET Plugins APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
611 if(WITH_QT5)
612     qt5_use_modules(Plugins Core)
613 else()
614     target_link_libraries(Plugins ${QT_QTCORE_LIBRARY})
615 endif()
617 add_library(UiUtils STATIC ${libUiUtils_SOURCES})
618 set_property(TARGET UiUtils APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
619 target_link_libraries(UiUtils Plugins Common ${QT_QTCORE_LIBRARY})
621 add_library(Streams STATIC ${libStreams_SOURCES})
622 set_property(TARGET Streams APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
623 target_link_libraries(Streams ${QT_QTNETWORK_LIBRARY} ${QT_QTCORE_LIBRARY})
624 if(WITH_ZLIB)
625     target_link_libraries(Streams ${ZLIB_LIBRARIES})
626 endif()
628 add_library(qwwsmtpclient STATIC ${libqwwsmtpclient_SOURCES})
629 target_link_libraries(qwwsmtpclient ${QT_QTNETWORK_LIBRARY} ${QT_QTCORE_LIBRARY})
631 add_library(MSA STATIC ${libMSA_SOURCES})
632 set_property(TARGET MSA APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
633 target_link_libraries(MSA Imap Streams qwwsmtpclient ${QT_QTCORE_LIBRARY})
635 add_library(Composer STATIC ${libComposer_SOURCES})
636 set_property(TARGET Composer APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
637 target_link_libraries(Composer Common MSA Streams UiUtils qwwsmtpclient ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
638 if(NOT WITH_QT5)
639     target_link_libraries(Composer MimetypesQt4)
640 endif()
642 add_library(Imap STATIC ${libImap_SOURCES})
643 set_property(TARGET Imap APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
644 target_link_libraries(Imap Common Streams UiUtils ${QT_QTNETWORK_LIBRARY} ${QT_QTSQL_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
645 if(WITH_ZLIB)
646     target_link_libraries(Imap ${ZLIB_LIBRARIES})
647 endif()
649 if(NOT WITH_QT5)
650     add_library(MimetypesQt4 STATIC ${libMimetypesQt4_SOURCES})
651     if(SUPPORTS_TARGET_INCLUDES)
652         set_property(TARGET MimetypesQt4 APPEND PROPERTY INCLUDE_DIRECTORIES
653             ${QT_MKSPECS_DIR}/default ${path_mimetypesqt4}/io/)
654     endif()
655     target_link_libraries(MimetypesQt4 ${QT_QTCORE_LIBRARY})
656     if(APPLE)
657         find_library(CARBON_LIBRARY Carbon REQUIRED)
658         target_link_libraries(MimetypesQt4 ${CARBON_LIBRARY})
659     endif()
660 endif()
662 ## ClearText password plugin
663 if(WITH_CLEARTEXT_PLUGIN)
664     trojita_add_plugin(trojita_plugin_ClearTextPasswordPlugin WITH_CLEARTEXT_PLUGIN src/Plugins/ClearTextPassword/ClearTextPassword.cpp)
665 endif()
667 ## QtKeyChain plugin
668 if(WITH_QTKEYCHAIN_PLUGIN)
669     trojita_add_plugin(trojita_plugin_QtKeychainPasswordPlugin WITH_QTKEYCHAIN_PLUGIN src/Plugins/QtKeyChain/QtKeyChainPassword.cpp)
670     if(WITH_QT5)
671         qt5_use_modules(trojita_plugin_QtKeychainPasswordPlugin Core DBus)
672     else()
673         target_link_libraries(trojita_plugin_QtKeychainPasswordPlugin ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY})
674     endif()
675     target_link_libraries(trojita_plugin_QtKeychainPasswordPlugin ${QTKEYCHAIN_LIBRARIES})
676     if(SUPPORTS_TARGET_INCLUDES)
677         set_property(TARGET trojita_plugin_QtKeychainPasswordPlugin APPEND PROPERTY INCLUDE_DIRECTORIES ${QTKEYCHAIN_INCLUDE_DIRS})
678     else()
679         include_directories(${QTKEYCHAIN_INCLUDE_DIRS})
680     endif()
681 endif()
683 # Generate file static_plugins.h.in
684 get_property(STATIC_PLUGINS GLOBAL PROPERTY TROJITA_STATIC_PLUGINS)
685 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h.in "#include <QtPlugin>\n")
686 foreach(PLUGIN ${STATIC_PLUGINS})
687     file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h.in "Q_IMPORT_PLUGIN(${PLUGIN})\n")
688 endforeach()
689 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h.in ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h)
691 if(WITH_DESKTOP)
692     if(WITH_QT5)
693         qt5_wrap_ui(libAbookAddressbook_UI_OUT ${libAbookAddressbook_UI})
694         qt5_wrap_ui(libDesktopGui_UI_OUT ${libDesktopGui_UI})
695         qt5_add_resources(libDesktopGui_RESOURCES_OUT ${libDesktopGui_RESOURCES})
696     else()
697         qt4_wrap_ui(libAbookAddressbook_UI_OUT ${libAbookAddressbook_UI})
698         qt4_wrap_ui(libDesktopGui_UI_OUT ${libDesktopGui_UI})
699         qt4_add_resources(libDesktopGui_RESOURCES_OUT ${libDesktopGui_RESOURCES})
700     endif()
702     add_library(AbookAddressbook STATIC ${libAbookAddressbook_SOURCES} ${libAbookAddressbook_UI_OUT})
703     set_property(TARGET AbookAddressbook APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
704     target_link_libraries(AbookAddressbook ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
706     add_library(DesktopGui STATIC ${libDesktopGui_SOURCES} ${libDesktopGui_UI_OUT} ${libDesktopGui_RESOURCES_OUT})
707     set_property(TARGET DesktopGui APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
708     # The following is needed for the LineEdit widget within the .ui files.
709     # The ${path_DesktopGui} is needed so that the generated ui_*.h file can find the headers of the custom widgets
710     if(SUPPORTS_TARGET_INCLUDES)
711         set_property(TARGET DesktopGui APPEND PROPERTY INCLUDE_DIRECTORIES ${path_DesktopGui})
712     endif()
713     target_link_libraries(DesktopGui Common UiUtils Composer Imap MSA Plugins Streams qwwsmtpclient AbookAddressbook ${QT_QTWEBKIT_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
715     # On Windows build a real Win32 GUI application without console window
716     # On other platforms WIN32 flag is ignored
717     add_executable(trojita WIN32 ${trojita_desktop_SOURCES} ${trojita_QM})
718     set_property(TARGET trojita APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
719     target_link_libraries(trojita AppVersion Common UiUtils DesktopGui ${STATIC_PLUGINS} ${QT_QTMAIN_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
720     if(NOT WITH_QT5)
721         target_link_libraries(trojita MimetypesQt4)
722     endif()
723     if(WITH_ZLIB)
724         target_link_libraries(trojita ${ZLIB_LIBRARIES})
725     endif()
727     add_executable(be.contacts ${be_contacts_SOURCES})
728     set_property(TARGET be.contacts APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
729     target_link_libraries(be.contacts AbookAddressbook ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
730 elseif(WITH_HARMATTAN)
731     add_library(trojitaqnamwebviewplugin SHARED ${libQNAMWebView_SOURCES})
732     add_executable(trojita-tp ${trojitaHarmattan_SOURCES})
733     set_property(TARGET trojita-tp APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII)
734     if(SUPPORTS_TARGET_INCLUDES)
735         set_property(TARGET trojita-tp APPEND PROPERTY INCLUDE_DIRECTORIES
736             ${QT_MKSPECS_DIR}/default ${CMAKE_CURRENT_SOURCE_DIR}/src/Harmattan/qmlapplicationviewer)
737     endif()
738     target_link_libraries(trojita-tp AppVersion Imap MSA Streams qwwsmtpclient Common Composer MimetypesQt4
739         ${QT_QTSQL_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${QT_QTWEBKIT_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY})
740 endif()
742 if(WITH_QT5)
743     qt5_use_modules(AppVersion Core)
744     qt5_use_modules(Common Core Network)
745     qt5_use_modules(UiUtils Core Gui Network)
746     qt5_use_modules(Streams Network)
747     qt5_use_modules(qwwsmtpclient Network)
748     qt5_use_modules(MSA Network)
749     qt5_use_modules(Composer Gui Network)
750     qt5_use_modules(Imap Gui Network Sql)
751     if (WITH_DESKTOP)
752         qt5_use_modules(DesktopGui Network WebKitWidgets)
753         qt5_use_modules(AbookAddressbook Widgets)
754         qt5_use_modules(be.contacts Widgets)
755         qt5_use_modules(trojita Widgets Network)
756     endif()
757 endif()
760 if(WITH_SHARED_PLUGINS)
761     install(TARGETS Plugins DESTINATION ${CMAKE_INSTALL_LIBDIR})
762 endif()
764 include(SanitizedDesktopFile)
766 if(WITH_DESKTOP)
767     copy_desktop_file_without_cruft("${CMAKE_CURRENT_SOURCE_DIR}/src/Gui/trojita.desktop" "${CMAKE_CURRENT_BINARY_DIR}/trojita-DesktopGui.desktop")
768     install(TARGETS trojita be.contacts RUNTIME DESTINATION bin)
769     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/trojita-DesktopGui.desktop DESTINATION share/applications/ RENAME trojita.desktop)
770     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/Gui/trojita.appdata.xml DESTINATION share/appdata/)
771     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/icons/trojita.png DESTINATION share/icons/hicolor/32x32/apps/)
772     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/icons/trojita.svg DESTINATION share/icons/hicolor/scalable/apps/)
773 endif()
775 if(WITH_HARMATTAN)
776     set(trojita_harmattan_path ${CMAKE_CURRENT_SOURCE_DIR}/src/Harmattan)
777     install(TARGETS trojita-tp RUNTIME DESTINATION bin)
778     install(TARGETS trojitaqnamwebviewplugin LIBRARY DESTINATION bin/net/flaska/QNAMWebView)
779     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/QmlSupport/QNAMWebView/qmldir DESTINATION bin/net/flaska/QNAMWebView)
780     install(DIRECTORY ${trojita_harmattan_path}/qml DESTINATION ${CMAKE_INSTALL_PREFIX})
781     install(FILES ${trojita_harmattan_path}/trojita-tp.desktop DESTINATION share/applications)
782     install(FILES ${trojita_harmattan_path}/trojita-tp80.png DESTINATION share/icons/hicolor/80x80/apps)
783 endif()
785 if(WITH_NSIS)
786     if(CMAKE_SIZEOF_VOID_P STREQUAL 4)
787         set(MAKENSIS_OUTPUT Trojita-installer.exe)
788     else()
789         set(MAKENSIS_FLAGS -DX86_64 ${MAKENSIS_FLAGS})
790         set(MAKENSIS_OUTPUT Trojita-installer-x86_64.exe)
791     endif()
793     if(NOT CMAKE_VERBOSE_MAKEFILE)
794         set(MAKENSIS_FLAGS -V2 -DQUIET ${MAKENSIS_FLAGS})
795     endif()
797     set(MAKENSIS_FLAGS ${MAKENSIS_FLAGS} -NOCD)
799     add_custom_command(OUTPUT ${MAKENSIS_OUTPUT}
800         COMMAND ${MAKENSIS}
801         ARGS ${MAKENSIS_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/packaging/trojita.nsi
802         DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/packaging/trojita.nsi ${CMAKE_CURRENT_BINARY_DIR}/trojita.exe version)
803     add_custom_target(installer ALL DEPENDS ${MAKENSIS_OUTPUT})
804 endif()
807 if(WITH_TESTS)
808     set(test_LibMailboxSync_SOURCES
809         tests/Utils/ModelEvents.cpp
810         tests/Utils/LibMailboxSync.cpp
811     )
812     add_library(test_LibMailboxSync STATIC ${test_LibMailboxSync_SOURCES})
813     if(WITH_QT5)
814         qt5_use_modules(test_LibMailboxSync Test Network)
815     endif()
816     if(SUPPORTS_TARGET_INCLUDES)
817         set_property(TARGET test_LibMailboxSync APPEND PROPERTY INCLUDE_DIRECTORIES
818             ${CMAKE_CURRENT_SOURCE_DIR}/tests
819             ${CMAKE_CURRENT_SOURCE_DIR}/tests/Utils)
820     endif()
821     target_link_libraries(test_LibMailboxSync Imap MSA Streams Common Composer ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY})
823     macro(trojita_test dir fname)
824         set(test_${fname}_SOURCES tests/${dir}/test_${fname}.cpp)
825         add_executable(test_${fname} ${test_${fname}_SOURCES})
826         target_link_libraries(test_${fname} Imap MSA Streams Common Composer test_LibMailboxSync)
827         if(WITH_QT5)
828             qt5_use_modules(test_${fname} Network Sql Test Widgets)
829         else()
830             target_link_libraries(test_${fname} ${QT_QTSQL_LIBRARY} ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY})
831         endif()
832         if(WITH_ZLIB)
833             target_link_libraries(test_${fname} ${ZLIB_LIBRARIES})
834         endif()
835         if(SUPPORTS_TARGET_INCLUDES)
836             set_property(TARGET test_${fname} APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/tests)
837         endif()
838         if(NOT CMAKE_CROSSCOMPILING)
839             add_test(test_${fname} test_${fname})
840         endif()
841     endmacro()
843     enable_testing()
844     trojita_test(Composer Composer_Submission)
845     trojita_test(Composer Composer_responses)
846     trojita_test(Composer Html_formatting)
847     if(WITH_QT5)
848         qt5_use_modules(test_Composer_responses WebKitWidgets)
849         qt5_use_modules(test_Html_formatting WebKitWidgets)
850     else()
851         target_link_libraries(test_Html_formatting ${QT_QTWEBKIT_LIBRARY})
852     endif()
853     trojita_test(Imap Imap_DisappearingMailboxes)
854     trojita_test(Imap Imap_Idle)
855     trojita_test(Imap Imap_LowLevelParser)
856     trojita_test(Imap Imap_Message)
857     trojita_test(Imap Imap_Model)
858     trojita_test(Imap Imap_MsgPartNetAccessManager)
859     trojita_test(Imap Imap_Parser_parse)
860     trojita_test(Imap Imap_Responses)
861     trojita_test(Imap Imap_SelectedMailboxUpdates)
862     trojita_test(Imap Imap_Tasks_CreateMailbox)
863     trojita_test(Imap Imap_Tasks_DeleteMailbox)
864     trojita_test(Imap Imap_Tasks_ListChildMailboxes)
865     trojita_test(Imap Imap_Tasks_ObtainSynchronizedMailbox)
866     trojita_test(Imap Imap_Tasks_OpenConnection)
867     trojita_test(Imap Imap_Threading)
868     trojita_test(Imap Imap_BodyParts)
869     trojita_test(Imap Imap_Offline)
870     trojita_test(Imap Imap_CopyAndFlagOperations)
871     trojita_test(Misc Rfc5322)
872     trojita_test(Misc RingBuffer)
873     trojita_test(Misc SenderIdentitiesModel)
874     trojita_test(Misc SqlCache)
875     trojita_test(Misc algorithms)
876     trojita_test(Misc rfccodecs)
878 endif()
880 if(WIN32) # Check if we are on Windows
881     if(MSVC10) # Check if we are using the Visual Studio compiler 2010
882         # Because of linker errors (see http://stackoverflow.com/questions/5625884/conversion-of-stdwstring-to-qstring-throws-linker-error)
883         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:wchar_t-")
884     elseif(MINGW)
885     else()
886         message(WARNING "You are using a compiler which we have not tested yet (not MSVC10 or MINGW).")
887         message(WARNING "Please let us know how well it works.")
888     endif()
889 endif()