0

I am trying to write a Qt .pro file that will run a set of commands, without compiling anything else first. Setting TEMPLATE=aux allows me to run just the script, and with help from this answer I have the following .pro file

# Target and build folders
TARGET = MySuperLibrary.dll
DESTDIR = ../../BuildAll

# Creates a Makefile for not building anything.
TEMPLATE = aux

extralib.target = extra
extralib.commands = echo \"Build the library\";
extralib.depends =

QMAKE_EXTRA_TARGETS += extralib
PRE_TARGETDEPS = extra

The problem is that the script commands are run every time, but I don't want them to run if the target file already exists. How should I modify the file so that the extralib commands are not run if the target file already exists?

Edit 16.01.2021

Following from zgyarmati's answer, I have modified the pro file as follows. Note that the new mytarget.commands actually generates the target dll and gives it a new timestamp. Unfortunately, this modified pro file still generates the dll every time it is run. Naturally the real script I want to run to generate this dll takes about ten minutes, so I really do not want it to run every time I build the project.

TARGET = MySuperLibrary.dll
DESTDIR = ../../BuildAll

# Creates a Makefile for not building anything.
TEMPLATE = aux

DESTDIR_WIN = $${DESTDIR}
DESTDIR_WIN ~= s,/,\\,g

mytarget.target = $${DESTDIR_WIN}\\$${TARGET}
mytarget.commands = echo \"MyDll\" > $${DESTDIR_WIN}\\$${TARGET}
mytarget.depends = mytarget2

mytarget2.commands = @echo Building $$mytarget.target

QMAKE_EXTRA_TARGETS += mytarget mytarget2
PRE_TARGETDEPS += mytarget2
eatyourgreens
  • 1,053
  • 1
  • 12
  • 16

1 Answers1

0

Your script should create the extra file, to flag that it has been run. See https://doc.qt.io/qt-5/qmake-advanced-usage.html#adding-custom-targets

zgyarmati
  • 1,135
  • 8
  • 15
  • Thank you. I have implemented the suggestions from the link you gave, but the script is still run every time. I have updated the question with the latest version of my pro file. – eatyourgreens Jan 16 '21 at 12:25