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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
|
# Copyright (C) 2022 Igalia S.L.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS
# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#[=======================================================================[.rst:
FindGIDocgen
------------
Finds the ``gi-docgen`` program and adds the :command:`GI_DOCGEN` command.
The following variables will also be set:
``GIDocgen_FOUND``
True if the ``gi-docgen`` program has been found.
``GIDocgen_VERSION``
Version of the ``gi-docgen`` program.
``GIDocgen_EXE``
Path to the ``gi-docgen`` program.
There are three different ways in which ``gi-docgen`` can be made available:
* Installed system-wide.
* A Python `virtualenv`__ placed at ``${CMAKE_SOURCE_DIR}/gi-docgen``.
* A copy of the ``gi-docgen`` source tree placed at
``${CMAKE_SOURCE_DIR}/gi-docgen``.
__ https://virtualenv.pypa.io/en/latest/
In particular, the last two methods allows distributors which do not have
access to a readily available installation of ``gi-docgen`` to provide a
local copy without needing to vendor it in the project source tree.
#]=======================================================================]
# Add a dummy command in case introspection is disabled. This allows
# always use it and automatically have it be a noop in that case, instead
# of having a check next to each invocation.
if (NOT ENABLE_DOCUMENTATION)
function(GI_DOCGEN)
endfunction()
return()
endif ()
find_package(GI REQUIRED)
# Allow dropping a copy of the tool source under gi-docgen/, as it can run
# uninstalled, and also search gi-docgen/bin/ to allow placing a virtualenv
# in that location.
find_program(GIDocgen_EXE
NAMES gi-docgen gi-docgen.py
HINTS "${CMAKE_SOURCE_DIR}/gi-docgen/bin"
"${CMAKE_SOURCE_DIR}/gi-docgen"
DOC "Path to the gi-docgen program"
)
if (GIDocgen_FIND_REQUIRED)
set(_GIDocgen_MSGLEVEL FATAL_ERROR)
else ()
set(_GIDocgen_MSGLEVEL WARNING)
endif ()
if (NOT GIDocgen_EXE)
message(${_GIDocgen_MSGLEVEL}
"Could not find gi-docgen. If your system does not provide a package "
"the following commands can be used to install it inside the WebKit "
"source tree, where it will be found automatically:\n"
" virtualenv gi-docgen ${CMAKE_SOURCE_DIR}/gi-docgen\n"
" ${CMAKE_SOURCE_DIR}/gi-docgen/bin/pip install gi-docgen\n"
"Another option is unpacking a gi-docgen release at the same location "
"but in this case dependencies will not be automatically installed.\n"
)
elseif (GIDocgen_EXE)
execute_process(
COMMAND ${GIDocgen_EXE} --version
OUTPUT_VARIABLE GIDocgen_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE _GIDocgen_CMDSTATUS
ERROR_QUIET
)
set(GIDocgen_VERSION "${GIDocgen_VERSION}" CACHE INTERNAL "")
if (NOT ${_GIDocgen_CMDSTATUS} EQUAL 0)
message(${_GIDocgen_MSGLEVEL}
"Could not execute ${GIDocgen_EXE}. This typically signals an "
"incorrect installation. You may want to run it by hand for "
"troubleshooting, the re-run CMake again.\n"
)
endif ()
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GIDocgen
FOUND_VAR GIDocgen_FOUND
REQUIRED_VARS GIDocgen_EXE GIDocgen_VERSION
VERSION_VAR GIDocgen_VERSION
)
if (NOT GIDocgen_FOUND)
return()
endif ()
#[=======================================================================[.rst:
.. command:: GI_DOCGEN
.. code-block:: cmake
GI_DOCGEN(<namespace> <toml-file>
[CONTENT_TEMPLATES <file...>]
[CONTENT_PATH <path...>])
Configures generating documentation for a GObject-Introspection
``<namespace>``, which needs to have been previously configured using
command:`GI_INTROSPECT`.
The ``<toml-file>`` is the path to a `configuration file`__ for
``gi-docgen``. The file is treated as a template, and can contain
expansions of CMake variables using ``@`` as delimiter, e.g.
``@PROJECT_VERSION@``.
__ https://gnome.pages.gitlab.gnome.org/gi-docgen/project-configuration.html
``CONTENT_TEMPLATES`` can be used to list files, for each of them a
template with the ``.in`` suffix will be expanded using the
command:`configure_file` in ``@ONLY`` mode. The ``.in`` sufix must
not be present.
``CONTENT_PATH`` may be used to specify additional directories where
to look for additional content files that may be then listed in the
TOML configuration in the ``extra.content_files`` array.
Documentation is generated in the ``Documentation/<pkgname>-<nsversion>/``
subdirectory by the ``doc-<namespace>`` target added by the command.
Additionally, a ``doc-check-<namespace>`` target is created as well,
which allows running ``gi-docgen`` as a linter to report issues with
the documentation.
Targets ``doc-all`` and ``doc-check-all`` can be used to build and check
the documentation modules configured for a project.
#]=======================================================================]
function(GI_DOCGEN namespace toml)
cmake_parse_arguments(PARSE_ARGV 1 opt
""
""
"CONTENT_TEMPLATES;CONTENT_PATH"
)
if (NOT TARGET "gir-${namespace}")
message(FATAL_ERROR
"Introspection not configured for '${namespace}'. "
"Did you forget a GI_INTROSPECT(${namespace} ..) call?"
)
endif ()
set(contentdir "${CMAKE_BINARY_DIR}/GIDocgenGenerated/${namespace}")
get_property(gir_path TARGET "gir-${namespace}" PROPERTY GI_GIR_PATH)
set(toml_path "${contentdir}.toml")
configure_file("${toml}" "${toml_path}" @ONLY)
get_filename_component(toml_dir "${toml}" DIRECTORY)
get_filename_component(toml_dir "${toml_dir}" ABSOLUTE)
get_property(package TARGET "gir-${namespace}" PROPERTY GI_PACKAGE)
if (NOT package)
set(package "${namespace}")
endif ()
set(outdir "${CMAKE_BINARY_DIR}/Documentation/${package}")
set(unifdef_defines)
if (PORT STREQUAL GTK)
list(APPEND unifdef_defines -DWPE=0 -DGTK=1)
if (USE_GTK4)
list(APPEND unifdef_defines -DGTK4=1 -DGTK3=0)
else ()
list(APPEND unifdef_defines -DGTK4=0 -DGTK3=1)
endif ()
else ()
list(APPEND unifdef_defines -DWPE=1 -DGTK=0)
endif ()
set(docdeps "${toml_path};${gir_path}")
foreach (item IN LISTS opt_CONTENT_TEMPLATES)
get_filename_component(filename "${item}" NAME)
configure_file("${item}.in" "${contentdir}/${filename}.in" @ONLY)
add_custom_command(
OUTPUT "${contentdir}/${filename}"
DEPENDS "${contentdir}/${filename}.in"
COMMENT "Generating (unifdef): ${namespace}/${filename}"
VERBATIM
COMMAND "${UNIFDEF_EXECUTABLE}" -t -x 2
${unifdef_defines}
-o "${contentdir}/${filename}"
"${contentdir}/${filename}.in"
)
list(APPEND docdeps "${contentdir}/${filename}")
endforeach ()
set(common_flags)
list(APPEND common_flags
--quiet
--config "${toml_path}"
--add-include-path "${CMAKE_BINARY_DIR}"
)
set(content_dir_flags
--content-dir "${contentdir}"
--content-dir "${toml_dir}"
)
foreach (item IN LISTS opt_CONTENT_PATH)
cmake_path(ABSOLUTE_PATH item OUTPUT_VARIABLE item_path)
if (NOT EXISTS "${item_path}")
message(FATAL_ERROR "Path does not exist: ${item_path}")
endif ()
list(APPEND content_dir_flags --content-dir "${item_path}")
endforeach ()
# Documentation generation.
add_custom_command(
OUTPUT "${outdir}/index.html"
COMMENT "Generating documentation: ${namespace}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
DEPENDS ${docdeps}
DEPFILE ${contentdir}.dep
VERBATIM
COMMAND "${GIDocgen_EXE}" gen-deps
${common_flags}
--config "${toml_path}"
${content_dir_flags}
"${gir_path}"
"${contentdir}.depfiles"
COMMAND "${Python_EXECUTABLE}" -c
"import sys; print(sys.argv[1], ':', ' '.join((l[:-1] for l in sys.stdin.readlines())))"
"${outdir}/index.html" < "${contentdir}.depfiles" > "${contentdir}.dep"
COMMAND "${GIDocgen_EXE}" generate
${common_flags}
--no-namespace-dir
${content_dir_flags}
--output-dir "${outdir}"
--config "${toml_path}"
"${gir_path}"
)
add_custom_target("doc-${namespace}" DEPENDS "${outdir}/index.html")
if (NOT TARGET doc-all)
add_custom_target(doc-all ALL COMMENT "All documentation targets")
endif ()
add_dependencies(doc-all "doc-${namespace}")
install(
DIRECTORY "${outdir}"
DESTINATION "${CMAKE_INSTALL_DATADIR}/doc"
COMPONENT development
)
# Documentation check.
add_custom_target("doc-check-${namespace}"
COMMENT "Checking documentation: ${namespace}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
DEPENDS "${toml_path}" "${gir_path}"
VERBATIM
COMMAND "${GIDocgen_EXE}" check ${common_flags} "${gir_path}"
)
if (NOT TARGET doc-check-all)
add_custom_target(doc-check-all COMMENT "Check all documentation targets")
endif ()
add_dependencies(doc-check-all "doc-check-${namespace}")
endfunction()
|