在cmake中使用doxygen生成document

1. 首先在CMakeLists.txt中添加如下的代码:

代码取自:http://www.tty1.net/blog/2014/cmake-doxygen_en.html

cmake相关document见:http://www.cmake.org/cmake/help/v3.0/

# add a target to generate API documentation with Doxygen

FIND_PACKAGE(Doxygen)
OPTION(BUILD_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND})

IF(BUILD_DOCUMENTATION)
    IF(NOT DOXYGEN_FOUND)
        MESSAGE(FATAL_ERROR "Doxygen is needed to build the documentation.")
    ENDIF()

    SET(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
    SET(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

    CONFIGURE_FILE(${doxyfile_in} ${doxyfile} @ONLY)

    ADD_CUSTOM_TARGET(doc
        COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        COMMENT "Generating API documentation with Doxygen"
        VERBATIM)

    INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc)
ENDIF()


 
  

2. 在Project的目录下创建Doxyfile.in文件,其内容如下,可跟据需要自行添加参数设定。

document见:http://www.stack.nl/~dimitri/doxygen/manual/config.html

PROJECT_NAME           = "@CMAKE_PROJECT_NAME@"
PROJECT_NUMBER         = @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@
STRIP_FROM_PATH        = @PROJECT_SOURCE_DIR@ \
                         @PROJECT_BINARY_DIR@
INPUT                  = @doxy_main_page@ \
                         @PROJECT_SOURCE_DIR@ \
                         @PROJECT_BINARY_DIR@
FILE_PATTERNS          = *.h \
                         *.cpp
RECURSIVE              = YES
EXTRACT_ALL            = YES
EXTRACT_PRIVATE        = YES
EXTRACT_STATIC         = YES
EXCLUDE_PATTERNS       = */thirdparty/*
USE_MDFILE_AS_MAINPAGE = @doxy_main_page@

3. 使用cmake生成makefile后,即可使用make doc来生成document。

你可能感兴趣的:(doxygen,cmake)