# - Try to find QISETOOLS 
# Once done, it will define
#
# QISETOOLS_FOUND - system has QISETOOLS
# QISETOOLS_INCLUDE_DIRS - QISETOOLS include directories
# QISETOOLS_DEFINITIONS - Compiler switches required for using QISETOOLS
# QISETOOLS_LIBRARIES - link these to use QISETOOLS

#include(LibFindMacros)


FIND_PACKAGE(ISE REQUIRED)
FIND_PACKAGE(Qt4 4.2.0 COMPONENTS QtCore QtGui QtOpenGL REQUIRED)


IF (QISETOOLS_INCLUDE_DIRS AND QISETOOLS_LIBRARIES)
  # in cache already
  SET(QISETOOLS_FIND_QUIETLY TRUE)
ENDIF (QISETOOLS_INCLUDE_DIRS AND QISETOOLS_LIBRARIES)


IF(APPLE)
  INCLUDE(CMakeFindFrameworks)
  CMAKE_FIND_FRAMEWORKS(qiseTools-1.0)
  
  IF(qiseTools-1.0_FRAMEWORKS)
    FOREACH(dir ${qiseTools-1.0_FRAMEWORKS})
      SET(QISETOOLS_FMWK_INCLUDES ${QISETOOLS_FMWK_INCLUDES} ${dir}/Headers) #add ${dir}/PrivateHeaders ???
    ENDFOREACH(dir)

    find_path(QISETOOLS_INCLUDE_DIR
      NAMES qiseTools/SplitAlgorithmFactory.hpp
      PATHS ${QISETOOLS_FMWK_INCLUDES}
      )

    SET(QISETOOLS_LIBRARY "-framework qiseTools-1.0")
  ENDIF(qiseTools-1.0_FRAMEWORKS)
ENDIF(APPLE)


IF(NOT QISETOOLS_LIBRARY OR NOT APPLE)

  ##On apple, we want framework to be of higher priority
  # but on linux, if we don't always do this, QISETOOLS_DEFINITIONS is not defined the second time we run cmake
  # TODO: investigate...



  #libfind_pkg_check_modules(QISETOOLS_PKGCONF qiseTools-1.0)
  IF (NOT WIN32)
    include(FindPkgConfig)
    pkg_check_modules(QISETOOLS_PKGCONF qiseTools-1.0)
    SET(QISETOOLS_DEFINITIONS ${GIRL_DEFINITIONS} ${QISETOOLS_PKGCONF_CFLAGS_OTHER})
  ENDIF (NOT WIN32)


  # Include dir
  find_path(QISETOOLS_INCLUDE_DIR
    NAMES qiseTools/SplitAlgorithmFactory.hpp
    PATHS ${QISETOOLS_PKGCONF_INCLUDE_DIRS})

  # Library
  find_library(QISETOOLS_LIBRARY
    NAMES qiseTools-1.0
    PATHS ${QISETOOLS_PKGCONF_LIBRARY_DIRS})

ENDIF()

#set(QISETOOLS_PROCESS_INCLUDES QISETOOLS_INCLUDE_DIR)
#set(QISETOOLS_PROCESS_LIBS QISETOOLS_LIBRARY)
#libfind_process(QISETOOLS)


INCLUDE(FindPackageHandleStandardArgs)

# handle the QUIETLY and REQUIRED arguments and set QISETOOLS_FOUND to TRUE if 
# all listed variables are TRUE
FIND_PACKAGE_HANDLE_STANDARD_ARGS(QISETOOLS DEFAULT_MSG QISETOOLS_LIBRARY QISETOOLS_INCLUDE_DIR)

IF (QISETOOLS_FOUND)
  set(QISETOOLS_INCLUDE_DIRS ${ISE_INCLUDE_DIRS} ${QISETOOLS_INCLUDE_DIR})
  set(QISETOOLS_LIBRARIES ${ISE_LIBRARIES} ${QISETOOLS_PKGCONF_LDFLAGS_OTHER} ${QISETOOLS_LIBRARY})
  #   MESSAGE("find QISETOOLS_INCLUDE_DIRS=${QISETOOLS_INCLUDE_DIRS}")
  #   MESSAGE("find QISETOOLS_LIBRARIES=${QISETOOLS_LIBRARIES}")
  #   MESSAGE("find QISETOOLS_INCLUDE_DIR=${QISETOOLS_INCLUDE_DIR}")
  #   MESSAGE("find QISETOOLS_LIBRARY=${QISETOOLS_LIBRARY}")
  #   MESSAGE("find QISETOOLS_LIBRARY=${QISETOOLS_LIBRARY}")

  #   MESSAGE("find  QISETOOLS_PKGCONF_LDFLAGS=${QISETOOLS_PKGCONF_LDFLAGS}")
  #   MESSAGE("find  QISETOOLS_PKGCONF_LDFLAGS_OTHER=${QISETOOLS_PKGCONF_LDFLAGS_OTHER}")
  #   MESSAGE("find  QISETOOLS_PKGCONF_CFLAGS=${QISETOOLS_PKGCONF_CFLAGS}")
  #   MESSAGE("find  QISETOOLS_PKGCONF_CFLAGS_OTHER=${QISETOOLS_PKGCONF_CFLAGS_OTHER}")
ENDIF (QISETOOLS_FOUND)


MARK_AS_ADVANCED(QISETOOLS_INCLUDE_DIRS QISETOOLS_LIBRARIES)

