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