Aurelien
Aurelien

Reputation: 1092

Add all subdirs in a QMake project file

I'm porting an old project to Qt, and I have a lot of unit tests project. Each unit test is a single executable.

Now my main .pro file looks like this :

SUBDIRS += UnitTests/Test01/Test01.pro
SUBDIRS += UnitTests/Test02/Test02.pro
SUBDIRS += UnitTests/Test03/Test03.pro
...
SUBDIRS += UnitTests/Test54/Test54.pro

Is there any way to include all subdirs at once ? I would like something like this :

SUBDIRS += UnitTests/*

Thanks

Upvotes: 0

Views: 441

Answers (2)

Aurelien
Aurelien

Reputation: 1092

Thanks to Martin Höher, this is working very well :

// Get a list of all .pro files
UNIT_TESTS_PRO_FILES = $$files($${PROJECT_ROOT_DIR}/Sources/UnitTests/*.pro, true)

// Add them as subdirs
for(unitTestProFile, UNIT_TESTS_PRO_FILES) SUBDIRS *= $${unitTestProFile}

Upvotes: 0

Martin Höher
Martin Höher

Reputation: 735

You can try to use qmake's files function to locate all *.pro files and add them like this:

SUBDIRS += $$files(UnitTests/*.pro,true)

files expects two parameters: A globbing expression as first parameter and whether or not to recurse into subdirectories.

Upvotes: 1

Related Questions