# - Find SLB
# Find the native SLB headers
#
#  SLB_INCLUDE_DIR  - where to find SLB.h, etc.
#  SLB_LIBRARIES    - SLB library
#  SLB_DEFINES      - SLB defines
#  SLB_FOUND        - True if SLB found.

IF(SLB_FOUND)
    # Already in cache, be silent
    SET(SLB_FIND_QUIETLY TRUE)
ENDIF()

INCLUDE(${CMAKE_CURRENT_LIST_DIR}/DefinesSLB.txt)

IF(BUILD_SLB OR ACGL_GLOBAL_EXTERN_DIR_FOUND_FIRST_TIME OR BUILD_TYPE_CHANGED)
    UNSET(SLB_INCLUDE_DIR CACHE)
    UNSET(SLB_LIBRARIES CACHE)
ENDIF()

IF(BUILD_SLB)
    SET(SLB_INCLUDE_DIR "${ACGL_LOCAL_EXTERN_DIR}/slb/include")
    SET(SLB_LIBRARIES SLB${COMPILE_POSTFIX})
ELSE()
    # Look for the header file.
    IF(ACGL_GLOBAL_EXTERN_DIR)
        FIND_PATH(SLB_INCLUDE_DIR NAMES SLB/SLB.hpp PATHS "${ACGL_GLOBAL_EXTERN_DIR}/slb/include" NO_DEFAULT_PATH)
    ENDIF()
    IF(NOT SLB_INCLUDE_DIR)
        FIND_PATH(SLB_INCLUDE_DIR NAMES SLB/SLB.hpp)
    ENDIF()

    # Look for the library file.
    IF(ACGL_GLOBAL_EXTERN_DIR)
        FIND_LIBRARY(SLB_LIBRARIES NAMES SLB${COMPILE_POSTFIX} PATHS "${ACGL_GLOBAL_EXTERN_DIR}/slb/lib" NO_DEFAULT_PATH)
    ENDIF()
    IF(NOT SLB_LIBRARIES)
        FIND_LIBRARY(SLB_LIBRARIES NAMES SLB${COMPILE_POSTFIX})
    ENDIF()
ENDIF()

# Copy the results to the output variables.
IF(SLB_INCLUDE_DIR AND SLB_LIBRARIES)
    SET(SLB_FOUND TRUE CACHE INTERNAL "")
ELSE()
    SET(SLB_FOUND FALSE CACHE INTERNAL "")
ENDIF()

# Report the results.
IF(NOT SLB_FOUND)
    SET(SLB_MESSAGE "SLB was not found. Make sure SLB_INCLUDE_DIR AND SLB_LIBRARIES are set correctly.")
    IF(SLB_FIND_REQUIRED)
        MESSAGE(FATAL_ERROR "${SLB_MESSAGE}")
    ELSEIF(NOT SLB_FIND_QUIETLY)
        MESSAGE(STATUS "${SLB_MESSAGE}")
    ENDIF()
ELSEIF(NOT SLB_FIND_QUIETLY)
    MESSAGE(STATUS "Looking for SLB - found")
ENDIF()

MESSAGE(STATUS "SLB_INCLUDE_DIR:${SLB_INCLUDE_DIR}")
MESSAGE(STATUS "SLB_LIBRARIES:${SLB_LIBRARIES}")

