# This module searches LASzip and defines
# LASZIP_LIBRARIES - link libraries
# LASZIP_FOUND, if false, do not try to link
# LASZIP_INCLUDE_DIR, where to find the headers
#
# $LASZIP_DIR is an environment variable that would
# correspond to the ./configure --prefix=$LASZIP_DIR

find_path(LASZIP_INCLUDE_DIR laszip.hpp HINTS ENV LASZIP_DIR PATH_SUFFIXES include/laszip)

find_library(LASZIP_LIBRARY_DEBUG NAMES laszipd HINTS ENV LASZIP_DIR PATH_SUFFIXES lib)
find_library(LASZIP_LIBRARY_RELEASE NAMES laszip HINTS ENV LASZIP_DIR PATH_SUFFIXES lib)

find_file(LASZIP_RUNTIME_DEBUG NAMES laszipd${CMAKE_SHARED_LIBRARY_SUFFIX} HINTS ENV LASZIP_DIR PATH_SUFFIXES lib bin)
find_file(LASZIP_RUNTIME_RELEASE NAMES laszip${CMAKE_SHARED_LIBRARY_SUFFIX} HINTS ENV LASZIP_DIR PATH_SUFFIXES lib bin)

set(LASZIP_RUNTIME_DIRS)
if(LASZIP_RUNTIME_DEBUG)
  get_filename_component(RUNTIME_DIR "${LASZIP_RUNTIME_DEBUG}" DIRECTORY)
  list(APPEND LASZIP_RUNTIME_DIRS "${RUNTIME_DIR}")
endif(LASZIP_RUNTIME_DEBUG)
if(LASZIP_RUNTIME_RELEASE)
  get_filename_component(RUNTIME_DIR "${LASZIP_RUNTIME_RELEASE}" DIRECTORY)
  list(APPEND LASZIP_RUNTIME_DIRS "${RUNTIME_DIR}")
endif(LASZIP_RUNTIME_RELEASE)
if(LASZIP_RUNTIME_DIRS)
  list(REMOVE_DUPLICATES LASZIP_RUNTIME_DIRS)
endif(LASZIP_RUNTIME_DIRS)
set(LASZIP_RUNTIME_DIRS "${LASZIP_RUNTIME_DIRS}" CACHE PATH "LASZIP runtime directories")

if(LASZIP_LIBRARY_DEBUG)
  list(APPEND LASZIP_LIBRARIES debug ${LASZIP_LIBRARY_DEBUG})
  if(LASZIP_LIBRARY_RELEASE)
    list(APPEND LASZIP_LIBRARIES optimized ${LASZIP_LIBRARY_RELEASE})
  endif(LASZIP_LIBRARY_RELEASE)
else(LASZIP_LIBRARY_DEBUG)
  list(APPEND LASZIP_LIBRARIES ${LASZIP_LIBRARY_RELEASE})
endif(LASZIP_LIBRARY_DEBUG)

# handle the QUIETLY and REQUIRED arguments and set LASZIP_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LASZIP REQUIRED_VARS LASZIP_LIBRARIES LASZIP_INCLUDE_DIR)

mark_as_advanced(LASZIP_INCLUDE_DIR LASZIP_LIBRARIES LASZIP_RUNTIME_DIRS LASZIP_RUNTIME_DEBUG LASZIP_RUNTIME_RELEASE)
