add_subdirectory( fli    )
add_subdirectory( apogee )
tde_conditional_add_subdirectory( WITH_V4L webcam )

include_directories(
  ${CMAKE_BINARY_DIR}
  ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${TDE_INCLUDE_DIR}
  ${TQT_INCLUDE_DIRS}
  ${ZLIB_INCLUDE_DIRS}
)

link_directories(
  ${TQT_LIBRARY_DIRS}
  ${TDE_LIB_DIR}
  ${CMAKE_BINARY_DIR}/kstars/kstars/indi/fli
)

set( INDIDRIVER_BASE_SRC base64.c indidrivermain.c eventloop.c )


##### lilxml (static )

tde_add_library( lilxml STATIC_PIC

  SOURCES
        lilxml.c
)


##### indicom (static )

tde_add_library( indicom STATIC_PIC

  SOURCES
        base64.c
        indicom.c
        fitsrw.c
)


##### indiserver (executable)

tde_add_executable( indiserver

  SOURCES
        indiserver.c
        fq.c
  LINK
     tdecore-shared
     lilxml-static
     ${CMAKE_THREAD_LIBS_INIT}
     
  DEPENDENCIES
        lilxml-static

  DESTINATION ${BIN_INSTALL_DIR}
)


##### lx200basic (executable)

tde_add_executable( lx200basic

  SOURCES
        ${INDIDRIVER_BASE_SRC}
        lx200driver.c
        lx200basic.cpp
  LINK
     lilxml-static
     indicom-static
     tdecore-shared
     
  DEPENDENCIES
        lilxml-static
        indicom-static

  DESTINATION ${BIN_INSTALL_DIR}
)


##### lx200generic (executable)

tde_add_executable( lx200generic

  SOURCES
        ${INDIDRIVER_BASE_SRC}
        lx200driver.c
        lx200autostar.cpp
        lx200_16.cpp
        lx200gps.cpp
        lx200generic.cpp
        lx200classic.cpp
  LINK
     tdecore-shared
     lilxml-static
     indicom-static
     ${LIBM}
     
  DEPENDENCIES
     lilxml-static
     indicom-static

  DESTINATION ${BIN_INSTALL_DIR}
)


foreach( _lx200 lx200classic lx200autostar lx200_16 lx200gps )
    tde_install_symlink( lx200generic ${BIN_INSTALL_DIR}/${_lx200} )
endforeach( )


##### celestrongps (executable)

tde_add_executable( celestrongps

  SOURCES
        ${INDIDRIVER_BASE_SRC}
        celestronprotocol.c
        celestrongps.cpp
  LINK
     tdecore-shared
     lilxml-static
     indicom-static
     ${LIBM}
     
  DEPENDENCIES
     lilxml-static
     indicom-static

  DESTINATION ${BIN_INSTALL_DIR}
)


##### apmount (executable)

tde_add_executable( apmount

  SOURCES
        ${INDIDRIVER_BASE_SRC}
        lx200driver.c
        apmount.cpp
  LINK
     tdecore-shared
     lilxml-static
     indicom-static
     
  DEPENDENCIES
     lilxml-static
     indicom-static

  DESTINATION ${BIN_INSTALL_DIR}
)


##### fliccd (executable)

tde_add_executable( fliccd

  SOURCES
        ${INDIDRIVER_BASE_SRC}
        fli_ccd.c
        
  LINK
     tdecore-shared
     fli_common-static
     ${LIB_FLI}
     indicom-static
     lilxml-static
     ${ZLIB_LIBRARIES}
     ${LIBM}

  DEPENDENCIES
     fli_common-static
     ${LIB_FLI}
     indicom-static
     lilxml-static

  DESTINATION ${BIN_INSTALL_DIR}
)


##### fliwheel (executable)

tde_add_executable( fliwheel

  SOURCES
        ${INDIDRIVER_BASE_SRC}
        fli_wheel.c
        
  LINK
     tdecore-shared
     fli_common-static
     ${LIB_FLI}
     indicom-static
     lilxml-static
     ${LIBM}

  DEPENDENCIES
     fli_common-static
     ${LIB_FLI}
     indicom-static
     lilxml-static

  DESTINATION ${BIN_INSTALL_DIR}
)


##### temma (executable)

tde_add_executable( temma

  SOURCES
        ${INDIDRIVER_BASE_SRC}
        temmadriver.c
  LINK
     tdecore-shared
     indicom-static
     lilxml-static
     ${LIBM}

  DEPENDENCIES
     indicom-static
     lilxml-static

  DESTINATION ${BIN_INSTALL_DIR}
)


##### skycommander (executable)

tde_add_executable( skycommander

  SOURCES
        ${INDIDRIVER_BASE_SRC}
        lx200driver.c
        skycommander.c
  LINK
     tdecore-shared
     indicom-static
     lilxml-static
     ${LIBM}

  DEPENDENCIES
     indicom-static
     lilxml-static

  DESTINATION ${BIN_INSTALL_DIR}
)


##### sbigccd (executable)

tde_add_executable( sbigccd

  SOURCES
        ${INDIDRIVER_BASE_SRC}
        sbigccd.cpp
        
  LINK
     tdecore-shared
     indicom-static
     lilxml-static
     ${ZLIB_LIBRARIES}

  DEPENDENCIES
     indicom-static
     lilxml-static
     
  DESTINATION ${BIN_INSTALL_DIR}
)


####### apogee_ppi (executable)

set_property(
    SOURCE apogee_ppi.cpp
    APPEND PROPERTY COMPILE_DEFINITIONS
    TOP_DATADIR="${DATA_INSTALL_DIR}/kstars"
)

if (WITH_LIBUSB)
set ( LIBAPOGEE_USB "libapogee_USB-static" )
endif (WITH_LIBUSB)

tde_add_executable( apogee_ppi

  SOURCES
        ${INDIDRIVER_BASE_SRC}
        apogee_ppi.cpp
  LINK
     tdecore-shared
     indicom-static
     lilxml-static
     libapogee_PPI-static
     ${LIBAPOGEE_USB}
     ${ZLIB_LIBRARIES}
     
  DEPENDENCIES
     indicom-static
     lilxml-static
     libapogee_PPI-static
     ${LIBAPOGEE_USB}
     
  DESTINATION ${BIN_INSTALL_DIR}
)


##### With Video4Linux support

if( WITH_V4L )


####### v4ldriver (executable)

tde_add_executable( v4ldriver

  SOURCES
        ${INDIDRIVER_BASE_SRC}
        v4ldriver.cpp
        indi_v4l.cpp
  LINK
     tdecore-shared
     indicom-static
     lilxml-static
     libwebcam_v4l-static
     ${ZLIB_LIBRARIES}
     ${LIBM}
     
  DEPENDENCIES
     indicom-static
     lilxml-static
     libwebcam_v4l-static
         
  DESTINATION ${BIN_INSTALL_DIR}
)


####### v4lphilips (executable)

tde_add_executable( v4lphilips

  SOURCES
        ${INDIDRIVER_BASE_SRC}
        v4ldriver.cpp
        v4lphilips.cpp
        indi_philips.cpp
  LINK
     tdecore-shared
     indicom-static
     lilxml-static
     libwebcam_v4l-static
     ${ZLIB_LIBRARIES}
     ${LIBM}
     
  DEPENDENCIES
     indicom-static
     lilxml-static
     libwebcam_v4l-static
  
  DESTINATION ${BIN_INSTALL_DIR}
)


##### meade_lpi (executable)

tde_add_executable( meade_lpi

  SOURCES
        ${INDIDRIVER_BASE_SRC}
        v4ldriver.cpp
        indi_lpi.cpp
  LINK
     tdecore-shared
     indicom-static
     lilxml-static
     libwebcam_v4l-static
     ${ZLIB_LIBRARIES}

  DEPENDENCIES
     indicom-static
     lilxml-static
     libwebcam_v4l-static

  DESTINATION ${BIN_INSTALL_DIR}
)

endif()


##### other data

install(
    FILES drivers.xml apogee_caminfo.xml
    DESTINATION ${DATA_INSTALL_DIR}/kstars
)
