# Find DoQuBook - 
#
# This module defines
#  DoQuBook_FOUND - whether the DoQuBook library was found
#  DoQuBook_LIBRARIES - the DoQuBook library
#  DoQuBook_INCLUDE_DIR - the include path of the DoQuBook library
#

if (DoQuBook_INCLUDE_DIRS AND DoQuBook_LIBRARIES)

  # Already in cache
  set (DoQuBook_FOUND TRUE)

else (DoQuBook_INCLUDE_DIRS AND DoQuBook_LIBRARIES)

  if (NOT WIN32)
  	if(NOT APPLE)
    # use pkg-config to get the values of DoQuBook_INCLUDE_DIRS
    # and DoQuBook_LIBRARY_DIRS to add as hints to the find commands.
	    include (FindPkgConfig)
    	pkg_check_modules (PC_DoQuBook DoQuBook>=1.0)
    endif(NOT APPLE)
    IF(APPLE)
	# We search for Frameworks
  		INCLUDE(CMakeFindFrameworks)
	  	CMAKE_FIND_FRAMEWORKS(DoQuBook)
	ENDIF(APPLE)
  endif (NOT WIN32)
  
  if(WIN32)
    # the hints
    SET(doqubook_POSSIBLE_ROOT_DIRS
        "$ENV{DOQUBOOK_ROOT_DIR}"
        "$ENV{SystemDrive}/DoQuBook"                    
        "$ENV{SystemDrive}/Program Files/DoQuBook"       
        "$ENV{SystemDrive}/Program Files (x86)/DoQuBook"
        )
	# find the right and only path
	FIND_PATH(doqubook_ROOT_DIR
          NAMES include/DoQuBook/Book.hpp
          PATHS ${doqubook_POSSIBLE_ROOT_DIRS}
          )
	# libs and includes
	SET(doqubook_LIB_SEARCH_PATH "${doqubook_ROOT_DIR}/bin")
	SET(doqubook_INCLUDE_SEARCH_PATH "${doqubook_ROOT_DIR}/include")
  endif(WIN32)

  find_library (DoQuBook_LIBRARIES
    NAMES
    DoQuBook
    PATHS
    ${PC_DoQuBook_LIBRARY_DIRS}
    ${DoQuBook_FRAMEWORKS}
    ${LIB_INSTALL_DIR}  
    ${doqubook_LIB_SEARCH_PATH}
  )


  find_path (DoQuBook_INCLUDE_DIR
    NAMES
    DoQuBook/Book.hpp
    PATHS
    ${PC_DoQuBook_INCLUDE_DIRS}
    ${INCLUDE_INSTALL_DIR}
    ${DoQuBook_FRAMEWORKS}
    ${doqubook_INCLUDE_SEARCH_PATH}
  )



  include(FindPackageHandleStandardArgs)
  find_package_handle_standard_args(DoQuBook DEFAULT_MSG DoQuBook_LIBRARIES DoQuBook_INCLUDE_DIR)

   if (DoQuBook_INCLUDE_DIR AND DoQuBook_LIBRARIES)

    # Already in cache
    set (DoQuBook_FOUND TRUE)
   endif (DoQuBook_INCLUDE_DIR AND DoQuBook_LIBRARIES)
    

endif (DoQuBook_INCLUDE_DIRS AND DoQuBook_LIBRARIES)

if(${DoQuBook_FOUND})
#OpenCv For DoQuBook  but it is not required
set(DoQuBook_INCLUDE_DIRS ${DoQuBook_INCLUDE_DIRS} ${DoQuBook_INCLUDE_DIR})
 message(Found doqubook headers in ${DoQuBook_INCLUDE_DIRS})

#Qt 4
FIND_PACKAGE( Qt4 REQUIRED )
# Les fichiers de Qt necessaire
INCLUDE( ${QT_USE_FILE} )
#QtNetWork
set(QT_USE_QTNETWORK true)
ADD_DEFINITIONS( ${QT_DEFINITIONS} )
IF (WIN32)
SET(QT_DEFINITIONS -DQT_DLL)
ENDIF(WIN32)
set(DoQuBook_LIBRARIES ${QT_LIBRARIES} ${QT_QTNETWORK_LIBRARY} ${DoQuBook_LIBRARIES})

endif(${DoQuBook_FOUND})

MARK_AS_ADVANCED(DoQuBook_INCLUDE_DIRS DoQuBook_LIBRARIES)