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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
find_program(MAKEINFO NAMES makeinfo)
mark_as_advanced(MAKEINFO)
find_program(PANDOC NAMES pandoc)
mark_as_advanced(PANDOC)
# sh is only used for a developer-only target.
find_program(SH NAMES ash dash sh)
mark_as_advanced(SH)
find_package(LATEX)
find_program(CTAGS NAMES ctags)
mark_as_advanced(CTAGS)
#-----------------------------------------------------------------------------#
# Pandoc < 1.0 is usable but doesn't have Texinfo support.
if(PANDOC AND NOT DEFINED PANDOC_WITH_TEXINFO)
message(STATUS "Checking Pandoc version")
execute_process(
COMMAND ${PANDOC} --version
OUTPUT_VARIABLE PANDOC_VERSION_TEXT
ERROR_VARIABLE PANDOC_VERSION_TEXT
)
if(PANDOC_VERSION_TEXT MATCHES "pandoc [1-9]")
set(PANDOC_WITH_TEXINFO 1 CACHE BOOL "Pandoc supports Texinfo")
else()
set(PANDOC_WITH_TEXINFO 0 CACHE BOOL "Pandoc supports Texinfo")
endif()
mark_as_advanced(PANDOC_WITH_TEXINFO)
endif()
# Pandoc 1.2 and 1.2.1 accidentally changed the way it generates HTML
# identifiers.
if(PANDOC AND NOT DEFINED PANDOC_STRIP_UNDERSCORES)
if(NOT PANDOC_VERSION_TEXT)
execute_process(
COMMAND ${PANDOC} --version
OUTPUT_VARIABLE PANDOC_VERSION_TEXT
ERROR_VARIABLE PANDOC_VERSION_TEXT
)
endif()
if(PANDOC_VERSION_TEXT MATCHES "pandoc 1[.]2(\n|[.]1)")
set(PANDOC_STRIP_UNDERSCORES 1 CACHE BOOL
"Pandoc strips underscores for HTML identifiers")
else()
set(PANDOC_STRIP_UNDERSCORES 0 CACHE BOOL
"Pandoc strips underscores for HTML identifiers")
endif()
mark_as_advanced(PANDOC_STRIP_UNDERSCORES)
endif()
# Pandoc 1.5 or later is required for LaTeX as it will begin
# sectioning with \chapter.
if(PANDOC AND NOT DEFINED PANDOC_FOR_LATEX)
if(NOT PANDOC_VERSION_TEXT)
execute_process(
COMMAND ${PANDOC} --version
OUTPUT_VARIABLE PANDOC_VERSION_TEXT
ERROR_VARIABLE PANDOC_VERSION_TEXT
)
endif()
if(PANDOC_VERSION_TEXT MATCHES "pandoc (0|1[.][01234])")
set(PANDOC_FOR_LATEX 0 CACHE BOOL
"Pandoc recent enough for LaTeX output")
else()
set(PANDOC_FOR_LATEX 1 CACHE BOOL
"Pandoc recent enough for LaTeX output")
endif()
mark_as_advanced(PANDOC_FOR_LATEX)
endif()
#-----------------------------------------------------------------------------#
set(all_docs)
macro(add_info n)
if(MAKEINFO)
makedoc(src/${n}._tx -texi texi/${n}.texi)
set(abs_info ${CMAKE_CURRENT_BINARY_DIR}/info/${n}.info)
set(abs_texi ${CMAKE_CURRENT_BINARY_DIR}/texi/${n}.texi)
list(APPEND all_docs ${abs_info})
add_custom_command(
OUTPUT ${abs_info}
DEPENDS ${abs_texi}
COMMAND ${MAKEINFO} --no-split -o ${abs_info} ${abs_texi}
)
endif(MAKEINFO)
endmacro(add_info)
#-----------------------------------------------------------------------------#
function(pandoc source output) # extraargs...
set(abs_source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
set(abs_output ${CMAKE_CURRENT_BINARY_DIR}/${output})
# Use native Windows syntax to avoid "c:/foo.txt" being treated as a
# remote URI by Pandoc 1.5 and 1.6.
file(TO_NATIVE_PATH ${abs_source} abs_source_native)
list(APPEND all_docs ${abs_output})
set(all_docs ${all_docs} PARENT_SCOPE)
add_custom_command(
OUTPUT ${abs_output}
DEPENDS ${abs_source}
COMMAND ${PANDOC} ${abs_source_native} --toc --standalone ${ARGN}
-o ${abs_output}
)
endfunction(pandoc source output)
function(texi2text source output)
# The source file is a generated Texinfo file.
set(abs_source ${CMAKE_CURRENT_BINARY_DIR}/${source})
set(abs_output ${CMAKE_CURRENT_BINARY_DIR}/${output})
list(APPEND all_docs ${abs_output})
set(all_docs ${all_docs} PARENT_SCOPE)
# Writing to stdout suppresses the table of contents.
# To get the table of contents, use `makeinfo -o ${output}`.
add_custom_command(
OUTPUT ${abs_output}
DEPENDS ${abs_source}
COMMAND ${MAKEINFO}
--plaintext
--paragraph-indent 0
--no-number-sections
${abs_source} > ${abs_output}
)
endfunction(texi2text)
if(PANDOC)
pandoc(
src/changes-5.0.txt
html/changes-5.0.html
-c pandoc.css
)
endif(PANDOC)
if(PANDOC_WITH_TEXINFO)
pandoc(
src/changes-5.0.txt
texi/changes-5.0.texi
)
if(MAKEINFO)
texi2text(
texi/changes-5.0.texi
txt/changes-5.0.txt
)
endif(MAKEINFO)
endif(PANDOC_WITH_TEXINFO)
add_custom_target(docs
ALL
DEPENDS ${all_docs}
)
#-----------------------------------------------------------------------------#
make_directory(${CMAKE_CURRENT_BINARY_DIR}/html/refman)
make_directory(${CMAKE_CURRENT_BINARY_DIR}/txt)
make_directory(${CMAKE_CURRENT_BINARY_DIR}/texi)
# Copy CSS files.
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/pandoc.css
${CMAKE_CURRENT_BINARY_DIR}/html/pandoc.css
COPYONLY
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/pandoc.css
${CMAKE_CURRENT_BINARY_DIR}/html/refman/pandoc.css
COPYONLY
)
if(PANDOC AND NOT CMAKE_CROSSCOMPILING)
include(Refman.cmake)
endif()
#-----------------------------------------------------------------------------#
# vim: set sts=4 sw=4 et:
|