aboutsummaryrefslogtreecommitdiff
path: root/docs/CMakeLists.txt
blob: 28a816ae5a46fa636268e3193f292289acd7702d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#=============================================================================
# Copyright 2000-2013 Kitware, Inc.
# Copyright 2014-2015 Alex Merry <alex.merry@kde.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
#    derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================

include(CMakeDependentOption)

find_package(Sphinx 1.2 MODULE)
set_package_properties(
    Sphinx
    PROPERTIES
        URL "http://sphinx-doc.org/"
        DESCRIPTION "Tool to generate documentation."
        TYPE OPTIONAL
        PURPOSE "Required to build documentation for Extra CMake Modules."
)

find_package(QCollectionGenerator MODULE)
set_package_properties(
    QCollectionGenerator
    PROPERTIES
        URL "https://www.qt.io/"
        DESCRIPTION "Qt help collection generator."
        TYPE OPTIONAL
        PURPOSE "Required to build Extra CMake Modules documentation in Qt Help format."
)

cmake_dependent_option(
    BUILD_HTML_DOCS "Build html help with Sphinx" ON
    "Sphinx_FOUND" OFF
)
add_feature_info(BUILD_HTML_DOCS BUILD_HTML_DOCS "Generate HTML documentation for installed modules.")

cmake_dependent_option(
    BUILD_MAN_DOCS "Build man pages with Sphinx" ON
    "Sphinx_FOUND" OFF
)
add_feature_info(BUILD_MAN_DOCS BUILD_MAN_DOCS "Generate man page documentation for installed modules.")

cmake_dependent_option(
    BUILD_QTHELP_DOCS "Build Qt help with Sphinx" OFF
    "Sphinx_FOUND;QCollectionGenerator_FOUND" OFF
)
add_feature_info(BUILD_QTHELP_DOCS BUILD_QTHELP_DOCS "Generate QtHelp documentation for installed modules.")


set(doc_formats "")
if(BUILD_HTML_DOCS)
    list(APPEND doc_formats html)
endif()
if(BUILD_MAN_DOCS)
    list(APPEND doc_formats man)
endif()
if(BUILD_QTHELP_DOCS)
    list(APPEND doc_formats qthelp)
    set(qthelp_extra_commands
        COMMAND
            QCollectionGenerator::Generator
            ${CMAKE_CURRENT_BINARY_DIR}/qthelp/ExtraCMakeModules.qhcp
    )
endif()

if(NOT doc_formats)
    return()
endif()

if (Sphinx_VERSION VERSION_LESS 1.3)
    set(sphinx_theme default)
else()
    set(sphinx_theme classic)
endif()
configure_file(sphinx/conf.py.in conf.py @ONLY)
configure_file(sphinx/ecm.css.in static/ecm.css)


set(doc_format_outputs "")
set(doc_format_last "")
foreach(format ${doc_formats})
    set(doc_format_output "doc_format_${format}")
    set(doc_format_log "build-${format}.log")
    add_custom_command(
        OUTPUT ${doc_format_output}
        COMMAND
            Sphinx::Build
            -c ${CMAKE_CURRENT_BINARY_DIR}
            -d ${CMAKE_CURRENT_BINARY_DIR}/doctrees
            -b ${format}
            ${CMAKE_CURRENT_SOURCE_DIR}
            ${CMAKE_CURRENT_BINARY_DIR}/${format}
            > ${doc_format_log} # log stdout, pass stderr
        ${${format}_extra_commands}
        DEPENDS ${doc_format_last}
        COMMENT "sphinx-build ${format}: see ${CMAKE_CURRENT_BINARY_DIR}/${doc_format_log}"
        VERBATIM
    )
    set_property(SOURCE ${doc_format_output} PROPERTY SYMBOLIC 1)
    list(APPEND doc_format_outputs ${doc_format_output})
    set(doc_format_last ${doc_format_output})
endforeach()

add_custom_target(documentation ALL DEPENDS ${doc_format_outputs})

if(BUILD_MAN_DOCS)
    file(GLOB man_rst RELATIVE ${ECM_SOURCE_DIR}/docs/manual
        ${ECM_SOURCE_DIR}/docs/manual/*.[1-9].rst)
    foreach(m ${man_rst})
        if("x${m}" MATCHES "^x(.+)\\.([1-9])\\.rst$")
            set(name "${CMAKE_MATCH_1}")
            set(sec "${CMAKE_MATCH_2}")
            install(
                FILES ${CMAKE_CURRENT_BINARY_DIR}/man/${name}.${sec}
                DESTINATION ${MAN_INSTALL_DIR}/man${sec}
            )
        endif()
    endforeach()
endif()
if(BUILD_HTML_DOCS)
    install(
        DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
        DESTINATION ${DOC_INSTALL_DIR}
        PATTERN .buildinfo EXCLUDE
        PATTERN objects.inv EXCLUDE
    )
endif()
if(BUILD_QTHELP_DOCS)
    install(
        FILES ${CMAKE_CURRENT_BINARY_DIR}/qthelp/ExtraCMakeModules.qch
        DESTINATION ${DOC_INSTALL_DIR}
    )
endif()