-
Notifications
You must be signed in to change notification settings - Fork 491
Expand file tree
/
Copy pathO2TargetManPage.cmake
More file actions
79 lines (74 loc) · 2.71 KB
/
O2TargetManPage.cmake
File metadata and controls
79 lines (74 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Copyright 2019-2020 CERN and copyright holders of ALICE O2.
# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
# All rights not expressly granted are reserved.
#
# This software is distributed under the terms of the GNU General Public
# License v3 (GPL Version 3), copied verbatim in the file "COPYING".
#
# In applying this license CERN does not waive the privileges and immunities
# granted to it by virtue of its status as an Intergovernmental Organization
# or submit itself to any jurisdiction.
include_guard()
# Generate a man page
#
# Make sure we have nroff. If that is not the case we will not generate man
# pages
find_program(NROFF_FOUND nroff)
function(o2_target_man_page target)
if(NOT NROFF_FOUND)
return()
endif()
cmake_parse_arguments(PARSE_ARGV
1
A
""
"NAME;SECTION"
"")
# check the target exists
if(NOT TARGET ${target})
# try with out naming conventions
set(baseTargetName ${target})
o2_name_target(${baseTargetName} NAME target)
if(NOT TARGET ${target})
# not a library, maybe an executable ?
o2_name_target(${baseTargetName} NAME target IS_EXE)
if(NOT TARGET ${target})
message(FATAL_ERROR "Target ${target} does not exist")
endif()
endif()
endif()
if(NOT A_SECTION)
set(A_SECTION 1)
endif()
if(NOT A_NAME)
message(
FATAL_ERROR
"You must provide the name of the input man file in doc/<name>.<section>.in"
)
endif()
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/doc/${A_NAME}.${A_SECTION}.in)
message(
FATAL_ERROR
"Input file ${CMAKE_CURRENT_SOURCE_DIR}/doc/${A_NAME}.${A_SECTION}.in does not exist"
)
endif()
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${A_NAME}.${A_SECTION}
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/doc/${A_NAME}.${A_SECTION}.in
COMMAND nroff
-Tascii
-man
${CMAKE_CURRENT_SOURCE_DIR}/doc/${A_NAME}.${A_SECTION}.in
>
${CMAKE_CURRENT_BINARY_DIR}/${A_NAME}.${A_SECTION}
VERBATIM)
# the prefix man. for the target name avoids circular dependencies for the man
# pages added at top level. Simply droping the dependency for those does not
# invoke the custom command on all systems.
set(CUSTOM_TARGET_NAME man.${A_NAME}.${A_SECTION})
add_custom_target(${CUSTOM_TARGET_NAME}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${A_NAME}.${A_SECTION})
add_dependencies(${target} ${CUSTOM_TARGET_NAME})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${A_NAME}.${A_SECTION}
DESTINATION ${CMAKE_INSTALL_DATADIR}/man/man${A_SECTION})
endfunction()