# This module searches liboctoma and defines
# OCTOMAP_LIBRARIES - link libraries
# OCTOMAP_FOUND, if false, do not try to link
# OCTOMAP_INCLUDE_DIRS, where to find the headers
# OCTOMAP_VERSION, reports either version 4 or 3 (for everything before version 4)
#
# $OCTOMAP_DIR is an environment variable that would
# correspond to the ./configure --prefix=$OCTOMAP_DIR

find_path(OCTOMAP_INCLUDE_DIRS octomap/octomap.h HINTS ENV OCTOMAP_DIR PATH_SUFFIXES include)

find_library(OCTOMAP_LIBRARY_DEBUG NAMES octomapd HINTS ENV OCTOMAP_DIR PATH_SUFFIXES lib)
find_library(OCTOMAP_LIBRARY_RELEASE NAMES octomap HINTS ENV OCTOMAP_DIR PATH_SUFFIXES lib)

find_library(OCTOMATH_LIBRARY_DEBUG NAMES octomathd HINTS ENV OCTOMAP_DIR PATH_SUFFIXES lib)
find_library(OCTOMATH_LIBRARY_RELEASE NAMES octomath HINTS ENV OCTOMAP_DIR PATH_SUFFIXES lib)

find_library(DYNAMICEDT3D_LIBRARY_DEBUG NAMES dynamicedt3dd HINTS ENV OCTOMAP_DIR PATH_SUFFIXES lib)
find_library(DYNAMICEDT3D_LIBRARY_RELEASE NAMES dynamicedt3d HINTS ENV OCTOMAP_DIR PATH_SUFFIXES lib)

if(OCTOMAP_LIBRARY_DEBUG)
  list(APPEND OCTOMAP_LIBRARIES debug ${OCTOMAP_LIBRARY_DEBUG})
  list(APPEND OCTOMAP_DEBUG_LIBRARIES ${OCTOMAP_LIBRARY_DEBUG})
  if(OCTOMAP_LIBRARY_RELEASE)
    list(APPEND OCTOMAP_LIBRARIES optimized ${OCTOMAP_LIBRARY_RELEASE})
    list(APPEND OCTOMAP_RELEASE_LIBRARIES ${OCTOMAP_LIBRARY_RELEASE})
  endif(OCTOMAP_LIBRARY_RELEASE)
else(OCTOMAP_LIBRARY_DEBUG)
  list(APPEND OCTOMAP_LIBRARIES ${OCTOMAP_LIBRARY_RELEASE})
endif(OCTOMAP_LIBRARY_DEBUG)

if(OCTOMATH_LIBRARY_DEBUG)
  list(APPEND OCTOMAP_LIBRARIES debug ${OCTOMATH_LIBRARY_DEBUG})
  list(APPEND OCTOMAP_DEBUG_LIBRARIES ${OCTOMATH_LIBRARY_DEBUG})
  if(OCTOMATH_LIBRARY_RELEASE)
    list(APPEND OCTOMAP_LIBRARIES optimized ${OCTOMATH_LIBRARY_RELEASE})
    list(APPEND OCTOMAP_RELEASE_LIBRARIES ${OCTOMATH_LIBRARY_RELEASE})
  endif(OCTOMATH_LIBRARY_RELEASE)
else(OCTOMATH_LIBRARY_DEBUG)
  list(APPEND OCTOMAP_LIBRARIES ${OCTOMATH_LIBRARY_RELEASE})
endif(OCTOMATH_LIBRARY_DEBUG)

if(DYNAMICEDT3D_LIBRARY_DEBUG)
  list(APPEND OCTOMAP_LIBRARIES debug ${DYNAMICEDT3D_LIBRARY_DEBUG})
  list(APPEND OCTOMAP_DEBUG_LIBRARIES ${DYNAMICEDT3D_LIBRARY_DEBUG})
  if(DYNAMICEDT3D_LIBRARY_RELEASE)
    list(APPEND OCTOMAP_LIBRARIES optimized ${DYNAMICEDT3D_LIBRARY_RELEASE})
    list(APPEND OCTOMAP_RELEASE_LIBRARIES ${DYNAMICEDT3D_LIBRARY_RELEASE})
  endif(DYNAMICEDT3D_LIBRARY_RELEASE)
else(DYNAMICEDT3D_LIBRARY_DEBUG)
  list(APPEND OCTOMAP_LIBRARIES ${DYNAMICEDT3D_LIBRARY_RELEASE})
endif(DYNAMICEDT3D_LIBRARY_DEBUG)

# handle the QUIETLY and REQUIRED arguments and set OCTOMAP_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OCTOMAP REQUIRED_VARS OCTOMAP_LIBRARIES OCTOMAP_INCLUDE_DIRS)

mark_as_advanced(OCTOMAP_INCLUDE_DIRS OCTOMAP_LIBRARIES)
