TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags
[wireshark-sm.git] / cmake / modules / FindAsciidoctor.cmake
blob19cb810ce07870872896cc35447b93a35ea0e77c
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 (_ad_failure_level_args)
44     if (ENABLE_WERROR)
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)
48         endif()
49     endif()
51     set (_asciidoctor_common_args
52         # AsciidoctorJ added --failure-level in version 2.5.6
53         # --trace
54         --quiet
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
64     )
66     unset(_ad_full_version)
67     unset(_ad_help)
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}
74     )
76     set(_asciidoctor_docbook_common_command
77         ${CMAKE_COMMAND} -E env TZ=UTC ASCIIDOCTORJ_OPTS=${_asciidoctorj_opts}
78         ${ASCIIDOCTOR_EXECUTABLE}
79         ${_asciidoctor_common_args}
80     )
82     MACRO( ASCIIDOCTOR2DOCBOOK _asciidocsource )
83         GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE )
84         set( _output_xml ${_source_base_name}.xml )
86         add_custom_command(
87             OUTPUT
88                 ${_output_xml}
89             COMMAND ${_asciidoctor_docbook_common_command}
90                 --backend docbook
91                 --out-file ${_output_xml}
92                 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
93             DEPENDS
94                 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
95                 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
96                 ${ARGN}
97         )
98         if(CMAKE_GENERATOR MATCHES "Visual Studio")
99             add_custom_command(
100                 OUTPUT
101                     ${_output_xml}-stamp
102                 COMMAND ${CMAKE_COMMAND} -E touch ${_output_xml}-stamp
103                 DEPENDS ${_output_xml}
104             )
105             add_custom_target(generate_${_output_xml} DEPENDS ${_output_xml}-stamp)
106         else()
107             add_custom_target(generate_${_output_xml} DEPENDS ${_output_xml})
108         endif()
109         set_asciidoctor_target_properties(generate_${_output_xml})
110         unset(_output_xml)
111     ENDMACRO()
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 )
118         ADD_CUSTOM_COMMAND(
119             OUTPUT
120                 ${_output_html}
121             COMMAND ${_asciidoctor_common_command}
122                 --backend html
123                 --out-file ${_output_html}
124                 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
125             DEPENDS
126                 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
127                 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
128                 ${ARGN}
129         )
130         add_custom_target(generate_${_output_html} DEPENDS ${_output_html})
131         set_asciidoctor_target_properties(generate_${_output_html})
132         unset(_output_html)
133     ENDMACRO()
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 )
140         ADD_CUSTOM_COMMAND(
141             OUTPUT
142                 ${_output_txt}
143             COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/html2text.py
144                 ${_input_html}
145                 > ${_output_txt}
146             DEPENDS
147                 ${MAN_INCLUDES}
148                 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
149                 ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
150                 ${_input_html}
151                 ${ARGN}
152         )
153         unset(_input_html)
154         unset(_output_txt)
155     ENDMACRO()
157     # Generate one or more ROFF man pages
158     function(ASCIIDOCTOR2ROFFMAN _man_section)
159         set(_input_adoc)
160         set(_output_man)
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} )
165         endforeach()
167         ADD_CUSTOM_COMMAND(
168             OUTPUT
169                 ${_output_man}
170             COMMAND ${_asciidoctor_common_command}
171                 --backend manpage
172                 --destination-dir ${CMAKE_CURRENT_BINARY_DIR}/man_pages
173                 ${_input_adoc}
174             DEPENDS
175                 ${MAN_INCLUDES}
176                 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
177                 ${_input_adoc}
178         )
179     endfunction()
181     # Generate one or more HTML man pages
182     function(ASCIIDOCTOR2HTMLMAN)
183         set(_input_adoc)
184         set(_output_man)
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 )
189         endforeach()
191         ADD_CUSTOM_COMMAND(
192             OUTPUT
193                 ${_output_man}
194             COMMAND ${_asciidoctor_common_command}
195                 --backend html
196                 --destination-dir ${CMAKE_CURRENT_BINARY_DIR}/man_pages
197                 ${_input_adoc}
198             DEPENDS
199                 ${MAN_INCLUDES}
200                 ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
201                 ${_input_adoc}
202         )
203     endfunction()
205     FIND_PROGRAM(ASCIIDOCTOR_PDF_EXECUTABLE
206         NAMES
207             asciidoctorj
208             asciidoctor-pdf.bat
209             asciidoctor-pdf
210         PATHS
211             /bin
212             /usr/bin
213             /usr/local/bin
214             ${CHOCOLATEY_BIN_PATH}
215         DOC "Path to Asciidoctor PDF or AsciidoctorJ"
216     )
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
224             --backend pdf
225             ${_asciidoctor_common_args}
226         )
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")
233             ADD_CUSTOM_COMMAND(
234             OUTPUT
235                     ${_output_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
240                     -a pdf-theme=wsug
241                     ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
242             DEPENDS
243                     ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
244                     ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
245                     ${ARGN}
246             VERBATIM
247             )
248             add_custom_target(${_generate_pdf} DEPENDS ${_output_pdf})
249             set_asciidoctor_target_properties(${_generate_pdf})
250             unset(_generate_pdf)
251             unset(_output_pdf)
252         ENDMACRO()
254     else(ASCIIDOCTOR_PDF_EXECUTABLE)
256         MACRO( ASCIIDOCTOR2PDF _asciidocsource )
257         ENDMACRO()
259     endif(ASCIIDOCTOR_PDF_EXECUTABLE)
261     FIND_PROGRAM(ASCIIDOCTOR_EPUB_EXECUTABLE
262         NAMES
263             asciidoctorj
264             asciidoctor-epub3.bat
265             asciidoctor-epub3
266         PATHS
267             /bin
268             /usr/bin
269             /usr/local/bin
270             ${CHOCOLATEY_BIN_PATH}
271         DOC "Path to Asciidoctor EPUB3 or AsciidoctorJ"
272     )
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}
279             --backend epub3
280             ${_asciidoctor_common_args}
281         )
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")
288             ADD_CUSTOM_COMMAND(
289             OUTPUT
290                     ${_output_epub}
291             COMMAND ${_asciidoctor_epub_common_command}
292                     --out-file "${_output_epub}"
293                     ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
294             DEPENDS
295                     ${CMAKE_SOURCE_DIR}/doc/attributes.adoc
296                     ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
297                     ${ARGN}
298             VERBATIM
299             )
300             add_custom_target(${_generate_epub} DEPENDS ${_output_epub})
301             set_asciidoctor_target_properties(${_generate_epub})
302             unset(_generate_epub)
303             unset(_output_epub)
304         ENDMACRO()
306     else(ASCIIDOCTOR_EPUB_EXECUTABLE)
308         MACRO(ASCIIDOCTOR2EPUB _asciidocsource)
309         ENDMACRO()
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
319     )
321 mark_as_advanced( ASCIIDOCTOR_EXECUTABLE )