Skip to content

Commit

Permalink
Add the documentation in the OSS repo (pytorch#464)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#464

Example output:
- Doxygen:
https://home.fburl.com/~jianyuhuang/fbgemm_gpu/docs2/doxygen/html/namespacefbgemm.html

- Sphinx:
https://home.fburl.com/~jianyuhuang/fbgemm_gpu/docs2/sphinx/

Reviewed By: jspark1105

Differential Revision: D25711378

fbshipit-source-id: e31df8bcfafbaa8972077c7aeee7a61f3eac9172
  • Loading branch information
jianyuh authored and facebook-github-bot committed Jan 5, 2021
1 parent 7567aca commit 199b498
Show file tree
Hide file tree
Showing 6 changed files with 2,736 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ set(FBGEMM_LIBRARY_TYPE "default" CACHE STRING
set_property(CACHE FBGEMM_LIBRARY_TYPE PROPERTY STRINGS default static shared)
option(FBGEMM_BUILD_TESTS "Build fbgemm unit tests" ON)
option(FBGEMM_BUILD_BENCHMARKS "Build fbgemm benchmarks" ON)
option(FBGEMM_BUILD_DOCS "Build fbgemm documentation" OFF)

if(FBGEMM_BUILD_TESTS)
enable_testing()
Expand Down Expand Up @@ -268,3 +269,7 @@ endif()
if(FBGEMM_BUILD_BENCHMARKS)
add_subdirectory(bench)
endif()

if(FBGEMM_BUILD_DOCS)
add_subdirectory(docs)
endif()
60 changes: 60 additions & 0 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
find_package(Doxygen REQUIRED)
find_package(Sphinx REQUIRED)

# Find all the public headers
get_target_property(FBGEMM_PUBLIC_HEADER_DIR
fbgemm INTERFACE_INCLUDE_DIRECTORIES)
file(GLOB_RECURSE FBGEMM_PUBLIC_HEADERS
${FBGEMM_PUBLIC_HEADER_DIR}/fbgemm/*.h)

set(DOXYGEN_INPUT_DIR ${FBGEMM_SOURCE_DIR}/include/fbgemm)
set(DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/doxygen)
set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/xml/index.xml)
set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set(DOXYFILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

# Set the Doxygen input and output directories in the Doxyfile
configure_file(${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY)

# Doxygen won't create this for us
file(MAKE_DIRECTORY ${DOXYGEN_OUTPUT_DIR})

# Only regenerate Doxygen when the Doxyfile or public headers change
add_custom_command(OUTPUT ${DOXYGEN_INDEX_FILE}
DEPENDS ${FBGEMM_PUBLIC_HEADERS}
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
MAIN_DEPENDENCY ${DOXYFILE_OUT} ${DOXYFILE_IN}
COMMENT "Generating docs"
VERBATIM)

# Nice named target so we can run the job easily
add_custom_target(Doxygen ALL DEPENDS ${DOXYGEN_INDEX_FILE})

set(SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR})
set(SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR}/sphinx)
set(SPHINX_INDEX_FILE ${SPHINX_BUILD}/index.html)

# Only regenerate Sphinx when:
# - Doxygen has rerun
# - Our doc files have been updated
# - The Sphinx config has been updated
add_custom_command(OUTPUT ${SPHINX_INDEX_FILE}
COMMAND
${SPHINX_EXECUTABLE} -b html
# Tell Breathe where to find the Doxygen output
-Dbreathe_projects.FBGEMM=${DOXYGEN_OUTPUT_DIR}/xml
${SPHINX_SOURCE} ${SPHINX_BUILD}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS
# Other docs files you want to track should go here (or in some variable)
${CMAKE_CURRENT_SOURCE_DIR}/index.rst
${DOXYGEN_INDEX_FILE}
MAIN_DEPENDENCY ${SPHINX_SOURCE}/conf.py
COMMENT "Generating documentation with Sphinx")

# Nice named target so we can run the job easily
add_custom_target(Sphinx ALL DEPENDS ${SPHINX_INDEX_FILE})

include(GNUInstallDirs)
install(DIRECTORY ${SPHINX_BUILD}
DESTINATION ${CMAKE_INSTALL_DOCDIR})
Loading

0 comments on commit 199b498

Please sign in to comment.