3

Using Qt 5.12. I have been trying to make some QMake commands to run only once (instead of three times). I found this answer, where they make use of the !build_pass condition. So I set up my working directory as follows:

│   subdirs_test.pro
│
└───test
        test.pro

The test/test.pro file only contains:

!build_pass:message("This message should appear only once")

And the subdirs_test.pro contains:

TEMPLATE = subdirs

SUBDIRS = \
test

test.subdir = $$PWD/test

If I run:

cd test
qmake -tp vc test.pro

Well enough it prints:

Project MESSAGE: This message should appear only once

But if I run the subdirs project:

cd ..
qmake -r -tp vc subsdirs_test.pro

It prints the message twice:

Project MESSAGE: This message should appear only once
Project MESSAGE: This message should appear only once

Is there a way to make QMake just run it once?

  • Could you try? !build_pass:CONFIG(debug, debug|release) { message("Hello from build_pass during debug") } – ManuelH Sep 06 '19 at 13:33
  • The thing is that message needs to be ran once, no matter if one selects debug or release build. In what you propose it would indeed only run once in the debug pass. But in a CI scenario, where we only do the release pass, then it would not be ran. – Juan Gonzalez Burgos Sep 07 '19 at 21:12

1 Answers1

0
defineReplace(commonFunctionality) {
    message("commonFunctionality")
}

build_pass {
    CONFIG(debug, debug|release) {
        message("Debug")
        $$commonFunctionality();
    }
    CONFIG(release, debug|release) {
        message("Release")
        $$commonFunctionality();
    }
}


$ qmake -r -tp vc subdirs_test.pro
Project MESSAGE: Release
Project MESSAGE: commonFunctionality
Project MESSAGE: Debug
Project MESSAGE: commonFunctionality

$ qmake -r -tp vc test.pro
Project MESSAGE: Release
Project MESSAGE: commonFunctionality
Project MESSAGE: Debug
Project MESSAGE: commonFunctionality
ManuelH
  • 846
  • 1
  • 15
  • 25