project( LOGSERVICE )
cmake_minimum_required( VERSION 2.6 )

set(LOGSERVICE_MAJOR_VERSION 2)
set(LOGSERVICE_MINOR_VERSION 7)
set(LOGSERVICE_REVISION_VERSION 0)

set(LOGSERVICE_VERSION ${LOGSERVICE_MAJOR_VERSION}.${LOGSERVICE_MINOR_VERSION}.${LOGSERVICE_REVISION_VERSION})



#-------------- PLATFORM SPECIFIC COMPILATION FLAGS -----------------------
# Requires CMake >= 2.4.7
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 )
 
if( AIX )
  message( STATUS "XXX System name Aix" )
  add_definitions( -D__aix__ )
elseif( APPLE )
  message( STATUS "XXX System name Darwin" )
  add_definitions( -D__darwin__ )
elseif( LINUX )
  message( STATUS "XXX System name Linux" )
  add_definitions( -D__linux__ )
elseif( SUNOS )
  message( STATUS "XXX System name SunOS" )
  add_definitions( -D__sunos__ )
elseif( FREEBSD )
  message( STATUS "XXX System name FreeBSD" )
  add_definitions( -D__freebsd__ )
endif()


# --------------------- DEPENDENCIES TOWARDS EXTERNAL PACKAGES -------------
# Path to additional modules (i.e. used by FIND_PACKAGE commands making
# reference to non CMake defined "standard" modules):
set( CMAKE_MODULE_PATH ${LOGSERVICE_SOURCE_DIR}/Cmake )

# ---------------- SET THE LINKER SEARCH PATH (RPATH) ----------------------
set( CMAKE_INSTALL_RPATH_USE_LINK_PATH ON
  CACHE BOOL "Whether to set an rpath for dynamic libraries." )
set( CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib
  CACHE STRING "Rpath set at install stage." FORCE )



# --------------------- DEPENDENCIES TOWARDS OmniORB -----------------------

# To remove an issue with Cmake internal rpath tool
if (NOT BUILT_SHARED_LIBS)
 set(CMAKE_NO_BUILTIN_CHRPATH 1)
endif ()

# because x86_64 can't link static libraries to shared libraries
# and from 2.5, this is what is done in DIET
# see http://www.mail-archive.com/cross-lfs%40linuxfromscratch.org/msg00411.html
# You will get these messages on x86_64 any place that libtool tries to use a static (.a) library in a .la, and as it says, it can't link. These "recompile with -fPIC" messages fall into three types -
# (i) recompile the current package with -fPIC
# (ii) fix a broken symlink (I had a dangling symlink for ncurses in my scripts, because of a typo - on x86 libtool couldn't find the .so but took the .a and ran with it, on x86_64 it barfed).
# (iii) convert a Makefile to use .la instead of .a (very uncommon).

# Note: CMAKE_SYSTEM_PROCESSOR return the equivalent of uname -p, note uname -m

if (UNIX AND NOT WIN32)
  find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
 if (CMAKE_UNAME)
   exec_program(uname ARGS -m OUTPUT_VARIABLE SYSTEM_PROC_TYPE)
   set(SYSTEM_PROC_TYPE ${SYSTEM_PROC_TYPE} CACHE INTERNAL
     "processor type (i386 and x86_64)")
     if (SYSTEM_PROC_TYPE MATCHES "x86_64|amd64")
     # TODO: Should be done only for libraries build
     add_definitions(-fPIC)
   endif()
 endif()
endif()

# Are libraries dynamic libraries as opposed to library archives ?
# Note: this variable is a cmake internal.
option(BUILD_SHARED_LIBS "Build libraries as shared libraries." ON)


# --------------------- DEPENDENCIES TOWARDS OmniORB -----------------------
find_package( OmniORB )
if (OMNIORB4_FOUND)
  add_definitions(-D__OMNIORB4__)
  if (BUILD_SHARED_LIBS)
    # Link DIET to OmniORB shared libs
    set(OMNIORB4_LIBRARIES ${OMNIORB4_LIBRARIES_sh})
  else ()
    # Link DIET to OmniORB static libs
    set(OMNIORB4_LIBRARIES ${OMNIORB4_LIBRARIES_st})
  endif ()
else ()
  message("omniORB installation was not found. Please provide OMNIORB4_DIR:")
  message("  - through the GUI when working with ccmake, ")
  message("  - as a command line argument when working with cmake e.g. ")
  message("    cmake .. -DOMNIORB4_DIR:PATH=/usr/local/omniORB-4.0.7 ")
  message("Note: the following message is triggered by cmake on the first ")
  message("    undefined necessary PATH variable (e.g.  OMNIORB4_INCLUDE_DIR).")
  message("    Providing OMNIORB4_DIR (as above described) is probably the")
  message("    simplest solution unless you have a really customized/odd")
  message("    omniORB installation...")
  set(OMNIORB4_DIR "" CACHE PATH "Root of omniORB install tree.")
endif ()


# ------------------------- BACKGROUND OPTION ----------------------------
option( LOGSERVICE_BACKGROUND "Add the background support..." ON )

if( LOGSERVICE_BACKGROUND )
  add_definitions( -DHAVE_BACKGROUND )
endif()

if (UNIX AND NOT WIN32)
  find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
  if (CMAKE_UNAME)
    exec_program(uname ARGS -m OUTPUT_VARIABLE SYSTEM_PROC_TYPE)
    set(SYSTEM_PROC_TYPE ${SYSTEM_PROC_TYPE} CACHE INTERNAL 
      "processor type (i386 and x86_64)")
    if (SYSTEM_PROC_TYPE MATCHES "x86_64|amd64")
      # TODO: Should be done only for libraries build
      add_definitions(-fPIC)
    endif()
  endif()
endif()

set (AR_DIR ${CMAKE_MODULE_PATH})
find_package (AR)

add_subdirectory( src )
add_subdirectory( docs/man )

