# - Try to find OPENMESH
# Once done this will define
#  
# OPENMESH_FOUND			- system has OPENMESH
# OPENMESH_INCLUDE_DIR		- the OPENMESH include directory
# OPENMESH_LIBRARIES		- the OPENMESH libraries
# OPENMESH_LIBRARY_DIR		- the OPENMESH libraries directory
#   

IF (OPENMESH_INCLUDE_DIR)
  # Already in cache, be silent
  SET(OPENMESH_FIND_QUIETLY TRUE)
ENDIF (OPENMESH_INCLUDE_DIR)

FIND_PATH(OPENMESH_INCLUDE_DIR OpenMesh/Core/Mesh/PolyMeshT.hh
	  PATHS /usr/local/include 
                /usr/include 
                /opt/local/include
				/opt/include
                $ENV{OPENMESH_DIR}/include 
                )

IF (OPENMESH_INCLUDE_DIR)
	IF (WIN32)
	   SET(OPENMESH_LIBRARY_DIR "${OPENMESH_INCLUDE_DIR}/../lib")
	ELSE (WIN32)
	   SET(OPENMESH_LIBRARY_DIR "${OPENMESH_INCLUDE_DIR}/../lib/OpenMesh")
	ENDIF (WIN32)

	FIND_LIBRARY(OPENMESH_CORE_LIBRARY_RELEASE NAMES OpenMeshCore libOpenMeshCore PATHS ${OPENMESH_LIBRARY_DIR})
	FIND_LIBRARY(OPENMESH_TOOLS_LIBRARY_RELEASE NAMES OpenMeshTools libOpenMeshTools PATHS ${OPENMESH_LIBRARY_DIR})
	SET(OPENMESH_LIBRARY_RELEASE
		${OPENMESH_CORE_LIBRARY_RELEASE}
		${OPENMESH_TOOLS_LIBRARY_RELEASE})
	    
	FIND_LIBRARY(OPENMESH_CORE_LIBRARY_DEBUG NAMES OpenMeshCored libOpenMeshCored PATHS ${OPENMESH_LIBRARY_DIR})
	FIND_LIBRARY(OPENMESH_TOOLS_LIBRARY_DEBUG NAMES OpenMeshToolsd libOpenMeshToolsd PATHS ${OPENMESH_LIBRARY_DIR})
	SET(OPENMESH_LIBRARY_DEBUG
		${OPENMESH_CORE_LIBRARY_DEBUG}
		${OPENMESH_TOOLS_LIBRARY_DEBUG})
ENDIF (OPENMESH_INCLUDE_DIR)

if(OPENMESH_LIBRARY_RELEASE)
  if(OPENMESH_LIBRARY_DEBUG)
    set(OPENMESH_LIBRARIES_ optimized ${OPENMESH_LIBRARY_RELEASE} debug ${OPENMESH_LIBRARY_DEBUG})
  else()
    set(OPENMESH_LIBRARIES_ ${OPENMESH_LIBRARY_RELEASE})
  endif()

  set(OPENMESH_LIBRARIES ${OPENMESH_LIBRARIES_} CACHE FILEPATH "The OpenMesh library")
endif()

IF(OPENMESH_INCLUDE_DIR AND OPENMESH_LIBRARIES)
	SET(OPENMESH_FOUND TRUE)
	MESSAGE(STATUS "Found OpenMesh: ${OPENMESH_LIBRARIES}")
ENDIF(OPENMESH_INCLUDE_DIR AND OPENMESH_LIBRARIES)
