Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

QmakeInvokeAutotools: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
[[Category:Tools::qmake]]
One of the more frustrating aspects of qmake is to get it to integrate with non-qmake-based projects. What follows unquestionably qualifies as abusing qmake, but it provides a method to build an Autotools-based project as part of a qmake-based project. (If you are facing more than one or two of these sorts of challenges, consider that qmake may not be the correct tool for the job!)
One of the more frustrating aspects of qmake is to get it to integrate with non-qmake-based projects. What follows unquestionably qualifies as abusing qmake, but it provides a method to build an Autotools-based project as part of a qmake-based project. (If you are facing more than one or two of these sorts of challenges, consider that qmake may not be the correct tool for the job!)


We will assume that the Autotools-based project is called “atproj”.
We will assume that the Autotools-based project is called "atproj".
 
In your SUBDIRS project, include something like the following:<br /><code>TEMPLATE = subdirs
 
atproj_build.subdir = atproj_build<br />atproj_build.makefile = Makefile.atproj_build
 
myApp.subdir = myApp<br />myApp.depends = atproj_build
 
SUBDIRS = atproj_build myApp</code>
 
We need to change the name of the makefile because running &quot;configure&amp;quot; would otherwise clobber it, so the &quot;atproj_build.makefile = atproj_build&amp;quot; will cause the top-level Makefile to call &quot;make -f Makefile.atproj_build&amp;quot; in that subdirectory. Note that this will not actually change the name of the file qmake generates there; we'll take care of that in a bit.
 
Then create a subdirectory called &quot;atproj_build&amp;quot;. In that directory, place a file named atproj_build.pro which contains:<br /><code>MAKEFILE = Makefile.atproj_build
 
ATPROJ_SRCDIR = ../atproj-1.2.3
 
autoreconf.target = $${ATPROJ_SRCDIR}/configure<br />autoreconf.commands = cd $${ATPROJ_SRCDIR} &amp;&amp; autoreconf
 
aclocal.target = $${ATPROJ_SRCDIR}/aclocal.m4<br />aclocal.depends = autoreconf
 
automake.target = $${ATPROJ_SRCDIR}/Makefile.in<br />automake.depends = autoreconf


In your <span class="caps">SUBDIRS</span> project, include something like the following:<br />
autoheader.target = $${ATPROJ_SRCDIR}/Makefile.in<br />autoheader.depends = autoreconf


We need to change the name of the makefile because running “configure” would otherwise clobber it, so the “atproj_build.makefile = atproj_build” will cause the top-level Makefile to call “make -f Makefile.atproj_build” in that subdirectory. Note that this will not actually change the name of the file qmake generates there; we’ll take care of that in a bit.
libtoolize.target = $${ATPROJ_SRCDIR}/ltmain.sh<br />libtoolize.depends = autoreconf


Then create a subdirectory called “atproj_build”. In that directory, place a file named atproj_build.pro which contains:<br />
Makefile.target = Makefile<br />Makefile.commands = $${ATPROJ_SRCDIR}/configure<br />Makefile.depends = autoreconf aclocal automake autoheader libtoolize


First, setting the <span class="caps">MAKEFILE</span> variable changes the name of the makefile to match the one we used above. There are “autoreconf”, “aclocal”, “automake”, “autoheader”, and “libtoolize” custom targets defined to ensure that all the Autotools file are up-to-date (though you may need to adjust these for your own project, as appropriate).
all.commands = make<br />all.depends = Makefile<br />all.CONFIG = phony


qmake always creates a target named “all”, which is the default build target; I have not found a way to prevent this. The makefile rule looks something like:<br />
TARGET =


Because we defined a ''custom'' rule named “all” as well and made it depend on “Makefile”, qmake will later on write an additional rule in the makefile for “all” which will simply call “make”. The remaining challenge is to get it not to call the linker!
QMAKE_DISTCLEAN ''= Makefile<br />QMAKE_EXTRA_TARGETS''= autoreconf aclocal automake autoheader libtoolize Makefile all</code>


The abuse of qmake that makes this possible is to define an effectively empty <span class="caps">TARGET</span>, causing the automatically-generated “all” rule to depend on nothing. If <span class="caps">TARGET</span> is actually empty, then qmake will set it to the name of the .pro file (which is not what we want), so the triple-backslash-space sequence above is sufficient to count as “not empty”, but will still evaluate to nothing in the generated makefile.
First, setting the MAKEFILE variable changes the name of the makefile to match the one we used above. There are &quot;autoreconf&amp;quot;, &quot;aclocal&amp;quot;, &quot;automake&amp;quot;, &quot;autoheader&amp;quot;, and &quot;libtoolize&amp;quot; custom targets defined to ensure that all the Autotools file are up-to-date (though you may need to adjust these for your own project, as appropriate).


Alternately, if you can depend on the name of the final binary output by configure’s Makefile, you may be able to simply set <span class="caps">TARGET</span> to match this file, and leave out the extra “all” rule, thus being a little kinder to qmake and avoiding the most flagrant abuse!
qmake always creates a target named &quot;all&amp;quot;, which is the default build target; I have not found a way to prevent this. The makefile rule looks something like:<br /><code>all: $(TARGET)<br />&amp;#09;$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)</code>


This should now allow you to include an Autotools project within your qmake framework!
Because we defined a ''custom'' rule named &quot;all&amp;quot; as well and made it depend on &quot;Makefile&amp;quot;, qmake will later on write an additional rule in the makefile for &quot;all&amp;quot; which will simply call &quot;make&amp;quot;. The remaining challenge is to get it not to call the linker!


===Categories:===
The abuse of qmake that makes this possible is to define an effectively empty TARGET, causing the automatically-generated &quot;all&amp;quot; rule to depend on nothing. If TARGET is actually empty, then qmake will set it to the name of the .pro file &amp;#40;which is not what we want&amp;amp;#41;, so the triple-backslash-space sequence above is sufficient to count as &quot;not empty&amp;quot;, but will still evaluate to nothing in the generated makefile.


* [[:Category:Tools|Tools]]
Alternately, if you can depend on the name of the final binary output by configure's Makefile, you may be able to simply set TARGET to match this file, and leave out the extra &quot;all&amp;quot; rule, thus being a little kinder to qmake and avoiding the most flagrant abuse!
** [[:Category:Tools::qmake|qmake]]

Revision as of 09:46, 24 February 2015


One of the more frustrating aspects of qmake is to get it to integrate with non-qmake-based projects. What follows unquestionably qualifies as abusing qmake, but it provides a method to build an Autotools-based project as part of a qmake-based project. (If you are facing more than one or two of these sorts of challenges, consider that qmake may not be the correct tool for the job!)

We will assume that the Autotools-based project is called "atproj&quot;.

In your SUBDIRS project, include something like the following:

TEMPLATE = subdirs

atproj_build.subdir = atproj_build<br />atproj_build.makefile = Makefile.atproj_build

myApp.subdir = myApp<br />myApp.depends = atproj_build

SUBDIRS = atproj_build myApp

We need to change the name of the makefile because running "configure&quot; would otherwise clobber it, so the "atproj_build.makefile = atproj_build&quot; will cause the top-level Makefile to call "make -f Makefile.atproj_build&quot; in that subdirectory. Note that this will not actually change the name of the file qmake generates there; we'll take care of that in a bit.

Then create a subdirectory called "atproj_build&quot;. In that directory, place a file named atproj_build.pro which contains:

MAKEFILE = Makefile.atproj_build

ATPROJ_SRCDIR = ../atproj-1.2.3

autoreconf.target = $${ATPROJ_SRCDIR}/configure<br />autoreconf.commands = cd $${ATPROJ_SRCDIR} &amp;&amp; autoreconf

aclocal.target = $${ATPROJ_SRCDIR}/aclocal.m4<br />aclocal.depends = autoreconf

automake.target = $${ATPROJ_SRCDIR}/Makefile.in<br />automake.depends = autoreconf

autoheader.target = $${ATPROJ_SRCDIR}/Makefile.in<br />autoheader.depends = autoreconf

libtoolize.target = $${ATPROJ_SRCDIR}/ltmain.sh<br />libtoolize.depends = autoreconf

Makefile.target = Makefile<br />Makefile.commands = $${ATPROJ_SRCDIR}/configure<br />Makefile.depends = autoreconf aclocal automake autoheader libtoolize

all.commands = make<br />all.depends = Makefile<br />all.CONFIG = phony

TARGET = 

QMAKE_DISTCLEAN ''= Makefile<br />QMAKE_EXTRA_TARGETS''= autoreconf aclocal automake autoheader libtoolize Makefile all

First, setting the MAKEFILE variable changes the name of the makefile to match the one we used above. There are "autoreconf&quot;, "aclocal&quot;, "automake&quot;, "autoheader&quot;, and "libtoolize&quot; custom targets defined to ensure that all the Autotools file are up-to-date (though you may need to adjust these for your own project, as appropriate).

qmake always creates a target named "all&quot;, which is the default build target; I have not found a way to prevent this. The makefile rule looks something like:

all: $(TARGET)<br />&amp;#09;$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)

Because we defined a custom rule named "all&quot; as well and made it depend on "Makefile&quot;, qmake will later on write an additional rule in the makefile for "all&quot; which will simply call "make&quot;. The remaining challenge is to get it not to call the linker!

The abuse of qmake that makes this possible is to define an effectively empty TARGET, causing the automatically-generated "all&quot; rule to depend on nothing. If TARGET is actually empty, then qmake will set it to the name of the .pro file &#40;which is not what we want&amp;#41;, so the triple-backslash-space sequence above is sufficient to count as "not empty&quot;, but will still evaluate to nothing in the generated makefile.

Alternately, if you can depend on the name of the final binary output by configure's Makefile, you may be able to simply set TARGET to match this file, and leave out the extra "all&quot; rule, thus being a little kinder to qmake and avoiding the most flagrant abuse!