~marcobiscaro2112/unity/fixes-767733

« back to all changes in this revision

Viewing changes to cmake/Documentation.cmake

  • Committer: Mathieu Trudel-Lapierre
  • Date: 2010-12-24 20:05:57 UTC
  • mto: This revision was merged to the branch mainline in revision 756.
  • Revision ID: mathieu.trudel-lapierre@canonical.com-20101224200557-06e57srl3vf5va6u
Include manpages, and make them translatable.

Documentation.cmake rules vastly inspired from Julian Andres Klose's amazing
work to migrate Apt to CMake (not included in apt yet).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 Julian Andres Klode <jak@debian.org>.
 
2
# Licensed under the same terms as APT; i.e. GPL 2 or later.
 
3
 
 
4
macro(add_debiandoc target sourcefiles installdest)
 
5
        foreach(file ${sourcefiles})
 
6
                get_filename_component(relfile ${file} NAME)
 
7
                string(REPLACE ".sgml" "" manual ${relfile})
 
8
                get_filename_component(absolute ${file} ABSOLUTE)
 
9
                
 
10
                add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${manual}.html
 
11
                        COMMAND debiandoc2html ${absolute}
 
12
                        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
 
13
                        DEPENDS ${file}
 
14
                )
 
15
                set(commands ${commands} ${CMAKE_CURRENT_BINARY_DIR}/${manual}.html)
 
16
                if (NOT ${installdest} EQUAL "" )
 
17
                install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${manual}.html
 
18
                        DESTINATION ${installdest})
 
19
                endif (NOT ${installdest} EQUAL "" )
 
20
        endforeach(file ${sourcefiles})
 
21
 
 
22
        add_custom_target(${target} ALL DEPENDS ${commands})
 
23
endmacro(add_debiandoc target sourcefiles installdest)
 
24
 
 
25
 
 
26
macro(add_po4a type master po target deps)
 
27
        add_custom_command(OUTPUT ${target}
 
28
                COMMAND po4a-translate --keep 0 -f ${type} -m ${master}
 
29
                                       -p ${po} -l ${target}
 
30
                WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
 
31
                DEPENDS ${deps} ${master} ${po})
 
32
endmacro(add_po4a type master po target deps)
 
33
 
 
34
 
 
35
# Macro for XML man pages.
 
36
macro(add_xml_manpages target manpages translations entities)
 
37
        foreach(manpage ${manpages})
 
38
                string(LENGTH ${manpage} manpage_length)
 
39
                math(EXPR manpage_length ${manpage_length}-1)
 
40
                string(SUBSTRING ${manpage} ${manpage_length} 1 section)
 
41
 
 
42
                add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${manpage}
 
43
                        COMMAND xmlto man ${CMAKE_CURRENT_SOURCE_DIR}/${manpage}.xml
 
44
                        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
 
45
                        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${manpage}.xml
 
46
                )
 
47
                
 
48
       
 
49
                set(commands ${commands} ${CMAKE_CURRENT_BINARY_DIR}/${manpage})
 
50
                
 
51
                install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${manpage}
 
52
                                DESTINATION share/man/man${section})
 
53
                                
 
54
                # Add the translations for the manpage.
 
55
                foreach(translation ${translations})
 
56
                        set(entities)
 
57
                        # transdir = shortcut to the output directory for translations.
 
58
                        set(transdir ${CMAKE_CURRENT_BINARY_DIR}/${translation})
 
59
                        
 
60
                        foreach(entity ${entities})                             
 
61
                                add_custom_command(OUTPUT ${transdir}/${entity}
 
62
                                        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
 
63
                                        COMMAND ${CMAKE_COMMAND} -E make_directory ${transdir}
 
64
                                        COMMAND ${CMAKE_COMMAND} -E copy ${entity} ${transdir})
 
65
                                set(ent_cmds ${ent_cmds} ${transdir}/${entity})
 
66
                        endforeach(entity ${entities})
 
67
                
 
68
                
 
69
                
 
70
                        add_po4a(docbook ${manpage}.xml po/${translation}.po
 
71
                                         ${transdir}/${manpage}.xml "${ent_cmds}")
 
72
 
 
73
                        
 
74
                        add_custom_command(OUTPUT ${transdir}/${manpage}
 
75
                                COMMAND xmlto -o ${transdir} man ${transdir}/${manpage}.xml
 
76
                                WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
 
77
                                DEPENDS ${transdir}/${manpage}.xml)
 
78
                        
 
79
                        set(nls-cmd ${nls-cmd} ${transdir}/${manpage})
 
80
                        install(FILES ${transdir}/${manpage}
 
81
                                    DESTINATION share/man/${translation}/man${section})
 
82
                        
 
83
                endforeach(translation ${translations})
 
84
        endforeach(manpage ${manpages})
 
85
        
 
86
        add_custom_target(${target} ALL DEPENDS ${commands})
 
87
        # Sort the list of the translations.
 
88
        list(SORT nls-cmd)
 
89
        add_custom_target(nls-${target} ALL DEPENDS ${nls-cmd})
 
90
endmacro(add_xml_manpages manpages)
 
91
 
 
92
 
 
93
macro(add_manpages target manpages translations)
 
94
        foreach(man ${manpages})
 
95
                string(LENGTH ${man} manpage_length)
 
96
                math(EXPR manpage_length ${manpage_length}-1)
 
97
                string(SUBSTRING ${man} ${manpage_length} 1 section)    
 
98
                install(FILES ${man} DESTINATION share/man/man${section})
 
99
                
 
100
                if (USE_NLS)
 
101
                        foreach(translation ${translations})
 
102
                                set(transdir ${CMAKE_CURRENT_BINARY_DIR}/${translation})
 
103
                                add_po4a(man ${man} po/${translation}.po ${transdir}/${man} "")
 
104
                                install(FILES ${transdir}/${man}
 
105
                                                DESTINATION share/man/${translation}/man${section})
 
106
                                set(files ${files} ${transdir}/${man})
 
107
                        endforeach(translation ${translations})
 
108
                endif(USE_NLS)
 
109
        endforeach(man ${manpages})
 
110
        add_custom_target(${target} ALL DEPENDS ${files})
 
111
endmacro(add_manpages target manpages translations)