1

So, I am starting using unit test using catch with Qt (plain c++, but using qmake with .pro file).

Its a small project with the following files:

DatagramSocket.cpp/h
main.cpp                     - this contains a main() function

But also for the unit test it has the files:

catch.hpp
unittestdatagramsocket.cpp   - this contains a main() function

In my .pro file I can build the project normally like this:

TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
# TARGET = unittest-UDPDatagram
TARGET = UDPDatagram

SOURCES += \
    main.cpp \
    DatagramSocket.cpp \
    # unittestdatagramsocket.cpp


HEADERS += \
    DatagramSocket.h \
    catch.hpp

LIBS += \
    -lwsock32
    -lws2_32

And then I can run UDPDatagram.exe - it works.

Or I can build it for unit test like this:

TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
TARGET = unittest-UDPDatagram
# TARGET = UDPDatagram

SOURCES += \
    # main.cpp \
    DatagramSocket.cpp \
    unittestdatagramsocket.cpp


HEADERS += \
    DatagramSocket.h \
    catch.hpp

LIBS += \
    -lwsock32
    -lws2_32

Then I can run unittest-UDPDatagram.exe - it works.

What I would like to do is for the build (whether debug or release) to build both every time. Is that possible?

drescherjm
  • 10,365
  • 5
  • 44
  • 64
code_fodder
  • 15,263
  • 17
  • 90
  • 167
  • Possible duplicate of [How do I use qmake to build multiple binaries in a single project?](http://stackoverflow.com/questions/1538398/how-do-i-use-qmake-to-build-multiple-binaries-in-a-single-project) – Gluttton Sep 13 '16 at 09:42
  • @Gluttton - it is kind of similar, thanks. I think I could use further ideas though and would like to keep it open a bit longer if possible to see if there are other options. – code_fodder Sep 13 '16 at 09:50
  • you can use `SUBDIRS` to make it. ref: https://stackoverflow.com/a/1538639/7943781 –  Oct 14 '19 at 10:04

1 Answers1

1

No, each .pro file is for just a single executable or library. But you can put the shared stuff in a separate .pro file and include it from the two .pro files, each one for a single program.

falkb
  • 1,294
  • 11
  • 35
  • Thanks for that. But does this mean it has to be a separate project? or is there a way to link the two .pro files to build together (maybe like a sub-dirs project?) but still produce two executables? - or must I switch projects each time? Thanks! – code_fodder Sep 13 '16 at 09:48
  • Just create a simple batch file (createAll.bat) calling qmake for both .pro files and done :-) – falkb Sep 13 '16 at 09:52
  • awww.....I suppose so!, thanks :) wanted to try to keep it build-able withing qtcreator, but its not priority. – code_fodder Sep 13 '16 at 10:00