From 31212226be5b37aa61bd1aa7ea772ee1f5e5830f Mon Sep 17 00:00:00 2001 From: xiehuc Date: Mon, 2 Dec 2013 14:06:26 +0800 Subject: [PATCH] support cmake Signed-off-by: xiehuc --- CMakeLists.txt | 12 +- cmake/FindMozJS.cmake | 0 cmake/FindSphinx.cmake | 246 +++++++++++++++++++++++++++++++++++++++++ doc | 2 +- 4 files changed, 258 insertions(+), 2 deletions(-) mode change 100755 => 100644 cmake/FindMozJS.cmake create mode 100644 cmake/FindSphinx.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 556dee5..67e20a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,8 @@ option(WITHOUT_ASYNC "Disable Async " Off) option(WITH_LIBUV "Use Libuv To Provide Async " Off) option(LWQQ_INSTALL "Install Lwqq Library" On) - +find_package(Sphinx) +message("${SPHINX_FOUND}") if(UNIX) find_package(PkgConfig REQUIRED) pkg_check_modules(CURL REQUIRED libcurl) @@ -75,12 +76,21 @@ if(WITH_MOZJS AND NOT MOZJS_FOUND) message(FATAL_ERROR "Reuired mozjs185 or mozjs-17.0 package not found") endif() +option(ENABLE_DOCS "Build Documentation" ${SPHINX_FOUND}) +if(ENABLE_DOCS AND NOT SPHINX_FOUND) + message(FATAL_ERROR "Reuired python-sphinx package not found") +endif() + message( "================lwqq flags=====================") message(STATUS "With Libev (Option) : ${WITH_LIBEV}") message(STATUS "With Mozjs (Option) : ${WITH_MOZJS}") +message(STATUS "Build Document (Option) : ${ENABLE_DOCS}") message( "===============================================") configure_file(config.h.in ${PROJECT_BINARY_DIR}/lwqq-config.h) install(FILES "${PROJECT_BINARY_DIR}/lwqq-config.h" DESTINATION include/lwqq) add_subdirectory(lib) add_subdirectory(src) +if(ENABLE_DOCS) + add_subdirectory(doc) +endif() diff --git a/cmake/FindMozJS.cmake b/cmake/FindMozJS.cmake old mode 100755 new mode 100644 diff --git a/cmake/FindSphinx.cmake b/cmake/FindSphinx.cmake new file mode 100644 index 0000000..5e7a9fb --- /dev/null +++ b/cmake/FindSphinx.cmake @@ -0,0 +1,246 @@ +############################################################################## +# @file FindSphinx.cmake +# @brief Find Sphinx documentation build tools. +# +# @par Input variables: +# +# +# @tp @b Sphinx_DIR @endtp +# +# +# +# @tp @b SPHINX_DIR @endtp +# +# +# +# @tp @b Sphinx_FIND_COMPONENTS @endtp +# +# +#
Installation directory of Sphinx tools. Can also be set as environment variable.
Alternative environment variable for @c Sphinx_DIR.
Sphinx build tools to look for, i.e., 'apidoc' and/or 'build'.
+# +# @par Output variables: +# +# +# @tp @b Sphinx_FOUND @endtp +# +# +# +# @tp @b SPHINX_FOUND @endtp +# +# +# @tp @b SPHINX_EXECUTABLE @endtp +# +# +# +# @tp @b Sphinx_PYTHON_EXECUTABLE @endtp +# +# +# +# @tp @b Sphinx_PYTHON_OPTIONS @endtp +# +# +# +# @tp @b Sphinx-build_EXECUTABLE @endtp +# +# +# +# @tp @b Sphinx-apidoc_EXECUTABLE @endtp +# +# +# +# @tp @b Sphinx_VERSION_STRING @endtp +# +# +# +# @tp @b Sphinx_VERSION_MAJOR @endtp +# +# +# +# @tp @b Sphinx_VERSION_MINOR @endtp +# +# +# +# @tp @b Sphinx_VERSION_PATCH @endtp +# +# +#
Whether all or only the requested Sphinx build tools were found.
Alias for @c Sphinx_FOUND. +#
Non-cached alias for @c Sphinx-build_EXECUTABLE.
Python executable used to run sphinx-build. This is either the +# by default found Python interpreter or a specific version as +# specified by the shebang (#!) of the sphinx-build script.
A list of Python options extracted from the shebang (#!) of the +# sphinx-build script. The -E option is added by this module +# if the Python executable is not the system default to avoid +# problems with a differing setting of the @c PYTHONHOME.
Absolute path of the found sphinx-build tool.
Absolute path of the found sphinx-apidoc tool.
Sphinx version found e.g. 1.1.2.
Sphinx major version found e.g. 1.
Sphinx minor version found e.g. 1.
Sphinx patch version found e.g. 2.
+# +# @ingroup CMakeFindModules +############################################################################## + +############################################################################## +#Useage: +# sphinx_build(BUILDER [html latex ...] +# [SOURCEDIR "${CMAKE_CURRENT_SOURCE_DIR}"] +# [OUTPUTDIR "${CMAKE_CURRENT_BINARY_DIR}"] +# [CONFIGDIR "${CMAKE_CURRENT_SOURCE_DIR}"] +# [CACHEDIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees"] +# ) +############################################################################## + +set (_Sphinx_REQUIRED_VARS) + +# ---------------------------------------------------------------------------- +# initialize search +if (NOT Sphinx_DIR) + if (NOT $ENV{Sphinx_DIR} STREQUAL "") + set (Sphinx_DIR "$ENV{Sphinx_DIR}" CACHE PATH "Installation prefix of Sphinx (docutils)." FORCE) + else () + set (Sphinx_DIR "$ENV{SPHINX_DIR}" CACHE PATH "Installation prefix of Sphinx (docutils)." FORCE) + endif () +endif () + +# ---------------------------------------------------------------------------- +# default components to look for +if (NOT Sphinx_FIND_COMPONENTS) + set (Sphinx_FIND_COMPONENTS "build" "apidoc") +elseif (NOT Sphinx_FIND_COMPONENTS MATCHES "^(build|apidoc)$") + message (FATAL_ERROR "Invalid Sphinx component in: ${Sphinx_FIND_COMPONENTS}") +endif () + +# ---------------------------------------------------------------------------- +# find components, i.e., build tools +foreach (_Sphinx_TOOL IN LISTS Sphinx_FIND_COMPONENTS) + if (Sphinx_DIR) + find_program ( + Sphinx-${_Sphinx_TOOL}_EXECUTABLE + NAMES sphinx-${_Sphinx_TOOL} sphinx-${_Sphinx_TOOL}.py + HINTS "${Sphinx_DIR}" + PATH_SUFFIXES bin + DOC "The sphinx-${_Sphinx_TOOL} Python script." + NO_DEFAULT_PATH + ) + else () + find_program ( + Sphinx-${_Sphinx_TOOL}_EXECUTABLE + NAMES sphinx-${_Sphinx_TOOL} sphinx-${_Sphinx_TOOL}.py + DOC "The sphinx-${_Sphinx_TOOL} Python script." + ) + endif () + mark_as_advanced (Sphinx-${_Sphinx_TOOL}_EXECUTABLE) + list (APPEND _Sphinx_REQUIRED_VARS Sphinx-${_Sphinx_TOOL}_EXECUTABLE) +endforeach () + +# ---------------------------------------------------------------------------- +# determine Python executable used by Sphinx +if (Sphinx-build_EXECUTABLE) + # extract python executable from shebang of sphinx-build + find_package (PythonInterp QUIET) + set (Sphinx_PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE}") + set (Sphinx_PYTHON_OPTIONS) + file (STRINGS "${Sphinx-build_EXECUTABLE}" FIRST_LINE LIMIT_COUNT 1) + if (FIRST_LINE MATCHES "^#!(.*/python.*)") # does not match "#!/usr/bin/env python" ! + string (REGEX REPLACE "^ +| +$" "" Sphinx_PYTHON_EXECUTABLE "${CMAKE_MATCH_1}") + if (Sphinx_PYTHON_EXECUTABLE MATCHES "([^ ]+) (.*)") + set (Sphinx_PYTHON_EXECUTABLE "${CMAKE_MATCH_1}") + string (REGEX REPLACE " +" ";" Sphinx_PYTHON_OPTIONS "${CMAKE_MATCH_2}") + endif () + endif () + # this is done to avoid problems with multiple Python versions being installed + # remember: CMake command if(STR EQUAL STR) is bad and may cause many troubles ! + string (REGEX REPLACE "([.+*?^$])" "\\\\\\1" _Sphinx_PYTHON_EXECUTABLE_RE "${PYTHON_EXECUTABLE}") + list (FIND Sphinx_PYTHON_OPTIONS -E IDX) + if (IDX EQUAL -1 AND NOT Sphinx_PYTHON_EXECUTABLE MATCHES "^${_Sphinx_PYTHON_EXECUTABLE_RE}$") + list (INSERT Sphinx_PYTHON_OPTIONS 0 -E) + endif () + unset (_Sphinx_PYTHON_EXECUTABLE_RE) +endif () + +# ---------------------------------------------------------------------------- +# determine Sphinx version +if (Sphinx-build_EXECUTABLE) + # intentionally use invalid -h option here as the help that is shown then + # will include the Sphinx version information + if (Sphinx_PYTHON_EXECUTABLE) + execute_process ( + COMMAND "${Sphinx_PYTHON_EXECUTABLE}" ${Sphinx_PYTHON_OPTIONS} "${Sphinx-build_EXECUTABLE}" -h + OUTPUT_VARIABLE _Sphinx_VERSION + ERROR_VARIABLE _Sphinx_VERSION + ) + elseif (UNIX) + execute_process ( + COMMAND "${Sphinx-build_EXECUTABLE}" -h + OUTPUT_VARIABLE _Sphinx_VERSION + ERROR_VARIABLE _Sphinx_VERSION + ) + endif () + if (_Sphinx_VERSION MATCHES "Sphinx v([0-9]+\\.[0-9]+\\.[0-9]+)") + set (Sphinx_VERSION_STRING "${CMAKE_MATCH_1}") + string (REPLACE "." ";" _Sphinx_VERSION "${Sphinx_VERSION_STRING}") + list(GET _Sphinx_VERSION 0 Sphinx_VERSION_MAJOR) + list(GET _Sphinx_VERSION 1 Sphinx_VERSION_MINOR) + list(GET _Sphinx_VERSION 2 Sphinx_VERSION_PATCH) + if (Sphinx_VERSION_PATCH EQUAL 0) + string (REGEX REPLACE "\\.0$" "" Sphinx_VERSION_STRING "${Sphinx_VERSION_STRING}") + endif () + endif() +endif () + +# ---------------------------------------------------------------------------- +# compatibility with FindPythonInterp.cmake and FindPerl.cmake +set (SPHINX_EXECUTABLE "${Sphinx-build_EXECUTABLE}") + +# ---------------------------------------------------------------------------- +# handle the QUIETLY and REQUIRED arguments and set SPHINX_FOUND to TRUE if +# all listed variables are TRUE +include (FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS ( + Sphinx + REQUIRED_VARS + ${_Sphinx_REQUIRED_VARS} + VERSION_VAR + Sphinx_VERSION_STRING +) + +# ---------------------------------------------------------------------------- +# set Sphinx_DIR +if (NOT Sphinx_DIR AND Sphinx-build_EXECUTABLE) + get_filename_component (Sphinx_DIR "${Sphinx-build_EXECUTABLE}" PATH) + string (REGEX REPLACE "/bin/?" "" Sphinx_DIR "${Sphinx_DIR}") + set (Sphinx_DIR "${Sphinx_DIR}" CACHE PATH "Installation directory of Sphinx tools." FORCE) +endif () + +unset (_Sphinx_VERSION) +unset (_Sphinx_REQUIRED_VARS) + +function(SPHINX_BUILD) + set(options ) + set(oneValueArgs SOURCEDIR OUTPUTDIR CONFIGDIR CACHEDIR ) + set(multiValueArgs BUILDER) + + cmake_parse_arguments(SPHINX_BUILD "${options}" "${oneValueArgs}" + "${multiValueArgs}" "${ARGN}") + if(NOT DEFINED SPHINX_BUILD_BUILDER) + set(SPHINX_BUILD_BUILDER html) + endif() + if(NOT DEFINED SPHINX_BUILD_SOURCEDIR) + set(SPHINX_BUILD_SOURCEDIR "${CMAKE_CURRENT_SOURCE_DIR}") + endif() + if(NOT DEFINED SPHINX_BUILD_CONFIGDIR) + set(SPHINX_BUILD_CONFIGDIR "${CMAKE_CURRENT_SOURCE_DIR}") + endif() + if(NOT DEFINED SPHINX_BUILD_CACHEDIR) + set(SPHINX_BUILD_CACHEDIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees") + endif() + if(NOT DEFINED SPHINX_BUILD_OUTPUTDIR) + set(SPHINX_BUILD_OUTPUTDIR "${CMAKE_CURRENT_BINARY_DIR}") + endif() + + foreach(builder ${SPHINX_BUILD_BUILDER}) + message(STATUS "${builder}") + add_custom_target("sphinx_build_${builder}_result" ALL + ${Sphinx-build_EXECUTABLE} + -q -b "${builder}" + -c "${SPHINX_BUILD_CONFIGDIR}" + -d "${SPHINX_BUILD_CACHEDIR}" + "${SPHINX_BUILD_SOURCEDIR}" + "${SPHINX_BUILD_OUTPUTDIR}/${builder}" + COMMENT "Building ${builder} documentation with Sphinx") + endforeach() +endfunction() diff --git a/doc b/doc index 902f223..f2a3f02 160000 --- a/doc +++ b/doc @@ -1 +1 @@ -Subproject commit 902f223f4e11d614a6df2b8182df5a34267247c7 +Subproject commit f2a3f02675adb4314811a060fa92c8cc593bf74d