Skip to content

Commit d443365

Browse files
committed
Added a new function for building multiple manpages at once.
1 parent 0ba14b3 commit d443365

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# =============== Project initialization ===============
99
# ======================================================
1010

11-
cmake_minimum_required(VERSION 3.14)
11+
cmake_minimum_required(VERSION 3.20)
1212

1313
project(zswap-cli
1414
VERSION 0.9.1
@@ -235,9 +235,8 @@ if (BUILD_DOC)
235235
endif()
236236

237237
if (BUILD_MANPAGE)
238-
configure_file("assets/manpage/${APP_NAME}.md.in" "${CMAKE_CURRENT_BINARY_DIR}/${APP_NAME}.md" @ONLY)
239-
build_manpage("${CMAKE_CURRENT_BINARY_DIR}/${APP_NAME}.md" "${CMAKE_CURRENT_BINARY_DIR}/${APP_NAME}.1")
240-
add_custom_target(${MAN_NAME} ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${APP_NAME}.1")
238+
configure_file("assets/manpage/${APP_NAME}.md.in" "${CMAKE_CURRENT_BINARY_DIR}/${APP_NAME}.1.md" @ONLY)
239+
pandoc_add_manpages(${MAN_NAME} FILES "${CMAKE_CURRENT_BINARY_DIR}/${APP_NAME}.1.md")
241240
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${APP_NAME}.1" DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
242241
endif()
243242

cmake/FindPandoc.cmake

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,27 @@ if (BUILD_MANPAGE)
1313
)
1414
mark_as_advanced(Pandoc_EXECUTABLE)
1515

16-
function(build_manpage SrcName DestName)
16+
function(_build_manpage _srcname _destname)
1717
add_custom_command(
18-
OUTPUT "${DestName}"
18+
OUTPUT "${_destname}"
1919
COMMAND "${Pandoc_EXECUTABLE}"
20-
ARGS "${SrcName}" -s -t man -o "${DestName}"
21-
DEPENDS "${SrcName}"
22-
COMMENT "Building the ${DestName} manpage using Pandoc."
20+
ARGS "${_srcname}" -s -t man -o "${_destname}"
21+
DEPENDS "${_srcname}"
22+
COMMENT "Building the manpage using Pandoc."
2323
VERBATIM
2424
)
2525
endfunction()
26+
27+
function(pandoc_add_manpages TargetName)
28+
set(_arguments_options)
29+
set(_arguments_one)
30+
set(_arguments_multi FILES)
31+
cmake_parse_arguments(_arguments "${_arguments_options}" "${_arguments_one}" "${_arguments_multi}" ${ARGN})
32+
foreach(_srcfile IN LISTS _arguments_FILES)
33+
cmake_path(REMOVE_EXTENSION _srcfile LAST_ONLY OUTPUT_VARIABLE _manfile)
34+
list(APPEND _manfiles "${_manfile}")
35+
_build_manpage("${_srcfile}" "${_manfile}")
36+
endforeach()
37+
add_custom_target(${TargetName} ALL DEPENDS ${_manfiles})
38+
endfunction()
2639
endif()

0 commit comments

Comments
 (0)