|
| 1 | +cmake_minimum_required(VERSION 3.18 FATAL_ERROR) |
| 2 | +project("Data-parallel Control (dpCtl)") |
| 3 | +# Add the cmake folder so the FindSphinx module is found |
| 4 | +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) |
| 5 | + |
| 6 | +find_package(Sphinx REQUIRED) |
| 7 | +find_package(Doxygen REQUIRED) |
| 8 | +find_package (Git) |
| 9 | + |
| 10 | +set(DOC_OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/generated_docs) |
| 11 | +if( DPCTL_DOCGEN_PREFIX ) |
| 12 | + message(STATUS "Generating dpCtl documents in " ${DPCTL_DOCGEN_PREFIX}) |
| 13 | + set(DOC_OUTPUT_DIR ${DPCTL_DOCGEN_PREFIX}) |
| 14 | +endif() |
| 15 | + |
| 16 | +set(CURRENT_RELEASE "") |
| 17 | + |
| 18 | +# Use git describe to get latest tag name |
| 19 | +if (GIT_FOUND) |
| 20 | + execute_process( |
| 21 | + COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 |
| 22 | + RESULT_VARIABLE result |
| 23 | + OUTPUT_VARIABLE CURRENT_RELEASE |
| 24 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 25 | + ) |
| 26 | +endif (GIT_FOUND) |
| 27 | + |
| 28 | +set(DOXYGEN_INPUT_DIR ../backends) |
| 29 | +set(DOXYGEN_OUTPUT_DIR ${DOC_OUTPUT_DIR}/doxygen) |
| 30 | +set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/html/index.html) |
| 31 | +set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) |
| 32 | +set(DOXYFILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) |
| 33 | + |
| 34 | +# Replace variables inside @@ with the current values |
| 35 | +configure_file(${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY) |
| 36 | + |
| 37 | +file(MAKE_DIRECTORY ${DOXYGEN_OUTPUT_DIR}) |
| 38 | + |
| 39 | +add_custom_command( |
| 40 | + OUTPUT ${DOXYGEN_INDEX_FILE} |
| 41 | + DEPENDS ${DPCTL_PUBLIC_HEADERS} |
| 42 | + COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT} |
| 43 | + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 44 | + MAIN_DEPENDENCY ${DOXYFILE_OUT} ${DOXYFILE_IN} |
| 45 | + COMMENT "Generating Doxygen documentation" |
| 46 | + VERBATIM |
| 47 | +) |
| 48 | + |
| 49 | +set(SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}) |
| 50 | +set(SPHINX_OUTPUT_DIR ${DOC_OUTPUT_DIR}/docs) |
| 51 | +set(SPHINX_INDEX_FILE ${SPHINX_OUTPUT_DIR}/index.html) |
| 52 | +set(SPHINX_CONF_IN ${SPHINX_SOURCE}/conf.in) |
| 53 | +set(SPHINX_CONF_OUT ${SPHINX_SOURCE}/conf.py) |
| 54 | + |
| 55 | +# Create a conf.py by replacing variables inside @@ with the current values |
| 56 | +configure_file(${SPHINX_CONF_IN} ${SPHINX_CONF_OUT} @ONLY) |
| 57 | + |
| 58 | +# Only regenerate Sphinx when: |
| 59 | +# - Doxygen has rerun |
| 60 | +# - Our doc files have been updated |
| 61 | +# - The Sphinx config has been updated |
| 62 | +add_custom_command( |
| 63 | + OUTPUT ${SPHINX_INDEX_FILE} |
| 64 | + COMMAND |
| 65 | + ${SPHINX_EXECUTABLE} -b html |
| 66 | + # Tell Breathe where to find the Doxygen output |
| 67 | + -Dbreathe_projects.dpCtl-CAPI=${DOXYGEN_OUTPUT_DIR}/xml |
| 68 | + ${SPHINX_SOURCE} ${SPHINX_OUTPUT_DIR} |
| 69 | + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 70 | + DEPENDS |
| 71 | + # Other docs files that can be edited manually |
| 72 | + ${CMAKE_CURRENT_SOURCE_DIR}/index.rst |
| 73 | + ${DOXYGEN_INDEX_FILE} |
| 74 | + MAIN_DEPENDENCY ${SPHINX_CONF_OUT} ${SPHINX_CONF_IN} |
| 75 | + COMMENT "Generating Sphinx documentation" |
| 76 | +) |
| 77 | + |
| 78 | +# Target to generate only Doxygen documentation |
| 79 | +add_custom_target( |
| 80 | + Doxygen |
| 81 | + ALL |
| 82 | + DEPENDS ${DOXYGEN_INDEX_FILE} |
| 83 | +) |
| 84 | + |
| 85 | +# Target to generate all documentation Sphinx and Doxygen |
| 86 | +add_custom_target( |
| 87 | + Sphinx |
| 88 | + ALL |
| 89 | + DEPENDS Doxygen ${SPHINX_INDEX_FILE} |
| 90 | +) |
0 commit comments