PROJECT(ossimPlanetQt)
MESSAGE("**********************Setting up ossimPlanetQt********************")
INCLUDE(OssimVersion)
INCLUDE(OssimUtilities)
INCLUDE(OssimCommonVariables)
INCLUDE(OssimQt4Macros)
IF(NOT APPLE)
  cmake_minimum_required(VERSION 2.6)
ELSE(NOT APPLE)
  cmake_minimum_required(VERSION 2.8)
ENDIF(NOT APPLE)

SET (QT_MIN_VERSION "4.2.2")
FIND_PACKAGE(Qt4 REQUIRED) # find and setup Qt4 for this project
INCLUDE(${QT_USE_FILE})
SET(QT_USE_QTOPENGL ON)
find_package(Qt4)

find_package(OpenThreads)
find_package(ossim)
find_package(ossimPlanet)
find_package(WMS)
find_package(OpenGL)
find_package(OSG)
find_package(GPSTK)

ADD_DEFINITIONS(${QT_DEFINITIONS}
	-DQT_CORE_LIB
	-DQT_GUI_LIB
	-DQT_THREAD_SUPPORT
)
INCLUDE_DIRECTORIES(${${PROJECT_NAME}_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${OSSIM_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${WMS_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${OSSIMPLANET_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${QT_INCLUDES})
INCLUDE_DIRECTORIES(${OSG_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})
ELSE()
   SET(GPSTK_LIBRARY "")
ENDIF()

IF(NOT OSSIMPREDATOR_LIBRARY)
  set(OSSIMPREDATOR_LIBRARY "")
ENDIF()


############################################## BUILD THE LIBRARY ############################################
SET(LIB_NAME ossimPlanetQt)
FILE(GLOB OSSIMPLANETQT_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/include/ossimPlanetQt/ossimPlanet*.h")
FILE(GLOB OSSIMPLANETQT_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/gui/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/core/*.cpp" )
FILE(GLOB OSSIMPLANETQT_UIS  "${CMAKE_CURRENT_SOURCE_DIR}/src/gui/ui/*.ui")

MESSAGE("QT4_LIBRARIES === ${QT_LIBRARIES}")
QT4_WRAP_CPP(OSSIMPLANETQT_MOC_SRCS ${OSSIMPLANETQT_INCLUDES} )

SET(UI_DESTINATION_DIR ${${PROJECT_NAME}_SOURCE_DIR}/include/ossimPlanetQt)
OSSIM_QT4_WRAP_UI(OSSIMPLANETQT_UI_SRC ${OSSIMPLANETQT_UIS} )

SET(INCLUDE_DIR "include/ossimPlanetQt")
OSSIM_LINK_LIBRARY(${LIB_NAME} COMPONENT_NAME ossim TYPE "${OSSIM_USER_DEFINED_DYNAMIC_OR_STATIC}" HEADERS ${OSSIMPLANETQT_INCLUDES} ${OSSIMPLANETQT_UI_SRC} SOURCE_FILES ${OSSIMPLANETQT_SRCS}  ${OSSIMPLANETQT_MOC_SRCS}
                   LIBRARIES ${OSSIM_LIBRARY} ${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} ${QT_LIBRARIES} ${QT_QTOPENGL_LIBRARY} ${WMS_LIBRARY} ${OSSIMPLANET_LIBRARY} 
                   INSTALL_LIB VERSION_SYMLINKS ADDITIONAL_COMPILE_FLAGS "-DOSSIMPLANETQT_LIBRARY")

############################################# BUILD THE APPLICATIONS #################################################

REMOVE_DEFINITIONS(-DOSSIMPLANETQT_LIBRARY)
QT4_ADD_RESOURCES(OSSIMPLANETQT_RC "${PROJECT_SOURCE_DIR}/apps/ossimPlanetQt.qrc")
set(TARGET_COMMON_LIBRARIES ossimPlanetQt)
FILE(GLOB SOURCE_FILES "${PROJECT_SOURCE_DIR}/apps/ossimplanet/main.cpp")
SET(OSSIM_BUILD_APPLICATION_BUNDLES ON)
OSSIM_SETUP_APPLICATION(ossimplanetGui REQUIRE_WINMAIN_FLAG INSTALL COMPONENT_NAME ossim SOURCE_FILES ${SOURCE_FILES} ${OSSIMPLANETQT_RC})
SET_TARGET_PROPERTIES(ossimplanetGui PROPERTIES RUNTIME_OUTPUT_NAME ossimplanet)


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