summaryrefslogtreecommitdiff
path: root/doc/CMakeLists.txt
blob: 87b9df6355cb048faedd80456a775694e03383b6 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#
# Copyright (C) 2003-2023 Sébastien Helleu <flashcode@flashtux.org>
# Copyright (C) 2009 Emmanuel Bouthenot <kolter@openics.org>
#
# This file is part of WeeChat, the extensible chat client.
#
# WeeChat 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.
#
# WeeChat 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 WeeChat.  If not, see <https://www.gnu.org/licenses/>.
#

if(ENABLE_MAN OR ENABLE_DOC)
  find_package(Asciidoctor)
  if(ASCIIDOCTOR_FOUND)
    # common asciidoctor arguments
    set(ASCIIDOCTOR_ARGS
      -a experimental
      -a reproducible
      -a "prewrap!"
      -a "webfonts!"
      -a icons=font
      -a revnumber="${VERSION}"
      -a sectanchors
      -a source-highlighter=pygments
      -a pygments-style=native
      -a autogendir="${CMAKE_CURRENT_BINARY_DIR}/autogen"
    )

    # sed arguments used to replace links in ChangeLog and release notes
    set(SED_LINKS_ARGS
      -e "'s/issue #\\([0-9][0-9]*\\)/https:\\/\\/github.com\\/weechat\\/weechat\\/issues\\/\\1[issue #\\1^]/g'"
      -e "'s/bug #\\([0-9][0-9]*\\)/https:\\/\\/savannah.nongnu.org\\/bugs\\/?\\1[bug #\\1^]/g'"
      -e "'s/task #\\([0-9][0-9]*\\)/https:\\/\\/savannah.nongnu.org\\/task\\/?\\1[task #\\1^]/g'"
      -e "'s/patch #\\([0-9][0-9]*\\)/https:\\/\\/savannah.nongnu.org\\/patch\\/?\\1[patch #\\1^]/g'"
      -e "'s/debian #\\([0-9][0-9]*\\)/http:\\/\\/bugs.debian.org\\/cgi-bin\\/bugreport.cgi?bug=\\1[debian bug #\\1^]/g'"
      -e "'s/\\(CVE-[0-9][0-9]*-[0-9][0-9]*\\)/https:\\/\\/cve.mitre.org\\/cgi-bin\\/cvename.cgi?name=\\1[\\1^]/g'"
    )

    # ChangeLog
    add_custom_command(
      OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ChangeLog-links.adoc"
      COMMAND sed ARGS ${SED_LINKS_ARGS} "${CMAKE_CURRENT_SOURCE_DIR}/../ChangeLog.adoc" > "${CMAKE_CURRENT_BINARY_DIR}/ChangeLog-links.adoc"
      DEPENDS
      "${CMAKE_CURRENT_SOURCE_DIR}/../ChangeLog.adoc"
      WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
    )
    add_custom_command(
      OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ChangeLog.html"
      COMMAND "${ASCIIDOCTOR_EXECUTABLE}" ARGS ${ASCIIDOCTOR_ARGS} -a docinfodir="${CMAKE_CURRENT_SOURCE_DIR}" -o ChangeLog.html "${CMAKE_CURRENT_BINARY_DIR}/ChangeLog-links.adoc"
      DEPENDS
      "${CMAKE_CURRENT_SOURCE_DIR}/docinfo.html"
      "${CMAKE_CURRENT_BINARY_DIR}/ChangeLog-links.adoc"
      WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
      COMMENT "Building ChangeLog.html"
    )
    add_custom_target(changelog DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/ChangeLog.html")

    # Release notes
    add_custom_command(
      OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ReleaseNotes-links.adoc"
      COMMAND sed ARGS ${SED_LINKS_ARGS} "${CMAKE_CURRENT_SOURCE_DIR}/../ReleaseNotes.adoc" > "${CMAKE_CURRENT_BINARY_DIR}/ReleaseNotes-links.adoc"
      DEPENDS
      "${CMAKE_CURRENT_SOURCE_DIR}/../ReleaseNotes.adoc"
      WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
    )
    add_custom_command(
      OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ReleaseNotes.html"
      COMMAND "${ASCIIDOCTOR_EXECUTABLE}" ARGS ${ASCIIDOCTOR_ARGS} -a docinfodir="${CMAKE_CURRENT_SOURCE_DIR}" -o ReleaseNotes.html "${CMAKE_CURRENT_BINARY_DIR}/ReleaseNotes-links.adoc"
      DEPENDS
      "${CMAKE_CURRENT_SOURCE_DIR}/docinfo.html"
      "${CMAKE_CURRENT_BINARY_DIR}/ReleaseNotes-links.adoc"
      WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
      COMMENT "Building ReleaseNotes.html"
    )
    add_custom_target(rn DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/ReleaseNotes.html")

    if(ENABLE_DOC)
      set(AUTOGEN_FILES "")
      set(AUTOGEN_LANG de en fr it ja pl sr)
      foreach(lang ${AUTOGEN_LANG})
        LIST(APPEND AUTOGEN_FILES
          # plugin API reference
          "${CMAKE_CURRENT_BINARY_DIR}/autogen/autogen_api_completions.${lang}.adoc"
          "${CMAKE_CURRENT_BINARY_DIR}/autogen/autogen_api_config_priority.${lang}.adoc"
          "${CMAKE_CURRENT_BINARY_DIR}/autogen/autogen_api_hdata.${lang}.adoc"
          "${CMAKE_CURRENT_BINARY_DIR}/autogen/autogen_api_infolists.${lang}.adoc"
          "${CMAKE_CURRENT_BINARY_DIR}/autogen/autogen_api_infos.${lang}.adoc"
          "${CMAKE_CURRENT_BINARY_DIR}/autogen/autogen_api_infos_hashtable.${lang}.adoc"
          "${CMAKE_CURRENT_BINARY_DIR}/autogen/autogen_api_plugins_priority.${lang}.adoc"
          "${CMAKE_CURRENT_BINARY_DIR}/autogen/autogen_api_url_options.${lang}.adoc"
          # user's guide
          "${CMAKE_CURRENT_BINARY_DIR}/autogen/autogen_user_commands.${lang}.adoc"
          "${CMAKE_CURRENT_BINARY_DIR}/autogen/autogen_user_default_aliases.${lang}.adoc"
          "${CMAKE_CURRENT_BINARY_DIR}/autogen/autogen_user_irc_colors.${lang}.adoc"
          "${CMAKE_CURRENT_BINARY_DIR}/autogen/autogen_user_options.${lang}.adoc"
        )
      endforeach()
      add_custom_target(doc-autogen ALL
        COMMAND "${CMAKE_COMMAND}" -E env "WEECHAT_EXTRA_LIBDIR=${PROJECT_BINARY_DIR}/src" "WEECHAT_DOCGEN_LOCALEDIR=${PROJECT_BINARY_DIR}/po" "${CMAKE_BINARY_DIR}/src/gui/curses/headless/weechat-headless" --temp-dir --doc-gen "${CMAKE_CURRENT_BINARY_DIR}/autogen"
        DEPENDS
        # the headless binary is required
        weechat-headless
        # translations must be compiled
        translations
        # all plugins must be loaded during doc generation
        alias buflist charset exec fifo fset guile irc logger lua perl php python relay ruby script spell tcl trigger typing xfer
        BYPRODUCTS ${AUTOGEN_FILES}
        WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
      )
    endif()

    # man/doc in all languages
    add_subdirectory(cs)
    add_subdirectory(de)
    add_subdirectory(en)
    add_subdirectory(es)
    add_subdirectory(fr)
    add_subdirectory(it)
    add_subdirectory(ja)
    add_subdirectory(pl)
    add_subdirectory(ru)
    add_subdirectory(sr)
  else()
    message(SEND_ERROR "Asciidoctor not found")
  endif()
endif()