0
0
mirror of https://github.com/OpenVPN/openvpn.git synced 2024-09-19 19:42:30 +02:00
openvpn/doc/CMakeLists.txt
Frank Lichtenheld 22213a8834 CMake: Support doc builds on Windows machines that do not have .py file association
On Windows we might need to call python because .py files are not
directly executable. This is true e.g. for GHA runners.
For now we assume that rst2html and rst2man can be handled in the same
way and do not test both of them.

Commit e8881ec6dd unconditionally
used $PYTHON, but that broke build on systems where the default
python can't be used and we need to respect the shebang.
Commit 5dbec1c019 unconditionally
did not use $PYTHON, but that broke build on the aformentioned
GHA runners.
This commit tries to establish a solution that works for both
systems.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20230704130902.105585-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26813.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
2023-07-06 13:52:24 +02:00

113 lines
4.1 KiB
CMake

set(_GENERATE_HTML_DOC YES)
set(_GENERATE_MAN_DOC YES)
set(_MAYBE_PYTHON "")
find_program(RST2HTML NAMES rst2html rst2html.py)
find_program(RST2MAN NAMES rst2man rst2man.py)
if (RST2HTML STREQUAL "RST2HTML-NOTFOUND")
message(STATUS "rst2html not found, not generating HTML documentation")
set(_GENERATE_HTML_DOC NO)
else ()
# We only run this for RST2HTML and assume the result would be the same
# for RST2MAN
if (DEFINED CACHE{DOCUTILS_NEED_PYTHON})
if ($CACHE{DOCUTILS_NEED_PYTHON})
set(_MAYBE_PYTHON ${PYTHON})
endif ()
else ()
execute_process(
COMMAND ${RST2HTML} --version
OUTPUT_VARIABLE RST2HTML_VERSION_EXE
)
execute_process(
COMMAND ${PYTHON} ${RST2HTML} --version
OUTPUT_VARIABLE RST2HTML_VERSION_PY
)
set(_DOCUTILS_NEED_PYTHON OFF)
if(RST2HTML_VERSION_EXE STREQUAL "")
if(RST2HTML_VERSION_PY STREQUAL "")
message(STATUS "${RST2HTML} found but not working, not generating documentation")
set(_GENERATE_HTML_DOC NO)
set(_GENERATE_MAN_DOC NO)
else ()
message(STATUS "${RST2HTML} needs to be executed by ${PYTHON} to work")
set(_MAYBE_PYTHON ${PYTHON})
set(_DOCUTILS_NEED_PYTHON ON)
endif ()
endif ()
set(DOCUTILS_NEED_PYTHON ${_DOCUTILS_NEED_PYTHON} CACHE BOOL
"Whether we need to call python instead of rst2*.py directly")
endif (DEFINED CACHE{DOCUTILS_NEED_PYTHON})
endif ()
if (RST2MAN STREQUAL "RST2MAN-NOTFOUND")
message(STATUS "rst2man not found, not generating man pages")
set(_GENERATE_MAN_DOC NO)
endif ()
set(OPENVPN_SECTIONS
man-sections/advanced-options.rst
man-sections/cipher-negotiation.rst
man-sections/client-options.rst
man-sections/connection-profiles.rst
man-sections/encryption-options.rst
man-sections/generic-options.rst
man-sections/inline-files.rst
man-sections/link-options.rst
man-sections/log-options.rst
man-sections/management-options.rst
man-sections/network-config.rst
man-sections/pkcs11-options.rst
man-sections/plugin-options.rst
man-sections/protocol-options.rst
man-sections/proxy-options.rst
man-sections/renegotiation.rst
man-sections/signals.rst
man-sections/script-options.rst
man-sections/server-options.rst
man-sections/tls-options.rst
man-sections/unsupported-options.rst
man-sections/virtual-routing-and-forwarding.rst
man-sections/vpn-network-options.rst
man-sections/windows-options.rst
)
set(OPENVPN_EXAMPLES_SECTIONS
man-sections/example-fingerprint.rst
man-sections/examples.rst
)
set(RST_FLAGS --strict)
if (_GENERATE_HTML_DOC)
list(APPEND ALL_DOCS openvpn.8.html openvpn-examples.5.html)
add_custom_command(
OUTPUT openvpn.8.html
COMMAND ${_MAYBE_PYTHON} ${RST2HTML} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn.8.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn.8.html
MAIN_DEPENDENCY openvpn.8.rst
DEPENDS ${OPENVPN_SECTIONS}
)
add_custom_command(
OUTPUT openvpn-examples.5.html
COMMAND ${_MAYBE_PYTHON} ${RST2HTML} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn-examples.5.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn-examples.5.html
MAIN_DEPENDENCY openvpn-examples.5.rst
DEPENDS ${OPENVPN_EXAMPLES_SECTIONS}
)
endif ()
if (_GENERATE_MAN_DOC)
list(APPEND ALL_DOCS openvpn.8 openvpn-examples.5)
add_custom_command(
OUTPUT openvpn.8
COMMAND ${_MAYBE_PYTHON} ${RST2MAN} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn.8.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn.8
MAIN_DEPENDENCY openvpn.8.rst
DEPENDS ${OPENVPN_SECTIONS}
)
add_custom_command(
OUTPUT openvpn-examples.5
COMMAND ${_MAYBE_PYTHON} ${RST2MAN} ${RST_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/openvpn-examples.5.rst ${CMAKE_CURRENT_BINARY_DIR}/openvpn-examples.5
MAIN_DEPENDENCY openvpn-examples.5.rst
DEPENDS ${OPENVPN_EXAMPLES_SECTIONS}
)
endif ()
add_custom_target(documentation ALL DEPENDS ${ALL_DOCS})