Debian Codegraph @

cmake/GroongaSphinx.cmake

raw
1 # Copyright(C) 2023 Sutou Kouhei <[email protected]>
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17 function(grn_sphinx SOURCE_DIR LOCALE SOURCES HTML_FILES)
18 set(ABSOLUT_SOURCES)
19 set(ALL_SOURCES)
20 foreach(SOURCE ${SOURCES} conf.py)
21 list(APPEND ABSOLUTE_SOURCES ${SOURCE_DIR}/${SOURCE})
22 list(APPEND ALL_ABSOLUTE_SOURCES ${SOURCE_DIR}/${SOURCE})
23 if("${SOURCE}" STREQUAL "conf.py")
24 # target
25 elseif(
26 "${SOURCE}" STREQUAL "install/server-use.rst"
27 OR "${SOURCE}" STREQUAL "install/server-use.md"
28 OR "${SOURCE}" STREQUAL "reference/commands/compress_filter.rst"
29 OR "${SOURCE}" STREQUAL "reference/scoring_note.rst"
30 OR "${SOURCE}" MATCHES "^example/")
31 # not target
32 continue()
33 elseif(NOT "${SOURCE}" MATCHES "\\.(rst|md)\$")
34 continue()
35 endif()
36 string(REGEX REPLACE "\\.[^.]+\$" "" SOURCE_BASE_NAME ${SOURCE})
37 set(POT "${LOCALE}/gettext/${SOURCE_BASE_NAME}.pot")
38 set(PO
39 "${SOURCE_DIR}/../locale/${LOCALE}/LC_MESSAGES/${SOURCE_BASE_NAME}.po")
40 set(PO_TIME_STAMP "${LOCALE}/LC_MESSAGES/${SOURCE_BASE_NAME}.po.time_stamp")
41 set(EDIT_PO "${LOCALE}/LC_MESSAGES/${SOURCE_BASE_NAME}.edit.po")
42 add_custom_command(
43 OUTPUT ${EDIT_PO}
44 COMMAND ${RUBY} ${CMAKE_CURRENT_SOURCE_DIR}/../doc/update-edit-po.rb
45 ${LOCALE} ${POT} ${PO} ${PO_TIME_STAMP} ${EDIT_PO}
46 DEPENDS ${LOCALE}-gettext.time_stamp ${LOCALE}/gettext/conf.pot)
47 add_custom_command(
48 OUTPUT ${PO} ${PO_TIME_STAMP}
49 COMMAND ${RUBY} ${CMAKE_CURRENT_SOURCE_DIR}/../doc/update-po.rb ${PO}
50 ${PO_TIME_STAMP} ${EDIT_PO}
51 DEPENDS ${EDIT_PO})
52 list(APPEND ALL_ABSOLUTE_SOURCES ${PO})
53 endforeach()
54
55 find_program(XGETTEXT xgettext REQUIRED)
56 add_custom_command(
57 OUTPUT ${LOCALE}/gettext/conf.pot
58 COMMAND ${XGETTEXT} --language Python --output ${LOCALE}/gettext/conf.pot
59 ${SOURCE_DIR}/conf.py
60 DEPENDS ${SOURCE_DIR}/conf.py)
61
62 find_program(SPHINX_BUILD sphinx-build REQUIRED)
63 foreach(BUILDER "gettext" "html" "markdown")
64 if("${BUILDER}" STREQUAL "gettext")
65 set(TARGET_SOURCES ${ABSOLUTE_SOURCES})
66 else()
67 set(TARGET_SOURCES ${ALL_ABSOLUTE_SOURCES})
68 endif()
69 set(OUTPUTS ${LOCALE}/doctrees/${BUILDER} ${LOCALE}-${BUILDER}.time_stamp)
70 if("${BUILDER}" STREQUAL "html")
71 list(APPEND OUTPUTS ${HTML_FILES})
72 endif()
73 add_custom_command(
74 OUTPUT ${OUTPUTS}
75 COMMAND
76 ${CMAKE_COMMAND} -E env DOCUMENT_VERSION=${GRN_VERSION}
77 DOCUMENT_VERSION_FULL=${GRN_VERSION_FULL} LOCALE=${LOCALE}
78 ${SPHINX_BUILD} $<$<CONFIG:Debug>:--fail-on-warning> --quiet -j auto -D
79 language=${LOCALE} -b ${BUILDER} -d ${LOCALE}/doctrees/${BUILDER}
80 ${SOURCE_DIR} ${LOCALE}/${BUILDER}
81 COMMAND ${CMAKE_COMMAND} -E touch ${LOCALE}-${BUILDER}.time_stamp
82 DEPENDS ${TARGET_SOURCES})
83 if("${BUILDER}" STREQUAL "html")
84 add_custom_target(doc_${LOCALE}_${BUILDER} ALL DEPENDS ${OUTPUTS})
85 else()
86 add_custom_target(doc_${LOCALE}_${BUILDER} DEPENDS ${OUTPUTS})
87 endif()
88 endforeach()
89 endfunction()