project (perls-src C CXX)

option (BUILD_SHARED_LIBS "Build shared libraries?" ON)

# select flags.
set (CMAKE_C_FLAGS "-std=gnu99 -Wfloat-equal -Wall -Wundef -Wno-strict-aliasing -Wno-unused-function")
set (CMAKE_CXX_FLAGS "-Wall -Wundef -Wno-strict-aliasing")

# check for all needed external libraries
find_library (LIB_M m
  DOC "Path to math library"
  )

# pthread
find_library (LIB_PTHREAD pthread
  DOC "Path to pthread library"
  )

# ncurses
find_library (LIB_NCURSES ncurses
  DOC "Path to ncurses library"
  )
if (NOT LIB_NCURSES)
  message (SEND_ERROR "on ubuntu `sudo apt-get install libncurses-dev`")
endif ()

# libgps
find_library (LIB_GPS gps
  DOC "Path to gps library"
)
if (NOT LIB_GPS)
  message (SEND_ERROR "on ubuntu `sudo apt-get install libgps-dev`")
endif ()


# # ImageMagick
# find_package (ImageMagick COMPONENTS MagickWand MagickCore Magick++)
# if (ImageMagick_FOUND)
#   include_directories (${ImageMagick_INCLUDE_DIRS})
#   set (LIB_IMAGEMAGICK ${ImageMagick_LIBRARIES})
# else ()
#   message (SEND_ERROR "on ubuntu `sudo apt-get install libmagick9-dev libmagick++9-dev`")
# endif ()

# TIFF
find_package (TIFF)
if (TIFF_FOUND)
  include_directories (${TIFF_INCLUDE_DIR})
  set (LIB_TIFF ${TIFF_LIBRARIES})
else ()
  message (SEND_ERROR "on ubuntu `sudo apt-get install libtiff4-dev`")
endif ()

# OpenCV
find_package (OpenCV)
if (OpenCV_FOUND)
  include_directories (${OpenCV_INCLUDE_DIR})
  set (LIB_OPENCV ${OpenCV_LIBRARIES})
else ()
  message (SEND_ERROR "on ubuntu `sudo apt-get install libcv-dev`")
endif ()

# GSL
find_package(GSL)
if (GSL_FOUND)
  include_directories (${GSL_INCLUDE_DIR})
  set (LIB_GSL ${GSL_LIBRARIES})
  set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${CMAKE_GSL_CXX_FLAGS})
else ()
  message (SEND_ERROR "on ubuntu `sudo apt-get install libgsl0-dev`")
endif ()

# Python
find_package (PythonLibs)
if (PYTHONLIBS_FOUND)
  include_directories (${PYTHON_INCLUDE_PATH})
  set (LIB_PYTHON ${PYTHON_LIBRARIES})
else ()
  message (SEND_ERROR "on ubuntu `sudo apt-get install python-dev`")
endif ()



# GLIB
find_package (Glib)
if (Glib_FOUND)
  include_directories (${Glib_INCLUDE_DIRS})
  set (LIB_GLIB ${Glib_LIBRARIES})
else ()
  message (SEND_ERROR "on ubuntu `sudo apt-get install libglib2.0-dev`")
endif ()

# VXL
option (BUILD_VXL_APPS "Build VXL dependent apps?" OFF)
if (BUILD_VXL_APPS)
  find_path (VXL_DIR UseVXL.cmake
    PATHS /usr/local/share/vxl/cmake
    DOC "Path to UseVXL.cmake"
    )
  find_package (VXL REQUIRED)
  if (VXL_FOUND)
    include (${VXL_CMAKE_DIR}/UseVXL.cmake)
    find_library (LIB_VNL vnl
      DOC "Path to VXL vnl library"
      )
    find_library (LIB_VIL vil
      DOC "Path to VXL vil library"
      )
    set (LIB_VXL ${LIB_VIL} ${LIB_VNL})
  endif ()
endif ()

# set root dir for header file includes
include_directories (${CMAKE_CURRENT_SOURCE_DIR})

# build libs
add_subdirectory (lcmtypes)
add_subdirectory (libcommon)
add_subdirectory (libmath)

if (BUILD_VXL_APPS)
  # ...
endif ()

set (LIB_PERLS lcmtypes common perl)

# build executables
add_subdirectory (dstar-ssp1)
add_subdirectory (easydaq)
add_subdirectory (heartbeat)
add_subdirectory (kvh-dsp3000)
add_subdirectory (lcmlog-export)
add_subdirectory (ms-gx1)
#add_subdirectory (miniterm)
add_subdirectory (prosilica)
add_subdirectory (os-compass)
add_subdirectory (os-conduit)
add_subdirectory (raw-spy)
add_subdirectory (rdi)
add_subdirectory (cam-attributes)
add_subdirectory (collie-compass)

# build python bindings
add_subdirectory (pybindings)

# build example apps?
option (BUILD_EXAMPLES "Build example programs?" OFF)
if (BUILD_EXAMPLES)
  add_subdirectory (examples)
endif ()
