|
1 | | -# @author Barthélémy von Haller |
2 | | - |
3 | 1 | include(FindDoxygen) |
4 | 2 |
|
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) |
| 3 | +# put doc in a subdirectory with project name, if not already set so |
| 4 | +if (NOT CMAKE_INSTALL_DOCDIR) |
| 5 | + set(CMAKE_INSTALL_DOCDIR "doc") |
| 6 | +endif() |
| 7 | +if (NOT "${CMAKE_INSTALL_DOCDIR}" MATCHES "${PROJECT_NAME}$") |
| 8 | + set(CMAKE_INSTALL_DOCDIR "${CMAKE_INSTALL_DOCDIR}/${PROJECT_NAME}") |
| 9 | +endif() |
| 10 | +set(DOC_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_DOCDIR}") |
| 11 | + |
| 12 | +# log doc build(install paths) |
| 13 | +message(STATUS "Documentation will be generated in ${DOC_OUTPUT_DIR}") |
| 14 | +message(STATUS "Documentation will be installed in ${CMAKE_INSTALL_DOCDIR}") |
8 | 15 |
|
| 16 | +# general files directly from source |
| 17 | +install( |
| 18 | + DIRECTORY . |
| 19 | + TYPE DOC |
| 20 | + FILES_MATCHING PATTERN "*.md" PATTERN "*.png" |
| 21 | +) |
| 22 | + |
| 23 | +# doxygen-generated files |
9 | 24 | if (DOXYGEN_FOUND) |
10 | | - # Configure the doxygen config file with current settings |
11 | | - set("DOC_OUTPUT_DIR" "${CMAKE_CURRENT_BINARY_DIR}") |
| 25 | + if(NOT DOXYGEN_DOT_FOUND) |
| 26 | + message(WARNING "dot not found. Please install Graphviz.") |
| 27 | + endif(NOT DOXYGEN_DOT_FOUND) |
| 28 | + |
| 29 | + # configure the doxygen config file with current cmake settings |
12 | 30 | configure_file(doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/documentation-config.doxygen @ONLY) |
13 | 31 |
|
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) |
| 32 | + # build documentation with target "doc" |
| 33 | + add_custom_target( |
| 34 | + doc |
| 35 | + ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/documentation-config.doxygen |
| 36 | + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 37 | + COMMENT "Generating API documentation using doxygen for ${PROJECT_NAME}" |
| 38 | + VERBATIM |
| 39 | + DEPENDS doc-dir |
| 40 | + ) |
| 41 | + |
| 42 | + # doxygen fails creating multi-level output directory, make sure it exists |
| 43 | + add_custom_target( |
| 44 | + doc-dir |
| 45 | + COMMAND ${CMAKE_COMMAND} -E make_directory "${DOC_OUTPUT_DIR}" |
| 46 | + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
| 47 | + COMMENT "Create the doxygen output directory" |
| 48 | + VERBATIM |
| 49 | + ) |
| 50 | + |
| 51 | + # install generated files |
| 52 | + install( |
| 53 | + DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_DOCDIR}/html |
| 54 | + TYPE DOC |
| 55 | + OPTIONAL # because available only after "make doc" |
| 56 | + ) |
| 57 | +else (DO) |
| 58 | + message(WARNING "Doxygen not found") |
27 | 59 | endif (DOXYGEN_FOUND) |
| 60 | + |
0 commit comments