File: GroongaSphinx.cmake

package info (click to toggle)
groonga 15.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 163,080 kB
  • sloc: ansic: 770,564; cpp: 48,925; ruby: 40,447; javascript: 10,250; yacc: 7,045; sh: 5,602; python: 2,821; makefile: 1,672
file content (89 lines) | stat: -rw-r--r-- 3,797 bytes parent folder | download | duplicates (2)
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
# Copyright(C) 2023  Sutou Kouhei <kou@clear-code.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

function(grn_sphinx SOURCE_DIR LOCALE SOURCES HTML_FILES)
  set(ABSOLUT_SOURCES)
  set(ALL_SOURCES)
  foreach(SOURCE ${SOURCES} conf.py)
    list(APPEND ABSOLUTE_SOURCES ${SOURCE_DIR}/${SOURCE})
    list(APPEND ALL_ABSOLUTE_SOURCES ${SOURCE_DIR}/${SOURCE})
    if("${SOURCE}" STREQUAL "conf.py")
      # target
    elseif(
      "${SOURCE}" STREQUAL "install/server-use.rst"
      OR "${SOURCE}" STREQUAL "install/server-use.md"
      OR "${SOURCE}" STREQUAL "reference/commands/compress_filter.rst"
      OR "${SOURCE}" STREQUAL "reference/scoring_note.rst"
      OR "${SOURCE}" MATCHES "^example/")
      # not target
      continue()
    elseif(NOT "${SOURCE}" MATCHES "\\.(rst|md)\$")
      continue()
    endif()
    string(REGEX REPLACE "\\.[^.]+\$" "" SOURCE_BASE_NAME ${SOURCE})
    set(POT "${LOCALE}/gettext/${SOURCE_BASE_NAME}.pot")
    set(PO
        "${SOURCE_DIR}/../locale/${LOCALE}/LC_MESSAGES/${SOURCE_BASE_NAME}.po")
    set(PO_TIME_STAMP "${LOCALE}/LC_MESSAGES/${SOURCE_BASE_NAME}.po.time_stamp")
    set(EDIT_PO "${LOCALE}/LC_MESSAGES/${SOURCE_BASE_NAME}.edit.po")
    add_custom_command(
      OUTPUT ${EDIT_PO}
      COMMAND ${RUBY} ${CMAKE_CURRENT_SOURCE_DIR}/../doc/update-edit-po.rb
              ${LOCALE} ${POT} ${PO} ${PO_TIME_STAMP} ${EDIT_PO}
      DEPENDS ${LOCALE}-gettext.time_stamp ${LOCALE}/gettext/conf.pot)
    add_custom_command(
      OUTPUT ${PO} ${PO_TIME_STAMP}
      COMMAND ${RUBY} ${CMAKE_CURRENT_SOURCE_DIR}/../doc/update-po.rb ${PO}
              ${PO_TIME_STAMP} ${EDIT_PO}
      DEPENDS ${EDIT_PO})
    list(APPEND ALL_ABSOLUTE_SOURCES ${PO})
  endforeach()

  find_program(XGETTEXT xgettext REQUIRED)
  add_custom_command(
    OUTPUT ${LOCALE}/gettext/conf.pot
    COMMAND ${XGETTEXT} --language Python --output ${LOCALE}/gettext/conf.pot
            ${SOURCE_DIR}/conf.py
    DEPENDS ${SOURCE_DIR}/conf.py)

  find_program(SPHINX_BUILD sphinx-build REQUIRED)
  foreach(BUILDER "gettext" "html" "markdown")
    if("${BUILDER}" STREQUAL "gettext")
      set(TARGET_SOURCES ${ABSOLUTE_SOURCES})
    else()
      set(TARGET_SOURCES ${ALL_ABSOLUTE_SOURCES})
    endif()
    set(OUTPUTS ${LOCALE}/doctrees/${BUILDER} ${LOCALE}-${BUILDER}.time_stamp)
    if("${BUILDER}" STREQUAL "html")
      list(APPEND OUTPUTS ${HTML_FILES})
    endif()
    add_custom_command(
      OUTPUT ${OUTPUTS}
      COMMAND
        ${CMAKE_COMMAND} -E env DOCUMENT_VERSION=${GRN_VERSION}
        DOCUMENT_VERSION_FULL=${GRN_VERSION_FULL} LOCALE=${LOCALE}
        ${SPHINX_BUILD} $<$<CONFIG:Debug>:--fail-on-warning> --quiet -j auto -D
        language=${LOCALE} -b ${BUILDER} -d ${LOCALE}/doctrees/${BUILDER}
        ${SOURCE_DIR} ${LOCALE}/${BUILDER}
      COMMAND ${CMAKE_COMMAND} -E touch ${LOCALE}-${BUILDER}.time_stamp
      DEPENDS ${TARGET_SOURCES})
    if("${BUILDER}" STREQUAL "html")
      add_custom_target(doc_${LOCALE}_${BUILDER} ALL DEPENDS ${OUTPUTS})
    else()
      add_custom_target(doc_${LOCALE}_${BUILDER} DEPENDS ${OUTPUTS})
    endif()
  endforeach()
endfunction()