How to add qmake commands from .pri correctly
-
Hello, I have a snippet of a .pro here as this:
QT += core gui opengl target.path = $$PWD/Assistant/simpletextviewer docs.files += $$PWD/documentation docs.path = $$target.path greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = ImportWizard #this .pri is shown below include(../../../LoadBuildFiles/BuildFunctions.pri) #this calls the only function of the .pri buildDependencies() TEMPLATE = lib
And then in the .pri I'm including, this is the function being called:
defineTest(buildDependencies){ #This forces a remake of the make file so the build command will always execute qmake and run our script qmakeforce.target = dummy qmakeforce.commands = rm -f $$PWD/Makefile ##this does the actual re-run of qmake qmakeforce.depends = FORCE PRE_TARGETDEPS += $$qmakeforce.target QMAKE_EXTRA_TARGETS += qmakeforce message($$PWD) if(!equals($$makeOptions, "clean")){ PRE_TARGETDEPS += ../../../Libraries/"$$TARGET"Library""/lib64 system(. ../../../LoadBuildFiles/./SubMake.sh && HeaderCopy "$$TARGET") QMAKE_POST_LINK = . ../../../LoadBuildFiles/./SubMake.sh && PostMakeLibCopy "$$TARGET"Library"" message("Called anything else $$makeOptions") }else{ message("Called clean $$makeOptions") } }
So, we're trying to automate the load build process by calling a script from the .pro through the system command call. This works fine if you manually run qmake, however we wanted to automate the entire process such that whether you make, qmake, or clean. Someone said the only way for build to call qmake implicitly is if the Makefile or .pro is dirtied is some fashion. My colleague and I assumed that this .pri is just expanded in place when the function is called, but there seems to be some side effects. If we drag the function out where the following is includedin the .pro:
#this .pri is shown below include(../../../LoadBuildFiles/BuildFunctions.pri) #this calls the only function of the .pri buildDependencies()
Afterwards it looks like this:
QT += core gui opengl target.path = $$PWD/Assistant/simpletextviewer docs.files += $$PWD/documentation docs.path = $$target.path greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = ImportWizard #This forces a remake of the make file so the build command will always execute qmake and run our script qmakeforce.target = dummy qmakeforce.commands = rm -f $$PWD/Makefile ##this does the actual re-run of qmake qmakeforce.depends = FORCE PRE_TARGETDEPS += $$qmakeforce.target QMAKE_EXTRA_TARGETS += qmakeforce message($$PWD) if(!equals($$makeOptions, "clean")){ PRE_TARGETDEPS += ../../../Libraries/"$$TARGET"Library""/lib64 system(. ../../../LoadBuildFiles/./SubMake.sh && HeaderCopy "$$TARGET") QMAKE_POST_LINK = . ../../../LoadBuildFiles/./SubMake.sh && PostMakeLibCopy "$$TARGET"Library"" message("Called anything else $$makeOptions") }else{ message("Called clean $$makeOptions") } TEMPLATE = lib
Then everything works just fine. Do the qMake commands not expand in place when including a .pri? Is there a way to achieve what we're doing with in place substitution?
-
Since this is pretty old, the solution is to at the bottom of the .pri file to use the export function. For every QMAKE key word you need an export for it.
In my above example I should append the following to the bottom:export(PRE_TARGETDEPS)
export(QMAKE_EXTRA_TARGETS)