mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-09 12:28:13 -04:00
build: factor out manpage generation from toplevel CMakeLists.txt
This commit is contained in:
parent
1cc2484040
commit
7798554114
@ -228,41 +228,9 @@ if(STATIC_BUILD_DO_NOT_USE)
|
||||
endif()
|
||||
|
||||
if(WITH_MAN_PAGES)
|
||||
if(DWARFS_GIT_BUILD)
|
||||
find_program(RONN_EXE ronn DOC "ronn man page generator" REQUIRED)
|
||||
endif()
|
||||
|
||||
include("${CMAKE_SOURCE_DIR}/cmake/manpage.cmake")
|
||||
foreach(man dwarfs.1 mkdwarfs.1 dwarfsck.1 dwarfsextract.1 dwarfs-format.5)
|
||||
string(REGEX MATCH "^[^.]*" docname "${man}")
|
||||
string(REGEX MATCH "[^.]*$" section "${man}")
|
||||
|
||||
if(DWARFS_GIT_BUILD)
|
||||
set(man_dir "${CMAKE_CURRENT_BINARY_DIR}/man${section}")
|
||||
set(man_input "${CMAKE_CURRENT_SOURCE_DIR}/doc/${docname}.md")
|
||||
set(man_output "${man_dir}/${man}")
|
||||
|
||||
execute_process(
|
||||
COMMAND ${RONN_EXE}
|
||||
INPUT_FILE "${man_input}"
|
||||
RESULT_VARIABLE ronn_result
|
||||
OUTPUT_VARIABLE ronn_output
|
||||
ERROR_VARIABLE ronn_error)
|
||||
|
||||
if(${ronn_result} EQUAL 0)
|
||||
add_custom_command(
|
||||
OUTPUT "${man_output}"
|
||||
COMMAND mkdir -p "${man_dir}"
|
||||
COMMAND ${RONN_EXE} <"${man_input}" >"${man_output}"
|
||||
DEPENDS "${man_input}")
|
||||
list(APPEND MAN_PAGES "${man_output}")
|
||||
list(APPEND MAN_DIRS "${man_dir}")
|
||||
else()
|
||||
message(WARNING "${RONN_EXE} failed to process ${man_input} -> ${man}")
|
||||
message(WARNING "error: ${ronn_error}")
|
||||
endif()
|
||||
else()
|
||||
list(APPEND MAN_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/doc/man${section}")
|
||||
endif()
|
||||
add_manpage(${man})
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
@ -851,13 +819,6 @@ if(WITH_FUZZ)
|
||||
list(APPEND BINARY_TARGETS fuzz_mkdwarfs)
|
||||
endif()
|
||||
|
||||
if(WITH_MAN_PAGES)
|
||||
list(REMOVE_DUPLICATES MAN_DIRS)
|
||||
if(DWARFS_GIT_BUILD)
|
||||
add_custom_target(manpages ALL DEPENDS ${MAN_PAGES})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_link_libraries(dwarfs_common PRIVATE dwarfs_thrift_lite)
|
||||
|
||||
add_cpp2_thrift_library(fbthrift/thrift/lib/thrift/frozen.thrift
|
||||
@ -1184,10 +1145,6 @@ add_custom_target(
|
||||
format
|
||||
COMMAND clang-format -i ${ALL_SOURCES})
|
||||
|
||||
foreach(man_dir ${MAN_DIRS})
|
||||
install(DIRECTORY "${man_dir}" DESTINATION share/man)
|
||||
endforeach()
|
||||
|
||||
if(NOT STATIC_BUILD_DO_NOT_USE)
|
||||
foreach(tgt dwarfs_common dwarfs_reader dwarfs_writer dwarfs_extractor dwarfs_rewrite)
|
||||
set_target_properties(${tgt} PROPERTIES VERSION ${PRJ_VERSION_MAJOR}.${PRJ_VERSION_MINOR}.${PRJ_VERSION_PATCH})
|
||||
|
73
cmake/manpage.cmake
Normal file
73
cmake/manpage.cmake
Normal file
@ -0,0 +1,73 @@
|
||||
#
|
||||
# Copyright (c) Marcus Holland-Moritz
|
||||
#
|
||||
# This file is part of dwarfs.
|
||||
#
|
||||
# dwarfs is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# dwarfs is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# dwarfs. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 3.28.0)
|
||||
|
||||
function(add_manpage MANPAGE)
|
||||
if(DWARFS_GIT_BUILD)
|
||||
find_program(RONN_EXE ronn DOC "ronn man page generator" REQUIRED)
|
||||
endif()
|
||||
|
||||
if(NOT TARGET manpages)
|
||||
add_custom_target(manpages ALL)
|
||||
set_target_properties(manpages PROPERTIES MANPAGE_DIRECTORIES "")
|
||||
endif()
|
||||
|
||||
string(REGEX MATCH "^[^.]*" _docname "${MANPAGE}")
|
||||
string(REGEX MATCH "[^.]*$" _section "${MANPAGE}")
|
||||
|
||||
set(_man_dir "")
|
||||
|
||||
if(DWARFS_GIT_BUILD)
|
||||
set(_man_input "${CMAKE_CURRENT_SOURCE_DIR}/doc/${_docname}.md")
|
||||
|
||||
execute_process(
|
||||
COMMAND ${RONN_EXE}
|
||||
INPUT_FILE "${_man_input}"
|
||||
RESULT_VARIABLE _ronn_result
|
||||
OUTPUT_VARIABLE _ronn_output
|
||||
ERROR_VARIABLE _ronn_error)
|
||||
|
||||
if(${_ronn_result} EQUAL 0)
|
||||
set(_man_dir "${CMAKE_CURRENT_BINARY_DIR}/man${_section}")
|
||||
set(_man_output "${_man_dir}/${MANPAGE}")
|
||||
add_custom_command(
|
||||
OUTPUT "${_man_output}"
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${_man_dir}"
|
||||
COMMAND ${RONN_EXE} <"${_man_input}" >"${_man_output}"
|
||||
DEPENDS "${_man_input}")
|
||||
add_custom_target("_manpage_${_docname}_${_section}" DEPENDS "${_man_output}")
|
||||
add_dependencies(manpages "_manpage_${_docname}_${_section}")
|
||||
else()
|
||||
message(WARNING "${RONN_EXE} failed to process ${_man_input} -> ${MANPAGE}")
|
||||
message(WARNING "error: ${_ronn_error}")
|
||||
endif()
|
||||
else()
|
||||
set(_man_dir "${CMAKE_CURRENT_SOURCE_DIR}/doc/man${_section}")
|
||||
endif()
|
||||
|
||||
if(_man_dir)
|
||||
get_target_property(_man_dirs manpages MANPAGE_DIRECTORIES)
|
||||
list(FIND _man_dirs "${_man_dir}" _index)
|
||||
if(${_index} EQUAL -1)
|
||||
list(APPEND _man_dirs "${_man_dir}")
|
||||
install(DIRECTORY "${_man_dir}" DESTINATION share/man)
|
||||
set_target_properties(manpages PROPERTIES MANPAGE_DIRECTORIES "${_man_dirs}")
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
Loading…
x
Reference in New Issue
Block a user