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

cmake_minimum_required( VERSION 2.8 )


##### general package setup #####################

project( tdemultimedia )

set( PACKAGE tdemultimedia )
set( VERSION R14.1.0 )

enable_testing( )


##### include essential cmake modules ###########

include( FindPkgConfig )
include( CheckIncludeFile )
include( CheckIncludeFileCXX )
include( CheckTypeSize )
include( CheckCSourceCompiles )
include( CheckCXXSourceCompiles )
include( CheckFunctionExists )
include( CheckLibraryExists )
include( CheckSymbolExists )


##### include our cmake modules #################

set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules" )
include( TDEMacros )


##### setup install paths #######################

include( TDESetupPaths )
tde_setup_paths( )


##### optional stuff ############################

OPTION( WITH_ALL_OPTIONS "Enable all optional support" OFF )
option( WITH_ALSA "Enable ALSA support (kscd, kmix)" ON )
option( WITH_ARTS_AKODE "Enable aRts akode plugin" ${WITH_ALL_OPTIONS} )
option( WITH_ARTS_AUDIOFILE "Enable aRts audiofile plugin" ${WITH_ALL_OPTIONS} )
option( WITH_ARTS_MPEGLIB "Enable aRts mpeglib pluing" ${WITH_ALL_OPTIONS} )
option( WITH_ARTS_XINE "Enable aRts xine plugin" ${WITH_ALL_OPTIONS} )
option( WITH_CDPARANOIA "Enable CDParanoia support (mpeglib, tdeioslave-audiocd)" ${WITH_ALL_OPTIONS} )
option( WITH_FLAC "Enable FLAC support (tdeioslave)" ${WITH_ALL_OPTIONS} )
option( WITH_GSTREAMER "Enable gstreamer support (juk)" ${WITH_ALL_OPTIONS} )
option( WITH_KSCD_CDDA "Enable cdda support in kscd" ${WITH_ALL_OPTIONS} )
option( WITH_LAME "Enable lame support (krec)" ${WITH_ALL_OPTIONS} )
option( WITH_MUSICBRAINZ "Enable MusicBrainz support (juk)" OFF )
option( WITH_TAGLIB "Enable taglib support (juk, tdefile-plugins)" ${WITH_ALL_OPTIONS} )
option( WITH_THEORA "Enable Ogg/Theora support (tdefile-plugins)" ${WITH_ALL_OPTIONS} )
option( WITH_VORBIS "Enable Ogg/Vorbis support (krec, mpeglib, oggarts, tdefile-plugins)" ${WITH_ALL_OPTIONS} )


##### user requested modules ####################

option( BUILD_ALL "Build all" OFF )
option( BUILD_ARTS "Build aRts" ${BUILD_ALL} )
option( BUILD_DOC "Build documentation" ${BUILD_ALL} )
option( BUILD_JUK "Build Juk player" ${BUILD_ALL} )
option( BUILD_KABOODLE "Build Kaboodle video player" ${BUILD_ALL} )
option( BUILD_KAPPFINDER_DATA "Build data for kappfinder" ${BUILD_ALL} )
option( BUILD_KAUDIOCREATOR "Build KAudio Creator" ${BUILD_ALL} )
option( BUILD_KMIX "Build kmix" ${BUILD_ALL} )
option( BUILD_KREC "Build krec" ${BUILD_ALL} )
option( BUILD_KSCD "Build kscd player" ${BUILD_ALL} )
option( BUILD_LIBKCDDB "Build kcddb library" ${BUILD_ALL} )
option( BUILD_MPEGLIB "Build mpeg library" ${BUILD_ALL} )
option( BUILD_NOATUN "Build noatun player" ${BUILD_ALL} )
option( BUILD_TDEFILE_PLUGINS "Build tdefile plugins" ${BUILD_ALL} )
option( BUILD_TDEIOSLAVE "Build tdeio slave plugins" ${BUILD_ALL} )
option( BUILD_TDEMID "Build tdemid" ${BUILD_ALL} )


##### configure checks ##########################

include( ConfigureChecks.cmake )


###### global compiler settings #################

add_definitions(
  -DHAVE_CONFIG_H
)

set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TQT_CXX_FLAGS}" )
set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined" )
set( CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined" )


##### activate dependencies #####################


##### tdemultimedia directories ########################

if( BUILD_MPEGLIB ) # must be before mpeglib_artsplug
  if( NOT BUILD_ARTS )
    tde_message_fatal( "mpeglib can not be built without building arts" )
  endif( )
  add_subdirectory( mpeglib )
endif( BUILD_MPEGLIB )
if( BUILD_ARTS )
  add_subdirectory( arts )
  tde_conditional_add_subdirectory( WITH_ARTS_AKODE akode_artsplugin )
  tde_conditional_add_subdirectory( WITH_ARTS_AUDIOFILE audiofile_artsplugin )
  if( WITH_ARTS_MPEGLIB )
    if( NOT BUILD_MPEGLIB )
      tde_message_fatal( "mpeglib aRts plugin can not be built without building mpeglib" )
    endif( )
    add_subdirectory( mpeglib_artsplug )
  else( WITH_ARTS_MPEGLIB )
    tde_conditional_add_subdirectory( WITH_VORBIS oggvorbis_artsplugin )
  endif( WITH_ARTS_MPEGLIB )
  tde_conditional_add_subdirectory( WITH_ARTS_XINE xine_artsplugin )
endif( BUILD_ARTS )
tde_conditional_add_subdirectory( BUILD_DOC doc )
tde_conditional_add_subdirectory( BUILD_JUK juk )
tde_conditional_add_subdirectory( BUILD_KABOODLE kaboodle )
tde_conditional_add_subdirectory( BUILD_KAPPFINDER_DATA kappfinder-data )
if( BUILD_KAUDIOCREATOR )
  if( NOT BUILD_KSCD )
    tde_message_fatal( "kaudiocreator can not be built without building kscd" )
  endif( )
  add_subdirectory( kaudiocreator )
endif( BUILD_KAUDIOCREATOR )
tde_conditional_add_subdirectory( BUILD_KMIX kmix )
if( BUILD_KREC )
  if( NOT BUILD_ARTS )
    tde_message_fatal( "krec can not be built without building arts" )
  endif( )
  add_subdirectory( krec )
endif( BUILD_KREC )
tde_conditional_add_subdirectory( BUILD_KSCD kscd )
tde_conditional_add_subdirectory( BUILD_LIBKCDDB libkcddb )
tde_conditional_add_subdirectory( BUILD_NOATUN noatun )
tde_conditional_add_subdirectory( BUILD_TDEFILE_PLUGINS tdefile-plugins )
tde_conditional_add_subdirectory( BUILD_TDEIOSLAVE tdeioslave )
tde_conditional_add_subdirectory( BUILD_TDEMID tdemid )


##### write configure files #####################

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


##### add apidox targets ############

add_custom_target(apidox
  COMMAND "./generate_apidox" "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" "${HTML_INSTALL_DIR}" "/usr/share/qt3/doc/html"
  WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/cmake/")

add_custom_target(install-apidox
  COMMAND "./install_apidox" "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" "${HTML_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}"
  WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/cmake/")