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