# SELF-CONTAINED SUBMODULES, FOR PREPARATION OF MIGRATION TO GIT

# Using macro_optional_add_subdirectory(...) does not work, because that
# needs at least "include(MacroLibrary)" before. But that would defeat the goal
# to only include the submodules here and do nothing else.
# So we create our own clone of macro_optional_add_subdirectory here,
# to continue support for everybody who does not have a complete checkout of
# the KDESDK module

# clone of macro_optional_add_subdirectory(...)
# Copyright (c) 2007, Alexander Neundorf, <neundorf@kde.org>
MACRO (KDESDK_OPTIONAL_ADD_SUBDIRECTORY _dir )
   GET_FILENAME_COMPONENT(_fullPath ${_dir} ABSOLUTE)
   IF(EXISTS ${_fullPath}/CMakeLists.txt)
      IF(DISABLE_ALL_OPTIONAL_SUBDIRECTORIES)
         SET(_DEFAULT_OPTION_VALUE FALSE)
      ELSE(DISABLE_ALL_OPTIONAL_SUBDIRECTORIES)
         SET(_DEFAULT_OPTION_VALUE TRUE)
      ENDIF(DISABLE_ALL_OPTIONAL_SUBDIRECTORIES)

      IF(DISABLE_ALL_OPTIONAL_SUBDIRS  AND NOT DEFINED  BUILD_${_dir})
         SET(_DEFAULT_OPTION_VALUE FALSE)
      ENDIF(DISABLE_ALL_OPTIONAL_SUBDIRS  AND NOT DEFINED  BUILD_${_dir})

      OPTION(BUILD_${_dir} "Build directory ${_dir}" ${_DEFAULT_OPTION_VALUE})
      IF(BUILD_${_dir})
         ADD_SUBDIRECTORY(${_dir})
      ENDIF(BUILD_${_dir})
   ENDIF(EXISTS ${_fullPath}/CMakeLists.txt)
ENDMACRO (KDESDK_OPTIONAL_ADD_SUBDIRECTORY)

cmake_minimum_required(VERSION 2.6)
project(kdesdk)

# list of self-contained submodules
kdesdk_optional_add_subdirectory(kapptemplate)
kdesdk_optional_add_subdirectory(dolphin-plugins)
kdesdk_optional_add_subdirectory(okteta)
kdesdk_optional_add_subdirectory(umbrello)
# kcachegrind is usable on Windows for XDebug etc.
kdesdk_optional_add_subdirectory(kcachegrind)

if( UNIX )
  kdesdk_optional_add_subdirectory(cervisia)
endif( UNIX )

############################
# START OF OLD MODULE SETUP

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules )


# search packages used by KDE
find_package(KDE4 REQUIRED)
include(KDE4Defaults)
include(MacroLibrary)
include(CheckIncludeFile)
include(CheckIncludeFileCXX)
include(CheckLibraryExists)
include(CheckCSourceCompiles)

macro_optional_find_package(KdepimLibs)

# The FindKDE4.cmake module sets _KDE4_PLATFORM_DEFINITIONS with
# definitions like _GNU_SOURCE that are needed on each platform.
set(CMAKE_REQUIRED_DEFINITIONS ${_KDE4_PLATFORM_DEFINITIONS} -DQT_STRICT_ITERATORS)

find_package(Strigi REQUIRED)

macro_optional_find_package(HUNSPELL)
macro_log_feature(HUNSPELL_FOUND "HUNSPELL" "Library used for stemming" "http://hunspell.sourceforge.net/" FALSE "" "Required to build Lokalize.")

add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)

include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES} ${KDEPIMLIBS_INCLUDE_DIR})

if(HUNSPELL_FOUND OR WIN32)
  macro_optional_add_subdirectory(lokalize)
endif(HUNSPELL_FOUND OR WIN32)

macro_optional_add_subdirectory(kpartloader)
macro_optional_add_subdirectory(strigi-analyzer)
macro_optional_add_subdirectory(kioslave)

check_c_source_compiles("
#include <stdlib.h>

int main() {
#ifndef __GLIBC__
  choke me
#endif
  return 0;
}" LIBC_IS_GLIBC)
if (LIBC_IS_GLIBC)
  macro_optional_add_subdirectory(kmtrace)
endif ()

macro_optional_add_subdirectory(kompare)
macro_optional_add_subdirectory(kprofilemethod)

# By default in kde3 kstartpref was not compiled, but well, if it compiles...
check_include_file(ltdl.h HAVE_LTDL_H)
if(HAVE_LTDL_H AND NOT APPLE AND NOT WIN32)
  macro_optional_add_subdirectory(kstartperf)
endif(HAVE_LTDL_H AND NOT APPLE AND NOT WIN32)

macro_optional_add_subdirectory(kuiviewer)
macro_optional_add_subdirectory(poxml)
macro_optional_add_subdirectory(scripts)
macro_optional_add_subdirectory(thumbnailers)

macro_optional_add_subdirectory(doc)
macro_display_feature_log()
