blob: d1b7cb0e80605cb863786bda9b59f1e38e71fbfe [file] [log] [blame]
Gyorgy Szing5b15f852018-09-24 17:07:36 +02001#-------------------------------------------------------------------------------
Minos Galanakis07689822020-03-10 15:37:20 +00002# Copyright (c) 2018-2020, Arm Limited. All rights reserved.
Gyorgy Szing5b15f852018-09-24 17:07:36 +02003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8#This file adds build and install targets to build the Doxygen documentation
9#for TF-M. This currently means the "Reference Manual". Further documentation
10#builds may be added in the future.
11
12Include(CMakeParseArguments)
13
14#This function will find the location of tools needed to build the
15#documentation. These are:
16# - Mandatory:
17# - Doxygen v1.8.0 or higher
18# - dot
19# - PlantUML and it's dependencies
20# - Optional
21# - LateX/PDFLateX
22#
23#Inputs:
24# none (some global variables might be used by FindXXX modules used. For
25# details please check the used modules.)
26#
27#Outputs:
28# NODOC - will be defined and set to true is any mandatory
29# tool is missing.
30# LATEX_PDFLATEX_FOUND - defined if PDFLateX is available.
31# DOXYGEN_EXECUTABLE - path to doxygen
32# DOXYGEN_DOT_EXECUTABLE - path to dot
33# PLANTUML_JAR_PATH - path to PlantUML
34
35#Examples
36# DoxyFindTools()
37#
38function(DoxyFindTools)
39 #Find doxygen and dot.
40 find_package(Doxygen 1.8.0)
41 #find_package(Doxygen) will not print an error if dot is not available,
42 #emit a message here to help users.
43 if (NOT DOXYGEN_DOT_FOUND)
44 message(STATUS "Could NOT find Graphviz (missing: DOXYGEN_DOT_EXECUTABLE).")
45 endif()
46
47 #Find plantUML
48 find_package(PlantUML)
49
50 #Find tools needed for PDF generation.
51 find_package(LATEX COMPONENTS PDFLATEX)
52 set (LATEX_PDFLATEX_FOUND ${LATEX_PDFLATEX_FOUND} PARENT_SCOPE)
53
54 if (DOXYGEN_FOUND AND DOXYGEN_DOT_FOUND AND PLANTUML_FOUND)
55 #Export executable locations to global scope.
56 set(DOXYGEN_EXECUTABLE "${DOXYGEN_EXECUTABLE}" PARENT_SCOPE)
57 set(DOXYGEN_DOT_EXECUTABLE "${DOXYGEN_DOT_EXECUTABLE}" PARENT_SCOPE)
58 set(PLANTUML_JAR_PATH "${PLANTUML_JAR_PATH}" PARENT_SCOPE)
Gyorgy Szing74dae3c2018-09-27 17:00:46 +020059 set(NODOC False PARENT_SCOPE)
Gyorgy Szing5b15f852018-09-24 17:07:36 +020060 else()
61 message(WARNING "Some tools are missing for document generation. Document generation target is not created.")
62 set(NODOC True PARENT_SCOPE)
63 endif()
64endfunction()
65
66#Find the needed tools.
67DoxyFindTools()
68
69#If mandatory tools are missing, skip creating document generation targets.
70#This means missing documentation tools is not a crytical error, and building
71#TF-M is still possible.
72if (NOT NODOC)
73 #The doxygen configuration file needs some project specific configuration.
74 #Variables with DOXYCFG_ prefix are settings related to that.
75 set(DOXYCFG_TEMPLATE_FILE ${TFM_ROOT_DIR}/doxygen/Doxyfile.in)
76 set(DOXYCFG_CONFIGURED_FILE ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
77
78 #This is where doxygen output will be written
79 set(DOXYCFG_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/doc")
80
81 #Eclipse help ID. The help files shall be installed under the plugin
82 #directory into a directory with a name matching this ID.
83 set(DOXYCFG_ECLIPSE_DOCID "org.arm.tf-m-refman")
84
85 #Version ID of TF-M.
86 #TODO: this shall not be hard-coded here. A process need to defined for
87 # versioning the document (and TF-M).
Mate Toth-Pal955235a2020-06-15 13:48:34 +020088 set(DOXYCFG_TFM_VERSION "v1.1")
Gyorgy Szing5b15f852018-09-24 17:07:36 +020089
90 #Using add_custom_command allows CMake to generate proper clean commands
91 #for document generation.
92 add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/doc"
93 COMMAND "${DOXYGEN_EXECUTABLE}" "${DOXYCFG_CONFIGURED_FILE}"
94 WORKING_DIRECTORY "${TFM_ROOT_DIR}"
95 COMMENT "Running doxygen.")
96
97 #Create build target to generate HTML documentation.
98 add_custom_target(doc_refman
99 WORKING_DIRECTORY ${TFM_ROOT_DIR}
100 COMMENT "Generating TF-M Reference Manual..."
101 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/doc"
102 VERBATIM)
103
104 #Add the HTML documentation to install content
105 install(DIRECTORY ${DOXYCFG_OUTPUT_PATH}/html DESTINATION doc/reference_manual
106 COMPONENT refman EXCLUDE_FROM_ALL)
107
108 #Add the HTML documentation to install content. This time to be copied to
109 #eclipse plugin directory.
110 #TODO: I could not find a working description how the doxygen output
111 #can be installed to eclipse. Re-enable eclipse help generation after
112 #this is investigated. (See Doxyfile.in::GENERATE_ECLIPSEHELP)
113
114 #install(DIRECTORY "${DOXYCFG_OUTPUT_PATH}/html/"
115 # DESTINATION "doc/reference_manual/${DOXYCFG_ECLIPSE_DOCID}"
116 # COMPONENT refman
117 # EXCLUDE_FROM_ALL)
118
119 #If PDF documentation is being made.
120 if (LATEX_PDFLATEX_FOUND)
121 if (NOT CMAKE_GENERATOR MATCHES "Makefiles")
Gyorgy Szingd9c57fb2019-09-02 17:08:18 +0200122 message(WARNING "Generator is not make based. PDF document generation target is not created.")
Gyorgy Szing5b15f852018-09-24 17:07:36 +0200123 else()
Gyorgy Szingd9c57fb2019-09-02 17:08:18 +0200124 #This file shall not be included before cmake did finish finding the make tool and thus
125 #setting CMAKE_MAKE_PROGRAM. Currently the search is triggered by the project() command.
126 if(NOT CMAKE_MAKE_PROGRAM)
127 message(FATAL_ERROR "CMAKE_MAKE_PROGRAM is not set. This file must be included after the project command is run.")
128 endif()
129
Gyorgy Szing5b15f852018-09-24 17:07:36 +0200130 #The add_custom_command is not used here to get proper clean
131 #command since the clean rules "added" above will remove the entire
132 #doc directory, and thus clean the PDF output too.
133 add_custom_target(doc_refman_pdf
134 COMMAND "${CMAKE_MAKE_PROGRAM}" pdf
135 WORKING_DIRECTORY ${DOXYCFG_OUTPUT_PATH}/latex
136 COMMENT "Generating PDF version of TF-M reference manual..."
137 DEPENDS doc_refman
138 VERBATIM)
139
140 #Add the pdf documentation to install content
141 install(FILES "${DOXYCFG_OUTPUT_PATH}/latex/refman.pdf" DESTINATION "doc/reference_manual"
142 RENAME "tf-m_reference_manual.pdf"
143 COMPONENT refman EXCLUDE_FROM_ALL)
144
145 set(DOXYCFG_TFM_GENERATE_PDF $(DOXYCFG_TFM_VERSION))
146 endif()
147 else()
148 message(WARNING "PDF generation tools are missing. PDF document generation target is not created.")
149 endif()
150
151 #Generate build target which installs the documentation.
152 if (TARGET doc_refman_pdf)
153 add_custom_target(install_doc
154 DEPENDS doc_refman doc_refman_pdf
155 COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=refman
156 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
157 else()
158 add_custom_target(install_doc
159 DEPENDS doc_refman
160 COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=refman
161 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
162 endif()
163
164 #Now instantiate a doxygen configuration file from the template.
165 message(STATUS "Writing doxygen configuration...")
166 configure_file(${DOXYCFG_TEMPLATE_FILE} ${DOXYCFG_CONFIGURED_FILE} @ONLY)
167endif()