2019-08-07 23:28:14 +08:00
|
|
|
add_subdirectory(tutorial)
|
2019-02-09 05:46:50 +08:00
|
|
|
# build a virtualenv
|
|
|
|
set(sphinx_dir ${CMAKE_CURRENT_SOURCE_DIR}/sphinx)
|
|
|
|
set(venv_dir ${CMAKE_CURRENT_BINARY_DIR}/venv)
|
|
|
|
if(WIN32)
|
2021-09-10 00:38:18 +08:00
|
|
|
set(venv_bin_dir ${CMAKE_CURRENT_BINARY_DIR}/venv/Scripts)
|
|
|
|
set(activate_script ${venv_bin_dir}/activate.bat)
|
2019-02-09 05:46:50 +08:00
|
|
|
set(EXE_SUFFIX ".exe")
|
2021-09-10 00:38:18 +08:00
|
|
|
else()
|
|
|
|
set(venv_bin_dir ${CMAKE_CURRENT_BINARY_DIR}/venv/bin)
|
|
|
|
set(activate_script . ${venv_bin_dir}/activate)
|
|
|
|
set(EXE_SUFFIX "")
|
2019-02-07 09:54:01 +08:00
|
|
|
endif()
|
2021-09-10 00:38:18 +08:00
|
|
|
set(python_command ${venv_bin_dir}/python${EXE_SUFFIX})
|
|
|
|
set(pip_command ${venv_bin_dir}/pip${EXE_SUFFIX})
|
2019-02-09 05:46:50 +08:00
|
|
|
|
|
|
|
add_custom_command(OUTPUT ${venv_dir}/venv_setup
|
2020-02-17 22:00:03 +08:00
|
|
|
COMMAND ${Python3_EXECUTABLE} -m venv venv &&
|
2019-02-09 05:46:50 +08:00
|
|
|
${CMAKE_COMMAND} -E copy ${sphinx_dir}/.pip.conf ${venv_dir}/pip.conf &&
|
2021-09-10 00:38:18 +08:00
|
|
|
${activate_script} &&
|
|
|
|
${python_command} -m pip install --upgrade pip &&
|
2019-02-09 05:46:50 +08:00
|
|
|
${pip_command} install --upgrade -r ${sphinx_dir}/requirements.txt &&
|
|
|
|
${pip_command} install sphinx-autobuild && # somehow this is missing in requirements.txt
|
|
|
|
${CMAKE_COMMAND} -E touch ${venv_dir}/venv_setup
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
COMMENT "Set up virtualenv")
|
|
|
|
add_custom_target(buildsphinx DEPENDS ${venv_dir}/venv_setup)
|
|
|
|
|
|
|
|
file(GLOB_RECURSE SRCS *.rst)
|
|
|
|
|
|
|
|
function(add_documentation_target)
|
|
|
|
set(options)
|
|
|
|
set(oneValueArgs GENERATOR SPHINX_COMMAND DOCTREE)
|
|
|
|
set(multiValueArgs ADDITIONAL_ARGUMENTS)
|
|
|
|
cmake_parse_arguments(ADT "${options}" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
|
|
|
|
if(NOT ADT_GENERATOR)
|
|
|
|
message(ERROR "GENERATOR is a required argument to add_documentation_target")
|
|
|
|
endif()
|
|
|
|
set(target ${ADT_GENERATOR})
|
2021-09-10 00:38:18 +08:00
|
|
|
set(SPHINX_COMMAND "${venv_bin_dir}/sphinx-build${EXE_SUFFIX}")
|
2019-02-09 05:46:50 +08:00
|
|
|
if(ADT_SPHINX_COMMAND)
|
2021-09-10 00:38:18 +08:00
|
|
|
set(SPHINX_COMMAND "${venv_bin_dir}/${ADT_SPHINX_COMMAND}")
|
2019-02-09 05:46:50 +08:00
|
|
|
endif()
|
|
|
|
set(doctree "doctree")
|
|
|
|
if (ADT_DOCTREE)
|
|
|
|
set(doctree "${ADT_DOCTREE}")
|
|
|
|
endif()
|
|
|
|
set(out_dir ${CMAKE_CURRENT_BINARY_DIR}/${target})
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}_done
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${out_dir} &&
|
2019-06-15 00:45:18 +08:00
|
|
|
${python_command} ${SPHINX_COMMAND} -W -b ${target}
|
2019-02-09 05:46:50 +08:00
|
|
|
-d ${doctree} -c ${sphinx_dir}
|
|
|
|
${sphinx_dir}/source
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${target} &&
|
|
|
|
${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${target}_done
|
|
|
|
DEPENDS ${SRCS}
|
|
|
|
WORKING_DIRECTORY ${venv_dir})
|
|
|
|
message(STATUS "add_custom_target(${target} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${target}_done)")
|
|
|
|
add_custom_target(${target} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${target}_done)
|
|
|
|
add_dependencies(${target} buildsphinx)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
message(STATUS "Add html target")
|
|
|
|
add_documentation_target(GENERATOR html)
|
2019-02-09 06:10:13 +08:00
|
|
|
|
2020-01-23 06:14:08 +08:00
|
|
|
set(DOCSERVER_PORT "-1" CACHE STRING "Port to which the documentation server should bind (negative means cmake will choose one)")
|
2020-01-23 06:04:31 +08:00
|
|
|
|
|
|
|
if(DOCSERVER_PORT GREATER_EQUAL 0)
|
|
|
|
set(port ${DOCSERVER_PORT})
|
|
|
|
else()
|
|
|
|
if(WIN32)
|
2020-01-23 06:24:01 +08:00
|
|
|
if(DEFINED $ENV{USERNAME})
|
|
|
|
set(username $ENV{USERNAME})
|
|
|
|
else()
|
|
|
|
set(username "dummy_user")
|
|
|
|
endif()
|
2020-01-23 06:04:31 +08:00
|
|
|
else()
|
2020-01-23 06:24:01 +08:00
|
|
|
if(DEFINED $ENV{USER})
|
|
|
|
set(username $ENV{USER})
|
|
|
|
else()
|
|
|
|
set(username "dummy_user")
|
|
|
|
endif()
|
2020-01-23 06:04:31 +08:00
|
|
|
endif()
|
|
|
|
string(MD5 username_hash ${username})
|
|
|
|
# cmake math function can only use 64 bit signed integers - so we just truncate the string
|
|
|
|
string(SUBSTRING "${username_hash}" 0 15 username_hash_small)
|
|
|
|
message(STATUS math(EXPR port "(0x${username_hash_small} % 8000) + 8000" OUTPUT_FORMAT DECIMAL))
|
|
|
|
math(EXPR port "(0x${username_hash_small} % 8000) + 8000" OUTPUT_FORMAT DECIMAL)
|
|
|
|
message(STATUS "Port is ${port}")
|
|
|
|
endif()
|
|
|
|
|
2020-01-23 05:38:39 +08:00
|
|
|
add_custom_target(docpreview
|
2020-02-21 15:01:46 +08:00
|
|
|
COMMAND ${python_command} -m http.server ${port}
|
2020-01-23 05:38:39 +08:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
|
|
|
|
USES_TERMINAL)
|
|
|
|
add_dependencies(docpreview html)
|
|
|
|
|
2019-02-10 14:08:34 +08:00
|
|
|
set(tar_file ${CMAKE_BINARY_DIR}/packages/${CMAKE_PROJECT_NAME}-docs-${FDB_VERSION}.tar.gz)
|
2019-02-09 06:10:13 +08:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${tar_file}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E tar czf ${tar_file} .
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html)
|
|
|
|
add_custom_target(package_html DEPENDS ${tar_file})
|
|
|
|
add_dependencies(package_html html)
|
2019-02-10 14:08:34 +08:00
|
|
|
add_dependencies(packages package_html)
|