PROJECT(oms)

IF(NOT APPLE)
  cmake_minimum_required(VERSION 2.6)
ELSE(NOT APPLE)
  cmake_minimum_required(VERSION 2.8)
ENDIF(NOT APPLE)

find_package(ossim)
find_package(OpenThreads)
find_package(ossimPredator)
find_package(FFmpeg)
find_package(GPSTK)
find_package(Regex)

# GEOS - Currently optional until it is actually called.:
find_package( GEOS )

if( GEOS_FOUND )
   include_directories( ${GEOS_INCLUDE_DIR} )
else( GEOS_FOUND )
  set(GEOS_LIBRARY "")
  message( FATAL_ERROR "Could not find geos package! Consider installing this as it will soon become a required package." )
endif( GEOS_FOUND )

MESSAGE( STATUS "OSSIM_INCLUDE_DIR=${OSSIM_INCLUDE_DIR}")
MESSAGE( STATUS "OSSIM_LIBRARIES =${OSSIM_LIBRARIES}")
MESSAGE( STATUS "OPENTHREADS_LIBRARY = ${OPENTHREADS_LIBRARY}")
MESSAGE( STATUS "OPENTHREADS_INCLUDE_DIR = ${OPENTHREADS_INCLUDE_DIR}")
MESSAGE( STATUS "OSSIMPREDATOR_LIBRARIES   = ${OSSIMPREDATOR_LIBRARIES}")
MESSAGE( STATUS "OSSIMPREDATOR_INCLUDE_DIR = ${OSSIMPREDATOR_INCLUDE_DIR}")
MESSAGE( STATUS "FFMPEG_LIBRARIES = ${FFMPEG_LIBRARIES}")
MESSAGE( STATUS "FFMPEG_INCLUDE_DIRS = ${FFMPEG_INCLUDE_DIRS}")


################################################## BUILD THE LIBRARY #######################################
SET(LIB_NAME oms)

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${OSSIM_INCLUDE_DIR})

SET(PREDATOR_LIBRARIES "")
IF(OSSIMPREDATOR_FOUND AND BUILD_OSSIMPREDATOR)
    ADD_DEFINITIONS(-DOSSIM_PREDATOR_VIDEO_ENABLED)
    INCLUDE_DIRECTORIES(${OSSIMPREDATOR_INCLUDE_DIR})
    INCLUDE_DIRECTORIES(${FFMPEG_INCLUDE_DIRS})
    SET(PREDATOR_LIBRARIES ${OSSIMPREDATOR_LIBRARY})
ELSE()
    MESSAGE(WARNING "********* PREDATOR video support was not found and will not be compiled into the oms library")
ENDIF()

IF(GPSTK_FOUND)
    MESSAGE(STATUS "GPSTK_LIBRARY               = ${GPSTK_LIBRARY}")
    MESSAGE(STATUS "GPSTK_INCLUDE_DIR           = ${GPSTK_INCLUDE_DIR}")
    ADD_DEFINITIONS("-DOSSIM_ENABLE_GPSTK")
    INCLUDE_DIRECTORIES(${GPSTK_INCLUDE_DIR})
    IF(REGEX_FOUND)
      INCLUDE_DIRECTORIES(${REGEX_INCLUDE_DIR})
      MESSAGE(STATUS "REGEX_INCLUDE_DIR          =  ${REGEX_INCLUDE_DIR}")
      MESSAGE(STATUS "REGEX_LIBRARIES            =  ${REGEX_LIBRARIES}")
    ELSE()
      set(REGEX_LIBRARIES "")
    ENDIF()
ELSE(GPSTK_FOUND)
    SET(GPSTK_LIBRARY "")
ENDIF(GPSTK_FOUND)

INCLUDE_DIRECTORIES(${OPENTHREADS_INCLUDE_DIR})

FILE(GLOB OMS_SRCS RELATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/src/oms/*.cpp")
FILE(GLOB OMS_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/oms/*.h")

set(INSTALL_INCLUDE_DIR "include/oms")
OSSIM_LINK_LIBRARY(${LIB_NAME} COMPONENT_NAME ossim TYPE "${OSSIM_USER_DEFINED_DYNAMIC_OR_STATIC}" HEADERS ${OMS_HEADERS} SOURCE_FILES ${OMS_SRCS} 
                   LIBRARIES ${OSSIM_LIBRARY} ${OPENTHREADS_LIBRARY} ${ZLIB_LIBRARY} ${GEOS_LIBRARY} ${PREDATOR_LIBRARIES} ${GPSTK_LIBRARY} ${REGEX_LIBRARIES}
                   INSTALL_LIB INSTALL_HEADERS VERSION_SYMLINKS ADDITIONAL_COMPILE_FLAGS "-DOMS_LIBRARY -D__STDC_CONSTANT_MACROS")



##################################### SETUP TEST APPLICATION BUILDS #############################
IF(BUILD_OSSIM_TEST_APPS)
   IF(OSSIMPREDATOR_FOUND AND BUILD_OSSIMPREDATOR)
       set(TARGET_COMMON_LIBRARIES ossim oms ossimPredator)
   ELSE()
       set(TARGET_COMMON_LIBRARIES ossim oms)
   ENDIF()
    IF(BUILD_OSSIMPREDATOR)
       OSSIM_SETUP_APPLICATION(oms-video-test COMMAND_LINE COMPONENT_NAME ossim SOURCE_FILES test/oms-video-test.cpp)
    ENDIF(BUILD_OSSIMPREDATOR)
    OSSIM_SETUP_APPLICATION(oms-stage-test COMMAND_LINE COMPONENT_NAME ossim SOURCE_FILES test/oms-stage-test.cpp)
    OSSIM_SETUP_APPLICATION(oms-image-info COMMAND_LINE COMPONENT_NAME ossim SOURCE_FILES apps/oms-image-info.cpp)
   
ENDIF(BUILD_OSSIM_TEST_APPS)

####################################### SETUP THE UNINSTALL #################################
#OSSIM_ADD_COMMON_MAKE_UNINSTALL()
