2018-03-25 19:00:54 +02:00
|
|
|
# Generate the sphinx config file
|
2018-03-22 18:11:39 +01:00
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/conf.py @ONLY)
|
|
|
|
|
2019-04-02 17:13:11 +02:00
|
|
|
# -----------------------------------------------------------------------------
|
2019-04-26 18:40:44 +02:00
|
|
|
# Create an optional target that allows us to regenerate the C++ doc with c++2rst
|
2019-04-02 17:13:11 +02:00
|
|
|
# -----------------------------------------------------------------------------
|
2020-05-13 21:54:51 +02:00
|
|
|
add_custom_target(${PROJECT_NAME}_docs_cpp2rst)
|
2019-09-24 21:17:47 +02:00
|
|
|
include(${PROJECT_SOURCE_DIR}/share/cmake/extract_flags.cmake)
|
2020-05-28 17:09:35 +02:00
|
|
|
extract_flags(${PROJECT_NAME}_c BUILD_INTERFACE)
|
|
|
|
separate_arguments(${PROJECT_NAME}_c_CXXFLAGS)
|
2018-03-22 18:11:39 +01:00
|
|
|
macro(generate_docs header_file)
|
2018-03-25 19:00:54 +02:00
|
|
|
add_custom_command(
|
2020-05-13 21:54:51 +02:00
|
|
|
TARGET ${PROJECT_NAME}_docs_cpp2rst
|
2019-04-26 18:40:44 +02:00
|
|
|
COMMAND rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/cpp2rst_generated
|
|
|
|
COMMAND
|
2020-05-15 18:09:22 +02:00
|
|
|
PYTHONPATH=${CPP2PY_BINARY_DIR}:$ENV{PYTHONPATH}
|
2020-06-18 23:10:15 +02:00
|
|
|
PATH=${CPP2PY_BINARY_DIR}/bin:${CPP2PY_ROOT}/bin:$ENV{PATH}
|
|
|
|
c++2rst
|
2019-04-26 18:40:44 +02:00
|
|
|
${header_file}
|
2020-05-28 17:09:35 +02:00
|
|
|
-N ${PROJECT_NAME}
|
2019-04-26 18:40:44 +02:00
|
|
|
--output_directory ${CMAKE_CURRENT_SOURCE_DIR}/cpp2rst_generated
|
2019-09-24 21:17:47 +02:00
|
|
|
-I${PROJECT_SOURCE_DIR}/c++
|
2020-05-28 17:09:35 +02:00
|
|
|
--cxxflags="${${PROJECT_NAME}_c_CXXFLAGS}"
|
2018-03-25 19:00:54 +02:00
|
|
|
)
|
2018-03-22 18:11:39 +01:00
|
|
|
endmacro(generate_docs)
|
|
|
|
|
2020-05-28 17:09:35 +02:00
|
|
|
generate_docs(${PROJECT_SOURCE_DIR}/c++/${PROJECT_NAME}/${PROJECT_NAME}.hpp)
|
2018-03-22 18:11:39 +01:00
|
|
|
|
2019-08-14 16:12:03 +02:00
|
|
|
# --------------------------------------------------------
|
|
|
|
# Build & Run the C++ doc examples and capture the output
|
|
|
|
# --------------------------------------------------------
|
|
|
|
|
2020-05-13 21:54:51 +02:00
|
|
|
add_custom_target(${PROJECT_NAME}_docs_example_output)
|
2019-08-14 16:12:03 +02:00
|
|
|
file(GLOB_RECURSE ExampleList RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
|
|
|
|
foreach(example ${ExampleList})
|
|
|
|
get_filename_component(f ${example} NAME_WE)
|
|
|
|
get_filename_component(d ${example} DIRECTORY)
|
2020-05-13 21:54:51 +02:00
|
|
|
add_executable(${PROJECT_NAME}_doc_${f} EXCLUDE_FROM_ALL ${example})
|
|
|
|
set_property(TARGET ${PROJECT_NAME}_doc_${f} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${d})
|
|
|
|
target_link_libraries(${PROJECT_NAME}_doc_${f} triqs)
|
|
|
|
add_custom_command(TARGET ${PROJECT_NAME}_doc_${f}
|
|
|
|
COMMAND ${PROJECT_NAME}_doc_${f} > ${CMAKE_CURRENT_SOURCE_DIR}/${d}/${f}.output 2>/dev/null
|
2019-08-14 16:12:03 +02:00
|
|
|
WORKING_DIRECTORY ${d}
|
|
|
|
)
|
2020-05-13 21:54:51 +02:00
|
|
|
add_dependencies(${PROJECT_NAME}_docs_example_output ${PROJECT_NAME}_doc_${f})
|
2019-08-14 16:12:03 +02:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# ---------------------------------
|
|
|
|
# Top Sphinx target
|
|
|
|
# ---------------------------------
|
2020-05-13 21:54:51 +02:00
|
|
|
if(NOT DEFINED SPHINXBUILD_EXECUTABLE)
|
|
|
|
find_package(Sphinx)
|
|
|
|
endif()
|
2020-05-07 23:40:39 +02:00
|
|
|
|
2019-08-14 16:12:03 +02:00
|
|
|
# Sphinx has internal caching, always run it
|
2020-05-13 21:54:51 +02:00
|
|
|
add_custom_target(${PROJECT_NAME}_docs_sphinx ALL)
|
2019-08-14 16:12:03 +02:00
|
|
|
add_custom_command(
|
2020-05-13 21:54:51 +02:00
|
|
|
TARGET ${PROJECT_NAME}_docs_sphinx
|
2022-02-16 20:49:35 +01:00
|
|
|
COMMAND PYTHONPATH=${PROJECT_BINARY_DIR}/python:$ENV{PYTHONPATH} ${SPHINXBUILD_EXECUTABLE} -j auto -c . -b html ${CMAKE_CURRENT_SOURCE_DIR} html
|
2019-08-14 16:12:03 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
option(Sphinx_Only "When building the documentation, skip the Python Modules and the generation of C++ Api and example outputs" OFF)
|
|
|
|
if(NOT Sphinx_Only)
|
|
|
|
# Autodoc usage requires the python modules to be built first
|
|
|
|
get_property(CPP2PY_MODULES_LIST GLOBAL PROPERTY CPP2PY_MODULES_LIST)
|
2019-12-02 21:16:13 +01:00
|
|
|
if(CPP2PY_MODULES_LIST)
|
2020-05-13 21:54:51 +02:00
|
|
|
add_dependencies(${PROJECT_NAME}_docs_sphinx ${CPP2PY_MODULES_LIST})
|
2019-12-02 21:16:13 +01:00
|
|
|
endif()
|
2019-08-14 16:12:03 +02:00
|
|
|
|
|
|
|
# Generation of C++ Api and Example Outputs
|
2020-05-13 21:54:51 +02:00
|
|
|
add_dependencies(${PROJECT_NAME}_docs_sphinx ${PROJECT_NAME}_docs_cpp2rst ${PROJECT_NAME}_docs_example_output)
|
2019-08-14 16:12:03 +02:00
|
|
|
endif()
|
|
|
|
|
2018-03-22 18:11:39 +01:00
|
|
|
# ---------------------------------
|
|
|
|
# Install
|
|
|
|
# ---------------------------------
|
2020-05-28 17:09:35 +02:00
|
|
|
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/ COMPONENT documentation DESTINATION share/doc/${PROJECT_NAME}
|
2018-03-25 19:00:54 +02:00
|
|
|
FILES_MATCHING
|
2021-08-18 22:45:33 +02:00
|
|
|
REGEX "\\.(html|pdf|png|gif|jpg|svg|js|xsl|css|py|txt|inv|bib|ttf|woff2|eot)$"
|
2018-03-25 19:00:54 +02:00
|
|
|
PATTERN "_*"
|
|
|
|
)
|