Skip to content

Commit

Permalink
Add pdf targets to CMake build system
Browse files Browse the repository at this point in the history
This comes with a few additional changes
- Japanese font selection logic is reduced to a minimum. That is,
  one can pass fonts and a font directory on the cmake command line
  with the appropriate -D flags, but none of these are checked for
  correctness. I thought of porting the autotools rules for this
  but looking closer they are totally broken. If really needed
  an improved variation could be written later in cmake.
- Every fop run now requires a fop config file (fop.xconf) in cmake.
  This allows fop to find our figures in the source tree instead
  eliminates the need for a link or copy of these figures in the
  build tree. The existing config files for Russian and Japanese
  are amended for this.
- All settings that just mimic the defaults have been removed from
  the Japanese fop config file.

In addition the target structure has been slightly re-arranged.
There are a few global targets like html, check, pdf, xml.
Each of these will depend on the equivalent targets per document.
For example: the global html target depends on gnucash-guide-html
and gnucash-help-html.
Each of these in turn then depend on the equivalent targets per
language. For example gnucash-help-html in turn depends on
C-gnucash-help-html, it-gnucash-help-html and so on.

This allows to make all documents in one go or only one document
in all supported languages or only one single document.
  • Loading branch information
gjanssens committed Sep 2, 2019
1 parent 25d3eff commit 40e4b17
Show file tree
Hide file tree
Showing 19 changed files with 195 additions and 505 deletions.
150 changes: 41 additions & 109 deletions CMakeLists.txt
Expand Up @@ -21,21 +21,32 @@ set (PACKAGE_URL "https://www.gnucash.org/")
# Extra cmake macros
set (CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
include (xmldocs)
include (pdf)
include (GNUInstallDirs)


# ############################################################
# These options are settable from the CMake command line. For example, to disable
# enable mobi, put -D WITH_MOBI=ON on the command line.
# These options are settable from the CMake command line. For example,
# to enable mobi, put -D WITH_MOBI=ON on the command line.

option (WITH_MOBI "Enable build rules for Mobipocket document format" OFF)

set(JP_FONTDIR "" CACHE STRING "Directory to search for Japanese fonts")
set(JP_MINCHO "ume-tmo3.ttf" CACHE STRING "Japanese Mincho TrueType font to use")
set(JP_GOTHIC "ume-tmo3.ttf" CACHE STRING "Japanese Gothic TrueType font to use")
# ############################################################
# Following parameters can equally be set using -D switches on the CMake command line.
# Set font dirs and font for Russian pdf documents
set(EXTENDED_SANS "opentype/freefont/FreeSans" CACHE STRING "Extended sans font used for Russian pdf")
set(EXTENDED_SERIF "opentype/freefont/FreeSerif" CACHE STRING "Extended serif font used for Russian pdf")
set(EXTENDED_MONO "opentype/freefont/FreeMono" CACHE STRING "Extended mono font used for Russian pdf")
set(extended_fontdir "${CMAKE_SOURCE_DIR}/fonts" CACHE STRING "Directory to search for extended fonts")
set(extended_extension "otf" CACHE STRING "Extended fonts extension")

# Set font dirs and font for Japanese pdf documents
set(JAPANESE_MINCHO_TTF "ume-tmo3.ttf" CACHE STRING "Mincho TrueType font used for Japanese pdf")
set(JAPANESE_GOTHIC_TTF "ume-tmo3.ttf" CACHE STRING "Gothic TrueType font used for Japanese pdf")
set(japanese_fontdir "${CMAKE_SOURCE_DIR}/fonts/truetype" CACHE STRING "Directory to search for Japanese fonts")

# AM_INIT_AUTOMAKE()
#
# ############################################################
# Find the documentation dependencies

# Check for xsltproc
# Some distributions package it separately of libxslt
Expand All @@ -51,104 +62,14 @@ if(NOT XMLLINT)
message(SEND_ERROR "Can't find xmllint, perhaps you should install the xsltproc or libxslt package ?")
endif(NOT XMLLINT)

#
# dnl
# dnl Check for optional fop
# dnl
# AC_PATH_PROG(FOP, fop)
# fop_version=0
# if test -z "$FOP"; then
# AC_MSG_WARN([fop not found. You will not be able to generate PDF files.])
# else
# fop_version=`$FOP -version | cut -f 3 -d ' ' | cut -c 1`
# fi
#
# dnl
# dnl Get the absolute path to $srcdir
# dnl
# ac_abs_top_srcdir=$(cd -- "$srcdir" && pwd)
#
# dnl
# dnl Set font dirs and font
# dnl
# EXTENDED_SANS=opentype/freefont/FreeSans
# EXTENDED_SERIF=opentype/freefont/FreeSerif
# EXTENDED_MONO=opentype/freefont/FreeMono
# extended_fontdir=$ac_abs_top_srcdir/fonts
# extended_extension=otf
# AC_SUBST(EXTENDED_SANS)
# AC_SUBST(EXTENDED_SERIF)
# AC_SUBST(EXTENDED_MONO)
# AC_SUBST(extended_fontdir)
# AC_SUBST(extended_extension)
#
# dnl
# dnl Check Japanese TrueType fonts for PDF
# dnl
# AC_ARG_WITH([japanese-fontdir],
# [AS_HELP_STRING([--with-japanese-fontdir=DIR],
# [use DIR for Japanese TrueType font directory])],,
# [with_japanese_fontdir=check])
# AC_ARG_WITH([japanese-mincho-ttf],
# [AS_HELP_STRING([--with-japanese-mincho-ttf],
# [specify Japanese Mincho TrueType font (default is ume-tmo3.ttf)])],,)
# AC_ARG_WITH([japanese-gothic-ttf],
# [AS_HELP_STRING([--with-japanese-gothic-ttf],
# [specify Japanese Gothic TrueType font (default is ume-tmo3.ttf)])],,)
# JAPANESE_MINCHO_TTF=ume-tmo3.ttf
# JAPANESE_GOTHIC_TTF=ume-tmo3.ttf
# japanese_fontdir=$ac_abs_top_srcdir/fonts/truetype
# JAPANESE_MINCHO_TTF_ABS=$japanese_fontdir/$JAPANESE_MINCHO_TTF
# JAPANESE_GOTHIC_TTF_ABS=$japanese_fontdir/$JAPANESE_GOTHIC_TTF
#
# dnl Japanese fonts search path (Ubuntu, RedHat, openSUSE:local, Fedora)
# japanese_fontdirs="/usr/share/fonts /usr/local/share/fonts /usr/local/share/fonts"
#
# if test "x$with_japanese_fontdir" != "xcheck" && test "x$with_japanese_fontdir" != "xyes" ; then
# japanese_fontdirs="$with_japanese_fontdir $japanese_fontdir"
# fi
#
# if test "x$with_japanese_mincho_ttf" != "x" ; then
# AC_CHECK_FILE($with_japanese_mincho_ttf,
# [JAPANESE_MINCHO_TTF=$with_japanase_mincho_ttf
# JAPANESE_MINCHO_TTF_ABS=$font
# font = $with_japanese_mincho_ttf],
# [for fontdir in $japanese_fontdirs ""; do
# font=$fontdir/$with_japanese_mincho_ttf
# AC_CHECK_FILE($font,
# [JAPANESE_MINCHO_TTF=$font
# JAPANESE_MINCHO_TTF_ABS=$font
# japanese_fontdir=$fontdir
# break],)
# done])
# if test -z $font; then
# AC_MSG_WARN([$with_japanese_mincho_ttf not found, using default mincho font])
# fi
# unset font
# fi
# if test "x$with_japanese_gothic_ttf" != "x" ; then
# AC_CHECK_FILE($with_japanese_gothic_ttf,
# [JAPANESE_GOTHIC_TTF=$with_japanase_gothic_ttf
# JAPANESE_GOTHIC_TTF_ABS=$font
# font = $with_japanese_gothic_ttf],
# [for fontdir in $japanese_fontdirs ""; do
# font=$fontdir/$with_japanese_gothic_ttf
# AC_CHECK_FILE($font,
# [JAPANESE_GOTHIC_TTF=$font
# JAPANESE_GOTHIC_TTF_ABS=$font
# japanese_fontdir=$fontdir
# break],)
# done])
# if test -z $font; then
# AC_MSG_WARN([$with_japanese_gothic_ttf not found, using default gothic font])
# fi
# unset font
# fi
# AC_SUBST(japanese_fontdir)
# AC_SUBST(JAPANESE_MINCHO_TTF)
# AC_SUBST(JAPANESE_MINCHO_TTF_ABS)
# AC_SUBST(JAPANESE_GOTHIC_TTF)
# AC_SUBST(JAPANESE_GOTHIC_TTF_ABS)
# Check for optional fop
set (PDF YES)
find_program(FOP fop)
if(NOT FOP)
message(WARNING "Can't find fop. You will not be able to generate PDF files.")
set (PDF NO)
endif(NOT FOP)

#
# dnl
# dnl Check for mobi target and optional ebook-convert
Expand Down Expand Up @@ -176,6 +97,16 @@ else()
set (XSLTFLAGS_FO "--stringparam paper.type A4")
endif()

# To find our figures in the source directory each run of fop
# will be passed a fop.xconf file to set a base-dir.
# The default fop.xconf file below does just that.
# Every document/language can define its own FOP_XCONF
# to point at a document/language specific fop.xconf
# instead for additional fop configuration as needed.
# For example the Japanese document will use it to embed Japanese fonts
set (FOP_XCONF_DFLT "${CMAKE_SOURCE_DIR}/fop.xconf.in")
set (FOP_XCONF "${FOP_XCONF_DFLT}")

#
# ac_cv_gnc_windows="no"
# case $host_os in
Expand Down Expand Up @@ -213,13 +144,14 @@ endif()
#
# AC_OUTPUT

# Add global targets. Their dependencies will be filled in by subsequent command in
# The global targets. Their dependencies will be filled in by subsequent commands in
# the respective subdirectories.
add_custom_target(html)
add_custom_target(check)
add_custom_target(xml
DEPENDS check
)
add_custom_target(xml)
if (PDF)
add_custom_target(pdf)
endif()


add_subdirectory (guide)
Expand Down
47 changes: 47 additions & 0 deletions cmake/pdf.cmake
@@ -0,0 +1,47 @@
function (add_pdf_target docname lang entities figdir)

set(fofile "${docname}.fo")
set(pdffile "${docname}.pdf")
file(GLOB figures "${CMAKE_CURRENT_SOURCE_DIR}/${figdir}/*.png")


add_custom_target("${lang}-${docname}-fo"
COMMAND ${XSLTPROC} ${XSLTPROCFLAGS} ${XSLTPROCFLAGS_FO}
-o "${CMAKE_CURRENT_BINARY_DIR}/${fofile}"
--stringparam fop1.extensions 1
"${CMAKE_SOURCE_DIR}/xsl/1.79.2/fo/docbook.xsl"
"${CMAKE_CURRENT_SOURCE_DIR}/${docname}.xml"
DEPENDS ${entities} "${docname}.xml" "${CMAKE_SOURCE_DIR}/docbook/gnc-docbookx.dtd")

configure_file("${FOP_XCONF}" "${CMAKE_CURRENT_BINARY_DIR}/fop.xconf")
add_custom_target("${lang}-${docname}-pdf"
COMMAND ${FOP} ${FOPFLAGS}
-l ${lang}
-c "${CMAKE_CURRENT_BINARY_DIR}/fop.xconf"
-fo "${CMAKE_CURRENT_BINARY_DIR}/${fofile}"
-pdf "${CMAKE_CURRENT_BINARY_DIR}/${pdffile}"
DEPENDS ${lang}-${docname}-fo ${figures})

add_dependencies(${docname}-pdf "${lang}-${docname}-pdf")

# $(pdffile): $(figfiles)
#
# pdf: $(abs_builddir)/figures $(pdffile)
#
# # This is only needed for out of tree builds. If you build
# # from within the source directory, the build system
# # will ignore this (mentioning a circular dependency)
# $(abs_builddir)/figures: $(abs_srcdir)/figures
# ln -s '$<' '$@'
#
# $(fofile): $(entities)
#
# .xml.fo:
# $(XSLTPROC) $(XSLTPROCFLAGS) $(XSLTFLAGS_FO) -o '$@' --stringparam fop1.extensions 1 $(top_srcdir)/xsl/1.79.2/fo/docbook.xsl '$<'
#
# .fo.pdf:
# $(FOP) $(FOPFLAGS) -fo '$<' -pdf '$@'
#
# CLEANFILES += $(pdffile) $(fofile)

endfunction()
4 changes: 2 additions & 2 deletions cmake/xmldocs.cmake
Expand Up @@ -30,7 +30,7 @@ function (add_xml_target docname lang entities figdir)
${CMAKE_CURRENT_SOURCE_DIR}/${docname}.xml
DEPENDS ${entities} "${docname}.xml" "${CMAKE_SOURCE_DIR}/docbook/gnc-docbookx.dtd")

add_dependencies(check "${lang}-${docname}-check")
add_dependencies(${docname}-check "${lang}-${docname}-check")

# TODO Uninstall and dist targets
# uninstall-hook:
Expand Down Expand Up @@ -77,7 +77,7 @@ function (add_html_target docname lang entities figdir)
add_custom_target("${lang}-${docname}-html"
DEPENDS "${lang}-${docname}-html-files" "${lang}-${docname}-html-figures" "${lang}-${docname}-html-style")

add_dependencies(html "${lang}-${docname}-html")
add_dependencies(${docname}-html "${lang}-${docname}-html")

install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${docname}
DESTINATION "${CMAKE_INSTALL_DOCDIR}/${PACKAGE_NAME}/${lang}"
Expand Down
4 changes: 4 additions & 0 deletions configure.ac
Expand Up @@ -78,11 +78,13 @@ EXTENDED_SERIF=opentype/freefont/FreeSerif
EXTENDED_MONO=opentype/freefont/FreeMono
extended_fontdir=$ac_abs_top_srcdir/fonts
extended_extension=otf
BASEDIR_RU=$ac_abs_top_srcdir/guide/ru
AC_SUBST(EXTENDED_SANS)
AC_SUBST(EXTENDED_SERIF)
AC_SUBST(EXTENDED_MONO)
AC_SUBST(extended_fontdir)
AC_SUBST(extended_extension)
AC_SUBST(BASEDIR_RU)

dnl
dnl Check Japanese TrueType fonts for PDF
Expand All @@ -102,6 +104,7 @@ JAPANESE_GOTHIC_TTF=ume-tmo3.ttf
japanese_fontdir=$ac_abs_top_srcdir/fonts/truetype
JAPANESE_MINCHO_TTF_ABS=$japanese_fontdir/$JAPANESE_MINCHO_TTF
JAPANESE_GOTHIC_TTF_ABS=$japanese_fontdir/$JAPANESE_GOTHIC_TTF
BASEDIR_JA=$ac_abs_top_srcdir/guide/ja

dnl Japanese fonts search path (Ubuntu, RedHat, openSUSE:local, Fedora)
japanese_fontdirs="/usr/share/fonts /usr/local/share/fonts /usr/local/share/fonts"
Expand Down Expand Up @@ -151,6 +154,7 @@ AC_SUBST(JAPANESE_MINCHO_TTF)
AC_SUBST(JAPANESE_MINCHO_TTF_ABS)
AC_SUBST(JAPANESE_GOTHIC_TTF)
AC_SUBST(JAPANESE_GOTHIC_TTF_ABS)
AC_SUBST(BASEDIR_JA)

dnl
dnl Check for mobi target and optional ebook-convert
Expand Down
12 changes: 12 additions & 0 deletions fop.xconf.in
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!-- $Id: fop.xconf 1616312 2014-08-06 19:19:31Z gadams $ -->
<!-- More details about this configuration file can be found here:
https://xmlgraphics.apache.org/fop/0.95/configuration.html -->

<!-- NOTE: This is the version of the configuration -->
<fop version="1.0">

<!-- Base URL for resolving relative URLs -->
<base>${CMAKE_CURRENT_SOURCE_DIR}</base>

</fop>
3 changes: 3 additions & 0 deletions guide/C/CMakeLists.txt
Expand Up @@ -31,3 +31,6 @@ set (entities

add_xml_target(${docname} ${lang} "${entities}" ${figdir})
add_html_target(${docname} ${lang} "${entities}" ${figdir})
if (PDF)
add_pdf_target(${docname} ${lang} "${entities}" ${figdir})
endif()
16 changes: 16 additions & 0 deletions guide/CMakeLists.txt
@@ -1,5 +1,21 @@
set (docname "gnucash-guide")

add_custom_target(${docname}-html)
add_dependencies(html ${docname}-html)

add_custom_target(${docname}-check)
add_dependencies(check ${docname}-check)

add_custom_target(${docname}-xml
DEPENDS ${docname}-check
)
add_dependencies(xml ${docname}-xml)

if (PDF)
add_custom_target(${docname}-pdf)
add_dependencies(pdf ${docname}-pdf)
endif()

add_subdirectory(C)
add_subdirectory(de)
add_subdirectory(it)
Expand Down
3 changes: 3 additions & 0 deletions guide/de/CMakeLists.txt
Expand Up @@ -32,3 +32,6 @@ set (entities

add_xml_target(${docname} ${lang} "${entities}" ${figdir})
add_html_target(${docname} ${lang} "${entities}" ${figdir})
if (PDF)
add_pdf_target(${docname} ${lang} "${entities}" ${figdir})
endif()
6 changes: 6 additions & 0 deletions guide/it/CMakeLists.txt
Expand Up @@ -34,3 +34,9 @@ set (COMPONENTS
# if test "${srcdir}" != "${builddir}"; then mv $@ ${srcdir}; fi

#EXTRA_DIST += it.po

# add_xml_target(${docname} ${lang} "${entities}" ${figdir})
# add_html_target(${docname} ${lang} "${entities}" ${figdir})
# if (PDF)
# add_pdf_target(${docname} ${lang} "${entities}" ${figdir})
# endif()
11 changes: 10 additions & 1 deletion guide/ja/CMakeLists.txt
@@ -1,6 +1,5 @@
set (figdir "figures")
set (lang "ja")
set (fopconfig "fop.xconf")
set (entities
fdl-appendix.xml
legal.xml
Expand All @@ -26,5 +25,15 @@ set (entities
appendixc.xml
appendixd.xml)

set (FOP_XCONF "${CMAKE_CURRENT_SOURCE_DIR}/fop.xconf.in")
# Compatibility hack for autotools
# When autotools gets dropped this line can be removed
# and CMAKE_CURRENT_SOURCE_DIR can be used directly in
# fop.xconf.in
set(BASEDIR_JA "${CMAKE_CURRENT_SOURCE_DIR}")

add_xml_target(${docname} ${lang} "${entities}" ${figdir})
add_html_target(${docname} ${lang} "${entities}" ${figdir})
if (PDF)
add_pdf_target(${docname} ${lang} "${entities}" ${figdir})
endif()

0 comments on commit 40e4b17

Please sign in to comment.