xref: /netbsd-src/external/bsd/ntp/dist/sntp/libevent/cmake/UseDoxygen.cmake (revision 897be3a4bac39d8b2e92077bf29f4a2e67d31983)
1*897be3a4Schristos# Use FindDoxygen.cmake to generate documentation.
2*897be3a4Schristos
3*897be3a4Schristosoption(DOXYGEN_GENERATE_HTML  "Generate HTML"      ON)
4*897be3a4Schristosoption(DOXYGEN_GENERATE_MAN   "Generate man pages" OFF)
5*897be3a4Schristosoption(DOXYGEN_MAN_LINKS      "Generate man links" ON)
6*897be3a4Schristosoption(DOXYGEN_GENERATE_LATEX "Generate LaTeX"     OFF)
7*897be3a4Schristos
8*897be3a4Schristos# If the case-insensitive value of the cmake option is one of
9*897be3a4Schristos# "off, no, false" or 0, it is equal to false, otherwise true.
10*897be3a4Schristos# And the values of the doxygen config does not exactly match it.
11*897be3a4Schristos# So we need to convert the cmake option to a doxygen config.
12*897be3a4Schristosmacro(_convert_to_dx_cfg CMK_OPTION)
13*897be3a4Schristos  if (${CMK_OPTION})
14*897be3a4Schristos    set(${CMK_OPTION} YES)
15*897be3a4Schristos  else()
16*897be3a4Schristos    set(${CMK_OPTION} NO)
17*897be3a4Schristos  endif()
18*897be3a4Schristosendmacro()
19*897be3a4Schristos
20*897be3a4Schristosmacro(UseDoxygen)
21*897be3a4Schristos  if (${CMAKE_VERSION} VERSION_LESS "3.9")
22*897be3a4Schristos    # Old versions of cmake have poor support for Doxygen generation.
23*897be3a4Schristos    message(FATAL_ERROR "Doxygen generation only enabled for cmake 3.9 and higher")
24*897be3a4Schristos  else()
25*897be3a4Schristos    find_package(Doxygen)
26*897be3a4Schristos    if (DOXYGEN_FOUND)
27*897be3a4Schristos      set(DOXYGEN_PROJECT_NAME ${PROJECT_NAME})
28*897be3a4Schristos      set(DOXYGEN_PROJECT_NUMBER ${EVENT_PACKAGE_VERSION})
29*897be3a4Schristos      set(DOXYGEN_PROJECT_BRIEF "Event notification library")
30*897be3a4Schristos      set(DOXYGEN_OUTPUT_DIRECTORY doxygen)
31*897be3a4Schristos      set(DOXYGEN_STRIP_FROM_PATH include)
32*897be3a4Schristos      set(DOXYGEN_JAVADOC_AUTOBRIEF YES)
33*897be3a4Schristos      set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C YES)
34*897be3a4Schristos      set(DOXYGEN_SORT_BRIEF_DOCS YES)
35*897be3a4Schristos      set(DOXYGEN_RECURSIVE NO)
36*897be3a4Schristos
37*897be3a4Schristos      _convert_to_dx_cfg(DOXYGEN_GENERATE_HTML)
38*897be3a4Schristos      _convert_to_dx_cfg(DOXYGEN_GENERATE_MAN)
39*897be3a4Schristos      _convert_to_dx_cfg(DOXYGEN_MAN_LINKS)
40*897be3a4Schristos      _convert_to_dx_cfg(DOXYGEN_GENERATE_LATEX)
41*897be3a4Schristos
42*897be3a4Schristos      set(DOXYGEN_LATEX_CMD_NAME latex)
43*897be3a4Schristos      set(DOXYGEN_PAPER_TYPE a4wide)
44*897be3a4Schristos      set(DOXYGEN_PDF_HYPERLINKS NO)
45*897be3a4Schristos
46*897be3a4Schristos      set(DOXYGEN_GENERATE_RTF NO)
47*897be3a4Schristos      set(DOXYGEN_GENERATE_XML NO)
48*897be3a4Schristos      set(DOXYGEN_GENERATE_CHI NO)
49*897be3a4Schristos
50*897be3a4Schristos      set(DOXYGEN_PREDEFINED TAILQ_ENTRY
51*897be3a4Schristos        RB_ENTRY
52*897be3a4Schristos        EVENT_DEFINED_TQENTRY_
53*897be3a4Schristos        EVENT_IN_DOXYGEN_
54*897be3a4Schristos      )
55*897be3a4Schristos
56*897be3a4Schristos      set(DOX_INPUT include/event2/buffer.h
57*897be3a4Schristos        include/event2/buffer_compat.h
58*897be3a4Schristos        include/event2/bufferevent.h
59*897be3a4Schristos        include/event2/bufferevent_compat.h
60*897be3a4Schristos        include/event2/bufferevent_ssl.h
61*897be3a4Schristos        include/event2/dns.h
62*897be3a4Schristos        include/event2/dns_compat.h
63*897be3a4Schristos        include/event2/event.h
64*897be3a4Schristos        include/event2/event_compat.h
65*897be3a4Schristos        include/event2/http.h
66*897be3a4Schristos        include/event2/http_compat.h
67*897be3a4Schristos        include/event2/listener.h
68*897be3a4Schristos        include/event2/rpc.h
69*897be3a4Schristos        include/event2/rpc_compat.h
70*897be3a4Schristos        include/event2/tag.h
71*897be3a4Schristos        include/event2/tag_compat.h
72*897be3a4Schristos        include/event2/thread.h
73*897be3a4Schristos        include/event2/util.h
74*897be3a4Schristos      )
75*897be3a4Schristos      # Add 'doxygen' target
76*897be3a4Schristos      doxygen_add_docs(doxygen
77*897be3a4Schristos        ${DOX_INPUT}
78*897be3a4Schristos        ALL
79*897be3a4Schristos        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
80*897be3a4Schristos        COMMENT "Generating doxygen documentation for ${PROJECT_NAME}..."
81*897be3a4Schristos      )
82*897be3a4Schristos
83*897be3a4Schristos      # Use 'make clean' to remove the generated directory
84*897be3a4Schristos      set_property(DIRECTORY
85*897be3a4Schristos        PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
86*897be3a4Schristos        "${PROJECT_BINARY_DIR}/${DOXYGEN_OUTPUT_DIRECTORY}"
87*897be3a4Schristos      )
88*897be3a4Schristos
89*897be3a4Schristos      # Install html into <prefix>/share/doc/<project>
90*897be3a4Schristos      if ("${DOXYGEN_GENERATE_HTML}" STREQUAL "YES")
91*897be3a4Schristos        install(DIRECTORY
92*897be3a4Schristos          ${PROJECT_BINARY_DIR}/${DOXYGEN_OUTPUT_DIRECTORY}/html
93*897be3a4Schristos          DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}
94*897be3a4Schristos          COMPONENT doc
95*897be3a4Schristos        )
96*897be3a4Schristos      endif()
97*897be3a4Schristos
98*897be3a4Schristos      # Install manual into <prefix>/share/man/man3
99*897be3a4Schristos      if ("${DOXYGEN_GENERATE_MAN}" STREQUAL "YES")
100*897be3a4Schristos        install(DIRECTORY
101*897be3a4Schristos          ${PROJECT_BINARY_DIR}/${DOXYGEN_OUTPUT_DIRECTORY}/man/man3
102*897be3a4Schristos          DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man
103*897be3a4Schristos          COMPONENT doc
104*897be3a4Schristos        )
105*897be3a4Schristos      endif()
106*897be3a4Schristos
107*897be3a4Schristos    else(DOXYGEN_FOUND)
108*897be3a4Schristos      message(FATAL_ERROR "Doxygen command not found, set EVENT__DOXYGEN to disable")
109*897be3a4Schristos    endif (DOXYGEN_FOUND)
110*897be3a4Schristos  endif()
111*897be3a4Schristosendmacro()
112