decrypt drsuapi attributes
[wireshark-sm.git] / cmake / modules / FindAsciidoctor.cmake
blob625337889d97680483e0f86870d470eb2fb21ff2
2 # - Find Asciidoctor
3 # Sets:
4 #  ASCIIDOCTOR_EXECUTABLE
7 INCLUDE(FindChocolatey)
9 FIND_PROGRAM(ASCIIDOCTOR_EXECUTABLE
10     NAMES
11         asciidoctorj.cmd
12         asciidoctorj.bat
13         asciidoctorj
14         asciidoctor.cmd
15         asciidoctor.bat
16         asciidoctor
17         asciidoctor.ruby2.1
18         # XXX Add Asciidoctor.js releases (asciidoctor-linux,
19         # asciidoctor-macos, asciidoctor-win) if that ever becomes an option.
20     PATHS
21         /bin
22         /usr/bin
23         /usr/local/bin
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
40         )
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
46         # --trace
47         --quiet
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
56     )
58     set(_asciidoctor_common_command
59         ${CMAKE_COMMAND} -E env TZ=UTC
60         ${ASCIIDOCTOR_EXECUTABLE}
61         ${_asciidoctor_common_args}
62     )
64     set(_asciidoctor_docbook_common_command
65         ${CMAKE_COMMAND} -E env TZ=UTC ASCIIDOCTORJ_OPTS=${_asciidoctorj_opts}
66         ${ASCIIDOCTOR_EXECUTABLE}
67         ${_asciidoctor_common_args}
68     )
70     MACRO( ASCIIDOCTOR2DOCBOOK _asciidocsource )
71         GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE )
72         set( _output_xml ${_source_base_name}.xml )
74         add_custom_command(
75             OUTPUT
76                 ${_output_xml}
77             COMMAND ${_asciidoctor_docbook_common_command}
78                 --backend docbook
79                 --out-file ${_output_xml}
80                 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
81             DEPENDS
82                 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
83                 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
84                 ${ARGN}
85         )
86         if(CMAKE_GENERATOR MATCHES "Visual Studio")
87             add_custom_command(
88                 OUTPUT
89                     ${_output_xml}-stamp
90                 COMMAND ${CMAKE_COMMAND} -E touch ${_output_xml}-stamp
91                 DEPENDS ${_output_xml}
92             )
93             add_custom_target(generate_${_output_xml} DEPENDS ${_output_xml}-stamp)
94         else()
95             add_custom_target(generate_${_output_xml} DEPENDS ${_output_xml})
96         endif()
97         set_asciidoctor_target_properties(generate_${_output_xml})
98         unset(_output_xml)
99     ENDMACRO()
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 )
106         ADD_CUSTOM_COMMAND(
107             OUTPUT
108                 ${_output_html}
109             COMMAND ${_asciidoctor_common_command}
110                 --backend html
111                 --out-file ${_output_html}
112                 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
113             DEPENDS
114                 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
115                 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
116                 ${ARGN}
117         )
118         add_custom_target(generate_${_output_html} DEPENDS ${_output_html})
119         set_asciidoctor_target_properties(generate_${_output_html})
120         unset(_output_html)
121     ENDMACRO()
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 )
128         ADD_CUSTOM_COMMAND(
129             OUTPUT
130                 ${_output_txt}
131             COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/html2text.py
132                 ${_input_html}
133                 > ${_output_txt}
134             DEPENDS
135                 ${MAN_INCLUDES}
136                 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
137                 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
138                 ${_input_html}
139                 ${ARGN}
140         )
141         unset(_input_html)
142         unset(_output_txt)
143     ENDMACRO()
145     # Generate one or more ROFF man pages
146     function(ASCIIDOCTOR2ROFFMAN _man_section)
147         set(_input_adoc)
148         set(_output_man)
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} )
153         endforeach()
155         ADD_CUSTOM_COMMAND(
156             OUTPUT
157                 ${_output_man}
158             COMMAND ${_asciidoctor_common_command}
159                 --backend manpage
160                 --destination-dir ${CMAKE_CURRENT_BINARY_DIR}/man_pages
161                 ${_input_adoc}
162             DEPENDS
163                 ${MAN_INCLUDES}
164                 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
165                 ${_input_adoc}
166         )
167     endfunction()
169     # Generate one or more HTML man pages
170     function(ASCIIDOCTOR2HTMLMAN)
171         set(_input_adoc)
172         set(_output_man)
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 )
177         endforeach()
179         ADD_CUSTOM_COMMAND(
180             OUTPUT
181                 ${_output_man}
182             COMMAND ${_asciidoctor_common_command}
183                 --backend html
184                 --destination-dir ${CMAKE_CURRENT_BINARY_DIR}/man_pages
185                 ${_input_adoc}
186             DEPENDS
187                 ${MAN_INCLUDES}
188                 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
189                 ${_input_adoc}
190         )
191     endfunction()
193     FIND_PROGRAM(ASCIIDOCTOR_PDF_EXECUTABLE
194         NAMES
195             asciidoctorj
196             asciidoctor-pdf.bat
197             asciidoctor-pdf
198         PATHS
199             /bin
200             /usr/bin
201             /usr/local/bin
202             ${CHOCOLATEY_BIN_PATH}
203         DOC "Path to Asciidoctor PDF or AsciidoctorJ"
204     )
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
212             --backend pdf
213             ${_asciidoctor_common_args}
214         )
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")
221             ADD_CUSTOM_COMMAND(
222             OUTPUT
223                     ${_output_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
228                     -a pdf-theme=wsug
229                     ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
230             DEPENDS
231                     ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
232                     ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
233                     ${ARGN}
234             VERBATIM
235             )
236             add_custom_target(${_generate_pdf} DEPENDS ${_output_pdf})
237             set_asciidoctor_target_properties(${_generate_pdf})
238             unset(_generate_pdf)
239             unset(_output_pdf)
240         ENDMACRO()
242     else(ASCIIDOCTOR_PDF_EXECUTABLE)
244         MACRO( ASCIIDOCTOR2PDF _asciidocsource )
245         ENDMACRO()
247     endif(ASCIIDOCTOR_PDF_EXECUTABLE)
249     FIND_PROGRAM(ASCIIDOCTOR_EPUB_EXECUTABLE
250         NAMES
251             asciidoctorj
252             asciidoctor-epub3.bat
253             asciidoctor-epub3
254         PATHS
255             /bin
256             /usr/bin
257             /usr/local/bin
258             ${CHOCOLATEY_BIN_PATH}
259         DOC "Path to Asciidoctor EPUB3 or AsciidoctorJ"
260     )
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}
267             --backend epub3
268             ${_asciidoctor_common_args}
269         )
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")
276             ADD_CUSTOM_COMMAND(
277             OUTPUT
278                     ${_output_epub}
279             COMMAND ${_asciidoctor_epub_common_command}
280                     --out-file "${_output_epub}"
281                     ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
282             DEPENDS
283                     ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
284                     ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
285                     ${ARGN}
286             VERBATIM
287             )
288             add_custom_target(${_generate_epub} DEPENDS ${_output_epub})
289             set_asciidoctor_target_properties(${_generate_epub})
290             unset(_generate_epub)
291             unset(_output_epub)
292         ENDMACRO()
294     else(ASCIIDOCTOR_EPUB_EXECUTABLE)
296         MACRO(ASCIIDOCTOR2EPUB _asciidocsource)
297         ENDMACRO()
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
307     )
309 mark_as_advanced( ASCIIDOCTOR_EXECUTABLE )