# Root CMakeLists.txt file
#
# Project: BatchSystemManagement
# Author: D. Traoré
# Date: Nov. 4th 2009

cmake_minimum_required(VERSION 2.6)
project(BatchSystemManagement)
set(CMAKE_MODULE_PATH ${BatchSystemManagement_SOURCE_DIR}/Cmake)

set(CFG_FILE  "/etc/DIET/diet-bmd.cfg" CACHE PATH "Path to the DIET Batch Manager Daemon configuration file")


set(DIET_FMS_INCLUDEDIR  "" CACHE PATH "Path to the DIET File Management System include directory")
set(DIET_FMS_LIBDIR  "" CACHE PATH "Path to the DIET File Management System libraries directory")

if (NOT EXISTS ${DIET_FMS_INCLUDEDIR})
  message(FATAL_ERROR "DIET_FMS_INCLUDEDIR (${DIET_FMS_INCLUDEDIR}) does not exist")
else (NOT EXISTS ${DIET_FMS_INCLUDEDIR})
  INCLUDE_DIRECTORIES( ${DIET_FMS_INCLUDEDIR} )  
endif (NOT EXISTS ${DIET_FMS_INCLUDEDIR})

if (NOT EXISTS ${DIET_FMS_LIBDIR})
  message(FATAL_ERROR "DIET_FMS_LIBDIR (${DIET_FMS_LIBDIR}) does not exist")
else (NOT EXISTS ${DIET_FMS_LIBDIR})
  LINK_DIRECTORIES( ${DIET_FMS_LIBDIR} )  
endif (NOT EXISTS ${DIET_FMS_LIBDIR})


if (APPLE)
  add_definitions(-DBSD_LIKE_SYSTEM)
endif (APPLE)

add_definitions(-DHAVE_DAGDA)
add_definitions(-DBMD_CONFIG_FILE="${CFG_FILE}")



# Requires CMake >= 2.4.7
# Used within omniORB, when set remove some warnings/errors
# Not tested under SunOS & FreeBSD

string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} "AIX" AIX)
string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} "Darwin" APPLE)
string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} "Linux" LINUX)
string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} "SunOS" SUNOS)
string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} "FreeBSD" FREEBSD)
string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} "CYGWIN" CYGWIN)

if (CYGWIN)
  add_definitions(-D__cygwin__)
elseif (AIX)
  add_definitions(-D__aix__)
elseif (APPLE)
  add_definitions( -D__darwin__)
elseif (LINUX)
  add_definitions(-D__linux__)
elseif (SUNOS)
  add_definitions(-D__sunos__)
elseif(FREEBSD)
  add_definitions(-D__freebsd__)
endif (CYGWIN)


find_package(OmniORB)
if (OMNIORB4_FOUND)

  INCLUDE_DIRECTORIES( ${OMNIORB4_INCLUDE_DIR} )

  find_package(DIET)
  if (DIET_FOUND)
     add_subdirectory(src)
     add_subdirectory(man)
  else (DIET_FOUND)
       message("DIET installation was not found. Define the DIET_DIR variable to continue.")
       message("	- You can define a DIET_DIR environment variable")
       message("	- You can pass it as argument to cmake:")
       message("	  $ cmake <source root directory> -DDIET_DIR:PATH=/path/to/DIET")
       message("	- You can use the ccmake GUI")
       set(DIET_DIR "" cache path "DIET installation path")
  endif(DIET_FOUND)

else(OMNIORB4_FOUND)
  message(FATAL_ERROR "OmniORB installation was not found. Define the OMNIORB_DIR variable to continue.")
endif(OMNIORB4_FOUND)

