summaryrefslogtreecommitdiff
path: root/media/libjxl/src/doc/sphinx/conf.py
blob: 1591aefc70c0a7485fb7c2535540d22c7458f83b (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
# Copyright (c) the JPEG XL Project Authors. All rights reserved.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

# Configuration file for the Sphinx documentation builder.
#
# See https://www.sphinx-doc.org/en/master/usage/configuration.html

import os
import re
import subprocess

def GetVersion():
    """Function to get the version of the current code."""
    with open(os.path.join(
            os.path.dirname(__file__), '../../lib/CMakeLists.txt'), 'r') as f:
        cmakevars = {}
        for line in f:
            m = re.match(r'set\(JPEGXL_([A-Z]+)_VERSION ([^\)]+)\)', line)
            if m:
                cmakevars[m.group(1)] = m.group(2)
    return '%s.%s.%s' % (cmakevars['MAJOR'], cmakevars['MINOR'], cmakevars['PATCH'])

def ConfigProject(app, config):
    # Configure the doxygen xml directory as the "xml" directory next to the
    # sphinx output directory. Doxygen generates by default the xml files in a
    # "xml" sub-directory of the OUTPUT_DIRECTORY.
    build_dir = os.path.dirname(app.outdir)
    xml_dir = os.path.join(build_dir, 'xml')
    config.breathe_projects['libjxl'] = xml_dir

    # Read the docs build environment doesn't run our cmake script so instead we
    # need to run doxygen manually here.
    if os.environ.get('READTHEDOCS', None) != 'True':
        return
    root_dir = os.path.realpath(os.path.join(app.srcdir, '../../'))
    doxyfile = os.path.join(build_dir, 'Doxyfile-rtd.doc')
    with open(doxyfile, 'w') as f:
        f.write(f"""
FILE_PATTERNS          = *.c *.h
GENERATE_HTML          = NO
GENERATE_LATEX         = NO
GENERATE_XML           = YES
INPUT                  = lib/include doc/api.txt
OUTPUT_DIRECTORY       = {build_dir}
PROJECT_NAME           = LIBJXL
QUIET                  = YES
RECURSIVE              = YES
STRIP_FROM_PATH        = lib/include
WARN_AS_ERROR          = YES
""")
    subprocess.check_call(['doxygen', doxyfile], cwd=root_dir)

def setup(app):
    # Generate doxygen XML on init when running from Read the docs.
    app.connect("config-inited", ConfigProject)

### Project information

project = 'libjxl'
project_copyright = 'JPEG XL Project Authors'
author = 'JPEG XL Project Authors'
version = GetVersion()

### General configuration

extensions = [
    # For integration with doxygen documentation.
    'breathe',
    # sphinx readthedocs theme.
    'sphinx_rtd_theme',
    # Do we use it?
    'sphinx.ext.graphviz',
]

breathe_default_project = 'libjxl'
breathe_projects = {}


# All the API is in C, except those files that end with cxx.h.
breathe_domain_by_extension = {'h': 'cpp'}
breathe_domain_by_file_pattern = {
    '*cxx.h': 'cpp',
}
breathe_implementation_filename_extensions = ['.cc']

# These are defined at build time by cmake.
c_id_attributes = [
    'JXL_EXPORT',
    'JXL_DEPRECATED',
    'JXL_THREADS_EXPORT',
]
cpp_id_attributes = c_id_attributes


breathe_projects_source = {
    'libjxl' : ('../../', [
        'doc/api.txt',
        'lib/include/jxl',
    ])
}

# Recognized suffixes.
source_suffix = ['.rst', '.md']

### Options for HTML output

# Use the readthedocs.io theme when generating the HTML output.
html_theme = 'sphinx_rtd_theme'