1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-11 13:50:56 -05:00
polybar/doc/CMakeLists.txt
patrick96 91e31317a7 doc: Set SPHINX_BUILD in standalone doc builds
If we build only the documentation by invoking `cmake` on the `doc`
folder, the `SPHINX_BUILD` variable is not set and instead of

```
sphinx-build -b html ...
```

it will just execute

```
-b html ...
```

This produces an error but doesn't fail the build because apparently if
the command starts with a dash an error is non-fatal.

Fixes #2191
2020-10-03 15:37:17 +02:00

69 lines
2.2 KiB
CMake

cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
# Only used if documentation is built on its own
project(polybar-doc NONE)
if(NOT SPHINX_BUILD)
set(SPHINX_BUILD "sphinx-build")
endif()
set(SPHINX_FLAGS "" CACHE STRING "Flags to pass to sphinx-build")
separate_arguments(sphinx_flags UNIX_COMMAND "${SPHINX_FLAGS}")
set(doc_path "${CMAKE_CURRENT_SOURCE_DIR}")
# Configures conf.py in the current folder and puts it in the build folder
configure_file(conf.py conf.py @ONLY)
# We want to run `sphinx-build` with the following builders
set(doc_builders "html" "man")
# Name of all documentation targets
set(doc_targets "")
foreach(builder ${doc_builders})
set(doc_target "doc_${builder}")
set(builder_log "builder-${builder}.log")
add_custom_target(${doc_target}
COMMAND ${SPHINX_BUILD}
-b ${builder}
# conf.py dir
-c "${CMAKE_CURRENT_BINARY_DIR}"
-d "${CMAKE_CURRENT_BINARY_DIR}/doctrees"
${sphinx_flags}
# Documentation source file dir
"${CMAKE_CURRENT_SOURCE_DIR}"
# Output dir
"${CMAKE_CURRENT_BINARY_DIR}/${builder}" > ${builder_log}
COMMENT "sphinx-build ${builder}: see doc/${builder_log}")
list(APPEND doc_targets ${doc_target})
endforeach()
# Dummy target that depends on all documentation targets
add_custom_target(doc ALL DEPENDS ${doc_targets})
# This is needed for the case where only the doc target is built
# CMAKE_INSTALL_DOCDIR uses PROJECT_NAME which is now polybar-doc, to be
# consistent with a regular install we temporarily override it with "polybar"
# before including GNUInstallDirs
# Also since no language is set and GNUInstallDirs cannot set
# CMAKE_INSTALL_LIBDIR, so we set it to a dummy value to suppress a warning
if(${CMAKE_PROJECT_NAME} STREQUAL "polybar-doc")
set(PROJECT_NAME "polybar")
set(CMAKE_INSTALL_LIBDIR "")
include(GNUInstallDirs)
set(PROJECT_NAME "polybar-doc")
endif()
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/
DESTINATION ${CMAKE_INSTALL_DOCDIR}
COMPONENT doc)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/polybar.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
COMPONENT doc)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/man/polybar.5
DESTINATION ${CMAKE_INSTALL_MANDIR}/man5
COMPONENT doc)