INCLUDE(FindPackageHandleStandardArgs)
MESSAGE("$ENV{POPLAR_ROOT}")
IF (DEFINED ENV{POPLAR_ROOT})
    SET(POPLAR_ROOT "$ENV{POPLAR_ROOT}")
ENDIF ()

find_path(POPLAR_INCLUDE_DIR NAMES poplar/IPUModel.hpp
        PATHS "${POPLAR_ROOT}" PATH_SUFFIXES "include" REQUIRED)


find_library(POPLAR_LIBRARY NAMES poplar
        PATHS "${POPLAR_ROOT}" PATH_SUFFIXES "lib")


find_library(POPOPS_LIBRARY NAMES popops
        PATHS "${POPLAR_ROOT}" PATH_SUFFIXES "lib")

find_library(POPUTIL_LIBRARY NAMES poputil
        PATHS "${POPLAR_ROOT}" PATH_SUFFIXES "lib")

find_library(POPFLOAT_LIBRARY NAMES popfloat
        PATHS "${POPLAR_ROOT}" PATH_SUFFIXES "lib")

find_library(POPLIN_LIBRARY NAMES poplin
        PATHS "${POPLAR_ROOT}" PATH_SUFFIXES "lib")

FIND_PACKAGE_HANDLE_STANDARD_ARGS(POPLAR DEFAULT_MSG
        POPLAR_INCLUDE_DIR POPLAR_LIBRARY POPOPS_LIBRARY POPUTIL_LIBRARY POPFLOAT_LIBRARY POPLIN_LIBRARY
        )

IF (POPLAR_FOUND)
    SET(POPLAR_INCLUDE_DIRS ${POPLAR_INCLUDE_DIR})

    MARK_AS_ADVANCED(
            POPLAR_INCLUDE_DIR
            POPLAR_ROOT
            POPLAR_LIBRARY
            POPLIN_LIBRARY
            POPFLOAT_LIBRARY
            POPUTIL_LIBRARY
            POPOPS_LIBRARY
    )

    add_library(poplar STATIC IMPORTED)
    set_target_properties(poplar PROPERTIES
            INTERFACE_INCLUDE_DIRECTORIES "${POPLAR_INCLUDE_DIRS}"
            IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
            IMPORTED_LOCATION "${POPLAR_LIBRARY}")

    add_library(poplin STATIC IMPORTED)
    set_target_properties(poplin PROPERTIES
            INTERFACE_INCLUDE_DIRECTORIES "${POPLAR_INCLUDE_DIRS}"
            IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
            IMPORTED_LOCATION "${POPLIN_LIBRARY}")

    add_library(popops STATIC IMPORTED)
    set_target_properties(popops PROPERTIES
            INTERFACE_INCLUDE_DIRECTORIES "${POPLAR_INCLUDE_DIRS}"
            IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
            IMPORTED_LOCATION "${POPOPS_LIBRARY}")


    add_library(popfloat STATIC IMPORTED)
    set_target_properties(popfloat PROPERTIES
            INTERFACE_INCLUDE_DIRECTORIES "${POPLAR_INCLUDE_DIRS}"
            IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
            IMPORTED_LOCATION "${POPFLOAT_LIBRARY}")



    add_library(poputil STATIC IMPORTED)
    set_target_properties(poputil PROPERTIES
            INTERFACE_INCLUDE_DIRECTORIES "${POPLAR_INCLUDE_DIRS}"
            IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
            IMPORTED_LOCATION "${POPUTIL_LIBRARY}")



ENDIF ()


