SET(LIB_TYPE SHARED)

OPTION(BUILD_SHARED_LIBS "Build shared libs" ON)
MARK_AS_ADVANCED(BUILD_SHARED_LIBS)

IF (BUILD_SHARED_LIBS)
    SET(LIB_TYPE SHARED)
ELSE()
    SET(LIB_TYPE STATIC)
ENDIF()

STRING(COMPARE NOTEQUAL "${BUILD_SHARED_STATUS}" "" BUILD_SHARED_STATUS_NOT_EMPTY)
IF(BUILD_SHARED_STATUS_NOT_EMPTY)
    STRING(COMPARE NOTEQUAL "${BUILD_SHARED_STATUS}" "${BUILD_SHARED_LIBS}" RESET)
ENDIF()

# Store in cache previous value of BUILD_SHARED_LIBS
SET(BUILD_SHARED_STATUS "${BUILD_SHARED_LIBS}" CACHE INTERNAL "Previous shared status" FORCE)

FUNCTION(FIND_LIBRARY VAR)
    IF(${RESET})
        SET(${VAR} NOTFOUND CACHE STRING "" FORCE)
    ENDIF()
    _FIND_LIBRARY(${VAR} ${ARGN})
    MARK_AS_ADVANCED(${VAR})
ENDFUNCTION()
