|
1 | | -# @author Barthélémy von Haller |
| 1 | +# Generate documentation |
2 | 2 |
|
3 | | -include(FindDoxygen) |
| 3 | +# define doc build path |
| 4 | +set(DOC_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/doc-build") |
| 5 | + |
| 6 | +# define doc installation path |
| 7 | +# ensures it ends with project name |
| 8 | +if (NOT CMAKE_INSTALL_DOCDIR) |
| 9 | + set(CMAKE_INSTALL_DOCDIR "doc") |
| 10 | +endif() |
| 11 | +if (NOT "${CMAKE_INSTALL_DOCDIR}" MATCHES "${PROJECT_NAME}$") |
| 12 | + set(CMAKE_INSTALL_DOCDIR "${CMAKE_INSTALL_DOCDIR}/${PROJECT_NAME}") |
| 13 | +endif() |
4 | 14 |
|
5 | | -if(NOT DOXYGEN_DOT_FOUND) |
6 | | - message(WARNING "Graphviz doesn't seem to be installed. Doxygen will not be able to generate graphs. Consider installing this package.") |
7 | | -endif(NOT DOXYGEN_DOT_FOUND) |
| 15 | +# log doc build(install paths) |
| 16 | +message(STATUS "Documentation will be built in ${DOC_BUILD_DIR}") |
| 17 | +message(STATUS "Documentation will be installed in ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DOCDIR}") |
8 | 18 |
|
| 19 | +# general files directly from source |
| 20 | +install( |
| 21 | + DIRECTORY . |
| 22 | + TYPE DOC |
| 23 | + FILES_MATCHING PATTERN "*.md" PATTERN "*.png" |
| 24 | +) |
| 25 | + |
| 26 | +# doxygen-generated files |
| 27 | +include(FindDoxygen) |
9 | 28 | if (DOXYGEN_FOUND) |
10 | | - # Configure the doxygen config file with current settings |
11 | | - set("DOC_OUTPUT_DIR" "${CMAKE_CURRENT_BINARY_DIR}") |
| 29 | + if(NOT DOXYGEN_DOT_FOUND) |
| 30 | + message(WARNING "dot not found. Please install Graphviz.") |
| 31 | + endif(NOT DOXYGEN_DOT_FOUND) |
| 32 | + |
| 33 | + # configure the doxygen config file with current cmake settings |
12 | 34 | configure_file(doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/documentation-config.doxygen @ONLY) |
13 | 35 |
|
14 | | - # target doc |
15 | | - add_custom_target(doc |
16 | | - ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/documentation-config.doxygen |
17 | | - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
18 | | - COMMENT "Generating API documentation using doxygen for ${PROJECT_NAME} |
19 | | - \n Output will be available in ${DOC_OUTPUT_DIR}/html" VERBATIM) |
20 | | - |
21 | | - # installation |
22 | | - option(DOC_INSTALL "Install the documentation when calling \"make install\"" OFF) |
23 | | - if(DOC_INSTALL) |
24 | | - message(STATUS "Documentation will be installed but you *must* run `make doc`") |
25 | | - install(DIRECTORY ${DOC_OUTPUT_DIR}/html DESTINATION share/doc/${PROJECT_NAME} COMPONENT doc) |
26 | | - endif(DOC_INSTALL) |
| 36 | + # build documentation with target "doc" |
| 37 | + add_custom_target( |
| 38 | + doc |
| 39 | + ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/documentation-config.doxygen |
| 40 | + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 41 | + COMMENT "Generating API documentation using doxygen for ${PROJECT_NAME}" |
| 42 | + VERBATIM |
| 43 | + DEPENDS doc-dir |
| 44 | + ) |
| 45 | + |
| 46 | + # doxygen fails creating multi-level output directory, make sure it exists |
| 47 | + add_custom_target( |
| 48 | + doc-dir |
| 49 | + COMMAND ${CMAKE_COMMAND} -E make_directory "${DOC_BUILD_DIR}" |
| 50 | + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
| 51 | + COMMENT "Create the doxygen output directory" |
| 52 | + VERBATIM |
| 53 | + ) |
| 54 | + |
| 55 | + # install generated files |
| 56 | + install( |
| 57 | + DIRECTORY ${DOC_BUILD_DIR}/html |
| 58 | + TYPE DOC |
| 59 | + OPTIONAL # because available only after "make doc" |
| 60 | + ) |
| 61 | +else () |
| 62 | + message(WARNING "Doxygen not found") |
27 | 63 | endif (DOXYGEN_FOUND) |
| 64 | + |
0 commit comments