Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding all external libraries stored from a directory into Qt project

Is there a way to add all libraries from a given folder without adding every single one to the LIBS variable in Qt project file.

I've put all libraries (DLLs (win) or SOs (unix)) in one directory (MYLIBS) along with header files and tried something like this:

LIBS *= -L$$PWD/MYLIBS -l*
INCLUDEPATH += $$PWD/MYLIBS
DEPENDPATH += $$PWD/MYLIBS

It didn't work with error message cannot find -l*. Is it possible for qmake to use the wildcards while creating Makefiles?

like image 998
Moomin Avatar asked Jul 08 '14 15:07

Moomin


1 Answers

You can use the files, basename and replace functions to get what you need:

LIBS *= -L$$PWD/MYLIBS
win32 {
    SHARED_LIB_FILES = $$files($$PWD/MYLIBS/*.dll)
    for(FILE, SHARED_LIB_FILES) {
        BASENAME = $$basename(FILE)
        LIBS += -l$$replace(BASENAME,.dll,)
    }
}
unix {
    SHARED_LIB_FILES = $$files($$PWD/MYLIBS/*.so)
    for(FILE, SHARED_LIB_FILES) {
        BASENAME = $$basename(FILE)
        LIBS += -l$$replace(BASENAME,.so,)
    }
}
like image 168
Bill Avatar answered Oct 06 '22 20:10

Bill