QmakeInvokeAutotools: Difference between revisions
No edit summary |
(Convert HTML entity number) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Cleanup | reason=Auto-imported from ExpressionEngine.}} | |||
[[Category:Tools::qmake]] | [[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 | We will assume that the Autotools-based project is called "atproj". | ||
In your SUBDIRS project, include something like the following: | In your SUBDIRS project, include something like the following: | ||
<code>TEMPLATE = subdirs | |||
atproj_build.subdir = atproj_build | atproj_build.subdir = atproj_build | ||
atproj_build.makefile = Makefile.atproj_build | |||
myApp.subdir = myApp | myApp.subdir = myApp | ||
myApp.depends = atproj_build | |||
SUBDIRS = atproj_build myApp</code> | SUBDIRS = atproj_build myApp</code> | ||
We need to change the name of the makefile because running | 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. | ||
Then create a subdirectory called | Then create a subdirectory called "atproj_build". In that directory, place a file named atproj_build.pro which contains: | ||
<code>MAKEFILE = Makefile.atproj_build | |||
ATPROJ_SRCDIR = ../atproj-1.2.3 | ATPROJ_SRCDIR = ../atproj-1.2.3 | ||
autoreconf.target = $${ATPROJ_SRCDIR}/configure | autoreconf.target = $${ATPROJ_SRCDIR}/configure | ||
autoreconf.commands = cd $${ATPROJ_SRCDIR} && autoreconf | |||
aclocal.target = $${ATPROJ_SRCDIR}/aclocal.m4 | aclocal.target = $${ATPROJ_SRCDIR}/aclocal.m4 | ||
aclocal.depends = autoreconf | |||
automake.target = $${ATPROJ_SRCDIR}/Makefile.in | automake.target = $${ATPROJ_SRCDIR}/Makefile.in | ||
automake.depends = autoreconf | |||
autoheader.target = $${ATPROJ_SRCDIR}/Makefile.in | autoheader.target = $${ATPROJ_SRCDIR}/Makefile.in | ||
autoheader.depends = autoreconf | |||
libtoolize.target = $${ATPROJ_SRCDIR}/ltmain.sh | libtoolize.target = $${ATPROJ_SRCDIR}/ltmain.sh | ||
libtoolize.depends = autoreconf | |||
Makefile.target = Makefile | Makefile.target = Makefile | ||
Makefile.commands = $${ATPROJ_SRCDIR}/configure | |||
Makefile.depends = autoreconf aclocal automake autoheader libtoolize | |||
all.commands = make | all.commands = make | ||
all.depends = Makefile | |||
all.CONFIG = phony | |||
TARGET = | TARGET = | ||
QMAKE_DISTCLEAN ''= Makefile | QMAKE_DISTCLEAN ''= Makefile | ||
QMAKE_EXTRA_TARGETS''= autoreconf aclocal automake autoheader libtoolize Makefile all</code> | |||
First, setting the MAKEFILE variable changes the name of the makefile to match the one we used above. There are | First, setting the MAKEFILE 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). | ||
qmake always creates a target named | 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: | ||
<code>all: $(TARGET) | |||
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)</code> | |||
Because we defined a ''custom'' rule named | 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! | ||
The abuse of qmake that makes this possible is to define an effectively empty TARGET, causing the automatically-generated | The abuse of qmake that makes this possible is to define an effectively empty TARGET, causing the automatically-generated "all" rule to depend on nothing. If TARGET 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. | ||
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 | 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" rule, thus being a little kinder to qmake and avoiding the most flagrant abuse! |
Latest revision as of 16:34, 13 March 2015
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine. Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean. |
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".
In your SUBDIRS project, include something like the following:
TEMPLATE = subdirs
atproj_build.subdir = atproj_build
atproj_build.makefile = Makefile.atproj_build
myApp.subdir = myApp
myApp.depends = atproj_build
SUBDIRS = atproj_build myApp
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.
Then create a subdirectory called "atproj_build". 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
autoreconf.commands = cd $${ATPROJ_SRCDIR} && autoreconf
aclocal.target = $${ATPROJ_SRCDIR}/aclocal.m4
aclocal.depends = autoreconf
automake.target = $${ATPROJ_SRCDIR}/Makefile.in
automake.depends = autoreconf
autoheader.target = $${ATPROJ_SRCDIR}/Makefile.in
autoheader.depends = autoreconf
libtoolize.target = $${ATPROJ_SRCDIR}/ltmain.sh
libtoolize.depends = autoreconf
Makefile.target = Makefile
Makefile.commands = $${ATPROJ_SRCDIR}/configure
Makefile.depends = autoreconf aclocal automake autoheader libtoolize
all.commands = make
all.depends = Makefile
all.CONFIG = phony
TARGET =
QMAKE_DISTCLEAN ''= Makefile
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", "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).
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:
all: $(TARGET)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
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!
The abuse of qmake that makes this possible is to define an effectively empty TARGET, causing the automatically-generated "all" rule to depend on nothing. If TARGET 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.
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" rule, thus being a little kinder to qmake and avoiding the most flagrant abuse!