cmake_minimum_required(VERSION 3.12)

if(CMT_PACKAGE_MANAGER MATCHES "find")
    if(NOT CMT_PACKAGE_MANAGER MATCHES "cmake")
        set(REQUIRED ${REQUIRED})
    endif()
    # Start finding the dependencies
    if(CMT_ENABLE_EIGEN3 AND NOT TARGET Eigen3::Eigen )
        find_package(Eigen3 3.3 ${REQUIRED})
        if(TARGET Eigen3::Eigen)
            list(APPEND H5PP_TARGETS Eigen3::Eigen)
            target_link_libraries(cmt-dependencies INTERFACE Eigen3::Eigen)
        endif()
    endif()


    if(H5PP_ENABLE_FMT AND NOT TARGET fmt::fmt)
        find_package(fmt 6.2.1 ${REQUIRED})
        if(TARGET fmt::fmt)
            list(APPEND H5PP_TARGETS fmt::fmt)
            target_link_libraries(cmt-dependencies INTERFACE fmt::fmt)
        endif()
    endif()

    if(H5PP_ENABLE_SPDLOG AND NOT TARGET spdlog::spdlog)
        find_package(spdlog 1.3.1 ${REQUIRED})
        if(TARGET spdlog)
            add_library(spdlog::spdlog ALIAS spdlog)
        endif()
        if(TARGET spdlog::spdlog)
            list(APPEND H5PP_TARGETS spdlog::spdlog)
            target_link_libraries(cmt-dependencies INTERFACE spdlog::spdlog)
        endif()
    endif()

    if (NOT TARGET hdf5::all)
        find_package(HDF5 1.8 COMPONENTS C HL ${REQUIRED})
        if(TARGET hdf5::all)
            list(APPEND H5PP_TARGETS hdf5::all)
            target_link_libraries(cmt-dependencies INTERFACE hdf5::all)
        elseif(DEFINED REQUIRED)
            message(FATAL_ERROR "Could not find HDF5")
        endif()
    endif()
endif()