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

cmake_minimum_required( VERSION 3.1 )


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

project( tdevelop )


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

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


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

include( TDEMacros )


##### set version number ########################

tde_set_project_version( )


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

include( TDESetupPaths )
tde_setup_paths( )


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

if( "${CMAKE_VERSION}" VERSION_LESS "3.1" )
  set( CMAKE_ENV "env" )
else()
  set( CMAKE_ENV "${CMAKE_COMMAND};-E;env" )
endif()

add_custom_target( apidox
  COMMAND ${CMAKE_ENV}
    "QTDOCDIR=/usr/share/tqt3/doc/html"
    "DOXDATA=${HTML_INSTALL_DIR}/en/common"
    ${CMAKE_SOURCE_DIR}/admin/doxygen.sh
    --no-modulename
    ${CMAKE_SOURCE_DIR}
  COMMAND
    find ${CMAKE_BINARY_DIR}/apidocs -name '*.html' |
    xargs -r sed -i 's|${CMAKE_BINARY_DIR}/apidocs|${HTML_INSTALL_DIR}/en/${PROJECT_NAME}-apidocs|g'
  COMMAND
    find ${CMAKE_BINARY_DIR}/apidocs -name '*.tag' |
    xargs -r sed -i 's|${CMAKE_SOURCE_DIR}/|${PROJECT_NAME}/|g'
  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

add_custom_target( install-apidox
  COMMAND ${CMAKE_COMMAND} -E echo Apidox installed in ${HTML_INSTALL_DIR}/en/${PROJECT_NAME}-apidocs
)

install( CODE "
  if( EXISTS ${CMAKE_BINARY_DIR}/apidocs )
    file(
      INSTALL ${CMAKE_BINARY_DIR}/apidocs/
      DESTINATION ${HTML_INSTALL_DIR}/en/${PROJECT_NAME}-apidocs
      PATTERN doxygen_sqlite3.db EXCLUDE
      PATTERN installdox-slow EXCLUDE
    )
  endif()"
)


##### build tools ###############################

option( WITH_BUILDTOOL_ALL "Enable all build tools" OFF )
option( WITH_BUILDTOOL_ADA "Enable ada build tool" ${WITH_BUILDTOOL_ALL} )
option( WITH_BUILDTOOL_ANT "Enable ant build tool" ${WITH_BUILDTOOL_ALL} )
option( WITH_BUILDTOOL_AUTOTOOLS "Enable autotools build tool" ${WITH_BUILDTOOL_ALL} )
option( WITH_BUILDTOOL_CUSTOMMAKEFILES "Enable custommakefiles build tool" ${WITH_BUILDTOOL_ALL} )
option( WITH_BUILDTOOL_PASCAL "Enable pascal build tool" ${WITH_BUILDTOOL_ALL} )
option( WITH_BUILDTOOL_QMAKE "Enable qmake build tool" ${WITH_BUILDTOOL_ALL} )
option( WITH_BUILDTOOL_SCRIPT "Enable script build tool" ${WITH_BUILDTOOL_ALL} )


##### languages #################################

option( WITH_LANGUAGE_ALL "Enable all languages" OFF )
option( WITH_LANGUAGE_ADA "Enable ada language" ${WITH_LANGUAGE_ALL} )
option( WITH_LANGUAGE_BASH "Enable bash language" ${WITH_LANGUAGE_ALL} )
option( WITH_LANGUAGE_CPP "Enable cpp language" ${WITH_LANGUAGE_ALL} )
option( WITH_LANGUAGE_FORTRAN "Enable fortran language" ${WITH_LANGUAGE_ALL} )
option( WITH_LANGUAGE_JAVA "Enable java language" ${WITH_LANGUAGE_ALL} )
option( WITH_LANGUAGE_CSHARP "Enable csharp language" ${WITH_LANGUAGE_ALL} )
option( WITH_LANGUAGE_PASCAL "Enable pascal language" ${WITH_LANGUAGE_ALL} )
option( WITH_LANGUAGE_PERL "Enable perl language" ${WITH_LANGUAGE_ALL} )
option( WITH_LANGUAGE_PHP "Enable php language" ${WITH_LANGUAGE_ALL} )
option( WITH_LANGUAGE_PYTHON "Enable python language" ${WITH_LANGUAGE_ALL} )
option( WITH_LANGUAGE_RUBY "Enable ruby language" ${WITH_LANGUAGE_ALL} )
option( WITH_LANGUAGE_SQL "Enable sql language" ${WITH_LANGUAGE_ALL} )


##### version control systems ###################

option( WITH_VCS_ALL "Enable all version control systems"  OFF )
option( WITH_VCS_CLEARCASE "Enable clearcase support" ${WITH_VCS_ALL} )
option( WITH_VCS_CVSSERVICE "Enable cvsservice support" ${WITH_VCS_ALL} )
option( WITH_VCS_PERFORCE "Enable perforce support" ${WITH_VCS_ALL} )
option( WITH_VCS_SUBVERSION "Enable subversion support" ${WITH_VCS_ALL} )


##### components ################################

option( BUILD_ALL "Build all components" OFF )
option( BUILD_KDEVDESIGNER "Build kdevdesigner" ${BUILD_ALL} )
option( BUILD_VISUALBOYADVANCE "Build embedded/visualboyadvance" ${BUILD_ALL} )
option( BUILD_DOC "Build doc" ${BUILD_ALL} )


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

option( WITH_DEPRECATION "Enable deprecation warnings" OFF )


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

include( ConfigureChecks.cmake )


##### various definitions #######################

if( NOT DEFINED QT_DOCDIR )
  find_path( QT_DOCDIR index.html
    ${QTDIR}/doc/html
    $ENV{QTDIR}/doc/html )
  if( NOT QT_DOCDIR )
    set( QT_DOCDIR "QT_DOCDIR is not set" )
  endif( )
endif( )

if( NOT DEFINED TDELIBS_DOXYDIR )
  set( TDELIBS_DOXYDIR "${TDE_HTML_DIR}/en/tdelibs-apidocs" )
endif( )


if( NOT DEFINED FULL_MAKE_COMMAND )
  find_program( FULL_MAKE_COMMAND
    NAMES gmake )
  if( NOT FULL_MAKE_COMMAND )
    find_program( FULL_MAKE_COMMAND
      NAMES make )
    if( NOT FULL_MAKE_COMMAND )
      tde_message_fatal( "Either make or gmake was NOT found." )
    endif( NOT FULL_MAKE_COMMAND )
  endif( NOT FULL_MAKE_COMMAND )
endif( NOT DEFINED FULL_MAKE_COMMAND )


if( NOT DEFINED MAKE_COMMAND )
  GET_FILENAME_COMPONENT( MAKE_COMMAND "${FULL_MAKE_COMMAND}" NAME )
endif( NOT DEFINED MAKE_COMMAND )


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

add_definitions(
  -DHAVE_CONFIG_H
  ${TQT_CFLAGS_OTHER}
)

if( NOT WITH_DEPRECATION )
  set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated" )
endif( )

set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include tqt.h" )
set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" )
set( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined" )


##### install data ##############################

tde_create_translated_desktop(
  SOURCE
    tdevelop.desktop kdevassistant.desktop tdevelop_ruby.desktop
    tdevelop_c_cpp.desktop tdevelop_kde_cpp.desktop
    tdevelop_scripting.desktop
  PO_DIR tdevelop-desktops
)

tde_create_translated_desktop(
  SOURCE tde-development-tdevelop.directory
  DESTINATION ${XDG_DIRECTORY_INSTALL_DIR}
  PO_DIR tdevelop-desktops
)

tde_create_translated_desktop(
  SOURCE x-tdevelop.desktop
  DESTINATION ${MIME_INSTALL_DIR}/application
  PO_DIR tdevelop-desktops
)

install( PROGRAMS
    kdevprj2kdevelop
  DESTINATION ${BIN_INSTALL_DIR} )


##### source directories ########################

add_subdirectory( lib )
add_subdirectory( src )
add_subdirectory( parts )
add_subdirectory( buildtools )
add_subdirectory( editors )
add_subdirectory( languages )
add_subdirectory( mimetypes )
add_subdirectory( pics )
add_subdirectory( vcs )
add_subdirectory( embedded )
tde_conditional_add_subdirectory( BUILD_KDEVDESIGNER kdevdesigner )
tde_conditional_add_subdirectory( BUILD_DOC doc )


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

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