/*
-----BEGIN QCMOD-----
name: Qt Keychain
-----END QCMOD-----
*/

//----------------------------------------------------------------------------
// qc_keychain
//----------------------------------------------------------------------------
// id, shortname, name, extraConfIfFound
QC_FIND_QT_COMP_BASE(Qt5Keychain, keychain, Qt Keychain, "CONFIG += keychain", _base)

class qc_keychain : public qc_keychain_base
{
public:
    qc_keychain(Conf *c) :
        qc_keychain_base(c)
    {}

    bool exec()
    {
        if (qc_keychain_base::exec()) {
            conf->addExtra("CONFIG += keychain_with_qtmodule");
            return true;
        }

        // try to find by path
        QString s;
        if (!conf->findHeader("qt5keychain/keychain.h", QStringList(), &s)) {
            qWarning("keychain header qt5keychain/keychain.h is not found");
            return false;
        }

        QStringList libnames;
#ifdef _MSC_VER
# ifdef QC_BUILDMODE
    	libnames += (qc_buildmode_debug? "libqt5keychaind" : "libqt5keychain"); // possibly static
        libnames += (qc_buildmode_debug? "qt5keychaind" : "qt5keychain"); // possibly dynamic
# else
    	libnames << "libqt5keychain" << "qt5keychain";
# endif
#else
        libnames << "qt5keychain";
#endif
        QString libName;
        foreach (const QString l, libnames) 
            if(conf->findLibrary(l, &s)) {
                libName = l;
                break;
            }

        if(libName.isEmpty()) {
            qWarning("keychain library qt5keychain is not found");
            return false;
        }
        conf->addLib(QString("-L%1 -l%2").arg(s, libName));

        // header and library were found by default paths. lets just add extra
        conf->addExtra(extraConfIfFound);
        return true;
    }
};
