4 # ASCIIDOCTOR_EXECUTABLE
7 INCLUDE(FindChocolatey)
9 FIND_PROGRAM(ASCIIDOCTOR_EXECUTABLE
18 # XXX Add Asciidoctor.js releases (asciidoctor-linux,
19 # asciidoctor-macos, asciidoctor-win) if that ever becomes an option.
24 ${CHOCOLATEY_BIN_PATH}
25 DOC "Path to Asciidoctor or AsciidoctorJ"
28 if(ASCIIDOCTOR_EXECUTABLE)
29 # As of 2.2.0 the AsciidctorJ wrapper script sets -Xmn128m -Xms256m -Xmx256m.
30 # This isn't enough for the User's Guide.
31 set(_asciidoctorj_opts "-Xmn256m -Xms512m -Xmx2048m $ENV{ASCIIDOCTORJ_OPTS}")
32 execute_process( COMMAND ${ASCIIDOCTOR_EXECUTABLE} --version OUTPUT_VARIABLE _ad_full_version )
33 separate_arguments(_ad_full_version)
34 list(GET _ad_full_version 1 ASCIIDOCTOR_VERSION)
36 function(set_asciidoctor_target_properties _target)
37 set_target_properties(${_target} PROPERTIES
38 FOLDER "Documentation"
39 EXCLUDE_FROM_DEFAULT_BUILD True
41 endfunction(set_asciidoctor_target_properties)
43 set (_asciidoctor_common_args
44 # AsciidoctorJ added --failure-level in version 2.5.6
45 # --failure-level=WARN
48 --attribute build_dir=${CMAKE_BINARY_DIR}/doc
49 --attribute css_dir=${CMAKE_SOURCE_DIR}/doc
50 --require ${CMAKE_SOURCE_DIR}/doc/asciidoctor-macros/ws_utils.rb
51 --require ${CMAKE_SOURCE_DIR}/doc/asciidoctor-macros/commaize-block.rb
52 --require ${CMAKE_SOURCE_DIR}/doc/asciidoctor-macros/cveidlink-inline-macro.rb
53 --require ${CMAKE_SOURCE_DIR}/doc/asciidoctor-macros/manarg-block.rb
54 --require ${CMAKE_SOURCE_DIR}/doc/asciidoctor-macros/wsbuglink-inline-macro.rb
55 --require ${CMAKE_SOURCE_DIR}/doc/asciidoctor-macros/wssalink-inline-macro.rb
58 set(_asciidoctor_common_command
59 ${CMAKE_COMMAND} -E env TZ=UTC
60 ${ASCIIDOCTOR_EXECUTABLE}
61 ${_asciidoctor_common_args}
64 set(_asciidoctor_docbook_common_command
65 ${CMAKE_COMMAND} -E env TZ=UTC ASCIIDOCTORJ_OPTS=${_asciidoctorj_opts}
66 ${ASCIIDOCTOR_EXECUTABLE}
67 ${_asciidoctor_common_args}
70 MACRO( ASCIIDOCTOR2DOCBOOK _asciidocsource )
71 GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE )
72 set( _output_xml ${_source_base_name}.xml )
77 COMMAND ${_asciidoctor_docbook_common_command}
79 --out-file ${_output_xml}
80 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
82 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
83 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
86 if(CMAKE_GENERATOR MATCHES "Visual Studio")
90 COMMAND ${CMAKE_COMMAND} -E touch ${_output_xml}-stamp
91 DEPENDS ${_output_xml}
93 add_custom_target(generate_${_output_xml} DEPENDS ${_output_xml}-stamp)
95 add_custom_target(generate_${_output_xml} DEPENDS ${_output_xml})
97 set_asciidoctor_target_properties(generate_${_output_xml})
101 # Single page only, for the release notes and man pages.
102 MACRO( ASCIIDOCTOR2HTML _asciidocsource )
103 GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE )
104 set( _output_html ${_source_base_name}.html )
109 COMMAND ${_asciidoctor_common_command}
111 --out-file ${_output_html}
112 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
114 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
115 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
118 add_custom_target(generate_${_output_html} DEPENDS ${_output_html})
119 set_asciidoctor_target_properties(generate_${_output_html})
123 MACRO( ASCIIDOCTOR2TXT _asciidocsource )
124 GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE )
125 set( _input_html ${_source_base_name}.html )
126 set( _output_txt ${_source_base_name}.txt )
131 COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/html2text.py
136 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
137 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
145 # Generate one or more ROFF man pages
146 function(ASCIIDOCTOR2ROFFMAN _man_section)
149 foreach(_src_file ${ARGN})
150 list(APPEND _input_adoc ${_src_file})
151 GET_FILENAME_COMPONENT(_source_base_name ${_src_file} NAME_WE )
152 list(APPEND _output_man man_pages/${_source_base_name}.${_man_section} )
158 COMMAND ${_asciidoctor_common_command}
160 --destination-dir ${CMAKE_CURRENT_BINARY_DIR}/man_pages
164 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
169 # Generate one or more HTML man pages
170 function(ASCIIDOCTOR2HTMLMAN)
173 foreach(_src_file ${ARGN})
174 list(APPEND _input_adoc ${_src_file})
175 GET_FILENAME_COMPONENT(_source_base_name ${_src_file} NAME_WE )
176 list(APPEND _output_man man_pages/${_source_base_name}.html )
182 COMMAND ${_asciidoctor_common_command}
184 --destination-dir ${CMAKE_CURRENT_BINARY_DIR}/man_pages
188 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
193 FIND_PROGRAM(ASCIIDOCTOR_PDF_EXECUTABLE
202 ${CHOCOLATEY_BIN_PATH}
203 DOC "Path to Asciidoctor PDF or AsciidoctorJ"
206 if(ASCIIDOCTOR_PDF_EXECUTABLE)
208 set(_asciidoctor_pdf_common_command
209 ${CMAKE_COMMAND} -E env TZ=UTC "ASCIIDOCTORJ_OPTS=${_asciidoctorj_opts}"
210 ${ASCIIDOCTOR_PDF_EXECUTABLE}
211 --require asciidoctor-pdf
213 ${_asciidoctor_common_args}
216 MACRO( ASCIIDOCTOR2PDF _title _asciidocsource )
217 GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE )
218 set(_generate_pdf "generate_${_source_base_name}_pdf")
219 set(_output_pdf "${_title}.pdf")
224 COMMAND ${_asciidoctor_pdf_common_command}
225 --out-file "${_output_pdf}"
226 -a pdf-fontsdir=${CMAKE_SOURCE_DIR}/resources/fonts
227 -a pdf-themesdir=${CMAKE_SOURCE_DIR}/doc/asciidoctor-themes
229 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
231 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
232 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
236 add_custom_target(${_generate_pdf} DEPENDS ${_output_pdf})
237 set_asciidoctor_target_properties(${_generate_pdf})
242 else(ASCIIDOCTOR_PDF_EXECUTABLE)
244 MACRO( ASCIIDOCTOR2PDF _asciidocsource )
247 endif(ASCIIDOCTOR_PDF_EXECUTABLE)
249 FIND_PROGRAM(ASCIIDOCTOR_EPUB_EXECUTABLE
252 asciidoctor-epub3.bat
258 ${CHOCOLATEY_BIN_PATH}
259 DOC "Path to Asciidoctor EPUB3 or AsciidoctorJ"
262 if(ASCIIDOCTOR_EPUB_EXECUTABLE)
264 set(_asciidoctor_epub_common_command
265 ${CMAKE_COMMAND} -E env TZ=UTC "ASCIIDOCTORJ_OPTS=${_asciidoctorj_opts}"
266 ${ASCIIDOCTOR_EPUB_EXECUTABLE}
268 ${_asciidoctor_common_args}
271 MACRO(ASCIIDOCTOR2EPUB _title _asciidocsource)
272 GET_FILENAME_COMPONENT(_source_base_name ${_asciidocsource} NAME_WE)
273 set(_generate_epub "generate_${_source_base_name}_epub")
274 set(_output_epub "${_title}.epub")
279 COMMAND ${_asciidoctor_epub_common_command}
280 --out-file "${_output_epub}"
281 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
283 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
284 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
288 add_custom_target(${_generate_epub} DEPENDS ${_output_epub})
289 set_asciidoctor_target_properties(${_generate_epub})
290 unset(_generate_epub)
294 else(ASCIIDOCTOR_EPUB_EXECUTABLE)
296 MACRO(ASCIIDOCTOR2EPUB _asciidocsource)
299 endif(ASCIIDOCTOR_EPUB_EXECUTABLE)
301 endif(ASCIIDOCTOR_EXECUTABLE)
303 include( FindPackageHandleStandardArgs )
304 find_package_handle_standard_args( Asciidoctor
305 REQUIRED_VARS ASCIIDOCTOR_EXECUTABLE
306 VERSION_VAR ASCIIDOCTOR_VERSION
309 mark_as_advanced( ASCIIDOCTOR_EXECUTABLE )