#################################################
#
#  (C) 2010-2011 Serghei Amelian
#  serghei (DOT) amelian (AT) gmail.com
#
#  Improvements and feedback are welcome
#
#  This file is released under GPL >= 2
#
#################################################

project( kmail )

if( WITH_INDEXLIB )
  tde_import( indexlib )
  add_definitions( -DHAVE_INDEXLIB )
  set( INDEX_LIBRARY index-shared )
endif( )

tde_import( libtdenetwork )
tde_import( certmanager )
tde_import( ktnef )
tde_import( libkcal )
tde_import( libkmime )
tde_import( libkpgp )
tde_import( libtdepim )
tde_import( mimelib )
tde_import( libkpimidentities )
tde_import( libksieve )

set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions" )

add_subdirectory( interfaces )
add_subdirectory( about )
add_subdirectory( pics )
add_subdirectory( profiles )
add_subdirectory( avscripts )
add_subdirectory( konqueror )

include_directories(
  ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_BINARY_DIR}
  ${CMAKE_SOURCE_DIR}
  ${CMAKE_SOURCE_DIR}/libemailfunctions
  ${CMAKE_SOURCE_DIR}/mimelib
  ${CMAKE_SOURCE_DIR}/libkmime
  ${CMAKE_SOURCE_DIR}/libtdepim
  ${CMAKE_SOURCE_DIR}/libkpgp
  ${CMAKE_SOURCE_DIR}/libtdenetwork
  ${CMAKE_SOURCE_DIR}/certmanager/lib
  ${CMAKE_SOURCE_DIR}/libksieve
  ${CMAKE_SOURCE_DIR}/ktnef
  ${CMAKE_SOURCE_DIR}/korganizer
  ${TDE_INCLUDE_DIR}
  ${TQT_INCLUDE_DIRS}
  ${GPGME_INCLUDE_DIRS}
)

link_directories(
  ${TQT_LIBRARY_DIRS}
)


##### headers ###################################

install( FILES
    kmailIface.h kmailpartIface.h kmailicalIface.h
  DESTINATION ${INCLUDE_INSTALL_DIR} )


##### other data ################################

tde_install_icons( )

tde_create_translated_desktop(
  SOURCE KMail.desktop kmail_view.desktop
  PO_DIR kmail-desktops
)

tde_create_translated_desktop(
  SOURCE eventsrc
  DESTINATION ${DATA_INSTALL_DIR}/kmail
  PO_DIR kmail-eventsrc
)

install(
  FILES kmcomposerui.rc kmmainwin.rc kmreadermainwin.rc kmail_part.rc
  DESTINATION ${DATA_INSTALL_DIR}/kmail
)

install( FILES
    kmail.upd
  DESTINATION ${KCONF_UPDATE_INSTALL_DIR} )

install( PROGRAMS
    upgrade-transport.pl kmail-pgpidentity.pl
    upgrade-signature.pl kmail-upd-identities.pl
    kmail-3.1-use-UOID-for-identities.pl
    kmail-3.1-update-new-mail-notification-settings.pl
    kmail-3.1.4-dont-use-UOID-0-for-any-identity.pl
    kmail-3.2-update-loop-on-goto-unread-settings.sh
    kmail-3.2-misc.sh kmail-3.3-use-ID-for-accounts.pl
    kmail-3.3-move-identities.pl kmail-3.3-aegypten.pl
    kmail-3.3-split-sign-encr-keys.sh kmail-3.3-misc.pl
    kmail-3.3b1-misc.pl kmail-3.4-misc.pl
    kmail-3.4.1-update-status-filters.pl
    kmail-3.5-filter-icons.pl kmail-3.5-trigger-flag-migration.pl
  DESTINATION ${KCONF_UPDATE_INSTALL_DIR} )

install( FILES
    kmail.antispamrc kmail.antivirusrc
  DESTINATION ${CONFIG_INSTALL_DIR} )

install( FILES
    tips
  DESTINATION ${DATA_INSTALL_DIR}/kmail )

tde_create_translated_desktop(
  SOURCE dcopmail.desktop dcopimap.desktop
  DESTINATION ${SERVICETYPES_INSTALL_DIR}
  PO_DIR kmail-desktops
)

tde_create_translated_desktop(
  SOURCE
    kmail_config_misc.desktop kmail_config_appearance.desktop
    kmail_config_identity.desktop kmail_config_accounts.desktop
    kmail_config_composer.desktop kmail_config_security.desktop
  DESTINATION ${SERVICES_INSTALL_DIR}
  PO_DIR kmail-desktops
)

install( FILES
    kmail.kcfg replyphrases.kcfg custommimeheader.kcfg
    templatesconfiguration_kfg.kcfg customtemplates_kfg.kcfg
  DESTINATION ${KCFG_INSTALL_DIR} )

tde_create_translated_desktop(
  SOURCE application_octetstream.desktop
  DESTINATION ${DATA_INSTALL_DIR}/kmail/plugins/bodypartformatter
  PO_DIR kmail-desktops
)


##### kmailprivate (shared) #####################

set( target kmailprivate )

set( ${target}_SRCS
  kmmessage.cpp kmmainwin.cpp configuredialog.cpp configuredialog_p.cpp
  tdelistviewindexedsearchline.cpp simplestringlisteditor.cpp index.cpp headeritem.cpp
  identitydrag.cpp identitylistview.cpp identitydialog.cpp kmfolderdia.cpp kmmsgdict.cpp
  kmfoldertree.cpp kmtransport.cpp kmfoldercombobox.cpp kmaccount.cpp kmheaders.cpp
  kmcomposewin.cpp kmfolder.cpp kmmsgpartdlg.cpp kmreaderwin.cpp htmlstatusbar.cpp
  kmgroupware.cpp folderstorage.cpp listjob.cpp csshelper.cpp tdelistboxdialog.cpp
  kmmsginfo.cpp actionscheduler.cpp messageproperty.cpp accountmanager.cpp kmacctfolder.cpp
  kmdict.cpp kmsystemtray.cpp kmacctlocal.cpp kmfolderdir.cpp kmfoldermgr.cpp
  kmfoldernode.cpp kmsender.cpp kmacctseldlg.cpp kmfiltermgr.cpp kmfilterdlg.cpp
  filterimporterexporter.cpp kmsearchpatternedit.cpp encodingdetector.cpp encodingdetector_ja.cpp
  kmfilteraction.cpp kmsearchpattern.cpp kmfolderimap.cpp kmfolderseldlg.cpp kmfilter.cpp
  kmmsgpart.cpp kmmsgbase.cpp kmmsglist.cpp kmaddrbook.cpp signatureconfigurator.cpp
  xfaceconfigurator.cpp networkaccount.cpp imapaccountbase.cpp popaccount.cpp kmservertest.cpp
  kmacctimap.cpp kmacctcachedimap.cpp kmfawidgets.cpp kmfoldermbox.cpp colorlistbox.cpp
  undostack.cpp kmfoldercachedimap.cpp attachmentstrategy.cpp kmfoldermaildir.cpp
  kmkernel.cpp accountdialog.cpp searchwindow.cpp vcardviewer.cpp vacationdialog.cpp
  vacation.cpp sievedebugdialog.cpp sieveconfig.cpp sievejob.cpp kmpopheaders.cpp
  kmpopfiltercnfrmdlg.cpp kmmimeparttree.cpp mailinglist-magic.cpp kmacctmaildir.cpp
  headerstyle.cpp headerstrategy.cpp tdehtmlparthtmlwriter.cpp filehtmlwriter.cpp
  teehtmlwriter.cpp mailcomposerIface.skel objecttreeparser.cpp objecttreeparser_p.cpp
  attachmentcollector.cpp bodypartformatterfactory.cpp bodypartformatter.cpp partNode.cpp
  mailsourceviewer.cpp kmcommands.cpp kmreadermainwin.cpp kmstartup.cpp kmmainwidget.cpp
  folderpropertiesdialog.ui kmfolderindex.cpp kmfoldersearch.cpp transportmanager.cpp
  imapjob.cpp folderjob.cpp cachedimapjob.cpp maildirjob.cpp mboxjob.cpp subscriptiondialog.cpp
  kmailicalifaceimpl.cpp aboutdata.cpp folderIface.cpp folderIface.skel mailserviceimpl.cpp
  attachmentlistview.cpp kmedit.cpp kmlineeditspell.cpp kmatmlistview.cpp composer.cpp
  isubject.cpp bodyvisitor.cpp antispamwizard.cpp urlhandlermanager.cpp dictionarycombobox.cpp
  secondarywindow.cpp filterlog.cpp filterlogdlg.cpp messagecomposer.cpp keyresolver.cpp
  globalsettings.cpp globalsettings_base.kcfgc regexplineedit.cpp rulewidgethandlermanager.cpp
  headerlistquicksearch.cpp acljobs.cpp folderdiaacltab.cpp quotajobs.cpp expirejob.cpp
  folderdiaquotatab.cpp folderdiaquotatab_p.cpp jobscheduler.cpp partnodebodypart.cpp
  compactionjob.cpp callback.cpp searchjob.cpp renamejob.cpp composercryptoconfiguration.ui
  warningconfiguration.ui smimeconfiguration.ui annotationjobs.cpp accountcombobox.cpp
  redirectdialog.cpp foldershortcutdialog.cpp folderrequester.cpp spamheaderanalyzer.cpp
  antispamconfig.cpp replyphrases.kcfgc custommimeheader.kcfgc recipientseditor.cpp
  recipientspicker.cpp twindowpositioner.cpp textsource.cpp distributionlistdialog.cpp
  expirypropertiesdialog.cpp scalix.cpp mailinglistpropertiesdialog.cpp newfolderdialog.cpp
  accountwizard.cpp managesievescriptsdialog.cpp chiasmuskeyselector.cpp
  util.cpp templatesinsertcommand.cpp customtemplates_base.ui customtemplates.cpp
  customtemplates_kfg.kcfgc templatesconfiguration_base.ui templatesconfiguration.cpp
  templatesconfiguration_kfg.kcfgc templateparser.cpp copyfolderjob.cpp messagecopyhelper.cpp
  localsubscriptiondialog.cpp editorwatcher.cpp favoritefolderview.cpp
  foldertreebase.cpp snippetdlgbase.ui snippetwidget.cpp snippetconfig.cpp
  snippetdlg.cpp snippetitem.cpp snippetsettings.cpp snippetsettingsbase.ui
  messageactions.cpp korghelper.cpp foldersetselector.cpp stringutil.cpp
  treebase.cpp backupjob.cpp importjob.cpp folderutil.cpp archivefolderdialog.cpp
  importarchivedialog.cpp ${CMAKE_SOURCE_DIR}/korganizer/kcalendariface.stub
  ${CMAKE_SOURCE_DIR}/korganizer/korganizeriface.stub )

tde_save( KDE3_DCOPIDL_EXECUTABLE )
set( KDE3_DCOPIDL_EXECUTABLE ${KDE3_DCOPIDLNG_EXECUTABLE} )
tde_add_dcop_skels( ${target}_SRCS kmailIface.h kmailicalIface.h )
tde_restore( KDE3_DCOPIDL_EXECUTABLE )

add_custom_target( kmail_settings_base
  DEPENDS
    ${CMAKE_BINARY_DIR}/kmail/globalsettings_base.h
    ${CMAKE_BINARY_DIR}/kmail/customtemplates_base.h
    ${CMAKE_BINARY_DIR}/kmail/templatesconfiguration_base.h
)

tde_add_library( ${target} SHARED AUTOMOC
  SOURCES ${${target}_SRCS}
  LINK
    kmime-shared kpgp-shared tdepim-shared kpimidentities-shared
    mimelib-shared ksieve-shared tdecore-shared tdehtml-shared ${INDEX_LIBRARY}
  DESTINATION ${LIB_INSTALL_DIR}
  DEPENDENCIES kmail_settings_base
)


##### kmail (executable) ########################

tde_add_executable( kmail
  SOURCES main.cpp
  LINK kmailprivate-shared
  DESTINATION ${BIN_INSTALL_DIR}
)


##### kcm_kmail (module) ########################

tde_add_kpart( kcm_kmail AUTOMOC
  SOURCES kcm_kmail.cpp
  LINK kmailprivate-shared
  DESTINATION ${PLUGIN_INSTALL_DIR}
)


##### libkmailpart (module) #####################

tde_add_kpart( libkmailpart AUTOMOC
  SOURCES kmailpartIface.skel kmail_part.cpp
  LINK kmailprivate-shared
  DESTINATION ${PLUGIN_INSTALL_DIR}
)


##### libkmail_bodypartformatter_application_octetstream (module)

tde_add_kpart( libkmail_bodypartformatter_application_octetstream
  SOURCES app_octetstream.cpp
  LINK ${TQT_LIBRARIES}
  DESTINATION ${PLUGIN_INSTALL_DIR}
)


##### install import cmake modules ###############

tde_install_export( )
