From 9f906fd88181bcb75132fc4a6f8127538a58f22a Mon Sep 17 00:00:00 2001 From: Abdessattar Sassi <457645+abdes@users.noreply.github.com> Date: Mon, 17 Apr 2023 14:20:15 +0400 Subject: [PATCH] feat: custom index.html should be optional in project doc root There are two possible documentation structure design: - submodules included inside the root doc folder (preferred) - submodules in their own doc folder and a separate sphinx target The custom index.html is really useful only in the second situation. Therefore it is now copied to the output dir only if it is present in the source dir. --- cmake/SphinxGeneration.cmake | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/cmake/SphinxGeneration.cmake b/cmake/SphinxGeneration.cmake index b0388c4..41fb2a4 100644 --- a/cmake/SphinxGeneration.cmake +++ b/cmake/SphinxGeneration.cmake @@ -90,27 +90,26 @@ if(SPHINX_FOUND) # invoked. set_target_properties(sphinx PROPERTIES EXCLUDE_FROM_ALL TRUE) - # Add a target for copying the index.html from the doc dir to the sphinx - # build dir. A dependency on this target will be added to the master sphinx - # target. - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sphinx/index.html - COMMAND - ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/doc/index.html - ${CMAKE_CURRENT_BINARY_DIR}/sphinx/index.html - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/doc/index.html) - add_custom_target(copy_doc_index ALL - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/sphinx/index.html) - # Setup sphinx doc master target and add other submodules as dependencies function(_add_master_sphinx_target) _master_sphinx_target() asap_with_sphinx(${master_sphinx_target}) - add_dependencies( - ${master_sphinx_target}_sphinx copy_doc_index - # Add more submodule documentation targets after this, using variables - # in the target names consistently with the module's CMakeLists.txt. - ) + + set(index_file_src "${CMAKE_CURRENT_SOURCE_DIR}/doc/index.html") + set(index_file_out "${CMAKE_CURRENT_BINARY_DIR}/sphinx/index.html") + if(EXISTS ${index_file_src}) + message( + STATUS "Will use project custom doc index file: ${index_file_src}") + # Add a target for copying the index.html from the doc dir to the sphinx + # build dir. A dependency on this target will be added to the master + # sphinx target. + add_custom_command( + OUTPUT ${index_file_out} + COMMAND ${CMAKE_COMMAND} -E copy ${index_file_src} ${index_file_out} + DEPENDS ${index_file_src}) + add_custom_target(copy_doc_index ALL DEPENDS ${index_file_out}) + add_dependencies(${master_sphinx_target}_sphinx copy_doc_index) + endif() add_dependencies(sphinx ${master_sphinx_target}_sphinx) endfunction() _add_master_sphinx_target()