Victor Polevoy Victor Polevoy - 2 months ago 10
C Question

Conditionally link to shared library on a define in qmake

I have a code which is branched by

#define
directive, for example:

#ifdef USE_LIB_CRYPTO
#include <openssl/evp.h>
#else
#include <cryptopp/pwdbased.h>
#include <cryptopp/sha.h>
#endif


Depending on is defined
USE_LIB_CRYPTO
or not I should add

LIBS += -lcrypto


or

LIBS += -lcryptopp


How can I do that? For example, this should be controlled by:


qmake ./ DEFINES+="USE_LIB_CRYPTO"


So I need to somehow check is
define
passed to qmake and link to the library I need.

Answer

You can use contains test function of the qmake.

contains ( DEFINES, USE_LIB_CRYPTO ){
    LIBS += -lcrypto
} else {
    LIBS += -lcryptopp
}