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

# Possible options:
# - WITH_EGROUPWARE
# - WITH_SLOX
# - WITH_KOLAB
# - WITH_NEWEXCHANGE
# - WITH_GROUPWISE
# - WITH_SCALIX

tde_import( libkmime )
tde_import( ktnef )
tde_import( libkcal )
tde_import( libtdepim )
tde_import( knotes )
tde_import( tderesources )

if( WITH_KOLAB OR WITH_GROUPWISE OR WITH_SCALIX )
  tde_import( libtdenetwork )
  tde_import( certmanager )
  tde_import( libkpimidentities )
endif()

include_directories(
  ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_BINARY_DIR}
  ${CMAKE_SOURCE_DIR}
  ${CMAKE_SOURCE_DIR}/libkpimidentities
  ${CMAKE_SOURCE_DIR}/libtdepim
  ${CMAKE_SOURCE_DIR}/certmanager/lib
  ${CMAKE_SOURCE_DIR}/knotes
  ${CMAKE_SOURCE_DIR}/tderesources/lib
  ${TDE_INCLUDE_DIR}
  ${TQT_INCLUDE_DIRS}
)

link_directories(
  ${TQT_LIBRARY_DIRS}
)


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

tde_create_translated_desktop( groupwarewizard.desktop )


##### helper ####################################

macro( process_kcfg _who _out _path _kcfg _kcfgc )
  add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_path}/${_out}
    COMMAND
      mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/${_path}
    COMMAND ${KDE3_KCFGC_EXECUTABLE}
      -d ${CMAKE_CURRENT_BINARY_DIR}/${_path}
      ${CMAKE_SOURCE_DIR}/${_path}/${_kcfg}
      ${CMAKE_SOURCE_DIR}/${_path}/${_kcfgc}
    DEPENDS
      ${CMAKE_SOURCE_DIR}/${_path}/${_kcfg}
      ${CMAKE_SOURCE_DIR}/${_path}/${_kcfgc} )
  set_property( SOURCE ${_who} APPEND
    PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_path}/${_out} )
endmacro()


######## egroupwarewizard #######################

if( WITH_EGROUPWARE )

  install( FILES egroupware.kcfg DESTINATION ${KCFG_INSTALL_DIR} )

  process_kcfg( egroupwarewizard.cpp tdeabc_egroupwareprefs.h tderesources/egroupware
    tderesources_tdeabc_egroupware.kcfg tdeabc_egroupwareprefs.kcfgc )

  process_kcfg( egroupwarewizard.cpp kcal_egroupwareprefs.h tderesources/egroupware
    tderesources_kcal_egroupware.kcfg kcal_egroupwareprefs.kcfgc )

  process_kcfg( egroupwarewizard.cpp knotes_egroupwareprefs.h tderesources/egroupware
    tderesources_knotes_egroupware.kcfg knotes_egroupwareprefs.kcfgc )

  tde_add_library( egroupwarewizard SHARED NO_EXPORT
    SOURCES
      egroupwarewizard.cpp egroupwareconfig.kcfgc
    LINK kcal_xmlrpc-shared tdeabc_xmlrpc-shared knotes_xmlrpc-shared
    DESTINATION ${PLUGIN_INSTALL_DIR} )

  tde_add_executable( egroupwarewizard
    SOURCES egroupwaremain.cpp
    LINK egroupwarewizard-shared
    DESTINATION ${BIN_INSTALL_DIR} )

  set( EGROUPWAREWIZARD_LIBRARY egroupwarewizard-shared )

endif()


######## sloxwizard #############################

if( WITH_SLOX )

  install( FILES slox.kcfg DESTINATION ${KCFG_INSTALL_DIR} )

  process_kcfg( sloxwizard.cpp tdeabcsloxprefs.h tderesources/slox
    tderesources_tdeabc_slox.kcfg tdeabcsloxprefs.kcfgc )

  process_kcfg( sloxwizard.cpp kcalsloxprefs.h tderesources/slox
    tderesources_kcal_slox.kcfg kcalsloxprefs.kcfgc )

  tde_add_library( sloxwizard SHARED NO_EXPORT
    SOURCES
      sloxwizard.cpp sloxconfig.kcfgc
    LINK kcal_slox-shared tdeabc_slox-shared
    DESTINATION ${PLUGIN_INSTALL_DIR} )

  tde_add_executable( sloxwizard
    SOURCES sloxmain.cpp
    LINK sloxwizard-shared
    DESTINATION ${BIN_INSTALL_DIR} )

  set( SLOXWIZARD_LIBRARY sloxwizard-shared )

endif()


######## kolabwizard ############################

if( WITH_KOLAB )

  install( FILES kolab.kcfg DESTINATION ${KCFG_INSTALL_DIR} )

  tde_add_library( kolabwizard SHARED NO_EXPORT
    SOURCES
      kolabwizard.cpp kmailchanges.cpp kolabconfig.kcfgc
      kolabkmailchanges.cpp
    LINK
      kcalkolab-shared tdeabckolab-shared knoteskolab-shared
      kpimidentities-shared
    DESTINATION ${PLUGIN_INSTALL_DIR} )

  tde_add_executable( kolabwizard
    SOURCES kolabmain.cpp
    LINK kolabwizard-shared
    DESTINATION ${BIN_INSTALL_DIR} )

  set( KOLABWIZARD_LIBRARY kolabwizard-shared )

endif( )


######## exchangewizard #########################

if( WITH_NEWEXCHANGE )

  tde_add_library( exchangewizard SHARED NO_EXPORT
    SOURCES exchangewizard.cpp
    LINK kcal_newexchange-shared
    DESTINATION ${PLUGIN_INSTALL_DIR} )

  tde_add_executable( exchangewizard
    SOURCES exchangemain.cpp
    LINK exchangewizard-shared
    DESTINATION ${BIN_INSTALL_DIR} )

  set( EXCHANGEWIZARD_LIBRARY exchangewizard-shared )

endif()


######## groupwisewizard ########################

if( WITH_GROUPWISE )

  install( FILES groupwise.kcfg DESTINATION ${KCFG_INSTALL_DIR} )

  process_kcfg( groupwisewizard.cpp kcal_groupwiseprefsbase.h tderesources/groupwise
    tderesources_kcal_groupwise.kcfg kcal_groupwiseprefsbase.kcfgc )

  process_kcfg( groupwisewizard.cpp tdeabc_groupwiseprefs.h tderesources/groupwise
    tderesources_tdeabc_groupwise.kcfg tdeabc_groupwiseprefs.kcfgc )

  tde_add_library( groupwisewizard SHARED AUTOMOC NO_EXPORT
    SOURCES
      groupwisewizard.cpp groupwiseconfig.kcfgc kmailchanges.cpp
    LINK kcal_groupwise-shared tdeabc_groupwise-shared kpimidentities-shared
    DESTINATION ${PLUGIN_INSTALL_DIR} )

  tde_add_executable( groupwisewizard
    SOURCES groupwisemain.cpp
    LINK groupwisewizard-shared
    DESTINATION ${BIN_INSTALL_DIR} )

endif()


######## scalixwizard ###########################

if( WITH_SCALIX )

  install( FILES scalix.kcfg DESTINATION ${KCFG_INSTALL_DIR} )

  tde_add_library( scalixwizard SHARED NO_EXPORT
    SOURCES
      scalixwizard.cpp kmailchanges.cpp scalixconfig.kcfgc
      scalixkmailchanges.cpp
    LINK kcalscalix-shared tdeabcscalix-shared kpimidentities-shared
    DESTINATION ${PLUGIN_INSTALL_DIR} )

  tde_add_executable( scalixwizard
    SOURCES scalixmain.cpp
    LINK scalixwizard-shared
    DESTINATION ${BIN_INSTALL_DIR} )

endif()


##### groupwarewizard (executable) ##############

if( WITH_EGROUPWARE OR WITH_SLOX OR WITH_KOLAB OR WITH_NEWEXCHANGE )

  configure_file( wizards-config.h.cmake wizards-config.h @ONLY )

  tde_add_executable( groupwarewizard AUTOMOC
    SOURCES
      groupwarewizard.cpp main.cpp overviewpage.cpp
    LINK
      ${EGROUPWAREWIZARD_LIBRARY} ${SLOXWIZARD_LIBRARY}
      ${KOLABWIZARD_LIBRARY} ${EXCHANGEWIZARD_LIBRARY}
    DESTINATION ${BIN_INSTALL_DIR} )

endif()
