blob: c93a2df90e4be66e169d8cf8477f1277dded9e8d [file] [log] [blame]
Tom Finegan0d066ce2017-05-30 11:07:05 -07001##
2## Copyright (c) 2017, Alliance for Open Media. All rights reserved
3##
4## This source code is subject to the terms of the BSD 2 Clause License and
5## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6## was not distributed with this source code in the LICENSE file, you can
7## obtain it at www.aomedia.org/license/software. If the Alliance for Open
8## Media Patent License 1.0 was not distributed with this source code in the
9## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10##
11if (NOT AOM_DOCS_CMAKE_)
12set(AOM_DOCS_CMAKE_ 1)
13
14cmake_minimum_required(VERSION 3.5)
15
16set(AOM_DOXYFILE "${AOM_CONFIG_DIR}/doxyfile")
17set(AOM_DOXYGEN_CONFIG_TEMPLATE "libs.doxy_template")
18set(AOM_DOXYGEN_OUTPUT_DIR "${AOM_CONFIG_DIR}/dox")
19set(AOM_DOXYGEN_SECTIONS "av1")
20
21set(AOM_DOXYGEN_SOURCES
22 "${AOM_ROOT}/aom/aom.h"
23 "${AOM_ROOT}/aom/aom_codec.h"
24 "${AOM_ROOT}/aom/aom_frame_buffer.h"
25 "${AOM_ROOT}/aom/aom_image.h"
26 "${AOM_ROOT}/aom/aom_integer.h"
27 "${AOM_ROOT}/keywords.dox"
28 "${AOM_ROOT}/mainpage.dox"
29 "${AOM_ROOT}/usage.dox")
30
31if (CONFIG_AV1_DECODER)
32 set(AOM_DOXYGEN_EXAMPLE_SOURCES
33 ${AOM_DOXYGEN_EXAMPLE_SOURCES}
34 "${AOM_ROOT}/aomdec.c"
35 "${AOM_ROOT}/examples/decode_to_md5.c"
36 "${AOM_ROOT}/examples/decode_with_drops.c"
37 "${AOM_ROOT}/examples/simple_decoder.c")
38
39 set(AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS
40 ${AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS}
41 "Full featured decoder."
42 "Frame by frame MD5 checksum."
43 "Drops frames while decoding."
44 "Simplified decoder loop.")
45
46 set(AOM_DOXYGEN_SECTIONS ${AOM_DOXYGEN_SECTIONS} "av1_decoder decoder")
47
48 set(AOM_DOXYGEN_SOURCES
49 ${AOM_DOXYGEN_SOURCES}
50 "${AOM_ROOT}/aom/aom_decoder.h"
51 "${AOM_ROOT}/aom/aomdx.h"
52 "${AOM_ROOT}/usage_dx.dox")
53
54 if (CONFIG_ANALYZER)
55 set(AOM_DOXYGEN_EXAMPLE_SOURCES
56 ${AOM_DOXYGEN_EXAMPLE_SOURCES}
57 "${AOM_ROOT}examples/analyzer.cc")
58
59 set(AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS
60 ${AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS}
61 "Bitstream analyzer.")
62 endif ()
63
64 if (CONFIG_INSPECTION)
65 set(AOM_DOXYGEN_EXAMPLE_SOURCES
66 ${AOM_DOXYGEN_EXAMPLE_SOURCES}
67 "${AOM_ROOT}/examples/inspect.c")
68
69 set(AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS
70 ${AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS}
71 "Bitstream inspector.")
72 endif ()
73endif ()
74
75if (CONFIG_AV1_ENCODER)
76 set(AOM_DOXYGEN_EXAMPLE_SOURCES
77 ${AOM_DOXYGEN_EXAMPLE_SOURCES}
78 "${AOM_ROOT}/aomenc.c"
79 "${AOM_ROOT}/examples/lossless_encoder.c"
80 "${AOM_ROOT}/examples/set_maps.c"
81 "${AOM_ROOT}/examples/simple_encoder.c"
82 "${AOM_ROOT}/examples/twopass_encoder.c")
83
84 set(AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS
85 ${AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS}
86 "Full featured encoder."
87 "Simplified lossless encoder."
88 "Set active and ROI maps."
89 "Simplified encoder loop."
90 "Two-pass encoder loop.")
91
92 set(AOM_DOXYGEN_SECTIONS ${AOM_DOXYGEN_SECTIONS} "av1_encoder encoder")
93
94 set(AOM_DOXYGEN_SOURCES
95 ${AOM_DOXYGEN_SOURCES}
96 "${AOM_ROOT}/aom/aomcx.h"
97 "${AOM_ROOT}/aom/aom_encoder.h"
98 "${AOM_ROOT}/usage_cx.dox")
99endif ()
100
101if (CONFIG_AV1_DECODER AND CONFIG_AV1_ENCODER)
102 set(AOM_DOXYGEN_EXAMPLE_SOURCES
103 ${AOM_DOXYGEN_EXAMPLE_SOURCES}
104 "${AOM_ROOT}/examples/aom_cx_set_ref.c")
105
106 set(AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS
107 ${AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS}
108 "Set encoder reference frame.")
109endif ()
110
111# Iterates over list named by $list_name and appends each item to $AOM_DOXYFILE
112# as values assigned to $var_name with no line breaks between list items.
113# Appends a new line after the entire config variable is expanded.
114function (write_cmake_list_to_doxygen_config_var var_name list_name)
115 unset(output_string)
116 foreach (list_item ${${list_name}})
117 set(output_string "${output_string} ${list_item} ")
118 endforeach ()
119 string(STRIP "${output_string}" output_string)
120 file(APPEND "${AOM_DOXYFILE}" "${var_name} += ${output_string}\n")
121endfunction ()
122
123function (get_name file_path name_var)
124 get_filename_component(file_basename ${file_path} NAME)
125 get_filename_component(${name_var} ${file_basename} NAME_WE)
126 set(${name_var} ${${name_var}} PARENT_SCOPE)
127endfunction ()
128
129function (setup_documentation_targets)
130 # Sanity check: the lengths of these lists must match.
131 list(LENGTH AOM_DOXYGEN_EXAMPLE_SOURCES num_sources)
132 list(LENGTH AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS num_descs)
133 if (NOT ${num_sources} EQUAL ${num_descs})
134 message(FATAL_ERROR "Unqeual example and description totals.")
135 endif ()
136
137 # Take the list of examples and produce example_basename.dox for each file in
138 # the list.
139 file(MAKE_DIRECTORY "${AOM_DOXYGEN_OUTPUT_DIR}")
140 foreach (example_file ${AOM_DOXYGEN_EXAMPLE_SOURCES})
141 unset(example_basename)
142 get_name("${example_file}" "example_name")
143 set(example_dox "${AOM_DOXYGEN_OUTPUT_DIR}/${example_name}.dox")
144 set(dox_string "/*!\\page example_${example_name} ${example_name}\n")
145 set(dox_string "${dox_string} \\includelineno ${example_file}\n*/\n")
146 file(WRITE "${example_dox}" ${dox_string})
147 set(AOM_DOXYGEN_SOURCES ${AOM_DOXYGEN_SOURCES} "${example_dox}")
148 endforeach ()
149
150 # Generate samples.dox, an index page that refers to the example_basename.dox
151 # files that were just created.
152 set(samples_header
153"
154/*!\\page samples Sample Code
155This SDK includes a number of sample applications. Each sample documents a
156feature of the SDK in both prose and the associated C code. The following
157samples are included:
158")
159
160 set(utils_desc
161"
162In addition, the SDK contains a number of utilities. Since these utilities are
163built upon the concepts described in the sample code listed above, they are not
164documented in pieces like the samples are. Their source is included here for
165reference. The following utilities are included:
166")
167
168 # Write the description for the samples section.
169 set(samples_dox "${AOM_CONFIG_DIR}/samples.dox")
170 file(WRITE "${samples_dox}" "${samples_header}\n")
171
172 # Iterate over $AOM_DOXYGEN_EXAMPLE_SOURCES and
173 # $AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS and massage example names as required by
174 # AV1's doxygen setup.
175 math(EXPR max_example_index "${num_sources} - 1")
176 foreach (NUM RANGE ${max_example_index})
177 list(GET AOM_DOXYGEN_EXAMPLE_SOURCES ${NUM} ex_name)
178 get_name("${ex_name}" "ex_name")
179
180 # AV1's doxygen lists aomdec and aomenc as utils apart from the examples.
181 # Save the indexes for another pass.
182 if ("${ex_name}" MATCHES "aomdec\|aomenc")
183 set(util_indexes "${util_indexes}" "${NUM}")
184 continue()
185 endif ()
186 list(GET AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS ${NUM} ex_desc)
187 file(APPEND "${samples_dox}" " - \\subpage example_${ex_name} ${ex_desc}\n")
188 endforeach ()
189
190 # Write the description and index for the utils.
191 file(APPEND "${samples_dox}" "${utils_desc}\n")
192 foreach (util_index ${util_indexes})
193 list(GET AOM_DOXYGEN_EXAMPLE_SOURCES ${util_index} ex_name)
194 get_name("${ex_name}" "ex_name")
195 list(GET AOM_DOXYGEN_EXAMPLE_DESCRIPTIONS ${util_index} ex_desc)
196 file(APPEND "${samples_dox}" " - \\subpage example_${ex_name} ${ex_desc}\n")
197 endforeach ()
198 file(APPEND "${samples_dox}" "*/")
199
200 # Add $samples_dox to the doxygen inputs.
201 get_filename_component(samples_dox ${samples_dox} NAME)
202 set(AOM_DOXYGEN_SOURCES ${AOM_DOXYGEN_SOURCES} ${samples_dox})
203
204 # Generate libaom's doxyfile.
Tom Finegan746a7852017-06-02 11:29:48 -0700205 file(WRITE "${AOM_DOXYFILE}" "##\n## GENERATED FILE. DO NOT EDIT\n##\n")
206 file(READ "${AOM_ROOT}/${AOM_DOXYGEN_CONFIG_TEMPLATE}" doxygen_template_data)
207 file(APPEND "${AOM_DOXYFILE}" ${doxygen_template_data})
Tom Finegan0d066ce2017-05-30 11:07:05 -0700208 file(APPEND "${AOM_DOXYFILE}"
209 "EXAMPLE_PATH += ${AOM_ROOT} ${AOM_ROOT}/examples\n")
210 file(APPEND
211 "${AOM_DOXYFILE}" "INCLUDE_PATH += ${AOM_CONFIG_DIR} ${AOM_ROOT}\n")
212 file(APPEND "${AOM_DOXYFILE}"
213 "STRIP_FROM_PATH += ${AOM_ROOT} ${AOM_CONFIG_DIR}\n")
214 write_cmake_list_to_doxygen_config_var("INPUT" "AOM_DOXYGEN_SOURCES")
215 write_cmake_list_to_doxygen_config_var("ENABLED_SECTIONS"
216 "AOM_DOXYGEN_SECTIONS")
217
218 # Add the doxygen generation rule.
219 add_custom_target(docs ALL
220 COMMAND "${DOXYGEN_EXECUTABLE}" "${AOM_DOXYFILE}"
221 DEPENDS "${AOM_DOXYFILE}" ${AOM_DOXYGEN_SOURCES}
222 ${AOM_DOXYGEN_EXAMPLE_SOURCES}
Tom Finegan746a7852017-06-02 11:29:48 -0700223 "${AOM_DOXYGEN_CONFIG_TEMPLATE}"
Tom Finegan0d066ce2017-05-30 11:07:05 -0700224 SOURCES "${AOM_DOXYFILE}" ${AOM_DOXYGEN_SOURCES}
Tom Finegan746a7852017-06-02 11:29:48 -0700225 ${AOM_DOXYGEN_EXAMPLE_SOURCES}
226 "${AOM_DOXYGEN_CONFIG_TEMPLATE}")
Tom Finegan0d066ce2017-05-30 11:07:05 -0700227endfunction ()
228
229endif () # AOM_DOCS_CMAKE_