Skip to content

Commit

Permalink
docs: simplify docs build (#64)
Browse files Browse the repository at this point in the history
Signed-off-by: msclock <msclock@qq.com>
  • Loading branch information
msclock authored Mar 5, 2024
1 parent 2adb394 commit c598866
Show file tree
Hide file tree
Showing 22 changed files with 130 additions and 96 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,6 @@ ASALocalRun/

# Ignore things from copier
.copier-answers.yml

# Documenation files
docs/_build
7 changes: 0 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ find_package(cmake-modules REQUIRED)
include(cmake-modules/configure/Default)
include(cmake-modules/configure/Common)
include(cmake-modules/configure/CheckBuildDir)
include(cmake-modules/configure/ConfigDoxygen)
include(cmake-modules/configure/FindSphinx)
include(cmake-modules/configure/UniqueOutputBinaryDir)
include(cmake-modules/build/Default)
include(cmake-modules/build/Ccache)
Expand All @@ -58,11 +56,6 @@ include(cmake-modules/install/Runpath)
# Add _DEBUG macro
add_debug_macro()

# LTO for release
if(${CMAKE_BUILD_TYPE} MATCHES [[Release]])
link_time_optimization()
endif()

create_uninstall_target()

# Project custom modules
Expand Down
6 changes: 1 addition & 5 deletions cmake/ConfigureCoverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,5 @@ add_code_coverage_all_targets(
${VCPKG_INSTALLED_DIR}/*
${CMAKE_BINARY_DIR}/*
/usr/*
HTML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}_docs/coverage)
HTML_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/docs/_build/coverage)
# cmake-format: on

if(TARGET ${CMAKE_PROJECT_NAME}_docs)
add_dependencies(ccov-all ${CMAKE_PROJECT_NAME}_docs)
endif()
25 changes: 15 additions & 10 deletions cmake/ConfigureDocs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,34 @@ configdoxygen()

if(DOXYGEN_FOUND)

# Generate docs needs XML OUTPUT with sphinx
# Generate XML OUTPUT for breathe
set(DOXYGEN_GENERATE_HTML NO)
set(DOXYGEN_GENERATE_XML YES)
set(DOXYGEN_QUIET NO)
set(DOXYGEN_REFERENCED_BY_RELATION YES)
set(DOXYGEN_REFERENCES_LINK_SOURCE YES)
set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

set(doxygen_docs ${CMAKE_PROJECT_NAME}_doxygen)
# cmake-format: off
doxygen_add_docs(
${CMAKE_PROJECT_NAME}_doxygen
${doxygen_docs}
"${CMAKE_BINARY_DIR}/git/include"
"${CMAKE_BINARY_DIR}/compile/include"
"${CMAKE_BINARY_DIR}/src/compile/include"
"${PROJECT_SOURCE_DIR}/src/compile/include"
"${PROJECT_SOURCE_DIR}/src/executable/include"
"${PROJECT_SOURCE_DIR}/src/header_only/include"
COMMENT "gen doxygen style docs automatically")
"${PROJECT_SOURCE_DIR}/src/header_only/include")
# cmake-format: on

if(TARGET ${CMAKE_PROJECT_NAME}_doxygen)
list(APPEND CMAKE_MODULE_PATH "${cmake-modules_MODULE_PATH}/configure")
find_package(Sphinx REQUIRED breathe)
if(TARGET ${doxygen_docs})
set(Sphinx_FIND_COMPONENTS breathe)
include(cmake-modules/configure/FindSphinx)
unset(Sphinx_FIND_COMPONENTS)

sphinx_add_docs(
${CMAKE_PROJECT_NAME}_docs
BREATHE_PROJECTS
${CMAKE_PROJECT_NAME}_doxygen
${doxygen_docs}
BUILDER
html
BREATH_DEBUG
Expand All @@ -38,6 +43,6 @@ if(DOXYGEN_FOUND)
SOURCE_DIRECTORY
docs
OUTPUT_DIRECTORY
${CMAKE_PROJECT_NAME}_docs)
${CMAKE_SOURCE_DIR}/docs/_build/html)
endif()
endif()
4 changes: 2 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# API Documentation
# ss-cpp API

This documentation was generated by Doxygen + Breathe
This API was generated by Doxygen + Breathe

```{doxygenindex}
:project: ss-cpp_doxygen
Expand Down
8 changes: 6 additions & 2 deletions docs/cmake_workflow.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CMake workflow
# CMake Workflow

CMake common workflow command.
## Without Presets

```bash
# Configure
Expand All @@ -13,7 +13,11 @@ cd build && ctest -C Debug -T test --output-on-failure
cd build && ctest -C Debug -T memcheck
# Install
cmake --build build --config Debug --target install
```

## With Presets

```bash
# with presets https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html
cmake -S . --list-presets # list all configure presets
cmake -S . --preset=<preset> # configure using desired configure preset
Expand Down
9 changes: 6 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
# there may be others here already, e.g. 'sphinx.ext.mathjax'
"myst_parser",
"breathe",
"myst_parser",
"sphinx_copybutton",
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.viewcode",
"sphinxcontrib.moderncmakedomain",
]
source_suffix = {
".rst": "restructuredtext",
Expand All @@ -51,7 +54,7 @@
highlight_language = "cpp"

cpp_id_attributes = [
"compile_EXPORT",
"COMPILE_EXPORT",
"GIT_EXTERN_C_BEGIN",
]

Expand Down
5 changes: 0 additions & 5 deletions docs/coverage.md

This file was deleted.

28 changes: 23 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,35 @@

```{toctree}
:hidden:
Overview <self>
cmake_workflow
changelog
api
coverage
```

<!-- Extract content from start line 1 of README.md -->

```{include} ../README.md
:start-line: 1
```

## Content

```{toctree}
:maxdepth: 2
:titlesonly:
:caption: Guide
:glob:
Overview <self>
cmake_workflow
```

```{toctree}
:maxdepth: 1
:titlesonly:
:caption: References
api
changelog
```

## 🔖 Indices and tables

* {ref}`genindex`
Expand Down
9 changes: 5 additions & 4 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
breathe
furo
breathe==4.35.0
furo==2024.1.29
sphinx==7.1.2
sphinx-copybutton
myst_parser
sphinx-copybutton==0.5.2
myst-parser==2.0.0
sphinxcontrib-moderncmakedomain==3.27.0
9 changes: 4 additions & 5 deletions src/compile/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ target_code_coverage(${target_name}-shared ALL)
include(GenerateExportHeader)
generate_export_header(
${target_name}-shared BASE_NAME "${target_name}" EXPORT_FILE_NAME
"${CMAKE_CURRENT_BINARY_DIR}/include/${target_name}/${target_name}_export.hpp"
)
"${CMAKE_CURRENT_BINARY_DIR}/include/${target_name}_export.hpp")

target_sources(${target_name}-shared PRIVATE ${_srcs} ${_hdrs})

target_include_interface_directories(
${target_name}-shared ${CMAKE_CURRENT_BINARY_DIR}/include/${target_name}
${target_name}-shared ${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/git/include)

target_compile_options(
Expand Down Expand Up @@ -50,7 +49,7 @@ target_compile_definitions(${target_name}-static
INTERFACE ${target_name}_STATIC_DEFINE)

target_include_interface_directories(
${target_name}-static ${CMAKE_CURRENT_BINARY_DIR}/include/${target_name}
${target_name}-static ${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/git/include)

target_compile_options(
Expand Down Expand Up @@ -87,7 +86,7 @@ install_target(
${CMAKE_PROJECT_VERSION}
INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/include/
${CMAKE_CURRENT_BINARY_DIR}/include/${target_name}/
${CMAKE_CURRENT_BINARY_DIR}/include/
${CMAKE_BINARY_DIR}/git/include/
LICENSE_FILE_LIST
${CMAKE_SOURCE_DIR}/LICENSE
Expand Down
3 changes: 3 additions & 0 deletions template/.gitignore.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,6 @@ ASALocalRun/
# Ignore things from copier
.copier-answers.yml
[%- endif %]

# Documenation files
docs/_build
7 changes: 0 additions & 7 deletions template/CMakeLists.txt.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ find_package(cmake-modules REQUIRED)
include(cmake-modules/configure/Default)
include(cmake-modules/configure/Common)
include(cmake-modules/configure/CheckBuildDir)
include(cmake-modules/configure/ConfigDoxygen)
include(cmake-modules/configure/FindSphinx)
include(cmake-modules/configure/UniqueOutputBinaryDir)
include(cmake-modules/build/Default)
include(cmake-modules/build/Ccache)
Expand All @@ -60,11 +58,6 @@ include(cmake-modules/install/Runpath)
# Add _DEBUG macro
add_debug_macro()

# LTO for release
if(${CMAKE_BUILD_TYPE} MATCHES [[Release]])
link_time_optimization()
endif()

create_uninstall_target()

# Project custom modules
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# API Documentation
# {{ repo_name }} API

This documentation was generated by Doxygen + Breathe
This API was generated by Doxygen + Breathe

```{doxygenindex}
:project: {{ repo_name }}_doxygen
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CMake workflow
# CMake Workflow

CMake common workflow command.
## Without Presets

```bash
# Configure
Expand All @@ -13,7 +13,11 @@ cd build && ctest -C Debug -T test --output-on-failure
cd build && ctest -C Debug -T memcheck
# Install
cmake --build build --config Debug --target install
```

## With Presets

```bash
# with presets https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html
cmake -S . --list-presets # list all configure presets
cmake -S . --preset=<preset> # configure using desired configure preset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ author = "{{ author_name }}"
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
# there may be others here already, e.g. 'sphinx.ext.mathjax'
"myst_parser",
"breathe",
"myst_parser",
"sphinx_copybutton",
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.viewcode",
"sphinxcontrib.moderncmakedomain",
]
source_suffix = {
".rst": "restructuredtext",
Expand All @@ -52,7 +55,7 @@ highlight_language = "cpp"

cpp_id_attributes = [
[%- if add_compile_target == true %]
"compile_EXPORT",
"COMPILE_EXPORT",
[%- endif %]
"GIT_EXTERN_C_BEGIN",
]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,35 @@

```{toctree}
:hidden:
```

<!-- Extract content from start line 1 of README.md -->

```{include} ../README.md
:start-line: 1
```

## Content

```{toctree}
:maxdepth: 2
:titlesonly:
:caption: Guide
:glob:

Overview <self>
[% if repo_name == 'ss-cpp' -%]
cmake_workflow
[% endif -%]
changelog
api
coverage
```

```{include} ../README.md
:start-line: 1
```{toctree}
:maxdepth: 1
:titlesonly:
:caption: References

api
changelog
```

## 🔖 Indices and tables
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
breathe
furo
breathe==4.35.0
furo==2024.1.29
sphinx==7.1.2
sphinx-copybutton
myst_parser
sphinx-copybutton==0.5.2
myst-parser==2.0.0
sphinxcontrib-moderncmakedomain==3.27.0
6 changes: 1 addition & 5 deletions template/cmake/ConfigureCoverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,5 @@ add_code_coverage_all_targets(
${VCPKG_INSTALLED_DIR}/*
${CMAKE_BINARY_DIR}/*
/usr/*
HTML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}_docs/coverage)
HTML_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/docs/_build/coverage)
# cmake-format: on

if(TARGET ${CMAKE_PROJECT_NAME}_docs)
add_dependencies(ccov-all ${CMAKE_PROJECT_NAME}_docs)
endif()
Loading

0 comments on commit c598866

Please sign in to comment.