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 (_ad_failure_level_args)
45 execute_process( COMMAND ${ASCIIDOCTOR_EXECUTABLE} --help OUTPUT_VARIABLE _ad_help )
46 if (_ad_help MATCHES "--failure-level")
47 set (_ad_failure_level_args --failure-level WARN)
51 set (_asciidoctor_common_args
52 # AsciidoctorJ added --failure-level in version 2.5.6
55 ${_ad_failure_level_args}
56 --attribute build_dir=${CMAKE_BINARY_DIR}/doc
57 --attribute css_dir=${CMAKE_SOURCE_DIR}/doc
58 --require ${CMAKE_SOURCE_DIR}/doc/asciidoctor-macros/ws_utils.rb
59 --require ${CMAKE_SOURCE_DIR}/doc/asciidoctor-macros/commaize-block.rb
60 --require ${CMAKE_SOURCE_DIR}/doc/asciidoctor-macros/cveidlink-inline-macro.rb
61 --require ${CMAKE_SOURCE_DIR}/doc/asciidoctor-macros/manarg-block.rb
62 --require ${CMAKE_SOURCE_DIR}/doc/asciidoctor-macros/wsbuglink-inline-macro.rb
63 --require ${CMAKE_SOURCE_DIR}/doc/asciidoctor-macros/wssalink-inline-macro.rb
66 unset(_ad_full_version)
68 unset(_ad_failure_level_args)
70 set(_asciidoctor_common_command
71 ${CMAKE_COMMAND} -E env TZ=UTC
72 ${ASCIIDOCTOR_EXECUTABLE}
73 ${_asciidoctor_common_args}
76 set(_asciidoctor_docbook_common_command
77 ${CMAKE_COMMAND} -E env TZ=UTC ASCIIDOCTORJ_OPTS=${_asciidoctorj_opts}
78 ${ASCIIDOCTOR_EXECUTABLE}
79 ${_asciidoctor_common_args}
82 MACRO( ASCIIDOCTOR2DOCBOOK _asciidocsource )
83 GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE )
84 set( _output_xml ${_source_base_name}.xml )
89 COMMAND ${_asciidoctor_docbook_common_command}
91 --out-file ${_output_xml}
92 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
94 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
95 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
98 if(CMAKE_GENERATOR MATCHES "Visual Studio")
102 COMMAND ${CMAKE_COMMAND} -E touch ${_output_xml}-stamp
103 DEPENDS ${_output_xml}
105 add_custom_target(generate_${_output_xml} DEPENDS ${_output_xml}-stamp)
107 add_custom_target(generate_${_output_xml} DEPENDS ${_output_xml})
109 set_asciidoctor_target_properties(generate_${_output_xml})
113 # Single page only, for the release notes and man pages.
114 MACRO( ASCIIDOCTOR2HTML _asciidocsource )
115 GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE )
116 set( _output_html ${_source_base_name}.html )
121 COMMAND ${_asciidoctor_common_command}
123 --out-file ${_output_html}
124 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
126 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
127 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
130 add_custom_target(generate_${_output_html} DEPENDS ${_output_html})
131 set_asciidoctor_target_properties(generate_${_output_html})
135 MACRO( ASCIIDOCTOR2TXT _asciidocsource )
136 GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE )
137 set( _input_html ${_source_base_name}.html )
138 set( _output_txt ${_source_base_name}.txt )
143 COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/html2text.py
148 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
149 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
157 # Generate one or more ROFF man pages
158 function(ASCIIDOCTOR2ROFFMAN _man_section)
161 foreach(_src_file ${ARGN})
162 list(APPEND _input_adoc ${_src_file})
163 GET_FILENAME_COMPONENT(_source_base_name ${_src_file} NAME_WE )
164 list(APPEND _output_man man_pages/${_source_base_name}.${_man_section} )
170 COMMAND ${_asciidoctor_common_command}
172 --destination-dir ${CMAKE_CURRENT_BINARY_DIR}/man_pages
176 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
181 # Generate one or more HTML man pages
182 function(ASCIIDOCTOR2HTMLMAN)
185 foreach(_src_file ${ARGN})
186 list(APPEND _input_adoc ${_src_file})
187 GET_FILENAME_COMPONENT(_source_base_name ${_src_file} NAME_WE )
188 list(APPEND _output_man man_pages/${_source_base_name}.html )
194 COMMAND ${_asciidoctor_common_command}
196 --destination-dir ${CMAKE_CURRENT_BINARY_DIR}/man_pages
200 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
205 FIND_PROGRAM(ASCIIDOCTOR_PDF_EXECUTABLE
214 ${CHOCOLATEY_BIN_PATH}
215 DOC "Path to Asciidoctor PDF or AsciidoctorJ"
218 if(ASCIIDOCTOR_PDF_EXECUTABLE)
220 set(_asciidoctor_pdf_common_command
221 ${CMAKE_COMMAND} -E env TZ=UTC "ASCIIDOCTORJ_OPTS=${_asciidoctorj_opts}"
222 ${ASCIIDOCTOR_PDF_EXECUTABLE}
223 --require asciidoctor-pdf
225 ${_asciidoctor_common_args}
228 MACRO( ASCIIDOCTOR2PDF _title _asciidocsource )
229 GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE )
230 set(_generate_pdf "generate_${_source_base_name}_pdf")
231 set(_output_pdf "${_title}.pdf")
236 COMMAND ${_asciidoctor_pdf_common_command}
237 --out-file "${_output_pdf}"
238 -a pdf-fontsdir=${CMAKE_SOURCE_DIR}/resources/fonts
239 -a pdf-themesdir=${CMAKE_SOURCE_DIR}/doc/asciidoctor-themes
241 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
243 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
244 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
248 add_custom_target(${_generate_pdf} DEPENDS ${_output_pdf})
249 set_asciidoctor_target_properties(${_generate_pdf})
254 else(ASCIIDOCTOR_PDF_EXECUTABLE)
256 MACRO( ASCIIDOCTOR2PDF _asciidocsource )
259 endif(ASCIIDOCTOR_PDF_EXECUTABLE)
261 FIND_PROGRAM(ASCIIDOCTOR_EPUB_EXECUTABLE
264 asciidoctor-epub3.bat
270 ${CHOCOLATEY_BIN_PATH}
271 DOC "Path to Asciidoctor EPUB3 or AsciidoctorJ"
274 if(ASCIIDOCTOR_EPUB_EXECUTABLE)
276 set(_asciidoctor_epub_common_command
277 ${CMAKE_COMMAND} -E env TZ=UTC "ASCIIDOCTORJ_OPTS=${_asciidoctorj_opts}"
278 ${ASCIIDOCTOR_EPUB_EXECUTABLE}
280 ${_asciidoctor_common_args}
283 MACRO(ASCIIDOCTOR2EPUB _title _asciidocsource)
284 GET_FILENAME_COMPONENT(_source_base_name ${_asciidocsource} NAME_WE)
285 set(_generate_epub "generate_${_source_base_name}_epub")
286 set(_output_epub "${_title}.epub")
291 COMMAND ${_asciidoctor_epub_common_command}
292 --out-file "${_output_epub}"
293 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
295 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
296 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
300 add_custom_target(${_generate_epub} DEPENDS ${_output_epub})
301 set_asciidoctor_target_properties(${_generate_epub})
302 unset(_generate_epub)
306 else(ASCIIDOCTOR_EPUB_EXECUTABLE)
308 MACRO(ASCIIDOCTOR2EPUB _asciidocsource)
311 endif(ASCIIDOCTOR_EPUB_EXECUTABLE)
313 endif(ASCIIDOCTOR_EXECUTABLE)
315 include( FindPackageHandleStandardArgs )
316 find_package_handle_standard_args( Asciidoctor
317 REQUIRED_VARS ASCIIDOCTOR_EXECUTABLE
318 VERSION_VAR ASCIIDOCTOR_VERSION
321 mark_as_advanced( ASCIIDOCTOR_EXECUTABLE )