Skip to content

Commit

Permalink
Attempt to use CMake on ReadTheDocs...
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed Feb 11, 2021
1 parent a6bc087 commit 20f802a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 10 deletions.
20 changes: 20 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: documentation/conf.py

# Optionally build your docs in additional formats such as PDF
formats:
- pdf

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.7
install:
- requirements: documentation/requirements.txt
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ include(GNUInstallDirs)
option(ZTD_TEXT_CI "Whether or not we are in continuous integration mode" OFF)
option(ZTD_TEXT_TESTS "Enable build of tests" OFF)
option(ZTD_TEXT_DOCUMENTATION "Enable build of documentation" OFF)
option(ZTD_TEXT_DOCUMENTATION_NO_SPHINX "Turn off Sphinx usage (useful for ReadTheDocs builds)" OFF)
option(ZTD_TEXT_EXAMPLES "Enable build of examples" OFF)
option(ZTD_TEXT_BENCHMARKS "Enable build of benchmarks" OFF)
option(ZTD_TEXT_GENERATE_SINGLE "Enable generation of a single header and its target" OFF)
Expand Down
27 changes: 17 additions & 10 deletions documentation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@

find_package(Doxygen REQUIRED)
find_package(Python3 REQUIRED)
find_package(Sphinx REQUIRED)
if (NOT ZTD_TEXT_DOCUMENTATION_NO_SPHINX)
find_package(Sphinx REQUIRED)
endif()

# Find all the public headers
file(GLOB_RECURSE ztd_text_public_headers LIST_DIRECTORIES false CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../include/**.*)
Expand Down Expand Up @@ -63,23 +65,28 @@ configure_file(${ZTD_TEXT_DOXYFILE_IN} ${ZTD_TEXT_DOXYFILE_OUT} @ONLY)

# Ensure Doxygen won't crash because it doesn't create directories for us
file(MAKE_DIRECTORY ${ZTD_TEXT_DOXYGEN_OUTPUT_DIR})
file(MAKE_DIRECTORY ${ZTD_TEXT_DOXYGEN_XML_OUTPUT_DIR})
file(MAKE_DIRECTORY ${ZTD_TEXT_DOXYGEN_HTML_OUTPUT_DIR})

add_custom_command(OUTPUT ${ZTD_TEXT_DOXYGEN_INDEX_FILE}
COMMAND ${DOXYGEN_EXECUTABLE} ${ZTD_TEXT_DOXYFILE_OUT}
MAIN_DEPENDENCY ${ZTD_TEXT_DOXYFILE_IN} ${ZTD_TEXT_DOXYFILE_OUT}
DEPENDS ${ztd_text_public_headers}
COMMENT "[ztd.text/documentation] Generating Doxygen XML..."
)
add_custom_target(ztd.text.documentation.doxygen ALL DEPENDS ${DOXYGEN_INDEX_FILE})
add_custom_target(ztd.text.documentation.doxygen ALL DEPENDS ${ZTD_TEXT_DOXYGEN_INDEX_FILE})

add_custom_target(ztd.text.documentation.sphinx ALL
COMMAND ${SPHINX_EXECUTABLE} -b html ${ZTD_TEXT_SPHINX_SOURCE_DIR} ${ZTD_TEXT_SPHINX_BUILD_DIR}
-Dbreathe_projects.ztd.text=${ZTD_TEXT_DOXYGEN_XML_OUTPUT_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${ZTD_TEXT_DOXYGEN_INDEX_FILE} ${ztd_text_sphinx_sources}
COMMENT "[ztd.text/documentation] Generating Sphinx documentation..."
)
add_dependencies(ztd.text.documentation.sphinx ztd.text.documentation.doxygen)
if (NOT ZTD_TEXT_DOCUMENTATION_NO_SPHINX)
add_custom_target(ztd.text.documentation.sphinx ALL
COMMAND ${SPHINX_EXECUTABLE} -b html ${ZTD_TEXT_SPHINX_SOURCE_DIR} ${ZTD_TEXT_SPHINX_BUILD_DIR}
-Dbreathe_projects.ztd.text=${ZTD_TEXT_DOXYGEN_XML_OUTPUT_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${ZTD_TEXT_DOXYGEN_INDEX_FILE} ${ztd_text_sphinx_sources}
COMMENT "[ztd.text/documentation] Generating Sphinx documentation..."
)

add_dependencies(ztd.text.documentation.sphinx ztd.text.documentation.doxygen)
endif()

# For the install target
include(GNUInstallDirs)
Expand Down
2 changes: 2 additions & 0 deletions documentation/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
breathe
cmake
ninja
16 changes: 16 additions & 0 deletions documentation/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,20 @@

# Breathe Configuration
#
breathe_projects = {}
breathe_default_project = "ztd.text"


# ReadTheDocs Build Help
#
def run_cmake_doxygen():
os.mkdir('build')
subprocess.call("cmake -DZTD_TEXT_DOCUMENTATION:BOOL=TRUE -DZTD_TEXT_DOCUMENTATION_NO_SPHINX:BOOL=TRUE ../..", shell=True, cwd='build')
subprocess.call("cmake --build .", shell=True, cwd='build')
breathe_projects["ztd.text"] = 'build/doxygen/xml'


# Are we on the ReadTheDocs server?
read_the_docs_build = os.environ.get('READTHEDOCS', None) == 'True'
if read_the_docs_build:
run_cmake_doxygen()

0 comments on commit 20f802a

Please sign in to comment.