# This file sets:
# - BOOST_INCLUDE_DIRS
# - BOOST_LIB_DIRS
# - BOOST_WT_FOUND  // All dependencies for wt found
# - BOOST_WT_MT_FOUND
# - BOOST_WTHTTP_FOUND // All dependencies for wthttp found
# - BOOST_WTHTTP_MT_FOUND
# - BOOST_SUPPORT_LIBRARIES (should always be added to the boost libs)
#
# Separate compiled boost libraries are also discovered:
# - BOOST_DT_LIB
# - BOOST_FS_LIB
# - BOOST_RANDOM_LIB
# - BOOST_REGEX_LIB
# - BOOST_PO_LIB
# - BOOST_SIGNALS_LIB
# - BOOST_SYSTEM_LIB
# - BOOST_THREAD_LIB (only if BOOST_MT_FOUND)
# Boost will try to find the same kind (mt or not) of library for all three
# of these libraries. Boost is considered to be found successfully only
# when the libraries are all of the same kind (mt or not). If the mt
# libraries exits, the mt versions will be used unless MULTI_THREADED is
# set to OFF. Otherwise, the non-mt versions will be used.

FIND_PATH(BOOST_INCLUDE_DIRS
    boost/lexical_cast.hpp
  PATHS
    ${BOOST_PREFIX}/include
    ${BOOST_PREFIX}/include/${BOOST_VERSION}
    ${BOOST_PREFIX}/include/boost-${BOOST_VERSION}
    ${BOOST_PREFIX}
  NO_DEFAULT_PATH
)

#SET (BOOST_LIB_DIRS "${BOOST_PREFIX}/lib ${BOOST_PREFIX}/lib64")
SET (BOOST_LIB_DIRS ${BOOST_PREFIX}/lib)

IF(MSVC)
# FIXME: write some TRY_COMPILEs here to verify that these libs exist
  SET(BOOST_SUPPORT_LIBRARIES "")
ELSE(MSVC)
  IF (USE_BOOST_FRAMEWORK)

    # Finds a boost.framework, through CMAKE_FRAMEWORK_PATH

    FIND_LIBRARY(BOOST_FRAMEWORK_LIB
      NAMES
        boost
      PATHS
        ${BOOST_LIB_DIRS}
    )

    SET(BOOST_THREAD_LIB ${BOOST_FRAMEWORK_LIB})
    SET(BOOST_REGEX_LIB ${BOOST_FRAMEWORK_LIB})
    IF(NOT WT_NO_BOOST_RANDOM)
      SET(BOOST_RANDOM_LIB ${BOOST_FRAMEWORK_LIB})
    ELSE(NOT WT_NO_BOOST_RANDOM)
      SET(BOOST_RANDOM_LIB "")
    ENDIF(NOT WT_NO_BOOST_RANDOM)
    SET(BOOST_PO_LIB ${BOOST_FRAMEWORK_LIB})
    SET(BOOST_DT_LIB ${BOOST_FRAMEWORK_LIB})
    SET(BOOST_SIGNALS_LIB ${BOOST_FRAMEWORK_LIB})
    SET(BOOST_SYSTEM_LIB  ${BOOST_FRAMEWORK_LIB})
    SET(BOOST_FS_LIB  ${BOOST_FRAMEWORK_LIB})

  ELSE(USE_BOOST_FRAMEWORK)

  FIND_LIBRARY(BOOST_THREAD_LIB
    NAMES
      boost_thread-${BOOST_COMPILER}-mt-${BOOST_FLAGS}-${BOOST_VERSION}
      boost_thread-${BOOST_COMPILER}-mt-${BOOST_VERSION}
      boost_thread-${BOOST_COMPILER}-mt
      boost_thread-mt-${BOOST_VERSION}
      boost_thread-mt
      boost_thread-${BOOST_COMPILER}-${BOOST_VERSION}
      boost_thread-${BOOST_COMPILER}
      boost_thread-${BOOST_VERSION}
      boost_thread
    PATHS
      ${BOOST_LIB_DIRS}
    NO_DEFAULT_PATH
 )

  IF(NOT WT_NO_BOOST_RANDOM)
    FIND_LIBRARY(BOOST_RANDOM_LIB
      NAMES
        boost_random-${BOOST_COMPILER}-mt-${BOOST_FLAGS}-${BOOST_VERSION}
        boost_random-${BOOST_COMPILER}-mt-${BOOST_VERSION}
        boost_random-${BOOST_COMPILER}-mt
        boost_random-${BOOST_VERSION}
        boost_random-mt
        boost_random-${BOOST_COMPILER}-${BOOST_VERSION}
        boost_random-${BOOST_COMPILER}
        boost_random-${BOOST_VERSION}
        boost_random
      PATHS
        ${BOOST_LIB_DIRS}
      NO_DEFAULT_PATH
    )
  ELSE(NOT WT_NO_BOOST_RANDOM)
    SET(BOOST_RANDOM_LIB "")
  ENDIF(NOT WT_NO_BOOST_RANDOM)

  FIND_LIBRARY(BOOST_REGEX_LIB
    NAMES
      boost_regex-${BOOST_COMPILER}-mt-${BOOST_FLAGS}-${BOOST_VERSION}
      boost_regex-${BOOST_COMPILER}-mt-${BOOST_VERSION}
      boost_regex-${BOOST_COMPILER}-mt
      boost_regex-mt-${BOOST_VERSION}
      boost_regex-mt
      boost_regex-${BOOST_COMPILER}-${BOOST_VERSION}
      boost_regex-${BOOST_COMPILER}
      boost_regex-${BOOST_VERSION}
      boost_regex
    PATHS
      ${BOOST_LIB_DIRS}
    NO_DEFAULT_PATH
  )

  FIND_LIBRARY(BOOST_PO_LIB
    NAMES
      boost_program_options-${BOOST_COMPILER}-mt-${BOOST_FLAGS}-${BOOST_VERSION}
      boost_program_options-${BOOST_COMPILER}-mt-${BOOST_VERSION}
      boost_program_options-${BOOST_COMPILER}-mt
      boost_program_options-mt-${BOOST_VERSION}
      boost_program_options-mt
      boost_program_options-${BOOST_COMPILER}-${BOOST_VERSION}
      boost_program_options-${BOOST_COMPILER}
      boost_program_options-${BOOST_VERSION}
      boost_program_options
    PATHS
      ${BOOST_LIB_DIRS}
    NO_DEFAULT_PATH
  )

  FIND_LIBRARY(BOOST_DT_LIB
    NAMES
      boost_date_time-${BOOST_COMPILER}-mt-${BOOST_FLAGS}-${BOOST_VERSION}
      boost_date_time-${BOOST_COMPILER}-mt-${BOOST_VERSION}
      boost_date_time-${BOOST_COMPILER}-mt
      boost_date_time-mt-${BOOST_VERSION}
      boost_date_time-mt
      boost_date_time-${BOOST_COMPILER}-${BOOST_VERSION}
      boost_date_time-${BOOST_COMPILER}
      boost_date_time-${BOOST_VERSION}
      boost_date_time
    PATHS
      ${BOOST_LIB_DIRS}
    NO_DEFAULT_PATH
  )

  FIND_LIBRARY(BOOST_SIGNALS_LIB
    NAMES
      boost_signals-${BOOST_COMPILER}-mt-${BOOST_FLAGS}-${BOOST_VERSION}
      boost_signals-${BOOST_COMPILER}-mt-${BOOST_VERSION}
      boost_signals-${BOOST_COMPILER}-mt
      boost_signals-mt-${BOOST_VERSION}
      boost_signals-mt
      boost_signals-${BOOST_COMPILER}-${BOOST_VERSION}
      boost_signals-${BOOST_COMPILER}
      boost_signals-${BOOST_VERSION}
      boost_signals
    PATHS
      ${BOOST_LIB_DIRS}
    NO_DEFAULT_PATH
  )

  FIND_LIBRARY(BOOST_SYSTEM_LIB
    NAMES
      boost_system-${BOOST_COMPILER}-mt-${BOOST_FLAGS}-${BOOST_VERSION}
      boost_system-${BOOST_COMPILER}-mt-${BOOST_VERSION}
      boost_system-${BOOST_COMPILER}-mt
      boost_system-mt-${BOOST_VERSION}
      boost_system-mt
      boost_system-${BOOST_COMPILER}-${BOOST_VERSION}
      boost_system-${BOOST_COMPILER}
      boost_system-${BOOST_VERSION}
      boost_system
    PATHS
      ${BOOST_LIB_DIRS}
    NO_DEFAULT_PATH
  )

  FIND_LIBRARY(BOOST_FS_LIB
    NAMES
      boost_filesystem-${BOOST_COMPILER}-mt-${BOOST_FLAGS}-${BOOST_VERSION}
      boost_filesystem-${BOOST_COMPILER}-mt-${BOOST_VERSION}
      boost_filesystem-${BOOST_COMPILER}-mt
      boost_filesystem-mt-${BOOST_VERSION}
      boost_filesystem-mt
      boost_filesystem-${BOOST_COMPILER}-${BOOST_VERSION}
      boost_filesystem-${BOOST_COMPILER}
      boost_filesystem-${BOOST_VERSION}
      boost_filesystem
    PATHS
      ${BOOST_LIB_DIRS}
    NO_DEFAULT_PATH
  )

  ENDIF (USE_BOOST_FRAMEWORK)

# FIXME: todo for Linux
  SET(RT_LIB "rt")
  SET(OTHER_LIBS "-lpthread")
  SET(BOOST_SUPPORT_LIBRARIES "")
ENDIF(MSVC)

SET(BOOST_WT_FOUND FALSE)
SET(BOOST_WT_MT_FOUND FALSE)
SET(BOOST_WTHTTP_FOUND FALSE)
SET(BOOST_WTHTTP_MT_FOUND FALSE)

IF(BOOST_INCLUDE_DIRS)
  IF(MSVC)
    # This is not really tested by this script yet - assume availability
    SET(BOOST_WT_MT_FOUND TRUE)
    SET(BOOST_WT_FOUND TRUE)
    SET(BOOST_WTHTTP_MT_FOUND TRUE)
    SET(BOOST_WTHTTP_FOUND TRUE)
    SET(BOOST_WT_LIBRARIES "")

    SET(BOOST_WT_THREAD_LIBRARY  "")
    SET(BOOST_WT_REGEX_LIBRARY   "")
    SET(BOOST_WT_SIGNALS_LIBRARY "")
    SET(BOOST_WT_DT_LIBRARY      "")
    SET(BOOST_WT_SYSTEM_LIBRARY  "")

    SET(BOOST_WTHTTP_THREAD_LIBRARY "")
    SET(BOOST_WTHTTP_FS_LIBRARY     "")
    SET(BOOST_WTHTTP_PO_LIBRARY     "")
    SET(BOOST_WTHTTP_DT_LIBRARY     "")
  ENDIF(MSVC)

  SET(BOOST_RANDOM_LIB_OK WT_NO_BOOST_RANDOM OR BOOST_RANDOM_LIB)

  IF(NOT BOOST_WT_FOUND
     AND MULTI_THREADED
     AND BOOST_THREAD_LIB
     AND BOOST_RANDOM_LIB_OK
     AND BOOST_REGEX_LIB
     AND BOOST_SIGNALS_LIB
     AND BOOST_SYSTEM_LIB
     AND BOOST_FS_LIB
     AND BOOST_DT_LIB)

    SET(BOOST_WT_MT_FOUND TRUE)
    SET(BOOST_WT_FOUND TRUE)

    SET(BOOST_WT_LIBRARIES
        ${BOOST_THREAD_LIB}
        ${BOOST_RANDOM_LIB}
        ${BOOST_REGEX_LIB}
        ${BOOST_SIGNALS_LIB}
        ${BOOST_SYSTEM_LIB}
        ${BOOST_FS_LIB}
        ${BOOST_DT_LIB})

    SET(BOOST_WT_THREAD_LIBRARY  ${BOOST_THREAD_LIB})
    SET(BOOST_WT_RANDOM_LIBRARY   ${BOOST_RANDOM_LIB})
    SET(BOOST_WT_REGEX_LIBRARY   ${BOOST_REGEX_LIB})
    SET(BOOST_WT_SIGNALS_LIBRARY ${BOOST_SIGNALS_LIB})
    SET(BOOST_WT_SYSTEM_LIBRARY  ${BOOST_SYSTEM_LIB})
    SET(BOOST_WT_FS_LIBRARY      ${BOOST_FS_LIB})
    SET(BOOST_WT_DT_LIBRARY      ${BOOST_DT_LIB})

  ENDIF(NOT BOOST_WT_FOUND
     AND MULTI_THREADED
     AND BOOST_THREAD_LIB
     AND BOOST_RANDOM_LIB_OK
     AND BOOST_REGEX_LIB
     AND BOOST_SIGNALS_LIB
     AND BOOST_SYSTEM_LIB
     AND BOOST_FS_LIB
     AND BOOST_DT_LIB)

  IF(NOT BOOST_WT_FOUND
     AND BOOST_RANDOM_LIB_OK
     AND BOOST_REGEX_LIB
     AND BOOST_SIGNALS_LIB
     AND BOOST_SYSTEM_LIB
     AND BOOST_PO_LIB
     AND BOOST_FS_LIB
     AND BOOST_DT_LIB)

    SET(BOOST_WT_MT_FOUND FALSE)
    SET(BOOST_WT_FOUND TRUE)

    SET(BOOST_WT_LIBRARIES
        ${BOOST_RANDOM_LIB}
        ${BOOST_REGEX_LIB}
        ${BOOST_SIGNALS_LIB}
	${BOOST_SYSTEM_LIB}
        ${BOOST_FS_LIB}
        ${BOOST_DT_LIB})

    SET(BOOST_WT_RANDOM_LIBRARY  ${BOOST_RANDOM_LIB})
    SET(BOOST_WT_REGEX_LIBRARY   ${BOOST_REGEX_LIB})
    SET(BOOST_WT_SIGNALS_LIBRARY ${BOOST_SIGNALS_LIB})
    SET(BOOST_WT_SYSTEM_LIBRARY  ${BOOST_SYSTEM_LIB})
    SET(BOOST_WT_DT_LIBRARY      ${BOOST_DT_LIB})
    SET(BOOST_WT_FS_LIBRARY      ${BOOST_FS_LIB})

  ENDIF(NOT BOOST_WT_FOUND
     AND BOOST_RANDOM_LIB_OK
     AND BOOST_REGEX_LIB
     AND BOOST_SIGNALS_LIB
     AND BOOST_SYSTEM_LIB
     AND BOOST_PO_LIB
     AND BOOST_FS_LIB
     AND BOOST_DT_LIB)

  IF(NOT BOOST_WTHTTP_FOUND
     AND MULTI_THREADED
     AND BOOST_THREAD_LIB
     AND BOOST_PO_LIB
     AND BOOST_DT_LIB)
    SET(BOOST_WTHTTP_MT_FOUND TRUE)
    SET(BOOST_WTHTTP_FOUND TRUE)

    SET(BOOST_WTHTTP_LIBRARIES
        ${BOOST_THREAD_LIB}
        ${BOOST_PO_LIB}
        ${BOOST_DT_LIB})

    SET(BOOST_WTHTTP_THREAD_LIBRARY ${BOOST_THREAD_LIB})
    SET(BOOST_WTHTTP_FS_LIBRARY     ${BOOST_FS_LIB})
    SET(BOOST_WTHTTP_PO_LIBRARY     ${BOOST_PO_LIB})
    SET(BOOST_WTHTTP_DT_LIBRARY     ${BOOST_DT_LIB})

  ENDIF(NOT BOOST_WTHTTP_FOUND
     AND MULTI_THREADED
     AND BOOST_THREAD_LIB
     AND BOOST_PO_LIB
     AND BOOST_DT_LIB)

  IF(NOT BOOST_WTHTTP_FOUND
     AND BOOST_PO_LIB
     AND BOOST_DT_LIB)

    SET(BOOST_WTHTTP_MT_FOUND FALSE)
    SET(BOOST_WTHTTP_FOUND TRUE)

    SET(BOOST_WTHTTP_LIBRARIES
        ${BOOST_PO_LIB}
        ${BOOST_DT_LIB})

    SET(BOOST_WTHTTP_FS_LIBRARY ${BOOST_FS_LIB})
    SET(BOOST_WTHTTP_PO_LIBRARY ${BOOST_PO_LIB})
    SET(BOOST_WTHTTP_DT_LIBRARY ${BOOST_DT_LIB})

  ENDIF(NOT BOOST_WTHTTP_FOUND
     AND BOOST_PO_LIB
     AND BOOST_DT_LIB)

ENDIF(BOOST_INCLUDE_DIRS)
