Fun with Qt Help and CMake

As a Windows application, Deep Sky Stacker stores all its help text in .chm files, but I need to get rid of the Windows dependencies. Fortunately I have the HTML and images that make up those files, and there’s the Qt Help system that can repackage them for their help engine so I can in theory make it work on Linux/MacOS.

Generating the XML files to describe which files should be packaged up doesn’t seem to be a major issue, but actually creating the necessary files in CMake is more of a problem. Allegedly it can be done with some of CMake’s recent support for Doxygen, but documentation for that appears to be a little thin. If I’m honest, documentation for the entire Qt Help system looks a bit thin compared with other parts of the project. For the time being, I’ve resigned myself to the help files being built every time and using custom commands and targets.

I’ve also had to work around the restriction that whilst qhelpgenerator can produce the .qhc files in the build directory structure, the .qch files seem to get a filename that’s generated by removing the .qhcp extension from the input file and adding the .qch extension whilst preserving the original pathname. Whether the program is run in the build directory tree or the source directory tree, the .qch file ends up in the source tree because that’s where the .qhcp file is. Copying the .qhcp file to the build tree doesn’t work either because all the HTML and image files are still in the source tree and can’t be found.

In the end I resorted to the following mess in CMakeLists.txt:

For brevity, create a couple of variables pointing to where the command is run and where the source files are:

set( cwd ${CMAKE_CURRENT_SOURCE_DIR} )
set( bin ${CMAKE_CURRENT_BINARY_DIR} )

Then create a glob containing the names of all the files that should cause a rebuild of the help files:

file(GLOB EN_DEPS
    english/*
    images/*.*
    images/Theory/*.*
    images/english/*.*
)

Use a custom command to run qhelpgenerator and move the .qch from the source tree back into the build tree:

add_custom_command (
  OUTPUT dsshelp-en.qhc dsshelp-en.qch
  COMMAND qhelpgenerator ${cwd}/dsshelp-en.qhcp -s -o dsshelp-en.qhc
  COMMAND mv ${cwd}/dsshelp-en.qch ${bin}
  DEPENDS ${EN_DEPS}
  COMMENT "Generating English help files"
)

And finally add a target that triggers the custom commands:

add_custom_target ( helpfiles ALL DEPENDS
  dsshelp-en.qhc
)

It’s really not pretty, but it seems to do the job. The worst bit is having it happen every time regardless of whether the files have been updated or not. As I have six different languages to cater for it would be nice to create a macro that makes adding a new one somewhat simpler too, but that can wait for another day.

This entry was posted in Computing, Linux and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *