CMake: Fix installing shared plugins
[trojita.git] / CMakeLists.txt
blobe48c13413e0dcd20f508457055e746691009eec3
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 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")
31 include(TrojitaOption)
33 trojita_option(WITH_DESKTOP "Build desktop version" ON)
34 trojita_option(WITH_HARMATTAN "Build MeeGo Harmattan version" OFF "NOT WITH_DESKTOP")
35 trojita_option(WITH_QT5 "Build with Qt5 library" OFF)
36 trojita_option(WITH_RAGEL "Build with Ragel library" AUTO)
37 trojita_option(WITH_ZLIB "Build with zlib library" AUTO)
38 trojita_option(WITH_SHARED_PLUGINS "Enable shared dynamic plugins" ON)
39 trojita_option(WITH_TESTS "Build tests" ON "NOT WITH_HARMATTAN")
41 if(WIN32)
42     trojita_option(WITH_NSIS "Build Windows NSIS installer" AUTO)
43 endif()
45 if(WITH_QT5)
46     message(STATUS "Building the Qt5 version")
47     find_package(Qt5Gui REQUIRED)
48     find_package(Qt5Network REQUIRED)
49     find_package(Qt5Sql REQUIRED)
50     find_package(Qt5WebKitWidgets REQUIRED)
51     find_package(Qt5Widgets REQUIRED)
52     find_package(Qt5LinguistTools)
53     if(WITH_TESTS)
54         find_package(Qt5Test REQUIRED)
55     endif()
56     if(Qt5LinguistTools_FOUND)
57         find_package(Qt5LinguistForTrojita)
58     endif()
59 else()
60     message(STATUS "Building the Qt4 version")
61     set(QT_USE_QTNETWORK 1)
62     set(QT_USE_QTSQL 1)
63     set(QT_USE_QTWEBKIT 1)
64     if(WITH_TESTS)
65         set(QT_USE_QTTEST 1)
66     endif()
67     if(WITH_HARMATTAN)
68         set(QT_USE_QTDECLARATIVE 1)
69     endif()
70     trojita_find_package(Qt4 4.6 "http://qt-project.org" "Qt4" "Needed for building" REQUIRED)
71     include(${QT_USE_FILE})
72     trojita_check_qt4_module(QTCORE REQUIRED)
73     trojita_check_qt4_module(QTGUI REQUIRED)
74     trojita_check_qt4_module(QTNETWORK REQUIRED)
75     trojita_check_qt4_module(QTSQL REQUIRED)
76     trojita_check_qt4_module(QTWEBKIT REQUIRED)
77     trojita_check_qt4_module(QTTEST WITH_TESTS)
78     trojita_check_qt4_module(QTDECLARATIVE WITH_HARMATTAN)
79     trojita_find_package(LinguistForTrojita "" "" "" "")
80 endif()
81 trojita_find_package(Git "" "" "" "")
83 if(WIN32)
84     trojita_find_package(MakeNSIS "" "http://nsis.sourceforge.net" "Nullsoft Scriptable Install System" "Needed for building Windows installer" WITH_NSIS)
85 endif()
87 # Add support for Mingw RC compiler
88 if(WIN32)
89     enable_language(RC)
90     include(CMakeDetermineRCCompiler)
92     if(MINGW)
93         set(CMAKE_RC_COMPILER_INIT windres)
94         set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
95     endif()
96 endif()
98 if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
99     set(CMAKE_INSTALL_LIBDIR "lib${LIB_SUFFIX}")
100 endif()
101 mark_as_advanced(CMAKE_INSTALL_LIBDIR)
103 if(NOT CMAKE_INSTALL_PLUGIN_DIR)
104     set(CMAKE_INSTALL_PLUGIN_DIR "${CMAKE_INSTALL_LIBDIR}/trojita")
105 endif()
106 mark_as_advanced(CMAKE_INSTALL_PLUGIN_DIR)
108 if(NOT PLUGIN_DIR)
109     set(PLUGIN_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_PLUGIN_DIR}")
110 endif()
111 mark_as_advanced(PLUGIN_DIR)
113 if(NOT WIN32 AND NOT MSVC)
114     # Check if we are NOT on Windows and don't use MSVC since -g is not supported by VC
115     # and Wall makes the build very noisy.
116     # At first, enable optimizations. In my testing, these do *not* make debugging any harder than no optimization and
117     # they (of course) optimize away stuff like QByteArray::operator[] etc.
118     # We put the user's CXXFLAGS *after* that so that they take priority.
119     set(CMAKE_CXX_FLAGS "-O2 -g ${CMAKE_CXX_FLAGS}")
120     # Now enable build warnings; these are useful tools (and Trojita should be warning-free anyway). We do not set
121     # -Werror for sanity reasons, though (one cannot know what warnings a future compiler might bring along).
122     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
123 endif(NOT WIN32 AND NOT MSVC)
125 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
126 # The following is required so that the moc_*.cpp and ui_*.h are found
127 include_directories(${CMAKE_CURRENT_BINARY_DIR})
128 add_definitions(-DQT_STRICT_ITERATORS)
130 # Make sure that plugins not export all symbols, only that which are explicitly marked
131 include(GenerateExportHeader)
132 add_compiler_export_flags()
134 if(NOT WITH_QT5 AND CMAKE_VERSION VERSION_LESS 2.8.10)
135     set(SUPPORTS_TARGET_INCLUDES 0)
136     include_directories(
137         ${QT_MKSPECS_DIR}/default
138         ${CMAKE_CURRENT_SOURCE_DIR}/src/Gui/
139         ${CMAKE_CURRENT_SOURCE_DIR}/src/mimetypes-qt4/io/
140         ${CMAKE_CURRENT_SOURCE_DIR}/src/Harmattan/qmlapplicationviewer
141         ${CMAKE_CURRENT_SOURCE_DIR}/tests
142         ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_LibMailboxSync)
143 else()
144     set(SUPPORTS_TARGET_INCLUDES 1)
145 endif()
147 set(CMAKE_AUTOMOC True)
149 trojita_find_package(RagelForTrojita "" "" "" "" WITH_RAGEL)
151 if(WIN32) # Check if we are on Windows
152     # On win32, qt can statically link to zlib and export their symbols.
153     # We check if we can find the string " zlib " in the QT_CONFIG list in
154     # ${QT_MKSPECS_DIR}/qconfig.pri and include on success ${QT_QTCORE_LIBRARY}
155     # and ${QTDIR}/src/3rdparty/zlib as lib and include folder
156     if(QT_QTCORE_FOUND)
157         message(STATUS "We are on Windows with Qt. Checking if zlib is built into Qt")
159         if(EXISTS "${QT_MKSPECS_DIR}/qconfig.pri")
160             file(READ ${QT_MKSPECS_DIR}/qconfig.pri _qconfig_FILE_contents_ZLIB_CHECK)
161             string(REGEX MATCH "QT_CONFIG[^\n]+" QT_CONFIG_ZLIB_CHECK ${_qconfig_FILE_contents_ZLIB_CHECK})
163             set(ENV_QTDIR $ENV{QTDIR})
164             if(NOT DEFINED ENV_QTDIR)
165                 message(STATUS "QTDIR not specified in environment, will not use zlib")
166             elseif(QT_CONFIG_ZLIB_CHECK)
167                 if(QT_CONFIG_ZLIB_CHECK MATCHES " zlib ")
168                     message(STATUS "Found zlib in QT_QCONFIG. zlib seems to be built into Qt")
169                     set(ZLIB_LIBRARY_RELEASE ${QT_QTCORE_LIBRARY_RELEASE})
170                     set(ZLIB_LIBRARY_DEBUG ${QT_QTCORE_LIBRARY_DEBUG})
171                     set(ZLIB_LIBRARY ${QT_QTCORE_LIBRARY})
173                     string(REGEX REPLACE "\\\\" "/" QTDIR ${ENV_QTDIR})
174                     set(ZLIB_INCLUDE_DIR "${QTDIR}/src/3rdparty/zlib")
176                     set(ZLIB_FOUND TRUE)
177                     set(ZLIB_LIBRARIES ${ZLIB_LIBRARY} )
178                     mark_as_advanced(ZLIB_LIBRARY ZLIB_INCLUDE_DIR ZLIB_FOUND)
179                 else(QT_CONFIG_ZLIB_CHECK MATCHES " zlib ")
180                     message(STATUS "Could not determine if Qt was built with zlib support.")
181                 endif(QT_CONFIG_ZLIB_CHECK MATCHES " zlib ")
183             endif()
184         endif(EXISTS "${QT_MKSPECS_DIR}/qconfig.pri")
185     endif(QT_QTCORE_FOUND)
186 endif()
188 if(NOT ZLIB_FOUND)
189     trojita_find_package(ZLIB "" "" "" "" WITH_ZLIB)
190 endif()
192 if(WITH_ZLIB)
193     set(TROJITA_HAVE_ZLIB True)
194     message(STATUS "Support for COMPRESS=DEFLATE enabled")
195 else()
196     set(TROJITA_HAVE_ZLIB False)
197     message(STATUS "Disabling COMPRESS=DEFLATE, zlib is not available")
198 endif()
200 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/configure.cmake.in
201     ${CMAKE_CURRENT_BINARY_DIR}/configure.cmake.h)
203 feature_summary(FATAL_ON_MISSING_REQUIRED_PACKAGES DESCRIPTION "\n" WHAT ALL)
205 set(path_Common ${CMAKE_CURRENT_SOURCE_DIR}/src/Common)
206 set(libCommon_SOURCES
207     ${path_Common}/Application.cpp
208     ${path_Common}/ConnectionId.cpp
209     ${path_Common}/DeleteAfter.cpp
210     ${path_Common}/FileLogger.cpp
211     ${path_Common}/Paths.cpp
212     ${path_Common}/SettingsNames.cpp
215 set(path_Plugins ${CMAKE_CURRENT_SOURCE_DIR}/src/Plugins)
216 set(libPlugins_SOURCES
217     ${path_Plugins}/AddressbookPlugin.cpp
218     ${path_Plugins}/PasswordPlugin.cpp
219     ${path_Plugins}/PluginJob.cpp
220     ${path_Plugins}/PluginManager.cpp
223 set(path_Composer ${CMAKE_CURRENT_SOURCE_DIR}/src/Composer)
224 set(libComposer_SOURCES
225     ${path_Composer}/ComposerAttachments.cpp
226     ${path_Composer}/MessageComposer.cpp
227     ${path_Composer}/PlainTextFormatter.cpp
228     ${path_Composer}/Recipients.cpp
229     ${path_Composer}/ReplaceSignature.cpp
230     ${path_Composer}/SenderIdentitiesModel.cpp
231     ${path_Composer}/SubjectMangling.cpp
232     ${path_Composer}/Submission.cpp
235 set(path_MSA ${CMAKE_CURRENT_SOURCE_DIR}/src/MSA)
236 set(libMSA_SOURCES
237     ${path_MSA}/AbstractMSA.cpp
238     ${path_MSA}/FakeMSA.cpp
239     ${path_MSA}/ImapSubmit.cpp
240     ${path_MSA}/SMTP.cpp
241     ${path_MSA}/Sendmail.cpp
244 set(path_Streams ${CMAKE_CURRENT_SOURCE_DIR}/src/Streams)
245 set(libStreams_SOURCES
246     ${path_Streams}/DeletionWatcher.cpp
247     ${path_Streams}/FakeSocket.cpp
248     ${path_Streams}/IODeviceSocket.cpp
249     ${path_Streams}/Socket.cpp
250     ${path_Streams}/SocketFactory.cpp
253 if(WITH_ZLIB)
254     set(libStreams_SOURCES ${libStreams_SOURCES}
255         ${path_Streams}/3rdparty/rfc1951.cpp)
256     include_directories(${ZLIB_INCLUDE_DIR})
257 endif()
259 if(NOT WITH_QT5)
260     set(path_mimetypesqt4 ${CMAKE_CURRENT_SOURCE_DIR}/src/mimetypes-qt4)
261     set(libMimetypesQt4_SOURCES
262         ${path_mimetypesqt4}/io/qstandardpaths.cpp
263         ${path_mimetypesqt4}/mimetypes/qmimedatabase.cpp
264         ${path_mimetypesqt4}/mimetypes/qmimeglobpattern.cpp
265         ${path_mimetypesqt4}/mimetypes/qmimemagicrule.cpp
266         ${path_mimetypesqt4}/mimetypes/qmimemagicrulematcher.cpp
267         ${path_mimetypesqt4}/mimetypes/qmimetype.cpp
268         ${path_mimetypesqt4}/mimetypes/qmimetypeparser.cpp
269         ${path_mimetypesqt4}/mimetypes/qmimeprovider.cpp
270     )
271     if(WIN32)
272         set(libMimetypesQt4_SOURCES ${libMimetypesQt4_SOURCES}
273             ${path_mimetypesqt4}/io/qstandardpaths_win.cpp)
274     elseif(APPLE)
275         set(libMimetypesQt4_SOURCES ${libMimetypesQt4_SOURCES}
276             ${path_mimetypesqt4}/io/qstandardpaths_mac.cpp)
277     elseif (OS2)
278         set(libMimetypesQt4_SOURCES ${libMimetypesQt4_SOURCES}
279             ${path_mimetypesqt4}/io/qstandardpaths_os2.cpp)
280     elseif (UNIX)
281         set(libMimetypesQt4_SOURCES ${libMimetypesQt4_SOURCES}
282             ${path_mimetypesqt4}/io/qstandardpaths_unix.cpp)
283     else()
284         message(FATAL_ERROR "Unsupported platform -- mimetypes-Qt4 support only Unix, MacOSX, Windows and OS/2")
285     endif()
286 endif()
288 set(path_DesktopGui ${CMAKE_CURRENT_SOURCE_DIR}/src/Gui)
289 set(libDesktopGui_SOURCES
290     ${path_DesktopGui}/AttachmentView.cpp
291     ${path_DesktopGui}/AutoCompletion.cpp
292     ${path_DesktopGui}/CompleteMessageWidget.cpp
293     ${path_DesktopGui}/ComposeWidget.cpp
294     ${path_DesktopGui}/ComposerAttachmentsList.cpp
295     ${path_DesktopGui}/ComposerTextEdit.cpp
296     ${path_DesktopGui}/EmbeddedWebView.cpp
297     ${path_DesktopGui}/EnvelopeView.cpp
298     ${path_DesktopGui}/ExternalElementsWidget.cpp
299     ${path_DesktopGui}/FindBar.cpp
300     ${path_DesktopGui}/FlowLayout.cpp
301     ${path_DesktopGui}/FromAddressProxyModel.cpp
302     ${path_DesktopGui}/LineEdit.cpp
303     ${path_DesktopGui}/LoadablePartWidget.cpp
304     ${path_DesktopGui}/MailBoxTreeView.cpp
305     ${path_DesktopGui}/MessageListWidget.cpp
306     ${path_DesktopGui}/MessageSourceWidget.cpp
307     ${path_DesktopGui}/MessageView.cpp
308     ${path_DesktopGui}/MsgListView.cpp
309     ${path_DesktopGui}/OnePanelAtTimeWidget.cpp
310     ${path_DesktopGui}/OverlayWidget.cpp
311     ${path_DesktopGui}/PartWidget.cpp
312     ${path_DesktopGui}/PartWidgetFactory.cpp
313     ${path_DesktopGui}/PasswordDialog.cpp
314     ${path_DesktopGui}/ProgressPopUp.cpp
315     ${path_DesktopGui}/ProtocolLoggerWidget.cpp
316     ${path_DesktopGui}/ReplaceCharValidator.cpp
317     ${path_DesktopGui}/SettingsDialog.cpp
318     ${path_DesktopGui}/SimplePartWidget.cpp
319     ${path_DesktopGui}/Spinner.cpp
320     ${path_DesktopGui}/TagListWidget.cpp
321     ${path_DesktopGui}/TagWidget.cpp
322     ${path_DesktopGui}/TaskProgressIndicator.cpp
323     ${path_DesktopGui}/UserAgentWebPage.cpp
324     ${path_DesktopGui}/Util.cpp
325     ${path_DesktopGui}/Window.cpp
326     ${path_DesktopGui}/ShortcutHandler/ShortcutConfigDialog.cpp
327     ${path_DesktopGui}/ShortcutHandler/ShortcutConfigWidget.cpp
328     ${path_DesktopGui}/ShortcutHandler/ShortcutHandler.cpp
330 set(libDesktopGui_UI
331     ${path_DesktopGui}/CreateMailboxDialog.ui
332     ${path_DesktopGui}/SettingsOutgoingPage.ui
333     ${path_DesktopGui}/SettingsGeneralPage.ui
334     ${path_DesktopGui}/ComposeWidget.ui
335     ${path_DesktopGui}/ProgressPopUpOld.ui
336     ${path_DesktopGui}/ShortcutHandler/ShortcutConfigWidget.ui
337     ${path_DesktopGui}/SettingsImapPage.ui
338     ${path_DesktopGui}/PasswordDialog.ui
339     ${path_DesktopGui}/SettingsCachePage.ui
340     ${path_DesktopGui}/EditIdentity.ui
341     ${path_DesktopGui}/ProgressPopUp.ui
343 set(libDesktopGui_RESOURCES
344     ${CMAKE_CURRENT_SOURCE_DIR}/src/icons.qrc
347 set(libqwwsmtpclient_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/qwwsmtpclient/qwwsmtpclient.cpp)
349 set(libAppVersion_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/AppVersion/SetCoreApplication.cpp)
351 set(path_Imap ${CMAKE_CURRENT_SOURCE_DIR}/src/Imap)
352 set(libImap_SOURCES
353     ${path_Imap}/ConnectionState.cpp
354     ${path_Imap}/Encoders.cpp
355     ${path_Imap}/Exceptions.cpp
356     ${path_Imap}/Parser/3rdparty/kcodecs.cpp
357     ${path_Imap}/Parser/3rdparty/rfccodecs.cpp
359     ${path_Imap}/Parser/Command.cpp
360     ${path_Imap}/Parser/Data.cpp
361     ${path_Imap}/Parser/LowLevelParser.cpp
362     ${path_Imap}/Parser/MailAddress.cpp
363     ${path_Imap}/Parser/Message.cpp
364     ${path_Imap}/Parser/Parser.cpp
365     ${path_Imap}/Parser/Response.cpp
366     ${path_Imap}/Parser/Sequence.cpp
367     ${path_Imap}/Parser/ThreadingNode.cpp
369     ${path_Imap}/Network/FileDownloadManager.cpp
370     ${path_Imap}/Network/ForbiddenReply.cpp
371     ${path_Imap}/Network/MsgPartNetAccessManager.cpp
372     ${path_Imap}/Network/MsgPartNetworkReply.cpp
374     ${path_Imap}/Model/Cache.cpp
375     ${path_Imap}/Model/CombinedCache.cpp
376     ${path_Imap}/Model/DragAndDrop.cpp
377     ${path_Imap}/Model/DelayedPopulation.cpp
378     ${path_Imap}/Model/DiskPartCache.cpp
379     ${path_Imap}/Model/FindInterestingPart.cpp
380     ${path_Imap}/Model/FlagsOperation.cpp
381     ${path_Imap}/Model/FullMessageCombiner.cpp
382     ${path_Imap}/Model/MailboxMetadata.cpp
383     ${path_Imap}/Model/MailboxModel.cpp
384     ${path_Imap}/Model/MailboxTree.cpp
385     ${path_Imap}/Model/MemoryCache.cpp
386     ${path_Imap}/Model/Model.cpp
387     ${path_Imap}/Model/MsgListModel.cpp
388     ${path_Imap}/Model/OneMessageModel.cpp
389     ${path_Imap}/Model/ParserState.cpp
390     ${path_Imap}/Model/PrettyMailboxModel.cpp
391     ${path_Imap}/Model/PrettyMsgListModel.cpp
392     ${path_Imap}/Model/SpecialFlagNames.cpp
393     ${path_Imap}/Model/SQLCache.cpp
394     ${path_Imap}/Model/SubtreeModel.cpp
395     ${path_Imap}/Model/TaskFactory.cpp
396     ${path_Imap}/Model/TaskPresentationModel.cpp
397     ${path_Imap}/Model/ThreadingMsgListModel.cpp
398     ${path_Imap}/Model/Utils.cpp
399     ${path_Imap}/Model/VisibleTasksModel.cpp
401     # The ModelTest is only needed when debugging manually
402     #${path_Imap}/Model/ModelTest/modeltest.cpp
403     # The ModelWatcher is another debugging aid
404     ${path_Imap}/Model/ModelWatcher.cpp
406     ${path_Imap}/Model/kdeui-itemviews/kdescendantsproxymodel.cpp
408     ${path_Imap}/Tasks/AppendTask.cpp
409     ${path_Imap}/Tasks/CopyMoveMessagesTask.cpp
410     ${path_Imap}/Tasks/CreateMailboxTask.cpp
411     ${path_Imap}/Tasks/DeleteMailboxTask.cpp
412     ${path_Imap}/Tasks/EnableTask.cpp
413     ${path_Imap}/Tasks/ExpungeMailboxTask.cpp
414     ${path_Imap}/Tasks/ExpungeMessagesTask.cpp
415     ${path_Imap}/Tasks/Fake_ListChildMailboxesTask.cpp
416     ${path_Imap}/Tasks/Fake_OpenConnectionTask.cpp
417     ${path_Imap}/Tasks/FetchMsgMetadataTask.cpp
418     ${path_Imap}/Tasks/FetchMsgPartTask.cpp
419     ${path_Imap}/Tasks/GenUrlAuthTask.cpp
420     ${path_Imap}/Tasks/GetAnyConnectionTask.cpp
421     ${path_Imap}/Tasks/IdTask.cpp
422     ${path_Imap}/Tasks/IdleLauncher.cpp
423     ${path_Imap}/Tasks/ImapTask.cpp
424     ${path_Imap}/Tasks/KeepMailboxOpenTask.cpp
425     ${path_Imap}/Tasks/ListChildMailboxesTask.cpp
426     ${path_Imap}/Tasks/NoopTask.cpp
427     ${path_Imap}/Tasks/NumberOfMessagesTask.cpp
428     ${path_Imap}/Tasks/ObtainSynchronizedMailboxTask.cpp
429     ${path_Imap}/Tasks/OfflineConnectionTask.cpp
430     ${path_Imap}/Tasks/OpenConnectionTask.cpp
431     ${path_Imap}/Tasks/SortTask.cpp
432     ${path_Imap}/Tasks/SubscribeUnsubscribeTask.cpp
433     ${path_Imap}/Tasks/ThreadTask.cpp
434     ${path_Imap}/Tasks/UidSubmitTask.cpp
435     ${path_Imap}/Tasks/UnSelectTask.cpp
436     ${path_Imap}/Tasks/UpdateFlagsTask.cpp
437     ${path_Imap}/Tasks/UpdateFlagsOfAllMessagesTask.cpp
440 if(WITH_RAGEL)
441     message(STATUS "Using Ragel for the RFC 5322 parser")
442     ragel_parser(${path_Imap}/Parser/Rfc5322HeaderParser.cpp)
443     set(libImap_SOURCES ${libImap_SOURCES}
444         ${CMAKE_CURRENT_BINARY_DIR}/Rfc5322HeaderParser.generated.cpp)
445 else()
446     message(STATUS "Using pregenerated RFC 5322 parser")
447     set(libImap_SOURCES ${libImap_SOURCES}
448         ${path_Imap}/Parser/Rfc5322HeaderParser.generated.cpp)
449 endif()
451 set(path_AbookAddressbook ${CMAKE_CURRENT_SOURCE_DIR}/src/AbookAddressbook)
452 set(libAbookAddressbook_SOURCES
453     ${path_AbookAddressbook}/AbookAddressbook.cpp
454     ${path_AbookAddressbook}/be-contacts.cpp
456 set(libAbookAddressbook_UI
457     ${path_AbookAddressbook}/be-contacts.ui
458     ${path_AbookAddressbook}/onecontact.ui
461 set(trojita_desktop_SOURCES
462     ${path_DesktopGui}/main.cpp
465 if(WIN32)
466     list(APPEND trojita_desktop_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/trojita_win32.rc)
467 endif()
469 set(be_contacts_SOURCES
470     ${CMAKE_CURRENT_SOURCE_DIR}/src/be.contacts/main.cpp
473 set(libQmlModelGlue_SOURCES
474     ${CMAKE_CURRENT_SOURCE_DIR}/src/QmlSupport/ModelGlue/ImapAccess.cpp
477 set(libQNAMWebView_SOURCES
478     ${CMAKE_CURRENT_SOURCE_DIR}/src/QmlSupport/QNAMWebView/plugin.cpp
479     ${CMAKE_CURRENT_SOURCE_DIR}/src/QmlSupport/QNAMWebView/qdeclarativewebview.cpp
482 set(trojitaHarmattan_SOURCES
483     ${CMAKE_CURRENT_SOURCE_DIR}/src/Harmattan/main.cpp
484     ${CMAKE_CURRENT_SOURCE_DIR}/src/Harmattan/qmlapplicationviewer/qmlapplicationviewer.cpp
487 if(LinguistForTrojita_FOUND OR Qt5LinguistForTrojita_FOUND)
488     file(GLOB_RECURSE lang_PO "${CMAKE_CURRENT_SOURCE_DIR}/po/trojita_common_*.po")
489     if(WITH_QT5)
490         qt5_wrap_po(trojita_QM ${lang_PO})
491     else()
492         qt4_wrap_po(trojita_QM ${lang_PO})
493     endif()
494     set(language_summary "")
495     foreach(po ${lang_PO})
496         string(REGEX REPLACE "^(.*)/trojita_common_(.*).po" "\\2" lang ${po})
497         list(APPEND language_summary ${lang})
498     endforeach()
499     list(SORT language_summary)
500     list(LENGTH language_summary num_languages)
501     if(num_languages)
502         message(STATUS "Available languages: ${language_summary}")
503         if(WITH_DESKTOP)
504            install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/locale/ DESTINATION share/trojita/locale FILES_MATCHING PATTERN *.qm)
505         endif()
506     else()
507         message(STATUS "No .po files found, will not install any languages")
508     endif()
509 else()
510     message(STATUS "Qt Linguist (lupdate/lrelease/lconvert) not found, disabling localization support")
511 endif()
513 set(version_files ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.h ${CMAKE_CURRENT_BINARY_DIR}/trojita-git-version.h)
514 if(WITH_NSIS)
515     set(version_files ${version_files} ${CMAKE_CURRENT_BINARY_DIR}/trojita-version.nsi)
516     set(NSIS TRUE)
517 endif()
519 add_custom_target(version DEPENDS version_fake_file)
520 add_custom_command(OUTPUT version_fake_file ${version_files}
521     COMMAND ${CMAKE_COMMAND} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DNSIS=${NSIS} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TrojitaVersion.cmake)
522 set_source_files_properties(${version_files}
523     PROPERTIES GENERATED TRUE
524     HEADER_FILE_ONLY TRUE)
526 add_library(Common ${libCommon_SOURCES})
527 add_dependencies(Common version)
528 target_link_libraries(Common ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
530 add_library(AppVersion ${libAppVersion_SOURCES})
531 add_dependencies(AppVersion version)
532 target_link_libraries(AppVersion Common ${QT_QTCORE_LIBRARY})
534 if(WITH_SHARED_PLUGINS)
535     add_library(Plugins SHARED ${libPlugins_SOURCES})
536 else()
537     add_library(Plugins STATIC ${libPlugins_SOURCES})
538     set_property(TARGET Plugins APPEND PROPERTY COMPILE_DEFINITIONS QT_STATICPLUGIN)
539 endif()
540 set_target_properties(Plugins PROPERTIES OUTPUT_NAME trojita_plugins)
541 if(WITH_QT5)
542     qt5_use_modules(Plugins Core)
543 else()
544     target_link_libraries(Plugins ${QT_QTCORE_LIBRARY})
545 endif()
547 add_library(Streams ${libStreams_SOURCES})
548 target_link_libraries(Streams ${QT_QTNETWORK_LIBRARY} ${QT_QTCORE_LIBRARY})
549 if(WITH_ZLIB)
550     target_link_libraries(Streams ${ZLIB_LIBRARIES})
551 endif()
553 add_library(qwwsmtpclient ${libqwwsmtpclient_SOURCES})
554 target_link_libraries(qwwsmtpclient ${QT_QTNETWORK_LIBRARY} ${QT_QTCORE_LIBRARY})
556 add_library(MSA ${libMSA_SOURCES})
557 target_link_libraries(MSA Imap Streams qwwsmtpclient ${QT_QTCORE_LIBRARY})
559 add_library(Composer ${libComposer_SOURCES})
560 target_link_libraries(Composer Common MSA Streams qwwsmtpclient ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
561 if(NOT WITH_QT5)
562     target_link_libraries(Composer MimetypesQt4)
563 endif()
565 add_library(Imap ${libImap_SOURCES})
566 target_link_libraries(Imap Common Streams ${QT_QTNETWORK_LIBRARY} ${QT_QTSQL_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
567 if(WITH_ZLIB)
568     target_link_libraries(Imap ${ZLIB_LIBRARIES})
569 endif()
571 if(NOT WITH_QT5)
572     add_library(MimetypesQt4 ${libMimetypesQt4_SOURCES})
573     if(SUPPORTS_TARGET_INCLUDES)
574         set_property(TARGET MimetypesQt4 APPEND PROPERTY INCLUDE_DIRECTORIES
575             ${QT_MKSPECS_DIR}/default ${path_mimetypesqt4}/io/)
576     endif()
577     target_link_libraries(MimetypesQt4 ${QT_QTCORE_LIBRARY})
578 endif()
580 # Generate file static_plugins.h.in
581 get_property(STATIC_PLUGINS GLOBAL PROPERTY TROJITA_STATIC_PLUGINS)
582 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h.in "#include <QtPlugin>\n")
583 foreach(PLUGIN ${STATIC_PLUGINS})
584     file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h.in "Q_IMPORT_PLUGIN(${PLUGIN})\n")
585 endforeach()
586 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h.in ${CMAKE_CURRENT_BINARY_DIR}/static_plugins.h)
588 if(WITH_DESKTOP)
589     if(WITH_QT5)
590         qt5_wrap_ui(libAbookAddressbook_UI_OUT ${libAbookAddressbook_UI})
591         qt5_wrap_ui(libDesktopGui_UI_OUT ${libDesktopGui_UI})
592         qt5_add_resources(libDesktopGui_RESOURCES_OUT ${libDesktopGui_RESOURCES})
593     else()
594         qt4_wrap_ui(libAbookAddressbook_UI_OUT ${libAbookAddressbook_UI})
595         qt4_wrap_ui(libDesktopGui_UI_OUT ${libDesktopGui_UI})
596         qt4_add_resources(libDesktopGui_RESOURCES_OUT ${libDesktopGui_RESOURCES})
597     endif()
599     add_library(AbookAddressbook ${libAbookAddressbook_SOURCES} ${libAbookAddressbook_UI_OUT})
600     target_link_libraries(AbookAddressbook ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
602     add_library(DesktopGui ${libDesktopGui_SOURCES} ${libDesktopGui_UI_OUT} ${libDesktopGui_RESOURCES_OUT})
603     # The following is needed for the LineEdit widget within the .ui files.
604     # The ${path_DesktopGui} is needed so that the generated ui_*.h file can find the headers of the custom widgets
605     if(SUPPORTS_TARGET_INCLUDES)
606         set_property(TARGET DesktopGui APPEND PROPERTY INCLUDE_DIRECTORIES ${path_DesktopGui})
607     endif()
608     target_link_libraries(DesktopGui Common Composer Imap MSA Plugins Streams qwwsmtpclient AbookAddressbook ${QT_QTWEBKIT_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
610     # On Windows build a real Win32 GUI application without console window
611     # On other platforms WIN32 flag is ignored
612     add_executable(trojita WIN32 ${trojita_desktop_SOURCES} ${trojita_QM})
613     target_link_libraries(trojita AppVersion Common DesktopGui ${STATIC_PLUGINS} ${QT_QTMAIN_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
614     if(NOT WITH_QT5)
615         target_link_libraries(trojita MimetypesQt4)
616     endif()
617     if(WITH_ZLIB)
618         target_link_libraries(trojita ${ZLIB_LIBRARIES})
619     endif()
621     add_executable(be.contacts ${be_contacts_SOURCES})
622     target_link_libraries(be.contacts AbookAddressbook ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
623 elseif(WITH_HARMATTAN)
624     set(harmattan_prefix "opt/trojita-tp")
625     set(CMAKE_INSTALL_RPATH "/${harmattan_prefix}/lib")
626     add_library(QmlModelGlue ${libQmlModelGlue_SOURCES})
627     add_library(trojitaqnamwebviewplugin SHARED ${libQNAMWebView_SOURCES})
628     add_executable(trojita-tp ${trojitaHarmattan_SOURCES})
629     if(SUPPORTS_TARGET_INCLUDES)
630         set_property(TARGET trojita-tp APPEND PROPERTY INCLUDE_DIRECTORIES
631             ${QT_MKSPECS_DIR}/default ${CMAKE_CURRENT_SOURCE_DIR}/src/Harmattan/qmlapplicationviewer)
632     endif()
633     target_link_libraries(trojita-tp QmlModelGlue AppVersion Imap MSA Streams qwwsmtpclient Common Composer MimetypesQt4
634         ${QT_QTSQL_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${QT_QTWEBKIT_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY})
635 endif()
637 if(WITH_QT5)
638     qt5_use_modules(AppVersion Core)
639     qt5_use_modules(Common Core)
640     qt5_use_modules(Streams Network)
641     qt5_use_modules(qwwsmtpclient Network)
642     qt5_use_modules(MSA Network)
643     qt5_use_modules(Composer Gui Network)
644     qt5_use_modules(Imap Gui Network Sql)
645     qt5_use_modules(DesktopGui Network WebKitWidgets)
646     qt5_use_modules(AbookAddressbook Widgets)
647     qt5_use_modules(be.contacts Widgets)
648     qt5_use_modules(trojita Widgets)
649 endif()
651 if(WITH_DESKTOP)
652     install(TARGETS trojita be.contacts RUNTIME DESTINATION bin)
653     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/Gui/trojita.desktop DESTINATION share/applications/)
654     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/icons/trojita.png DESTINATION share/icons/hicolor/32x32/apps/)
655     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/icons/trojita.svg DESTINATION share/icons/hicolor/scalable/apps/)
656 endif()
658 if(WITH_HARMATTAN)
659     set(trojita_harmattan_path ${CMAKE_CURRENT_SOURCE_DIR}/src/Harmattan)
660     install(TARGETS trojita-tp RUNTIME DESTINATION ${harmattan_prefix}/bin)
661     install(TARGETS trojitaqnamwebviewplugin LIBRARY DESTINATION ${harmattan_prefix}/bin/net/flaska/QNAMWebView)
662     install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/QmlSupport/QNAMWebView/qmldir DESTINATION ${harmattan_prefix}/bin/net/flaska/QNAMWebView)
663     install(DIRECTORY ${trojita_harmattan_path}/qml DESTINATION ${harmattan_prefix})
664     install(FILES ${trojita_harmattan_path}/trojita-tp.desktop DESTINATION usr/share/applications/)
665     install(FILES ${trojita_harmattan_path}/trojita-tp80.png DESTINATION usr/share/icons/hicolor/80x80/apps/)
666     if(WITH_SHARED_PLUGINS)
667         install(TARGETS Plugins DESTINATION "${harmattan_prefix}/lib")
668     endif()
669 else()
670     if(WITH_SHARED_PLUGINS)
671         install(TARGETS Plugins DESTINATION "${CMAKE_INSTALL_LIBDIR}")
672     endif()
673 endif()
675 if(WITH_NSIS)
676     if(CMAKE_SIZEOF_VOID_P STREQUAL 4)
677         set(MAKENSIS_OUTPUT Trojita-installer.exe)
678     else()
679         set(MAKENSIS_FLAGS -DX86_64 ${MAKENSIS_FLAGS})
680         set(MAKENSIS_OUTPUT Trojita-installer-x86_64.exe)
681     endif()
683     if(NOT CMAKE_VERBOSE_MAKEFILE)
684         set(MAKENSIS_FLAGS -V2 -DQUIET ${MAKENSIS_FLAGS})
685     endif()
687     set(MAKENSIS_FLAGS ${MAKENSIS_FLAGS} -NOCD)
689     add_custom_command(OUTPUT ${MAKENSIS_OUTPUT}
690         COMMAND ${MAKENSIS}
691         ARGS ${MAKENSIS_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/packaging/trojita.nsi
692         DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/packaging/trojita.nsi ${CMAKE_CURRENT_BINARY_DIR}/trojita.exe version)
693     add_custom_target(installer ALL DEPENDS ${MAKENSIS_OUTPUT})
694 endif()
697 if(WITH_TESTS)
698     set(test_LibMailboxSync_SOURCES
699         tests/Utils/ModelEvents.cpp
700         tests/Utils/LibMailboxSync.cpp
701     )
702     add_library(test_LibMailboxSync ${test_LibMailboxSync_SOURCES})
703     if(WITH_QT5)
704         qt5_use_modules(test_LibMailboxSync Test Network)
705     endif()
706     if(SUPPORTS_TARGET_INCLUDES)
707         set_property(TARGET test_LibMailboxSync APPEND PROPERTY INCLUDE_DIRECTORIES
708             ${CMAKE_CURRENT_SOURCE_DIR}/tests
709             ${CMAKE_CURRENT_SOURCE_DIR}/tests/Utils)
710     endif()
711     target_link_libraries(test_LibMailboxSync Imap MSA Streams Common Composer ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY})
713     macro(trojita_test dir fname)
714         set(test_${fname}_SOURCES tests/${dir}/test_${fname}.cpp)
715         add_executable(test_${fname} ${test_${fname}_SOURCES})
716         target_link_libraries(test_${fname} Imap MSA Streams Common Composer test_LibMailboxSync)
717         if(WITH_QT5)
718             qt5_use_modules(test_${fname} Network Sql Test Widgets)
719         else()
720             target_link_libraries(test_${fname} ${QT_QTSQL_LIBRARY} ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY})
721         endif()
722         if(WITH_ZLIB)
723             target_link_libraries(test_${fname} ${ZLIB_LIBRARIES})
724         endif()
725         if(SUPPORTS_TARGET_INCLUDES)
726             set_property(TARGET test_${fname} APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/tests)
727         endif()
728         if(NOT CMAKE_CROSSCOMPILING)
729             add_test(test_${fname} test_${fname})
730         endif()
731     endmacro()
733     enable_testing()
734     trojita_test(Composer Composer_Submission)
735     trojita_test(Composer Composer_responses)
736     trojita_test(Composer Html_formatting)
737     if(WITH_QT5)
738         qt5_use_modules(test_Composer_responses WebKitWidgets)
739         qt5_use_modules(test_Html_formatting WebKitWidgets)
740     else()
741         target_link_libraries(test_Html_formatting ${QT_QTWEBKIT_LIBRARY})
742     endif()
743     trojita_test(Imap Imap_DisappearingMailboxes)
744     trojita_test(Imap Imap_Idle)
745     trojita_test(Imap Imap_LowLevelParser)
746     trojita_test(Imap Imap_Message)
747     trojita_test(Imap Imap_Model)
748     trojita_test(Imap Imap_Parser_parse)
749     trojita_test(Imap Imap_Responses)
750     trojita_test(Imap Imap_SelectedMailboxUpdates)
751     trojita_test(Imap Imap_Tasks_CreateMailbox)
752     trojita_test(Imap Imap_Tasks_DeleteMailbox)
753     trojita_test(Imap Imap_Tasks_ListChildMailboxes)
754     trojita_test(Imap Imap_Tasks_ObtainSynchronizedMailbox)
755     trojita_test(Imap Imap_Tasks_OpenConnection)
756     trojita_test(Imap Imap_Threading)
757     trojita_test(Imap Imap_BodyParts)
758     trojita_test(Misc Rfc5322)
759     trojita_test(Misc RingBuffer)
760     trojita_test(Misc SenderIdentitiesModel)
761     trojita_test(Misc SqlCache)
762     trojita_test(Misc algorithms)
763     trojita_test(Misc rfccodecs)
764 endif()
766 if(WIN32) # Check if we are on Windows
767     if(MSVC10) # Check if we are using the Visual Studio compiler 2010
768         # Because of linker errors (see http://stackoverflow.com/questions/5625884/conversion-of-stdwstring-to-qstring-throws-linker-error)
769         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:wchar_t-")
770     elseif(MINGW)
771     else()
772         message(WARNING "You are using a compiler which we have not tested yet (not MSVC10 or MINGW).")
773         message(WARNING "Please let us know how well it works.")
774     endif()
775 endif()
777 # FIXME: fix build warnings