############################################
#                                          #
#  Improvements and feedbacks are welcome  #
#                                          #
#  This file is released under GPL >= 3    #
#                                          #
############################################


##### set project version ########################

include( TDEVersion )
cmake_minimum_required( VERSION ${TDE_CMAKE_MINIMUM_VERSION} )
tde_set_project_version( )


#### general package setup

project( kvirc )
set( PACKAGE_VERSION 3.4.0 )


#### include essential cmake modules

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


#### include our cmake modules

include( TDEMacros )


##### setup install paths

include( TDESetupPaths )
tde_setup_paths( )


##### optional stuff

option( WITH_ALL_OPTIONS    "Enable all optional support"                                    ON )
option( WITH_TDE            "Build with TDE integration instead of TQt"                      ON )

option( WITH_ARTS           "Build aRts integration"                        ${WITH_ALL_OPTIONS} )
option( WITH_AUDIOFILE      "Build audiofile support (require OSS support)" ${WITH_ALL_OPTIONS} )
option( WITH_BIG_CHANNELS   "Optimize for big channels"                     ${WITH_ALL_OPTIONS} )
option( WITH_CRYPT          "Build cryptography support"                    ${WITH_ALL_OPTIONS} )
option( WITH_DCC_VOICE      "Build DCC voice support (require OSS support)" ${WITH_ALL_OPTIONS} )
option( WITH_DYN_LABELS     "Enable dynamic label support"                                  OFF )
option( WITH_ESD            "Build ESound Daemon support"                                   OFF )
option( WITH_GSM            "Build with GSM support"                        ${WITH_ALL_OPTIONS} )
option( WITH_INFO_TIPS      "Build info tip support"                        ${WITH_ALL_OPTIONS} )
option( WITH_IPC            "Build inter-process communication support"     ${WITH_ALL_OPTIONS} )
option( WITH_IPV6           "Build with IP v6 support"                      ${WITH_ALL_OPTIONS} )
# The behavior of the following option is partially affected by WITH_SYSTEM_MEMMOVE settings
option( WITH_ix86_ASM       "Build with ix86 assembly optimization"         ${WITH_ALL_OPTIONS} )
option( WITH_MEMORY_CHECKS  "Build malloc memory check support"                             OFF )
option( WITH_MEMORY_PROFILE "Build memory profiling support"                                OFF )
option( WITH_NO_SIGALARM    "Ignore SIGALARM signal"                                        OFF )
option( WITH_OSS            "Build with OSS support"                        ${WITH_ALL_OPTIONS} )
option( WITH_PERL           "Build with Perl support"                       ${WITH_ALL_OPTIONS} )
option( WITH_SSL            "Build with SSL support"                        ${WITH_ALL_OPTIONS} )
option( WITH_SYSTEM_MEMMOVE "Use system memmove and memcpy"                                  ON )
option( WITH_TRANSPARENCY   "Build pseudo transparency support"             ${WITH_ALL_OPTIONS} )
option( WITH_XSCREENSAVER   "Build with XScreensaver support"                                ON )
option( WITH_ZLIB           "Build with zlib support"                       ${WITH_ALL_OPTIONS} )

option( WITH_GCC_VISIBILITY "Enable fvisibility and fvisibility-inlines-hidden" ${WITH_ALL_OPTIONS} )


##### user requested modules

option( BUILD_ALL          "Build all"           ON           )
option( BUILD_DOC          "Build documentation" ${BUILD_ALL} )
option( BUILD_TRANSLATIONS "Build translations"  ${BUILD_ALL} )


##### configure checks

include( ConfigureChecks.cmake )


###### global compiler settings

add_definitions( -DHAVE_CONFIG_H )
add_definitions( -UTQT_NO_TRANSLATION )

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


##### directories

add_subdirectory( data )
add_subdirectory( icons )
add_subdirectory( pics )
add_subdirectory( src )


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

tde_conditional_add_subdirectory( BUILD_DOC doc )
# When building without TDE support, the locale files are placed
# in a subfolder of the application folder.
if( NOT WITH_TDE )
  set( LOCALE_INSTALL_DIR "${DATA_INSTALL_DIR}/${PROJECT_NAME}/locale" )
endif( )
tde_conditional_add_project_translations( BUILD_TRANSLATIONS )


##### write configure files

configure_file( config.h.cmake config.h @ONLY )
install(
  FILES ${CMAKE_BINARY_DIR}/config.h
  RENAME kvi_configstatus.h
  DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}
)
