Noah Watkins
Noah Watkins

Reputation: 5546

man page generation/packaging/installation with cmake

I am looking for some good examples / tutorials on how to generate, package, and install man pages in projects using CMake.

Upvotes: 16

Views: 4630

Answers (4)

csjpeter
csjpeter

Reputation: 1946

Here is a very simple solution, that works well with both deb and rpm packages:

install(FILES manfile.1 TYPE MAN)

Official documentation can be found here: https://cmake.org/cmake/help/latest/command/install.html#install Look for word TYPE with match case.

Upvotes: 2

Nickolay Olshevsky
Nickolay Olshevsky

Reputation: 14160

Maybe you would be interested in the following solution, which allows to generate and install man pages, written in Markdown or AsciiDoc:

https://github.com/rnpgp/cmake-modules/

To generate and install man page, written in Markdown, it would be as easy as add two lines to your CMakeLists.txt:

include(PandocMan)
add_pandoc_man("${CMAKE_CURRENT_SOURCE_DIR}/utility.1.md")

The same with AsciiDoc and AsciiDoctor:

include(AdocMan)
add_adoc_man("${CMAKE_CURRENT_SOURCE_DIR}/utility.1.adoc")

Upvotes: 3

Joachim W
Joachim W

Reputation: 8167

With cmake 2.8.12 under Linux, the following works for me:

ADD_CUSTOM_TARGET(man ALL)

ADD_CUSTOM_COMMAND(
  TARGET man
  SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/myprog.pod
  COMMAND pod2man ARGS -s 1 -c "myprog manual" ${CMAKE_CURRENT_SOURCE_DIR}/myprog.pod ${CMAKE_CURRENT_BINARY_DIR}/myprog.1
  OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/myprog.1
)

ADD_CUSTOM_COMMAND(
  TARGET man
  SOURCE man
  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/myprog.1
)

INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/myprog.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1)

Which looks unelegant even by CMake standards. I would like to see a solution with less stammering.

Upvotes: 7

DLRdave
DLRdave

Reputation: 14250

You can delve into the source tree of CMake itself to see how it installs its own man pages.

It is sure to be a combination of:

  • using CMake's add_custom_command
  • calling tools to produce/generate documentation in those custom commands
  • installing the results in the correct location

See the documentation for CMake's add_custom_command and install commands for more information:

Upvotes: 0

Related Questions