Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt - Using asterisk (*) in .pro-File with directories

I have a .pro file which looks like:

SOURCES += myfolder/source1.cpp \
           myfolder/source2.cpp
HEADERS  += myfolder/header1.h\
            myfolder/header2.h
FORMS    += myfolder/form1.ui\
            myfolder/form2.ui

And everything works great. However, if I try to use an asterisk to include all the files, i.e.:

SOURCES  += myfolder/*.cpp
HEADERS  += myfolder/*.h
FORMS    += myfolder/*.ui

qmake throws a file-not-found-error:

WARNING: Failure to find: myfolder\*.cpp
[...]
:-1: error: No rule to make target `myfolder/*.cpp', needed by `release/source1.o'.  Stop.

In both cases, Qt-Creator can find the files.

Is there a way to use the asterisk? It's annoying to type the files manually.

Thank you!

[EDIT: Qt 4.8.4, Windows 7, Qt-Creator 2.6.1. Sry for forgetting this thought it isnt needed.]

[EDIT: Found solution: http://qt-project.org/forums/viewthread/1127 . Thank you anyway!]

like image 512
Matze Klein Avatar asked May 07 '13 01:05

Matze Klein


1 Answers

At first, using asterisk is bad practice - despite that qmake allows it, QtCreator cannot edit such *.pro correctly on adding new, renaming or deleting file. So try to add new files with "New file" or "Add existing files" dialogs.

QMake has for loop and function $$files(directory_path: String). Also append files to SOURCES or HEADERS variable respectively.

Brief example, which adds all files, but not directories, to variable FILES (not affect build or project tree):

files = $$files($$PWD/src)
win32:files ~= s|\\\\|/|g
for(file, files):!exists($$file/*):FILES += $$file

If you want to check if file is *.cpp, try to use contains($$file, ".cpp").

files = $$files($$PWD/src)
win32:files ~= s|\\\\|/|g
for(file, files):!exists($$file/*):contains($$file, ".cpp"):SOURCES += $$file
like image 150
Sergey Shambir Avatar answered Oct 03 '22 15:10

Sergey Shambir