# On Solaris, some of the name resolution functions are in libnsl;
# this needs to be linked in if found. Copied from kdelibs.
check_library_exists(nsl gethostbyname "" HAVE_NSL_LIBRARY)

option(WITH_testbed "Enable Kopete testbed protocol" ON)
option(WITH_oscar "Enable Kopete Oscar (ICQ and AIM) protocol" ON)
option(WITH_yahoo "Enable Kopete Yahoo protocol" ON)
option(WITH_qq "Enable Kopete QQ protocol" ON)
option(WITH_sms "Enable Kopete SMS protocol" ON)
option(WITH_groupwise "Enable Novell GroupWise Messenger protocol" ON)
option(WITH_winpopup "Enable Kopete winpopup protocol" ON)
option(WITH_gadu "Enable Kopete Gadu-Gadu protocol" ON)
option(WITH_jabber "Enable Kopete Jabber protocol" ON)
option(WITH_GOOGLETALK "Enable Kopete Jabber Google Talk support" ON)
option(WITH_bonjour "Enable Kopete Bonjour protocol" ON)
option(WITH_irc "Enable Kopete IRC protocol" OFF)
option(WITH_wlm "Enable Window Live Messenger support" ON)
option(WITH_meanwhile "Enable Kopete meanwhile protocol" ON)
option(WITH_skype "Enable Kopete Skype protocol" ON)

if(LIBORTP_FOUND AND SPEEX_FOUND AND ALSA_FOUND AND WITH_JINGLE)
  message(STATUS "Building jingle support")
  set(BUILD_JINGLE TRUE)
else(LIBORTP_FOUND AND SPEEX_FOUND AND ALSA_FOUND AND WITH_JINGLE)
  message(STATUS "Not building jingle support (recommanded)")
  set(BUILD_JINGLE FALSE)
endif(LIBORTP_FOUND AND SPEEX_FOUND AND ALSA_FOUND AND WITH_JINGLE)

# TODO: remove LIBORTP_FOUND and MEDIASTREAMER_FOUND if google libjingle filetransfer will be supported
if(SSL_FOUND OR WIN32)
  if(EXPAT_FOUND AND LIBORTP_FOUND AND MEDIASTREAMER_FOUND AND WITH_GOOGLETALK)
    message(STATUS "Building Google Talk libjingle support")
    set(BUILD_GOOGLETALK TRUE)
  else(EXPAT_FOUND AND LIBORTP_FOUND AND MEDIASTREAMER_FOUND AND WITH_GOOGLETALK)
    message(STATUS "Not building Google Talk libjingle support")
    set(BUILD_GOOGLETALK FALSE)
  endif(EXPAT_FOUND AND LIBORTP_FOUND AND MEDIASTREAMER_FOUND AND WITH_GOOGLETALK)
else(SSL_FOUND OR WIN32)
  message(STATUS "Not building Google Talk libjingle support")
  set(BUILD_GOOGLETALK FALSE)
endif(SSL_FOUND OR WIN32)

include_directories(${KOPETE_INCLUDES})

if(WITH_wlm AND LIBMSN_FOUND)
  add_subdirectory( wlm )
endif(WITH_wlm AND LIBMSN_FOUND)

if(WITH_oscar)
  add_subdirectory( oscar )
endif(WITH_oscar)
if(WITH_yahoo)
  add_subdirectory( yahoo ) 
endif(WITH_yahoo)
if(WITH_qq)
  add_subdirectory( qq )
endif(WITH_qq)
if(WITH_irc)
  message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}: WARNING: Building the irc plugin, even if  it hasn't been completely ported yet")
  add_subdirectory( irc )
endif(WITH_irc)
if(NOT WIN32)
  if(WITH_winpopup)
    add_subdirectory( winpopup )
  endif(WITH_winpopup)
  if(WITH_gadu AND LIBGADU_FOUND)
    add_subdirectory( gadu )
  endif(WITH_gadu AND LIBGADU_FOUND)
  if(WITH_sms)
    add_subdirectory( sms )
  endif(WITH_sms)
  if(NOT APPLE AND WITH_skype)
    add_subdirectory( skype )
  endif(NOT APPLE AND WITH_skype)
endif(NOT WIN32)

if(QCA2_FOUND)
  if(IDN_FOUND)
    if(WITH_jabber)
      add_subdirectory( jabber )
    endif(WITH_jabber)
  else(IDN_FOUND)
    message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}: Disabled Jabber because libidn-devel was not found")
  endif(IDN_FOUND)
  if(WITH_groupwise)
    add_subdirectory( groupwise )
  endif(WITH_groupwise)
else(QCA2_FOUND)
  message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}: Disabled GroupWise and Jabber because QCA2 was not found")
endif(QCA2_FOUND)

if(WITH_testbed)
  add_subdirectory( testbed )
endif(WITH_testbed)

if(WITH_bonjour)
  add_subdirectory( bonjour )
endif(WITH_bonjour)

if(WITH_meanwhile)
  if(LIBMEANWHILE_FOUND)
    add_subdirectory( meanwhile )
  else(LIBMEANWHILE_FOUND)
    message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}: Disabled Meanwhile beause libmeanwhile was not found")
  endif(LIBMEANWHILE_FOUND)
endif(WITH_meanwhile)

