• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13# Convenience functions for autogenerate documentation.
14option(ENABLE_DOXYGEN "Enable documentation generation" false)
15
16add_custom_target(doc_build COMMENT "Building doxygen documentation")
17
18# Example usage:
19#
20#   add_doxygen(
21#     NAME      "project_name"
22#     PATH      "${ROOT_PROJECT_PATH}"
23#   )
24#
25# Notes:
26#    * This function is a no-op if Doxygen is not found.
27#
28
29function(add_doxygen)
30    set(prefix ARG)
31    set(noValues)
32    set(singleValues NAME)
33
34    find_package(Doxygen)
35
36    if ((NOT ENABLE_DOXYGEN) OR (NOT DOXYGEN_FOUND))
37        return()
38    endif()
39
40    set(DOXYGEN_CONFIG_TEMPLATE "${PANDA_ROOT}/docs/doxygen.config")
41
42    cmake_parse_arguments(${prefix}
43                          "${noValues}"
44                          "${singleValues}"
45                          "${multiValues}"
46                          ${ARGN})
47
48    set(DOXYGEN_CONF_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
49
50    # Configuration - replace @CMAKE_MACRO@ definition in config template
51    CONFIGURE_FILE(${DOXYGEN_CONFIG_TEMPLATE} ${DOXYGEN_CONF_OUT})
52
53    add_custom_target( doc_${ARG_NAME}
54        COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_CONF_OUT}
55        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
56        COMMENT "Generating API documentation with Doxygen"
57        VERBATIM )
58
59    add_dependencies(doc_build doc_${ARG_NAME})
60endfunction()
61