summaryrefslogtreecommitdiffstats
path: root/third_party/aom/docs.cmake
blob: d6c5c26c9eb1681bf9ea81b32636440a05eac7fd (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
##
## Copyright (c) 2017, Alliance for Open Media. All rights reserved
##
## This source code is subject to the terms of the BSD 2 Clause License and
## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
## was not distributed with this source code in the LICENSE file, you can
## obtain it at www.aomedia.org/license/software. If the Alliance for Open
## Media Patent License 1.0 was not distributed with this source code in the
## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
##
if (NOT AOM_DOCS_CMAKE_)
set(AOM_DOCS_CMAKE_ 1)

cmake_minimum_required(VERSION 3.5)

set(AOM_DOXYFILE "${AOM_CONFIG_DIR}/doxyfile")
set(AOM_DOXYGEN_CONFIG_TEMPLATE "libs.doxy_template")
set(AOM_DOXYGEN_OUTPUT_DIR "${AOM_CONFIG_DIR}/dox")
set(AOM_DOXYGEN_SECTIONS "av1")

set(AOM_DOXYGEN_SOURCES
    "${AOM_ROOT}/aom/aom.h"
    "${AOM_ROOT}/aom/aom_codec.h"
    "${AOM_ROOT}/aom/aom_frame_buffer.h"
    "${AOM_ROOT}/aom/aom_image.h"
    "${AOM_ROOT}/aom/aom_integer.h"
    "${AOM_ROOT}/keywords.dox"
    "${AOM_ROOT}/mainpage.dox"
    "${AOM_ROOT}/usage.dox")

if (CONFIG_AV1_DECODER)
  set(AOM_DOXYGEN_EXAMPLE_SOURCES
      ${AOM_DOXYGEN_EXAMPLE_SOURCES}
      "${AOM_ROOT}/aomdec.c"
      "${AOM_ROOT}/examples/decode_to_md5.c"
      "${AOM_ROOT}/examples/decode_with_drops.c"
      "${AOM_ROOT}/examples/simple_decoder.c")

  set(AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS
      ${AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS}
      "Full featured decoder."
      "Frame by frame MD5 checksum."
      "Drops frames while decoding."
      "Simplified decoder loop.")

  set(AOM_DOXYGEN_SECTIONS ${AOM_DOXYGEN_SECTIONS} "av1_decoder decoder")

  set(AOM_DOXYGEN_SOURCES
      ${AOM_DOXYGEN_SOURCES}
      "${AOM_ROOT}/aom/aom_decoder.h"
      "${AOM_ROOT}/aom/aomdx.h"
      "${AOM_ROOT}/usage_dx.dox")

  if (CONFIG_ANALYZER)
    set(AOM_DOXYGEN_EXAMPLE_SOURCES
        ${AOM_DOXYGEN_EXAMPLE_SOURCES}
        "${AOM_ROOT}examples/analyzer.cc")

    set(AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS
        ${AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS}
        "Bitstream analyzer.")
  endif ()

  if (CONFIG_INSPECTION)
     set(AOM_DOXYGEN_EXAMPLE_SOURCES
         ${AOM_DOXYGEN_EXAMPLE_SOURCES}
         "${AOM_ROOT}/examples/inspect.c")

    set(AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS
        ${AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS}
        "Bitstream inspector.")
  endif ()
endif ()

if (CONFIG_AV1_ENCODER)
  set(AOM_DOXYGEN_EXAMPLE_SOURCES
      ${AOM_DOXYGEN_EXAMPLE_SOURCES}
      "${AOM_ROOT}/aomenc.c"
      "${AOM_ROOT}/examples/lossless_encoder.c"
      "${AOM_ROOT}/examples/set_maps.c"
      "${AOM_ROOT}/examples/simple_encoder.c"
      "${AOM_ROOT}/examples/twopass_encoder.c")

  set(AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS
      ${AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS}
      "Full featured encoder."
      "Simplified lossless encoder."
      "Set active and ROI maps."
      "Simplified encoder loop."
      "Two-pass encoder loop.")

  set(AOM_DOXYGEN_SECTIONS ${AOM_DOXYGEN_SECTIONS} "av1_encoder encoder")

  set(AOM_DOXYGEN_SOURCES
      ${AOM_DOXYGEN_SOURCES}
      "${AOM_ROOT}/aom/aomcx.h"
      "${AOM_ROOT}/aom/aom_encoder.h"
      "${AOM_ROOT}/usage_cx.dox")
endif ()

if (CONFIG_AV1_DECODER AND CONFIG_AV1_ENCODER)
  set(AOM_DOXYGEN_EXAMPLE_SOURCES
      ${AOM_DOXYGEN_EXAMPLE_SOURCES}
      "${AOM_ROOT}/examples/aom_cx_set_ref.c")

  set(AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS
      ${AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS}
      "Set encoder reference frame.")
endif ()

# Iterates over list named by $list_name and appends each item to $AOM_DOXYFILE
# as values assigned to $var_name with no line breaks between list items.
# Appends a new line after the entire config variable is expanded.
function (write_cmake_list_to_doxygen_config_var var_name list_name)
  unset(output_string)
  foreach (list_item ${${list_name}})
    set(output_string "${output_string} ${list_item} ")
  endforeach ()
  string(STRIP "${output_string}" output_string)
  file(APPEND "${AOM_DOXYFILE}" "${var_name} += ${output_string}\n")
endfunction ()

function (get_name file_path name_var)
    get_filename_component(file_basename ${file_path} NAME)
    get_filename_component(${name_var} ${file_basename} NAME_WE)
    set(${name_var} ${${name_var}} PARENT_SCOPE)
endfunction ()

function (setup_documentation_targets)
  # Sanity check: the lengths of these lists must match.
  list(LENGTH AOM_DOXYGEN_EXAMPLE_SOURCES num_sources)
  list(LENGTH AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS num_descs)
  if (NOT ${num_sources} EQUAL ${num_descs})
    message(FATAL_ERROR "Unqeual example and description totals.")
  endif ()

  # Take the list of examples and produce example_basename.dox for each file in
  # the list.
  file(MAKE_DIRECTORY "${AOM_DOXYGEN_OUTPUT_DIR}")
  foreach (example_file ${AOM_DOXYGEN_EXAMPLE_SOURCES})
    unset(example_basename)
    get_name("${example_file}" "example_name")
    set(example_dox "${AOM_DOXYGEN_OUTPUT_DIR}/${example_name}.dox")
    set(dox_string "/*!\\page example_${example_name} ${example_name}\n")
    set(dox_string "${dox_string} \\includelineno ${example_file}\n*/\n")
    file(WRITE "${example_dox}" ${dox_string})
    set(AOM_DOXYGEN_SOURCES ${AOM_DOXYGEN_SOURCES} "${example_dox}")
  endforeach ()

  # Generate samples.dox, an index page that refers to the example_basename.dox
  # files that were just created.
  set(samples_header
"
/*!\\page samples Sample Code
This SDK includes a number of sample applications. Each sample documents a
feature of the SDK in both prose and the associated C code. The following
samples are included:
")

  set(utils_desc
"
In addition, the SDK contains a number of utilities. Since these utilities are
built upon the concepts described in the sample code listed above, they are not
documented in pieces like the samples are. Their source is included here for
reference. The following utilities are included:
")

  # Write the description for the samples section.
  set(samples_dox "${AOM_CONFIG_DIR}/samples.dox")
  file(WRITE "${samples_dox}" "${samples_header}\n")

  # Iterate over $AOM_DOXYGEN_EXAMPLE_SOURCES and
  # $AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS and massage example names as required by
  # AV1's doxygen setup.
  math(EXPR max_example_index "${num_sources} - 1")
  foreach (NUM RANGE ${max_example_index})
    list(GET AOM_DOXYGEN_EXAMPLE_SOURCES ${NUM} ex_name)
    get_name("${ex_name}" "ex_name")

    # AV1's doxygen lists aomdec and aomenc as utils apart from the examples.
    # Save the indexes for another pass.
    if ("${ex_name}" MATCHES "aomdec\|aomenc")
      set(util_indexes "${util_indexes}" "${NUM}")
      continue()
    endif ()
    list(GET AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS ${NUM} ex_desc)
    file(APPEND "${samples_dox}" " - \\subpage example_${ex_name} ${ex_desc}\n")
  endforeach ()

  # Write the description and index for the utils.
  file(APPEND "${samples_dox}" "${utils_desc}\n")
  foreach (util_index ${util_indexes})
    list(GET AOM_DOXYGEN_EXAMPLE_SOURCES ${util_index} ex_name)
    get_name("${ex_name}" "ex_name")
    list(GET AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS ${util_index} ex_desc)
    file(APPEND "${samples_dox}" " - \\subpage example_${ex_name} ${ex_desc}\n")
  endforeach ()
  file(APPEND "${samples_dox}" "*/")

  # Add $samples_dox to the doxygen inputs.
  get_filename_component(samples_dox ${samples_dox} NAME)
  set(AOM_DOXYGEN_SOURCES ${AOM_DOXYGEN_SOURCES} ${samples_dox})

  # Generate libaom's doxyfile.
  file(COPY "${AOM_ROOT}/${AOM_DOXYGEN_CONFIG_TEMPLATE}"
       DESTINATION "${AOM_CONFIG_DIR}")
  file(RENAME
       "${AOM_CONFIG_DIR}/${AOM_DOXYGEN_CONFIG_TEMPLATE}" "${AOM_DOXYFILE}")
  file(APPEND "${AOM_DOXYFILE}"
       "EXAMPLE_PATH += ${AOM_ROOT} ${AOM_ROOT}/examples\n")
  file(APPEND
       "${AOM_DOXYFILE}" "INCLUDE_PATH += ${AOM_CONFIG_DIR} ${AOM_ROOT}\n")
  file(APPEND "${AOM_DOXYFILE}"
       "STRIP_FROM_PATH += ${AOM_ROOT} ${AOM_CONFIG_DIR}\n")
  write_cmake_list_to_doxygen_config_var("INPUT" "AOM_DOXYGEN_SOURCES")
  write_cmake_list_to_doxygen_config_var("ENABLED_SECTIONS"
                                         "AOM_DOXYGEN_SECTIONS")

  # Add the doxygen generation rule.
  add_custom_target(docs ALL
                    COMMAND "${DOXYGEN_EXECUTABLE}" "${AOM_DOXYFILE}"
                    DEPENDS "${AOM_DOXYFILE}" ${AOM_DOXYGEN_SOURCES}
                             ${AOM_DOXYGEN_EXAMPLE_SOURCES}
                    SOURCES "${AOM_DOXYFILE}" ${AOM_DOXYGEN_SOURCES}
                             ${AOM_DOXYGEN_EXAMPLE_SOURCES})
endfunction ()

endif ()  # AOM_DOCS_CMAKE_