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