Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
90cbac4002db75e8208771f84766809e2caf0c40
[simgrid.git] / buildtools / Cmake / GenerateDoc.cmake
1 #### Generate the manpages
2 if( NOT MANPAGE_DIRECTORY )
3         set( MANPAGE_DIRECTORY /usr/share/man/man1 )
4 endif( NOT MANPAGE_DIRECTORY)
5
6 set(MANPAGES doc/simgrid_update_xml.1)
7
8 add_custom_command(OUTPUT doc/simgrid_update_xml.1
9         COMMAND pod2man tools/simgrid_update_xml.pl > doc/simgrid_update_xml.1
10         COMMENT "Generating manpage for simgrid_update_xml"
11 )
12 install(FILES ${MANPAGES} 
13                 DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/share/man/man1/)
14
15 #### Generate the html documentation
16
17 if(BIBTEX2HTML)
18         set(BIBTEX2HTML_PATH ${BIBTEX2HTML})
19 else(BIBTEX2HTML)
20         find_path(BIBTEX2HTML_PATH      NAMES bibtex2html       PATHS NO_DEFAULT_PATHS)
21 endif(BIBTEX2HTML)
22
23 find_path(FIG2DEV_PATH  NAMES fig2dev   PATHS NO_DEFAULT_PATHS)
24 find_path(DOXYGEN_PATH  NAMES doxygen   PATHS NO_DEFAULT_PATHS)
25 find_path(BIBTOOL_PATH  NAMES bibtool   PATHS NO_DEFAULT_PATHS)
26 find_path(ICONV_PATH    NAMES iconv     PATHS NO_DEFAULT_PATHS)
27
28 ### Check whether the bibtex2html that we found is the one that Arnaud requires
29 exec_program("${BIBTEX2HTML_PATH}/bibtex2html -version" OUTPUT_VARIABLE OUTPUT_BIBTEX2HTML_VERSION)
30 STRING(REPLACE "[-bibtex]" "" OUTPUT_BIBTEX2HTML_VERSION_2 ${OUTPUT_BIBTEX2HTML_VERSION})
31
32 file(GLOB_RECURSE source_doxygen
33         "${CMAKE_HOME_DIRECTORY}/tools/gras/*.[chl]"
34         "${CMAKE_HOME_DIRECTORY}/src/*.[chl]"
35         "${CMAKE_HOME_DIRECTORY}/include/*.[chl]"
36 )
37
38 if(${OUTPUT_BIBTEX2HTML_VERSION_2} STREQUAL ${OUTPUT_BIBTEX2HTML_VERSION}) # wrong version
39         SET(GOOD_BIBTEX2HTML_VERSION 0)
40 else(${OUTPUT_BIBTEX2HTML_VERSION_2} STREQUAL ${OUTPUT_BIBTEX2HTML_VERSION}) # good version
41         SET(GOOD_BIBTEX2HTML_VERSION 1)
42 endif(${OUTPUT_BIBTEX2HTML_VERSION_2} STREQUAL ${OUTPUT_BIBTEX2HTML_VERSION})
43
44 if(DOXYGEN_PATH AND FIG2DEV_PATH AND BIBTOOL_PATH AND BIBTEX2HTML_PATH AND ICONV_PATH AND GOOD_BIBTEX2HTML_VERSION)
45
46         string(REGEX REPLACE ";.*logcategories.doc" "" LISTE_DEUX "${LISTE_DEUX}")
47
48         #DOC_SOURCE=doc/*.doc, defined in DefinePackage
49         set(DOCSSOURCES "${source_doxygen}\n${DOC_SOURCE}")
50         string(REPLACE "\n" ";" DOCSSOURCES ${DOCSSOURCES})
51
52
53         set(DOC_PNGS 
54                 ${CMAKE_HOME_DIRECTORY}/doc/webcruft/simgrid_logo.png
55                 ${CMAKE_HOME_DIRECTORY}/doc/webcruft/simgrid_logo_small.png
56                 ${CMAKE_HOME_DIRECTORY}/doc/webcruft/poster_thumbnail.png
57         )
58         
59         configure_file(${CMAKE_HOME_DIRECTORY}/doc/Doxyfile.in ${CMAKE_HOME_DIRECTORY}/doc/Doxyfile @ONLY)
60         configure_file(${CMAKE_HOME_DIRECTORY}/doc/footer.html.in ${CMAKE_HOME_DIRECTORY}/doc/footer.html @ONLY)                
61         
62         ADD_CUSTOM_TARGET(simgrid_documentation
63                 COMMENT "Generating the SimGrid documentation..."
64                 DEPENDS ${DOC_SOURCES} ${DOC_FIGS} ${source_doxygen} ${DOC_bib} ${MANPAGES}
65                 COMMAND ${FIG2DEV_PATH}/fig2dev -Lmap ${CMAKE_HOME_DIRECTORY}/doc/fig/simgrid_modules.fig | perl -pe 's/imagemap/simgrid_modules/g'| perl -pe 's/<IMG/<IMG style=border:0px/g' | ${CMAKE_HOME_DIRECTORY}/tools/doxygen/fig2dev_postprocessor.pl > ${CMAKE_HOME_DIRECTORY}/doc/simgrid_modules.map
66                 WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/doc
67         )
68
69         ADD_CUSTOM_COMMAND(
70                 OUTPUT ${CMAKE_HOME_DIRECTORY}/doc/logcategories.doc
71                 DEPENDS ${source_doxygen}
72                 COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_HOME_DIRECTORY}/doc/logcategories.doc
73                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/xbt_log_extract_hierarchy.pl > ${CMAKE_HOME_DIRECTORY}/doc/logcategories.doc
74                 WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
75         )
76
77         foreach(file ${DOC_FIGS})
78                 string(REPLACE ".fig" ".png" tmp_file ${file})
79                 string(REPLACE "${CMAKE_HOME_DIRECTORY}/doc/fig/" "${CMAKE_HOME_DIRECTORY}/doc/html/" tmp_file ${tmp_file})
80                 ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
81                         COMMAND ${FIG2DEV_PATH}/fig2dev -Lpng ${file} ${tmp_file}
82                 )
83         endforeach(file ${DOC_FIGS})
84         
85         foreach(file ${DOC_PNGS})
86                 ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
87                         COMMAND ${CMAKE_COMMAND} -E copy ${file} ${CMAKE_HOME_DIRECTORY}/doc/html/
88                 )
89         endforeach(file ${DOC_PNGS})
90
91         ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
92                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/doc/webcruft/Paje_MSG_screenshot_thn.jpg ${CMAKE_HOME_DIRECTORY}/doc/html/
93                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/doc/webcruft/Paje_MSG_screenshot.jpg     ${CMAKE_HOME_DIRECTORY}/doc/html/
94                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/doc/triva-graph_configuration.png        ${CMAKE_HOME_DIRECTORY}/doc/html/
95                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/doc/triva-graph_visualization.png        ${CMAKE_HOME_DIRECTORY}/doc/html/
96                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/doc/simgrid.css                          ${CMAKE_HOME_DIRECTORY}/doc/html/
97         )
98         
99         ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
100             COMMAND ${CMAKE_COMMAND} -E echo "XX First Doxygen pass"
101                 COMMAND ${DOXYGEN_PATH}/doxygen Doxyfile
102                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/index_create.pl simgrid.tag index-API.doc
103                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/toc_create.pl FAQ.doc index.doc contrib.doc gtut-introduction.doc history.doc
104                 
105                 COMMAND ${CMAKE_COMMAND} -E echo "XX Second Doxygen pass"
106                 COMMAND ${DOXYGEN_PATH}/doxygen Doxyfile
107                 
108                 COMMAND ${CMAKE_COMMAND} -E echo "XX Post-processing Doxygen result"
109                 COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/doc/html/dir*
110                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/doxygen_postprocesser.pl
111                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/index_php.pl index.php.in html/index.html index.php
112                 
113                 COMMAND ${CMAKE_COMMAND} -E echo "XX Create shortcuts pages"
114                 COMMAND ${CMAKE_COMMAND} -E echo \"<html><META HTTP-EQUIV='Refresh' content='0;URL=http://simgrid.gforge.inria.fr/doc/group__GRAS__API.html'>\" > ${CMAKE_HOME_DIRECTORY}/doc/html/gras.html
115                 COMMAND ${CMAKE_COMMAND} -E echo \"<center><h2><br><a href='http://simgrid.gforge.inria.fr/doc/group__GRAS__API.html'>Grid Reality And Simulation.</a></h2></center></html>\" >> ${CMAKE_HOME_DIRECTORY}/doc/html/gras.html
116                 
117                 COMMAND ${CMAKE_COMMAND} -E echo \"<html><META HTTP-EQUIV='Refresh' content='0;URL=http://simgrid.gforge.inria.fr/doc/group__AMOK__API.html'>\" > ${CMAKE_HOME_DIRECTORY}/doc/html/amok.html
118                 COMMAND ${CMAKE_COMMAND} -E echo \"<center><h2><br><a href='http://simgrid.gforge.inria.fr/doc/group__AMOK__API.html'>Advanced Metacomputing Overlay Kit.</a></h2></center></html>\" >> ${CMAKE_HOME_DIRECTORY}/doc/html/amok.html
119         
120                 COMMAND ${CMAKE_COMMAND} -E echo \"<html><META HTTP-EQUIV='Refresh' content='0;URL=http://simgrid.gforge.inria.fr/doc/group__MSG__API.html'>\" > ${CMAKE_HOME_DIRECTORY}/doc/html/msg.html
121                 COMMAND ${CMAKE_COMMAND} -E echo \"<center><h2><br><a href='http://simgrid.gforge.inria.fr/doc/group__MSG__API.html'>Meta SimGrid.</a></h2></center></html>\" >> ${CMAKE_HOME_DIRECTORY}/doc/html/msg.html
122         
123                 COMMAND ${CMAKE_COMMAND} -E echo \"<html><META HTTP-EQUIV='Refresh' content='0;URL=http://simgrid.gforge.inria.fr/doc/group__SD__API.html'>\" > ${CMAKE_HOME_DIRECTORY}/doc/html/simdag.html
124                 COMMAND ${CMAKE_COMMAND} -E echo \"<center><h2><br><a href='http://simgrid.gforge.inria.fr/doc/group__SD__API.html'>DAG Simulator.</a></h2></center></html>\" >> ${CMAKE_HOME_DIRECTORY}/doc/html/simdag.html
125                 WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/doc/
126         )
127
128         ADD_CUSTOM_TARGET(bib_files
129                 DEPENDS ${CMAKE_HOME_DIRECTORY}/doc/all.bib
130                 COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_HOME_DIRECTORY}/doc/html
131                 COMMAND ${CMAKE_COMMAND} -E make_directory   ${CMAKE_HOME_DIRECTORY}/doc/html
132                 COMMAND ${CMAKE_COMMAND} -E echo "XX Generate publis_core.bib publis_extern.bib publis_intra.bib"
133                 COMMAND ${BIBTOOL_PATH}/bibtool -- 'select.by.string={category \"core\"}' -- 'preserve.key.case={on}' -- 'preserve.keys={on}' all.bib -o publis_core.bib
134                 COMMAND ${BIBTOOL_PATH}/bibtool -- 'select.by.string={category \"extern\"}' -- 'preserve.key.case={on}' -- 'preserve.keys={on}' all.bib -o publis_extern.bib
135                 COMMAND ${BIBTOOL_PATH}/bibtool -- 'select.by.string={category \"intra\"}' -- 'preserve.key.case={on}' -- 'preserve.keys={on}' all.bib -o publis_intra.bib
136
137                 COMMAND ${CMAKE_COMMAND} -E echo "XX Generate publis_count.html"
138                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/bibtex2html_table_count.pl < ${CMAKE_HOME_DIRECTORY}/doc/all.bib > ${CMAKE_HOME_DIRECTORY}/doc/publis_count.html
139                 
140                 COMMAND ${CMAKE_COMMAND} -E echo "XX Generate publis_core.html publis_extern.html publis_intra.html"
141                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/bibtex2html_wrapper.pl publis_core
142                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/bibtex2html_wrapper.pl publis_extern
143                 COMMAND ${CMAKE_HOME_DIRECTORY}/tools/doxygen/bibtex2html_wrapper.pl publis_intra
144                 
145                 WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/doc/
146         )
147
148         add_dependencies(simgrid_documentation bib_files)
149         
150 else(DOXYGEN_PATH AND FIG2DEV_PATH AND BIBTOOL_PATH AND BIBTEX2HTML_PATH AND ICONV_PATH AND GOOD_BIBTEX2HTML_VERSION)
151
152         ADD_CUSTOM_TARGET(simgrid_documentation
153                         COMMENT "Generating the SimGrid documentation..."
154                         )
155
156         if(NOT GOOD_BIBTEX2HTML_VERSION) # wrong version
157                 ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
158                         COMMAND ${CMAKE_COMMAND} -E echo "This is not the good bibtex2html program !!!"
159                         COMMAND ${CMAKE_COMMAND} -E echo  "You can download it from:"
160                         COMMAND ${CMAKE_COMMAND} -E echo  "  ftp://ftp-sop.inria.fr/epidaure/Softs/bibtex2html/bibtex2html-1.02.tar.gz"
161                         COMMAND ${CMAKE_COMMAND} -E echo  "There is also an unofficial Debian/Ubuntu package, see:"
162                         COMMAND ${CMAKE_COMMAND} -E echo  "  http://www.loria.fr/~lnussbau/bibtex2html/README"
163                         )
164         endif(NOT GOOD_BIBTEX2HTML_VERSION)
165
166         ADD_CUSTOM_COMMAND(TARGET simgrid_documentation
167                         COMMAND ${CMAKE_COMMAND} -E echo "DOXYGEN_PATH          = ${DOXYGEN_PATH}"
168                         COMMAND ${CMAKE_COMMAND} -E echo "FIG2DEV_PATH          = ${FIG2DEV_PATH}"
169                         COMMAND ${CMAKE_COMMAND} -E echo "BIBTOOL_PATH          = ${BIBTOOL_PATH}"
170                         COMMAND ${CMAKE_COMMAND} -E echo "BIBTEX2HTML_PATH      = ${BIBTEX2HTML_PATH}"
171                         COMMAND ${CMAKE_COMMAND} -E echo "ICONV_PATH            = ${ICONV_PATH}"
172                         COMMAND ${CMAKE_COMMAND} -E echo "IN ORDER TO GENERATE THE DOCUMENTATION YOU NEED ALL TOOLS !!!"
173                         COMMAND ${CMAKE_COMMAND} -E echo "FAIL TO MAKE SIMGRID DOCUMENTATION see previous messages for details ..."
174                         COMMAND false
175                         )
176
177                 
178 endif(DOXYGEN_PATH AND FIG2DEV_PATH AND BIBTOOL_PATH AND BIBTEX2HTML_PATH AND ICONV_PATH AND GOOD_BIBTEX2HTML_VERSION)
179
180 ##############################################################################"
181
182 message(STATUS "Check individual TOCs")
183 set(LISTE_GTUT
184         doc/gtut-tour-00-install.doc
185         doc/gtut-tour-01-bones.doc
186         doc/gtut-tour-02-simple.doc
187         doc/gtut-tour-03-args.doc
188         doc/gtut-tour-04-callback.doc
189         doc/gtut-tour-05-globals.doc
190         doc/gtut-tour-06-logs.doc
191         doc/gtut-tour-07-timers.doc
192         doc/gtut-tour-08-exceptions.doc
193         doc/gtut-tour-09-simpledata.doc
194         doc/gtut-tour-10-rpc.doc
195         doc/gtut-tour-11-explicitwait.doc
196         doc/gtut-tour-recap-messages.doc
197         doc/gtut-tour-12-staticstruct.doc
198         doc/gtut-tour-13-pointers.doc
199         doc/gtut-tour-14-dynar.doc
200         doc/gtut-tour-15-manualdatadef.doc
201         doc/gtut-tour-16-exchangecb.doc
202 )
203
204 foreach(file_name ${LISTE_GTUT})
205         file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc)
206         file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc)
207         
208         file(READ "${file_name}" file_content)
209         string(REGEX MATCH "Table of Contents.*<hr>" valeur_line "${file_content}")
210         string(REPLACE "\n" ";" valeur_line "${valeur_line}")
211         string(REPLACE "\n" ";" file_content "${file_content}")
212                
213         file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc "\n") # make sure it exists
214         foreach(line ${file_content})
215                 string(REGEX MATCH "[\\]s?u?b?s?u?b?section.*" line2 "${line}")
216                 string(REGEX MATCH ".*_toc.*" line3 "${line}")
217                 if(line2 AND NOT line3)
218                         string(REPLACE "\\section " "" line2 ${line2})
219                         string(REPLACE "\\subsection " "subsection" line2 ${line2})
220                         string(REPLACE "\\subsubsection " "subsubsection" line2 ${line2})
221                         string(REGEX REPLACE " .*" "" line2 ${line2})
222                         set(line2                               " - \\ref ${line2}")
223                         string(REPLACE " - \\ref subsection"    "   - \\ref " line2 ${line2})
224                         string(REPLACE " - \\ref subsubsection" "     - \\ref " line2 ${line2})
225                         file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc "${line2}\n")
226                 endif(line2 AND NOT line3)
227         endforeach(line ${file_content})
228         
229         file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc "\n") # make sure it exists
230         foreach(line ${valeur_line})
231                 string(REGEX MATCH ".*ref.*" line_ok ${line})
232                 if(line_ok)
233                         file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc "${line_ok}\n")
234                 endif(line_ok)
235         endforeach(line ${valeur_line})
236         
237         exec_program("${CMAKE_COMMAND} -E compare_files ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc" OUTPUT_VARIABLE compare_files)
238         if(compare_files)
239                 message(STATUS "Wrong toc for ${file_name}. Should be:")
240                 file(READ "${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc" file_content)
241                 message("${file_content}")
242                 exec_program("diff -u ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc")
243         endif(compare_files)
244 endforeach(file_name ${LISTE_GTUT})
245
246 file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc)
247 file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc)
248
249 message(STATUS "Check main TOC")
250
251 foreach(file_name ${LISTE_GTUT})
252         file(READ "${file_name}" file_content)  
253         string(REGEX MATCH "Table of Contents.*<hr>" valeur_line "${file_content}")
254         string(REPLACE "\n" ";" valeur_line "${valeur_line}")
255         string(REPLACE "\n" ";" file_content "${file_content}")
256         
257         foreach(line ${file_content})
258                 string(REGEX MATCH ".*@page.*" line2 "${line}")
259                 if(line2)
260                         string(REPLACE "@page " "" line2 "${line2}")
261                         string(REGEX REPLACE " .*" "" line2 "${line2}")
262                         set(line2 " - \\ref ${line2}")
263                         file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc "${line2}\n")
264                 endif(line2)
265         endforeach(line ${file_content})
266         
267         foreach(line ${valeur_line})
268                 string(REGEX MATCH ".*toc.*" line1 "${line}")
269                 string(REGEX MATCH ".*<hr>.*" line2 "${line}")
270                 string(REGEX MATCH "^[ ]*$" line3 "${line}")
271                 string(REGEX MATCH "Table of Contents" line4 "${line}")
272                 if(NOT line1 AND NOT line2 AND NOT line3 AND NOT line4)
273                         file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc "   ${line}\n")
274                 endif(NOT line1 AND NOT line2 AND NOT line3 AND NOT line4)
275         endforeach(line ${valeur_line})
276 endforeach(file_name ${LISTE_GTUT})     
277
278 file(READ "${CMAKE_HOME_DIRECTORY}/doc/gtut-tour.doc" file_content)
279 string(REPLACE "\n" ";" file_content "${file_content}")
280 foreach(line ${file_content})
281         string(REGEX MATCH "^[ ]+.*\\ref" line1 "${line}")
282         if(line1)
283                 file(APPEND ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc "${line}\n")
284         endif(line1)
285 endforeach(line ${file_content})
286         
287 exec_program("${CMAKE_COMMAND} -E compare_files ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc" OUTPUT_VARIABLE compare_files)
288 if(compare_files)
289         message(STATUS "Wrong toc for gtut-tour.doc Right one is in tmp.realtoc")
290         exec_program("diff -u ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc")
291 else(compare_files)
292         file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.realtoc)
293 endif(compare_files)    
294   
295 file(REMOVE ${CMAKE_HOME_DIRECTORY}/doc/tmp.curtoc)