project(kalarm-package)

# search packages used by KDE
set(KDE_MIN_VERSION 4.2.0)
find_package(KDE4 4.2.0 REQUIRED)
message(STATUS "KDE Version: ${KDE_VERSION}")
include(KDE4Defaults)
include(MacroLibrary)
include(CheckIncludeFiles)
find_package(KdepimLibs REQUIRED)
macro_optional_find_package(Gettext)
macro_log_feature(GETTEXT_FOUND "Gettext" "GNU Internationalization utilities" "http://www.gnu.org" FALSE "" "Gettext is required to install language translations")

if(WIN32)
  # detect oxygen icon dir at configure time based on KDEDIRS - there may be different package installation locations
  execute_process(COMMAND "${KDE4_KDECONFIG_EXECUTABLE}" --path icon OUTPUT_VARIABLE _dir ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  file(TO_CMAKE_PATH "${_dir}" __dir)
  find_path(KDE4_ICON_DIR oxygen PATHS
      ${__dir}
  )
  message(STATUS "using oxygen application icons from ${KDE4_ICON_DIR}")
else(WIN32)
    set (KDE4_ICON_DIR  ${CMAKE_INSTALL_PREFIX}/share/icons)
endif(WIN32)

# this macro exists to work around a stupid Mac OS X linker bug
# where it can't handle the same library being referenced multiple
# times on the linker line
macro (KDEPIM4_LINK_UNIQUE_LIBRARIES)
  target_link_libraries(${ARGN})
endmacro (KDEPIM4_LINK_UNIQUE_LIBRARIES)

add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})

if(KDE_VERSION VERSION_LESS 4.3)
  # KDE 4.2
  include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/compat ${CMAKE_SOURCE_DIR}/compat/kde4.2 ${KDEPIMLIBS_INCLUDE_DIR} ${KDE4_INCLUDES} ${QT_QTDBUS_INCLUDE_DIR})
elseif(KDE_VERSION VERSION_LESS 4.3.80)
  # KDE 4.3
  include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/compat ${KDEPIMLIBS_INCLUDE_DIR} ${KDE4_INCLUDES} ${QT_QTDBUS_INCLUDE_DIR})
else(KDE_VERSION VERSION_LESS 4.3)
  # KDE >= 4.4
  include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/compat ${CMAKE_SOURCE_DIR}/compat/libkdepim ${KDEPIMLIBS_INCLUDE_DIR} ${KDE4_INCLUDES} ${QT_QTDBUS_INCLUDE_DIR})
endif(KDE_VERSION VERSION_LESS 4.3)

add_subdirectory(compat)
add_subdirectory(kalarm)
add_subdirectory(doc)
if (GETTEXT_FOUND)
  macro_optional_add_subdirectory(po)
endif (GETTEXT_FOUND)
