# - Try to find log4cxx
# Once done this will define
#  
#  LOG4CXX_FOUND	 - system has LOG4CXX
#  LOG4CXX_INCLUDE_DIR	 - the include directories
#  LOG4CXX_LIBRARY_DIR	 - the directory containing the libraries
#  LOG4CXX_LIBRARIES	 - link these to use LOG4CXX
#   

SET( LOG4CXX_HEADERS logger.h )
SET( LOG4CXX_PATH_SUFFIXES log4cxx )
SET( LOG4CXX_LIBRARIES log4cxx )

SET( LOG4CXX_LIBRARY_DIR   ${LOG4CXX_LIBRARY_DIRS} )
SET( LOG4CXX_INCLUDE_PATHS ${LOG4CXX_INCLUDE_DIRS} )


# find includes
SET( INC_SUCCESS 0 )
SET( TMP_ TMP-NOTFOUND )
SET( LOG4CXX_INCLUDE_DIR ${LOG4CXX_INCLUDE_PATHS} )
FOREACH( INC_ ${LOG4CXX_HEADERS} )
   message( "checking: " ${INC_} )

   FIND_PATH( TMP_ ${INC_}
	      PATHS ${LOG4CXX_INCLUDE_PATHS}
	      PATH_SUFFIXES ${LOG4CXX_PATH_SUFFIXES} )
   IF ( TMP_ )
      message( "found: " ${TMP_} )
      MATH( EXPR INC_SUCCESS ${INC_SUCCESS}+1 )
      SET( LOG4CXX_INCLUDE_DIR ${LOG4CXX_INCLUDE_DIR} ${TMP_} )
   ENDIF ( TMP_ )
   SET( TMP_ TMP-NOTFOUND )
ENDFOREACH( INC_ )

# clear out duplicates
#LIST( REMOVE_DUPLICATES LOG4CXX_INCLUDE_DIR )
#LIST( REMOVE_DUPLICATES LOG4CXX_LIBRARY_DIR )

# find the full paths of the libraries
SET( TMP_ TMP-NOTFOUND )
FOREACH( LIB_ ${LOG4CXX_LIBRARIES} )
  FIND_LIBRARY( TMP_ NAMES ${LIB_} PATHS ${LOG4CXX_LIBRARY_DIR} )
  IF ( TMP_ )
    SET( LOG4CXX_LIBRARIES_FULL ${LOG4CXX_LIBRARIES_FULL} ${TMP_} )
  ENDIF ( TMP_ )
  SET( TMP_ TMP-NOTFOUND )
ENDFOREACH( LIB_ )
SET ( LOG4CXX_LIBRARIES ${LOG4CXX_LIBRARIES_FULL} )

LIST( LENGTH LOG4CXX_HEADERS LIST_SIZE_ )

SET( LOG4CXX_FOUND FALSE )
IF ( ${INC_SUCCESS} EQUAL ${LIST_SIZE_} )
   SET( LOG4CXX_FOUND TRUE )
ENDIF ( ${INC_SUCCESS} EQUAL ${LIST_SIZE_} )

