qmake subdirs

.pro file can specify a subdirs template. You may think to use subdirs template, you need to create sub directories and create sub project files in them. But actually you do not need to do so. Just create a subdirs .pro file and qmake can create a Makefile from it without problem even the sub-directories and sub .pro files does not exist yet. The following is a minimal .pro file with the subdirs template:

TEMPLATE      = subdirs
SUBDIRS = dir1 dir2

The created Makefile will include the following targets:

  • sub-dir1-qmake_all
  • sub-dir1
  • sub-dir1-make_first
  • sub-dir1-all
  • sub-dir1-clean
  • sub-dir1-distclean
  • sub-dir1-install_subtargets
  • sub-dir1-uninstall_subtargets
  • sub-dir2-qmake_all
  • sub-dir2
  • sub-dir2-make_first
  • sub-dir2-all
  • sub-dir2-clean
  • sub-dir2-distclean
  • sub-dir2-install_subtargets
  • sub-dir2-uninstall_subtargets
  • Makefile
  • qmake
  • qmake_all
  • make_first
  • all
  • clean
  • distclean
  • install_subtargets
  • uninstall_subtargets
  • sub-dir1-debug
  • sub-dir2-debug
  • debug
  • sub-dir1-release
  • sub-dir2-release
  • release
  • sub-dir1-check
  • sub-dir2-check
  • check
  • sub-dir1-benchmark
  • sub-dir2-benchmark
  • benchmark
  • install
  • uninstall
  • FORCE

Most of the targets are just to enter a subdir and execute make -f Makefile there(if the Makefile does not exist, call qmake to generate it). So if the subdirectories/sub-projects have not been created yet, the make will fail. The Makefile target in the generated Makefile is kind of special. It depends not only on the .pro file but also on  numerous .pri/ .prf files and qmake.conf in the mkspecs directory, and .qmake.stash(created by qmake) in current directory.

dir1, dir2, etc can have sub variables/child variables/member variables, e.g.  dir1.target=myapp1. Then all sub-dir1-xxx targets in the generated Makefile will be replaced by myapp1-xxx. If you set dir1.subdir=mysubdir, all occurrences of dir1 will be replaced with mysubdir in the generated Makefile, e.g, sub-dir1-make_first will become sub-mysubdir-make_first. If you set dir1.file=myfile, all dir1s will be replaced by myfile and qmake assumes myfile is the name of the sub-directory. An important sub-variable is the depends variable. It will make all targets dependent on other targets. For example, dir1.depends=mydeps will create a prerequisite for sub-dir1 as follows:

sub-dir1: mydeps FORCE

So using .depends can create dependencies between sub-modules.

 

 

 

If you like my content, please consider buying me a coffee. Buy me a coffeeBuy me a coffee Thank you for your support!
Posted in

Leave a Reply