PDA

View Full Version : Building documentation with qmake



nurtsi
24th April 2008, 15:15
I'm having problems trying to use qmake to build my documentation. I have a directory where my documentation is as latex files. I want to use qmake (since I use it everywhere else in the project) to build pdfs out of the .tex files and also provide an install target to install them to a specified directory.

I've tried doing it using a custom compiler:



# Dummy, just to avoid qmake error because we're not compiling any application
TEMPLATE = subdirs

TEX = help.tex

# Compiler for pdfs
doc_builder.name = tex2pdf
doc_builder.input = $$TEX
doc_builder.output = ${QMAKE_FILE_IN_BASE}.pdf
doc_builder.commands = pdflatex ${QMAKE_FILE_IN}
doc_builder.variable_out = PDFS
QMAKE_EXTRA_COMPILERS += doc_builder

# Install documentation
docs.path = $$PREFIX/share/doc/MyApp
docs.files = changelog.txt $$PDFS

INSTALLS += docs


This doesn't work, because the $$PDFS is expanded when qmake is run and it is naturally empty at the time because the custom compiler hasn't been run. How can I get around this? Is there any way of telling that the install target depends on something? Or is there another approach to achieve the same results I'm after?

fullmetalcoder
24th April 2008, 18:57
I think the problem lies here :

doc_builder.input = $$TEX

should be :

doc_builder.input = TEX

nurtsi
25th April 2008, 12:15
Ah, that was indeed one error. There was another reason as well. A feature of qmake seems to be that custom compilers are not executed if the template is set to 'subdirs'. After I set it to lib it works fine. I just get a dummy empty library in the process but oh well...

Another annoying feature I discovered was that by default the files in installation sets are checked that they exists when qmake is run. This effectively prevents you from writing any installers for any generated files (like the .pdfs in my case). However after reading through the qmake source code, there is a nice undocumented option to disable that check.

Anyway here's my project file for reference if someone else runs into these problems:



# Dummy, just to get custom compilers to work in qmake
TEMPLATE = lib
TARGET = Dummy

# .tex files to build
TEX += help.tex

# Compiler for pdfs
doc_builder.name = tex2pdf
doc_builder.input = TEX
doc_builder.output = ${QMAKE_FILE_BASE}.pdf
doc_builder.commands = pdflatex ${QMAKE_FILE_BASE}

# This makes the custom compiler run before anything else
doc_builder.CONFIG += target_predeps

doc_builder.variable_out = documents.files
doc_builder.clean = ${QMAKE_FILE_BASE}.pdf \
${QMAKE_FILE_BASE}.aux \
${QMAKE_FILE_BASE}.toc \
${QMAKE_FILE_BASE}.log
QMAKE_EXTRA_COMPILERS += doc_builder

# Install documentation
documents.path = $$PREFIX/share/doc/
# If you don't specify this, all files must exist when you run qmake or else they will
# just silently be ignored
documents.CONFIG += no_check_exist

INSTALLS += documents


I still have to check if there's a way to get rid of the dummy library, but it will do for now.

wysota
27th April 2008, 20:58
According to me you have two choices. One is to make the docs a separate "subdir" target. It doesn't even have to be in a separate directory, but it should reside as a separate .pro file in one of other directories and be pointed to as part of SUBDIRS variable of the main project file, i.e. SUBDIRS = sub1 sub2 docs.pro

Another option is to make your docs a custom target in one of already existing project files - the one with subdirs template should be suitable as well. It should look more or less like this:

QMAKE_EXTRA_TARGETS += docs
docs.commands = pdflatex ${QMAKE_FILE_BASE}
... your other directives go here ...

Then you can call "make docs" and they should be built. You can probably add "docs" as a post dependency for the project to have them built automatically, but that's just a guess.