PDA

View Full Version : qmake exclude specific file in SOURCES



Scope
22nd July 2016, 12:36
Is there any way to exclude one file from statement


SOURCES += ../src/*.cpp

I want to join to SOURCES all .cpp files from src dir but without main.cpp

anda_skoa
22nd July 2016, 13:14
Have you tried



SOURCES += ../src/*.cpp
SOURCES -= ../src/main.cpp


Cheers,
_

Scope
22nd July 2016, 13:58
Yes, but i get and error


error: multiple definition of `main'

I want to join each .h and .cpp file for unit testing project which is a part of subdirs template project.

But test project has own main function which is declared by means of command

QTEST_MAIN(myClass)
#include "myClass.moc"

I do not want to add each file separately

HEADERS += myclass.h \
myclass2.h \
itd

SOURCES += myclass.cpp \
myclass2.cpp \
itd \

So I try to find better solution.
Screenshot of project structure
12039

Lesiok
22nd July 2016, 17:12
First solution - common files in src directory, two main.cpp files in subdirs of src.
In pro file You have :
SOURCES += ../src/*.cpp
SOURCES += ../src/subdir/main.cpp

Second solution - one main.cpp with conditional compilation.

Scope
22nd July 2016, 18:31
Is there any official or good template for projects with unit testing? In Qt documentation i have not found any information about that how to join main project with unit testing. Whether it should be 2 completely separated projects? Or as I use in example above - subdirs template?

ChrisW67
22nd July 2016, 21:43
Is there any way to exclude one file from statement


SOURCES += ../src/*.cpp

I want to join to SOURCES all .cpp files from src dir but without main.cpp

See if this works for you:
http://sergey.vlasov.me/2013/03/expanding-wildcards-with-qmake.html

You will still have to rerun qmake if you add or remove files from any of the globbed directories.

anda_skoa
23rd July 2016, 12:41
Is there any official or good template for projects with unit testing? In Qt documentation i have not found any information about that how to join main project with unit testing. Whether it should be 2 completely separated projects? Or as I use in example above - subdirs template?

For a QMake based project I would go for a SUBDIRS template.

Cheers,
_

Scope
23rd July 2016, 22:08
I also found information that QtCeator sinve 4.0 version has feature called "Autotest integration". It sound promising ;)
http://doc-snapshots.qt.io/qtcreator-4.0/creator-autotest.html