PROJECT(ossimPlanet)
MESSAGE("**********************Setting up ossimPlanet********************")
INCLUDE(OssimVersion)
INCLUDE(OssimUtilities)
INCLUDE(OssimCommonVariables)

OPTION(OSSIMPLANET_ENABLE_EPHEMERIS "Set to ON enable ephemeris support if GPSTK is found.  Use OFF to not enable ephemeris." ON)

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

find_package(OpenThreads)
find_package(ossim)
find_package(ossimPredator)
find_package(GPSTK)
find_package(JPEG)
find_package(OSG)
find_package(WMS)
find_package(ZLIB)
find_package(OpenGL)
find_package(FFmpeg)
find_package(Regex)

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

MESSAGE( STATUS "OSG_LIBRARY               = ${OSG_LIBRARY}")
MESSAGE( STATUS "OSG_INCLUDE_DIR           = ${OSG_INCLUDE_DIR}")
MESSAGE( STATUS "OSGUTIL_LIBRARY           = ${OSGUTIL_LIBRARY}")
################################################## BUILD THE LIBRARY #######################################
SET(LIB_NAME ossimPlanet)

INCLUDE_DIRECTORIES(${${PROJECT_NAME}_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${OSSIM_INCLUDE_DIR})

IF(OSSIMPREDATOR_FOUND AND BUILD_OSSIMPREDATOR)
   INCLUDE_DIRECTORIES(${OSSIMPREDATOR_INCLUDE_DIR})
   ADD_DEFINITIONS("-DOSSIMPLANET_ENABLE_PREDATOR")
   INCLUDE_DIRECTORIES(${FFMPEG_INCLUDE_DIRS})
ELSE(OSSIMPREDATOR_FOUND AND BUILD_OSSIMPREDATOR)
   MESSAGE(STATUS "Disabling Predator support in Planet")
   SET(OSSIMPREDATOR_LIBRARY "")
   SET(OSSIMPREDATOR_LIBRARIES "")
   SET(OSSIMPREDATOR_INCLUDE_DIR "")
   SET(FFMPEG_LIBRARIES "")
   SET(FFMPEG_LIBRARY "")
ENDIF(OSSIMPREDATOR_FOUND AND BUILD_OSSIMPREDATOR)

INCLUDE_DIRECTORIES(${OPENTHREADS_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${WMS_INCLUDE_DIR})

IF(GPSTK_FOUND AND OSSIMPLANET_ENABLE_EPHEMERIS)
    MESSAGE(STATUS "GPSTK_LIBRARY               = ${GPSTK_LIBRARY}")
    MESSAGE(STATUS "GPSTK_INCLUDE_DIR           = ${GPSTK_INCLUDE_DIR}")
    ADD_DEFINITIONS("-DOSSIMPLANET_ENABLE_EPHEMERIS")
    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 AND OSSIMPLANET_ENABLE_EPHEMERIS)
    SET(GPSTK_LIBRARY "")
ENDIF(GPSTK_FOUND AND OSSIMPLANET_ENABLE_EPHEMERIS)


INCLUDE_DIRECTORIES(${OSG_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIR})


FILE(GLOB OSSIMPLANET_SRCS RELATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/src/ossimPlanet/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/ossimPlanet/*.c")
FILE(GLOB OSSIMPLANET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/ossimPlanet/*.h")

IF(NOT BUILD_OSSIMPREDATOR)
   LIST(REMOVE_ITEM OSSIMPLANET_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/ossimPlanet/ossimPlanetPredatorVideoLayerNode.cpp")
   LIST(REMOVE_ITEM OSSIMPLANET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/ossimPlanet/ossimPlanetPredatorVideoLayerNode.h")
ENDIF()

IF(NOT WIN32)
   LIST(REMOVE_ITEM OSSIMPLANET_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/ossimPlanet/iowin32.c")
ELSE(NOT WIN32)
   LIST(APPEND ${LIB_NAME}_EXTRA_LIBS "ws2_32" "winmm")
ENDIF(NOT WIN32)

SET(INSTALL_INCLUDE_DIR "include/ossimPlanet")
OSSIM_LINK_LIBRARY(${LIB_NAME} COMPONENT_NAME ossim TYPE "${OSSIM_USER_DEFINED_DYNAMIC_OR_STATIC}" HEADERS ${OSSIMPLANET_HEADERS} SOURCE_FILES ${OSSIMPLANET_SRCS} 
                   LIBRARIES ${OSSIM_LIBRARIES} ${OSGVIEWER_LIBRARY} ${OSGDB_LIBRARY} ${OSGGA_LIBRARY}  ${OSGTEXT_LIBRARY} ${OSGUTIL_LIBRARY}  ${OSG_LIBRARY}  ${OPENTHREADS_LIBRARY} ${JPEG_LIBRARY} ${WMS_LIBRARY} ${GPSTK_LIBRARY} ${OSSIMPREDATOR_LIBRARY} ${ZLIB_LIBRARY} ${OPENGL_LIBRARIES} ${FFMPEG_LIBRARIES} ${REGEX_LIBRARIES}
                   INSTALL_LIB INSTALL_HEADERS VERSION_SYMLINKS ADDITIONAL_COMPILE_FLAGS "-DOSSIMPLANET_LIBRARY")


############################################################# SETUP APPLICATIONS ##################################################
set(TARGET_COMMON_LIBRARIES ossimPlanet ${OSSIMPREDATOR_LIBRARIES})
FILE(GLOB SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/examples/ossimplanetviewer/*.cpp")
OSSIM_SETUP_APPLICATION(ossimplanetviewer INSTALL COMMAND_LINE COMPONENT_NAME ossim SOURCE_FILES ${SOURCE_FILES})
FILE(GLOB SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/examples/ossimplanettest/*.cpp")
OSSIM_SETUP_APPLICATION(ossimplanettest INSTALL COMMAND_LINE COMPONENT_NAME ossim SOURCE_FILES ${SOURCE_FILES})
IF(BUILD_OSSIMPREDATOR)
   FILE(GLOB SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/examples/ossimplanetklv/*.cpp")
   OSSIM_SETUP_APPLICATION(ossimplanetklv INSTALL COMMAND_LINE COMPONENT_NAME ossim SOURCE_FILES ${SOURCE_FILES})
ENDIF()

FILE(GLOB SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/apps/ossimplanet-chip/*.cpp")
OSSIM_SETUP_APPLICATION(ossimplanet-chip INSTALL COMMAND_LINE COMPONENT_NAME ossim SOURCE_FILES ${SOURCE_FILES})

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