FUNCTION(ADD_DEPENDENCY_TO_BOOST VERSION)
    SET(REQUIRED_LIBRARIES ${ARGN})
    IF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
        SET_CLANG_BOOST_COMPILER_FLAGS() #because FindBoost sucks at finding boost compiled with versioned layout by Clang
    ENDIF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")

    FIND_PACKAGE(Boost ${VERSION} REQUIRED COMPONENTS ${REQUIRED_LIBRARIES})
    IF(NOT ("${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}" STREQUAL ${VERSION}))
        MESSAGE(WARNING "Using Boost ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION} - application is not tested with ${VERSION}, so keep cautious!")
    ENDIF(NOT ("${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}" STREQUAL ${VERSION}))

	IF("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
	    SET(Boost_USE_DEBUG_RUNTIME ON)
	ELSE()
	    SET(Boost_USE_DEBUG_RUNTIME OFF)
	ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
	
	
	
    MESSAGE(STATUS "Using Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
    MESSAGE(STATUS "Using Boost libraries: ${Boost_LIBRARIES}")
    MESSAGE(STATUS "Using Boost libraries from: ${Boost_LIBRARY_DIRS}")
    MESSAGE(STATUS "Using Boost headers from: ${Boost_INCLUDE_DIRS}")
	
	SET(Boost_LIBRARIES ${Boost_LIBRARIES} PARENT_SCOPE)
	SET(Boost_LIBRARY_DIRS ${Boost_LIBRARY_DIRS} PARENT_SCOPE)
	SET(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} PARENT_SCOPE)

	LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
ENDFUNCTION(ADD_DEPENDENCY_TO_BOOST VERSION LIBRARIES)

FUNCTION(ADD_DEPENDENCY_TO_OPEN_CV)
    FIND_PACKAGE(OpenCV REQUIRED COMPONENTS core imgproc highgui)
    
	MESSAGE(STATUS "Using OpenCV version: ${OpenCV_VERSION}")
    MESSAGE(STATUS "Using OpenCV libraries: ${OpenCV_LIBS}")
    MESSAGE(STATUS "Using OpenCV libraries from: ${OpenCV_LIB_DIR}")
    MESSAGE(STATUS "Using OpenCV headers from: ${OpenCV_INCLUDE_DIRS}")
	
	SET(OpenCV_LIBS ${OpenCV_LIBS} PARENT_SCOPE)
	SET(OpenCV_LIB_DIR ${OpenCV_LIB_DIR} PARENT_SCOPE)
	SET(OpenCV_INCLUDE_DIRS ${OpenCV_INCLUDE_DIRS} PARENT_SCOPE)
	
	LINK_DIRECTORIES(${OpenCV_LIB_DIR})
ENDFUNCTION(ADD_DEPENDENCY_TO_OPEN_CV)

FUNCTION(ADD_DEPENDENCY_TO_LAPACK)
    FIND_PACKAGE(LAPACK REQUIRED)
    
    MESSAGE(STATUS "Using LAPACK libraries: ${LAPACK_LIBRARIES}")
    MESSAGE(STATUS "Using LAPACK linker flags: ${LAPACK_LINKER_FLAGS}")
	
	SET(LAPACK_LIBS ${LAPACK_LIBRARIES } PARENT_SCOPE)
	SET(LAPACK_LINKER_FLAGS  ${LAPACK_LINKER_FLAGS } PARENT_SCOPE)
	SET(LAPACK_FOUND ${LAPACK_FOUND} PARENT_SCOPE)
ENDFUNCTION(ADD_DEPENDENCY_TO_LAPACK)
