Home > other >  Within qmake how can I get the full path to static library created by a subproject?
Within qmake how can I get the full path to static library created by a subproject?

Time:08-26

I am currently using qmake to build an application. The project is structured to have some sub libraries. So my project looks like this:

--root project (.pro file)
       --app
          |_ pro file and cpp/h files
       --core
          |_ pro file and cpp/h files
       --gui
          |_ pro file and cpp/h files

When the build runs, it outputs the static libraries from each of these sub projects to a default location as follows.

$$top_builddir/src/core/common/debug/  
$$top_builddir/src/core/helpers/debug/ 
$$top_builddir/src/core/models/debug/  
$$top_builddir/src/core/services/debug/
$$top_builddir/src/gui/forms/debug/    
$$top_builddir/src/gui/widgets/debug/  

So, when building my app and linking to the LIBS I do this:

unix|win32: LIBS  = \
    -L$$top_builddir/src/core/common/debug/     -lcommon \
    -L$$top_builddir/src/core/helpers/debug/    -lhelpers \
    -L$$top_builddir/src/core/models/debug/     -lmodels \
    -L$$top_builddir/src/core/services/debug/   -lservices \
    -L$$top_builddir/src/gui/forms/debug/       -lforms \
    -L$$top_builddir/src/gui/widgets/debug/     -lwidgets

I can turn "debug" into a variable that is populated based off the config in order to dynamically build this path to be either debug or release. I could also set the destination directory for each project (DESTDIR) to something known based on my build config, store it in a variable, and then use that.

But I want to ask if this is the best way to handle this, or there a better way? I'm worried I am overlooking a simpler way to specify where my app should look for the static libraries it depends on.

CodePudding user response:

In my projects I use the solution as you suggested:

I can turn "debug" into a variable that is populated based off the config in order to dynamically build this path to be either debug or release.

The .pro file code example:

CONFIG(debug, debug|release) : BUILD_TYPE = debug
CONFIG(release, debug|release) : BUILD_TYPE = release
LIBS  = -L$${LIB_DIR}/mylib/$${BUILD_TYPE} -lmylib

I think it is a comprehensible and good way to handle this case.

  • Related